blob: 4ec408ae3af2dc82ae307eb123e0f6bee4a49fa6 [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
428/* returns ptr to null terminator */
429static char *
430describe_type(char *dst, shader_module const *src, unsigned type)
431{
Chris Forbes21977d92016-01-26 13:41:39 +1300432 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300433 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700434
Chris Forbes1257f912016-01-18 12:07:01 +1300435 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700436 case spv::OpTypeBool:
437 return dst + sprintf(dst, "bool");
438 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300439 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700440 case spv::OpTypeFloat:
Chris Forbes1257f912016-01-18 12:07:01 +1300441 return dst + sprintf(dst, "float%d", insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700442 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300443 dst += sprintf(dst, "vec%d of ", insn.word(3));
444 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700445 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300446 dst += sprintf(dst, "mat%d of ", insn.word(3));
447 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700448 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300449 dst += sprintf(dst, "arr[%d] of ", insn.word(3));
450 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700451 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300452 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
453 return describe_type(dst, src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700454 case spv::OpTypeStruct:
455 {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700456 dst += sprintf(dst, "struct of (");
Chris Forbes1257f912016-01-18 12:07:01 +1300457 for (unsigned i = 2; i < insn.len(); i++) {
458 dst = describe_type(dst, src, insn.word(i));
459 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700460 }
461 return dst;
462 }
463 case spv::OpTypeSampler:
464 return dst + sprintf(dst, "sampler");
465 default:
466 return dst + sprintf(dst, "oddtype");
467 }
468}
469
470static bool
471types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
472{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700473 /* walk two type trees together, and complain about differences */
Chris Forbes21977d92016-01-26 13:41:39 +1300474 auto a_insn = a->get_def(a_type);
475 auto b_insn = b->get_def(b_type);
Chris Forbes1257f912016-01-18 12:07:01 +1300476 assert(a_insn != a->end());
477 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700478
Chris Forbes1257f912016-01-18 12:07:01 +1300479 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700480 /* 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 +1300481 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700482 }
483
Chris Forbes1257f912016-01-18 12:07:01 +1300484 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700485 return false;
486 }
487
Chris Forbes1257f912016-01-18 12:07:01 +1300488 switch (a_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700489 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
490 case spv::OpTypeBool:
491 return true && !b_arrayed;
492 case spv::OpTypeInt:
493 /* match on width, signedness */
Chris Forbes1257f912016-01-18 12:07:01 +1300494 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 -0700495 case spv::OpTypeFloat:
496 /* match on width */
Chris Forbes1257f912016-01-18 12:07:01 +1300497 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700498 case spv::OpTypeVector:
499 case spv::OpTypeMatrix:
500 case spv::OpTypeArray:
501 /* match on element type, count. these all have the same layout. we don't get here if
502 * b_arrayed -- that is handled above. */
Chris Forbes1257f912016-01-18 12:07:01 +1300503 return !b_arrayed && types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) && a_insn.word(3) == b_insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700504 case spv::OpTypeStruct:
505 /* match on all element types */
506 {
507 if (b_arrayed) {
508 /* for the purposes of matching different levels of arrayness, structs are leaves. */
509 return false;
510 }
511
Chris Forbes1257f912016-01-18 12:07:01 +1300512 if (a_insn.len() != b_insn.len()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700513 return false; /* structs cannot match if member counts differ */
514 }
515
Chris Forbes1257f912016-01-18 12:07:01 +1300516 for (unsigned i = 2; i < a_insn.len(); i++) {
517 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700518 return false;
519 }
520 }
521
522 return true;
523 }
524 case spv::OpTypePointer:
525 /* match on pointee type. storage class is expected to differ */
Chris Forbes1257f912016-01-18 12:07:01 +1300526 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700527
528 default:
529 /* remaining types are CLisms, or may not appear in the interfaces we
530 * are interested in. Just claim no match.
531 */
532 return false;
533
534 }
535}
536
537static int
538value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
539{
540 auto it = map.find(id);
541 if (it == map.end())
542 return def;
543 else
544 return it->second;
545}
546
547
548static unsigned
549get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
550{
Chris Forbes21977d92016-01-26 13:41:39 +1300551 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300552 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700553
Chris Forbesc7e2e202016-01-18 08:56:40 +1300554 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700555 case spv::OpTypePointer:
556 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
557 * we're never actually passing pointers around. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300558 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700559 case spv::OpTypeArray:
560 if (strip_array_level) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300561 return get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700562 }
563 else {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300564 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700565 }
566 case spv::OpTypeMatrix:
567 /* num locations is the dimension * element size */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300568 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700569 default:
570 /* everything else is just 1. */
571 return 1;
572
573 /* TODO: extend to handle 64bit scalar types, whose vectors may need
574 * multiple locations. */
575 }
576}
577
578
579struct interface_var {
580 uint32_t id;
581 uint32_t type_id;
582 uint32_t offset;
583 /* TODO: collect the name, too? Isn't required to be present. */
584};
585
Chris Forbesa3e85f62016-01-15 14:53:11 +1300586
587static void
588collect_interface_block_members(layer_data *my_data, VkDevice dev,
589 shader_module const *src,
590 std::map<uint32_t, interface_var> &out,
591 std::map<uint32_t, interface_var> &builtins_out,
592 std::unordered_map<unsigned, unsigned> const &blocks,
593 bool is_array_of_verts,
594 uint32_t id,
595 uint32_t type_id)
596{
597 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes21977d92016-01-26 13:41:39 +1300598 auto type = src->get_def(type_id);
Chris Forbes1257f912016-01-18 12:07:01 +1300599
Chris Forbesa3e85f62016-01-15 14:53:11 +1300600 while (true) {
601
Chris Forbes1257f912016-01-18 12:07:01 +1300602 if (type.opcode() == spv::OpTypePointer) {
Chris Forbes21977d92016-01-26 13:41:39 +1300603 type = src->get_def(type.word(3));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300604 }
Chris Forbes1257f912016-01-18 12:07:01 +1300605 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
Chris Forbes21977d92016-01-26 13:41:39 +1300606 type = src->get_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300607 is_array_of_verts = false;
608 }
Chris Forbes1257f912016-01-18 12:07:01 +1300609 else if (type.opcode() == spv::OpTypeStruct) {
610 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300611 /* This isn't an interface block. */
612 return;
613 }
614 else {
615 /* We have found the correct type. Walk its members. */
616 break;
617 }
618 }
619 else {
620 /* not an interface block */
621 return;
622 }
623 }
624
Chris Forbes1257f912016-01-18 12:07:01 +1300625 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300626 for (auto insn : *src) {
Chris Forbes1257f912016-01-18 12:07:01 +1300627 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300628 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300629 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300630
Chris Forbesc7e2e202016-01-18 08:56:40 +1300631 if (insn.word(3) == spv::DecorationLocation) {
632 unsigned location = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300633 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
634 for (unsigned int offset = 0; offset < num_locations; offset++) {
635 interface_var v;
636 v.id = id;
637 /* TODO: member index in interface_var too? */
638 v.type_id = member_type_id;
639 v.offset = offset;
640 out[location + offset] = v;
641 }
642 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300643 else if (insn.word(3) == spv::DecorationBuiltIn) {
644 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300645 interface_var v;
646 v.id = id;
647 v.type_id = member_type_id;
648 v.offset = 0;
649 builtins_out[builtin] = v;
650 }
651 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300652 }
653}
654
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700655static void
656collect_interface_by_location(layer_data *my_data, VkDevice dev,
657 shader_module const *src, spv::StorageClass sinterface,
658 std::map<uint32_t, interface_var> &out,
659 std::map<uint32_t, interface_var> &builtins_out,
660 bool is_array_of_verts)
661{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700662 std::unordered_map<unsigned, unsigned> var_locations;
663 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300664 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700665
Chris Forbesc7e2e202016-01-18 08:56:40 +1300666 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700667
668 /* We consider two interface models: SSO rendezvous-by-location, and
669 * builtins. Complain about anything that fits neither model.
670 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300671 if (insn.opcode() == spv::OpDecorate) {
672 if (insn.word(2) == spv::DecorationLocation) {
673 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700674 }
675
Chris Forbesc7e2e202016-01-18 08:56:40 +1300676 if (insn.word(2) == spv::DecorationBuiltIn) {
677 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700678 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300679
Chris Forbesc7e2e202016-01-18 08:56:40 +1300680 if (insn.word(2) == spv::DecorationBlock) {
681 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300682 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700683 }
684
685 /* TODO: handle grouped decorations */
686 /* TODO: handle index=1 dual source outputs from FS -- two vars will
687 * have the same location, and we DONT want to clobber. */
688
Chris Forbesc7e2e202016-01-18 08:56:40 +1300689 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
690 unsigned id = insn.word(2);
691 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700692
Chris Forbesc7e2e202016-01-18 08:56:40 +1300693 int location = value_or_default(var_locations, id, -1);
694 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700695
Chris Forbesf5020cf2016-01-13 09:29:31 +1300696 /* All variables and interface block members in the Input or Output storage classes
697 * must be decorated with either a builtin or an explicit location.
698 *
699 * TODO: integrate the interface block support here. For now, don't complain --
700 * a valid SPIRV module will only hit this path for the interface block case, as the
701 * individual members of the type are decorated, rather than variable declarations.
702 */
703
704 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700705 /* A user-defined interface variable, with a location. Where a variable
706 * occupied multiple locations, emit one result for each. */
707 unsigned num_locations = get_locations_consumed_by_type(src, type,
708 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700709 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700710 interface_var v;
711 v.id = id;
712 v.type_id = type;
713 v.offset = offset;
714 out[location + offset] = v;
715 }
716 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300717 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700718 /* A builtin interface variable */
719 /* Note that since builtin interface variables do not consume numbered
720 * locations, there is no larger-than-vec4 consideration as above
721 */
722 interface_var v;
723 v.id = id;
724 v.type_id = type;
725 v.offset = 0;
726 builtins_out[builtin] = v;
727 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300728 else {
729 /* An interface block instance */
730 collect_interface_block_members(my_data, dev, src, out, builtins_out,
731 blocks, is_array_of_verts, id, type);
732 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700733 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700734 }
735}
736
737static void
738collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
739 shader_module const *src, spv::StorageClass sinterface,
740 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
741{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700742
743 std::unordered_map<unsigned, unsigned> var_sets;
744 std::unordered_map<unsigned, unsigned> var_bindings;
745
Chris Forbesc7e2e202016-01-18 08:56:40 +1300746 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700747 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
748 * DecorationDescriptorSet and DecorationBinding.
749 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300750 if (insn.opcode() == spv::OpDecorate) {
751 if (insn.word(2) == spv::DecorationDescriptorSet) {
752 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700753 }
754
Chris Forbesc7e2e202016-01-18 08:56:40 +1300755 if (insn.word(2) == spv::DecorationBinding) {
756 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700757 }
758 }
759
Chris Forbesc7e2e202016-01-18 08:56:40 +1300760 else if (insn.opcode() == spv::OpVariable &&
761 (insn.word(3) == spv::StorageClassUniform ||
762 insn.word(3) == spv::StorageClassUniformConstant)) {
763 unsigned set = value_or_default(var_sets, insn.word(2), 0);
764 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700765
766 auto existing_it = out.find(std::make_pair(set, binding));
767 if (existing_it != out.end()) {
768 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700769 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 -0700770 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
771 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
Chris Forbesc7e2e202016-01-18 08:56:40 +1300772 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700773 existing_it->first.first, existing_it->first.second);
774 }
775
776 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300777 v.id = insn.word(2);
778 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700779 out[std::make_pair(set, binding)] = v;
780 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700781 }
782}
783
784static bool
785validate_interface_between_stages(layer_data *my_data, VkDevice dev,
786 shader_module const *producer, char const *producer_name,
787 shader_module const *consumer, char const *consumer_name,
788 bool consumer_arrayed_input)
789{
790 std::map<uint32_t, interface_var> outputs;
791 std::map<uint32_t, interface_var> inputs;
792
793 std::map<uint32_t, interface_var> builtin_outputs;
794 std::map<uint32_t, interface_var> builtin_inputs;
795
796 bool pass = true;
797
798 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
799 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
800 consumer_arrayed_input);
801
802 auto a_it = outputs.begin();
803 auto b_it = inputs.begin();
804
805 /* maps sorted by key (location); walk them together to find mismatches */
806 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
807 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
808 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
809 auto a_first = a_at_end ? 0 : a_it->first;
810 auto b_first = b_at_end ? 0 : b_it->first;
811
812 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700813 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 -0700814 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
815 pass = false;
816 }
817 a_it++;
818 }
819 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700820 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 -0700821 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
822 pass = false;
823 }
824 b_it++;
825 }
826 else {
827 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
828 /* OK! */
829 }
830 else {
831 char producer_type[1024];
832 char consumer_type[1024];
833 describe_type(producer_type, producer, a_it->second.type_id);
834 describe_type(consumer_type, consumer, b_it->second.type_id);
835
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700836 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 -0700837 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
838 pass = false;
839 }
840 }
841 a_it++;
842 b_it++;
843 }
844 }
845
846 return pass;
847}
848
849enum FORMAT_TYPE {
850 FORMAT_TYPE_UNDEFINED,
851 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
852 FORMAT_TYPE_SINT,
853 FORMAT_TYPE_UINT,
854};
855
856static unsigned
857get_format_type(VkFormat fmt) {
858 switch (fmt) {
859 case VK_FORMAT_UNDEFINED:
860 return FORMAT_TYPE_UNDEFINED;
861 case VK_FORMAT_R8_SINT:
862 case VK_FORMAT_R8G8_SINT:
863 case VK_FORMAT_R8G8B8_SINT:
864 case VK_FORMAT_R8G8B8A8_SINT:
865 case VK_FORMAT_R16_SINT:
866 case VK_FORMAT_R16G16_SINT:
867 case VK_FORMAT_R16G16B16_SINT:
868 case VK_FORMAT_R16G16B16A16_SINT:
869 case VK_FORMAT_R32_SINT:
870 case VK_FORMAT_R32G32_SINT:
871 case VK_FORMAT_R32G32B32_SINT:
872 case VK_FORMAT_R32G32B32A32_SINT:
873 case VK_FORMAT_B8G8R8_SINT:
874 case VK_FORMAT_B8G8R8A8_SINT:
875 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
876 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
877 return FORMAT_TYPE_SINT;
878 case VK_FORMAT_R8_UINT:
879 case VK_FORMAT_R8G8_UINT:
880 case VK_FORMAT_R8G8B8_UINT:
881 case VK_FORMAT_R8G8B8A8_UINT:
882 case VK_FORMAT_R16_UINT:
883 case VK_FORMAT_R16G16_UINT:
884 case VK_FORMAT_R16G16B16_UINT:
885 case VK_FORMAT_R16G16B16A16_UINT:
886 case VK_FORMAT_R32_UINT:
887 case VK_FORMAT_R32G32_UINT:
888 case VK_FORMAT_R32G32B32_UINT:
889 case VK_FORMAT_R32G32B32A32_UINT:
890 case VK_FORMAT_B8G8R8_UINT:
891 case VK_FORMAT_B8G8R8A8_UINT:
892 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
893 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
894 return FORMAT_TYPE_UINT;
895 default:
896 return FORMAT_TYPE_FLOAT;
897 }
898}
899
900/* characterizes a SPIR-V type appearing in an interface to a FF stage,
901 * for comparison to a VkFormat's characterization above. */
902static unsigned
903get_fundamental_type(shader_module const *src, unsigned type)
904{
Chris Forbes21977d92016-01-26 13:41:39 +1300905 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300906 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700907
Chris Forbes1257f912016-01-18 12:07:01 +1300908 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700909 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300910 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700911 case spv::OpTypeFloat:
912 return FORMAT_TYPE_FLOAT;
913 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300914 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700915 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300916 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700917 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300918 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700919 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300920 return get_fundamental_type(src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700921 default:
922 return FORMAT_TYPE_UNDEFINED;
923 }
924}
925
926static bool
927validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
928{
929 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
930 * each binding should be specified only once.
931 */
932 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
933 bool pass = true;
934
935 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
936 auto desc = &vi->pVertexBindingDescriptions[i];
937 auto & binding = bindings[desc->binding];
938 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700939 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 -0700940 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
941 pass = false;
942 }
943 }
944 else {
945 binding = desc;
946 }
947 }
948
949 return pass;
950}
951
952static bool
953validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
954{
955 std::map<uint32_t, interface_var> inputs;
956 /* we collect builtin inputs, but they will never appear in the VI state --
957 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
958 */
959 std::map<uint32_t, interface_var> builtin_inputs;
960 bool pass = true;
961
962 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
963
964 /* Build index by location */
965 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
966 if (vi) {
967 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
968 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
969 }
970
971 auto it_a = attribs.begin();
972 auto it_b = inputs.begin();
973
974 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
975 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
976 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
977 auto a_first = a_at_end ? 0 : it_a->first;
978 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +1300979 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700980 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 -0700981 "Vertex attribute at location %d not consumed by VS", a_first)) {
982 pass = false;
983 }
984 it_a++;
985 }
Chris Forbes7d83cd52016-01-15 11:32:03 +1300986 else if (!b_at_end && (a_at_end || b_first < a_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700987 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 -0700988 "VS consumes input at location %d but not provided", b_first)) {
989 pass = false;
990 }
991 it_b++;
992 }
993 else {
994 unsigned attrib_type = get_format_type(it_a->second->format);
995 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
996
997 /* type checking */
998 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
999 char vs_type[1024];
1000 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001001 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 -07001002 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
1003 string_VkFormat(it_a->second->format), a_first, vs_type)) {
1004 pass = false;
1005 }
1006 }
1007
1008 /* OK! */
1009 it_a++;
1010 it_b++;
1011 }
1012 }
1013
1014 return pass;
1015}
1016
1017static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001018validate_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 -07001019{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001020 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001021 std::map<uint32_t, interface_var> outputs;
1022 std::map<uint32_t, interface_var> builtin_outputs;
1023 bool pass = true;
1024
1025 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1026
1027 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
1028
1029 auto it = outputs.begin();
1030 uint32_t attachment = 0;
1031
1032 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1033 * are currently dense, but the parallel with matching between shader stages is nice.
1034 */
1035
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001036 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1037 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001038 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 -07001039 "FS writes to output location %d with no matching attachment", it->first)) {
1040 pass = false;
1041 }
1042 it++;
1043 }
1044 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001045 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 -07001046 "Attachment %d not written by FS", attachment)) {
1047 pass = false;
1048 }
1049 attachment++;
1050 }
1051 else {
1052 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1053 unsigned att_type = get_format_type(color_formats[attachment]);
1054
1055 /* type checking */
1056 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
1057 char fs_type[1024];
1058 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001059 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 -07001060 "Attachment %d of type `%s` does not match FS output type of `%s`",
1061 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
1062 pass = false;
1063 }
1064 }
1065
1066 /* OK! */
1067 it++;
1068 attachment++;
1069 }
1070 }
1071
1072 return pass;
1073}
1074
1075
1076struct shader_stage_attributes {
1077 char const * const name;
1078 bool arrayed_input;
1079};
1080
1081
1082static shader_stage_attributes
1083shader_stage_attribs[] = {
1084 { "vertex shader", false },
1085 { "tessellation control shader", true },
1086 { "tessellation evaluation shader", false },
1087 { "geometry shader", true },
1088 { "fragment shader", false },
1089};
1090
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001091// For given pipelineLayout verify that the setLayout at slot.first
1092// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001093static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001094has_descriptor_binding(layer_data* my_data,
1095 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001096 std::pair<unsigned, unsigned> slot)
1097{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001098 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001099 return false;
1100
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001101 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001102 return false;
1103
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001104 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001105
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001106 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001107}
1108
1109static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1110{
1111 uint32_t bit_pos = u_ffs(stage);
1112 return bit_pos-1;
1113}
1114
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001115// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001116
1117static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1118
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001119// 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 -06001120// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1121// to that same cmd buffer by separate thread are not changing state from underneath us
1122// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001123
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001124// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001125static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001126
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001127static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001128{
1129 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1130 if (pCB->drawCount[i])
1131 return VK_TRUE;
1132 }
1133 return VK_FALSE;
1134}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001135
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001136// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001137static 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 -06001138{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001139 // If non-zero enable mask is present, check it against status but if enable_mask
1140 // is 0 then no enable required so we should always just check status
1141 if ((!enable_mask) || (enable_mask & pNode->status)) {
1142 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001143 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001144 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 -07001145 "CB object %#" PRIxLEAST64 ": %s", (uint64_t)(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001146 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001147 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001148 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001149}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001150
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001151// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001152static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001153{
1154 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001155 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001156 loader_platform_thread_unlock_mutex(&globalLock);
1157 return NULL;
1158 }
1159 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001160 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001161}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001162
Tobin Ehlisd332f282015-10-02 11:00:56 -06001163// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1164static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1165{
1166 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1167 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1168 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1169 return VK_TRUE;
1170 }
1171 }
1172 return VK_FALSE;
1173}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001174
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001175// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001176static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001177 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001178 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");
1179 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");
1180 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");
1181 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");
1182 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");
1183 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");
1184 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");
1185 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");
1186 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 -06001187 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001188 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 -06001189 return result;
1190}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001191
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001192// Verify attachment reference compatibility according to spec
1193// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1194// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1195// to make sure that format and samples counts match.
1196// If not, they are not compatible.
1197static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1198 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1199{
1200 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1201 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1202 return false;
1203 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1204 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1205 return false;
1206 } else { // format and sample count must match
1207 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1208 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1209 return true;
1210 }
1211 // Format and sample counts didn't match
1212 return false;
1213}
1214
1215// For give primary and secondary RenderPass objects, verify that they're compatible
1216static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1217{
1218 stringstream errorStr;
1219 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1220 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1221 errorMsg = errorStr.str();
1222 return false;
1223 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1224 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1225 errorMsg = errorStr.str();
1226 return false;
1227 }
1228 // Trivial pass case is exact same RP
1229 if (primaryRP == secondaryRP)
1230 return true;
1231 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1232 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1233 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1234 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1235 errorMsg = errorStr.str();
1236 return false;
1237 }
1238 uint32_t spIndex = 0;
1239 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1240 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1241 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1242 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1243 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1244 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1245 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1246 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1247 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1248 errorMsg = errorStr.str();
1249 return false;
1250 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1251 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1252 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1253 errorMsg = errorStr.str();
1254 return false;
1255 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1256 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1257 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1258 errorMsg = errorStr.str();
1259 return false;
1260 }
1261 }
1262 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1263 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1264 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1265 for (uint32_t i = 0; i < inputMax; ++i) {
1266 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1267 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1268 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1269 errorMsg = errorStr.str();
1270 return false;
1271 }
1272 }
1273 }
1274 return true;
1275}
1276
Tobin Ehlis559c6382015-11-05 09:52:49 -07001277// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1278static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1279{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001280 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001281 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001282 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1283 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001284 return false;
1285 }
1286 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1287 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001288 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;
1289 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001290 return false;
1291 }
1292 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001293 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001294 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1295 return true;
1296 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001297 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001298 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1300 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001301 return false; // trivial fail case
1302 }
1303 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001304 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001305 // Need to verify that layouts are identically defined
1306 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1307 // do we also need to check immutable samplers?
1308 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001309 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]) << "'";
1310 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001311 return false;
1312 }
1313 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001314 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1315 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001316 return false;
1317 }
1318 }
1319 return true;
1320}
1321
Tobin Ehlis88452832015-12-03 09:40:56 -07001322// Validate that the shaders used by the given pipeline
1323// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001324static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001325validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001326{
Tobin Ehlis88452832015-12-03 09:40:56 -07001327 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001328 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1329 * before trying to do anything more: */
1330 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1331 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1332 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1333
1334 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1335 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001336 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001337 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001338 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001339
1340 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1341 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1342 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1343
1344 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1345 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001346 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 -07001347 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001348 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001349 }
1350 }
1351 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001352 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001353 shaders[get_shader_stage_id(pStage->stage)] = module;
1354
1355 /* validate descriptor set layout against what the spirv module actually uses */
1356 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1357 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1358 descriptor_uses);
1359
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001360 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1361 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001362
1363 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001364 // As a side-effect of this function, capture which sets are used by the pipeline
1365 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001366
1367 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001368 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001369
1370 if (!found) {
1371 char type_name[1024];
1372 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001373 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 -07001374 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1375 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1376 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001377 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001378 }
1379 }
1380 }
1381 }
1382 }
1383 }
1384
1385 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001386 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001387
1388 vi = pCreateInfo->pVertexInputState;
1389
1390 if (vi) {
1391 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1392 }
1393
1394 if (shaders[vertex_stage]) {
1395 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1396 }
1397
1398 /* TODO: enforce rules about present combinations of shaders */
1399 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1400 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1401
1402 while (!shaders[producer] && producer != fragment_stage) {
1403 producer++;
1404 consumer++;
1405 }
1406
1407 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1408 assert(shaders[producer]);
1409 if (shaders[consumer]) {
1410 pass = validate_interface_between_stages(my_data, dev,
1411 shaders[producer], shader_stage_attribs[producer].name,
1412 shaders[consumer], shader_stage_attribs[consumer].name,
1413 shader_stage_attribs[consumer].arrayed_input) && pass;
1414
1415 producer = consumer;
1416 }
1417 }
1418
1419 if (shaders[fragment_stage] && rp) {
1420 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1421 }
1422
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001423 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001424
1425 return pass;
1426}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001427
Tobin Ehlisf6585052015-12-17 11:48:42 -07001428// Return Set node ptr for specified set or else NULL
1429static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1430{
1431 loader_platform_thread_lock_mutex(&globalLock);
1432 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1433 loader_platform_thread_unlock_mutex(&globalLock);
1434 return NULL;
1435 }
1436 loader_platform_thread_unlock_mutex(&globalLock);
1437 return my_data->setMap[set];
1438}
1439
1440// For the given set, verify that for each dynamic descriptor in that set that its
1441// dynamic offset combined with the offet and range from its descriptor update
1442// do not overflow the size of its buffer being updated
1443static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1444{
1445 VkBool32 result = VK_FALSE;
1446 if (pSet->dynamicOffsets.empty())
1447 return result;
1448
1449 VkWriteDescriptorSet* pWDS = NULL;
1450 uint32_t dynOffsetIndex = 0;
1451 VkDeviceSize bufferSize = 0;
1452 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1453 switch (pSet->ppDescriptors[i]->sType) {
1454 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1455 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1456 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1457 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1458 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001459 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001460 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001461 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 -07001462 "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 ".",
1463 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1464 }
1465 dynOffsetIndex++;
1466 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)
1467 }
1468 }
1469 break;
1470 default: // Currently only shadowing Write update nodes so shouldn't get here
1471 assert(0);
1472 continue;
1473 }
1474 }
1475 return result;
1476}
1477
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001478// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001479static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001480 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001481 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001482 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001483 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001484 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1485 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1486 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001487 if (pPipe) {
1488 if (pCB->lastBoundPipelineLayout) {
1489 string errorString;
1490 for (auto setIndex : pPipe->active_sets) {
1491 // If valid set is not bound throw an error
1492 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001493 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 -07001494 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1495 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1496 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1497 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001498 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 -07001499 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1500 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001501 } 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 -07001502 // Add this set as a valid set for this CB
1503 pCB->activeSets.insert(pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001504 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001505 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001506 // Make sure set has been updated
1507 if (!pSet->pUpdateStructs) {
1508 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",
1509 "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);
1510 }
1511 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001512 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001513 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001514 }
1515 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001516
Mark Lobodzinski74635932015-12-18 15:35:38 -07001517 // Verify Vtx binding
1518 if (pPipe->vtxBindingCount > 0) {
1519 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1520 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001521 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001522 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 -07001523 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1524 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001525
Mark Lobodzinski74635932015-12-18 15:35:38 -07001526 }
1527 }
1528 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001529 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001530 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 -07001531 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1532 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001533 }
1534 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001535
Mark Lobodzinski74635932015-12-18 15:35:38 -07001536 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1537 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1538 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1539 if (dynViewport) {
1540 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001541 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 -07001542 "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);
1543 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001544 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001545 if (dynScissor) {
1546 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
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_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001548 "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);
1549 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001550 }
1551 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001552 return result;
1553}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001554
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001555// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001556static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001557{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001558 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001559
Tobin Ehlis88452832015-12-03 09:40:56 -07001560 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001561 skipCall = VK_TRUE;
1562 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001563 // VS is required
1564 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001565 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001566 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001567 }
1568 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001569 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1570 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001571 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 -06001572 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001573 }
1574 // Compute shaders should be specified independent of Gfx shaders
1575 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001576 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1577 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001578 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001579 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 -06001580 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001581 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001582 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001583 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001584 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001585 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001586 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 +08001587 "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 -06001588 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001589 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001590 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001591 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 +08001592 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001593 }
1594 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001595 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 +08001596 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001597 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1598 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001599 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001600 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001601 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001602 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001603 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 -06001604 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1605 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001606 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 -06001607 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001608 } else {
1609 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1610 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1611 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1612 if (!dynViewport) {
1613 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001614 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 -07001615 "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 -06001616 }
1617 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001618 if (!dynScissor) {
1619 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
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_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001621 "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 -06001622 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001623 }
1624 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001625 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001626}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001627
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001628// Init the pipeline mapping info based on pipeline create info LL tree
1629// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001630// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001631static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001632{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001633 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001634
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001635 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001636 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001637 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001638
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001639 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001640 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001641
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001642 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001643 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001644 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001645
1646 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1647 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1648
Chia-I Wu28e06912015-10-31 00:31:16 +08001649 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001650 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001651 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1652 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001653 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001654 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001655 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001656 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001657 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001658 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001659 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001660 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001661 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001662 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001663 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1664 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001665 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001666 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001667 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1668 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001669 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001670 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001671 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1672 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001673 break;
1674 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001675 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001676 break;
1677 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001678 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001679 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1680 if (pCreateInfo->stageCount != 0) {
1681 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1682 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1683 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1684 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001685 if (pCreateInfo->pVertexInputState != NULL) {
1686 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1687 // Copy embedded ptrs
1688 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001689 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001690 if (pPipeline->vtxBindingCount) {
1691 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1692 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1693 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1694 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001695 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001696 if (pPipeline->vtxAttributeCount) {
1697 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1698 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1699 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1700 }
1701 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1702 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001703 if (pCreateInfo->pInputAssemblyState != NULL) {
1704 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1705 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001706 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001707 if (pCreateInfo->pTessellationState != NULL) {
1708 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1709 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001710 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001711 if (pCreateInfo->pViewportState != NULL) {
1712 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1713 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001714 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001715 if (pCreateInfo->pRasterizationState != NULL) {
1716 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1717 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001718 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001719 if (pCreateInfo->pMultisampleState != NULL) {
1720 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1721 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001722 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001723 if (pCreateInfo->pDepthStencilState != NULL) {
1724 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1725 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1726 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001727 if (pCreateInfo->pColorBlendState != NULL) {
1728 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001729 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001730 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001731 pPipeline->attachmentCount = pCBCI->attachmentCount;
1732 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001733 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1734 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001735 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1736 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001737 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001738 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001739 if (pCreateInfo->pDynamicState != NULL) {
1740 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1741 if (pPipeline->dynStateCI.dynamicStateCount) {
1742 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1743 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1744 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1745 }
1746 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001747 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001748 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001749 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001750}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001751
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001752// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001753static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001754{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001755 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001756 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001757 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001758 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1759 delete[] (*ii).second->graphicsPipelineCI.pStages;
1760 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001761 if ((*ii).second->pVertexBindingDescriptions) {
1762 delete[] (*ii).second->pVertexBindingDescriptions;
1763 }
1764 if ((*ii).second->pVertexAttributeDescriptions) {
1765 delete[] (*ii).second->pVertexAttributeDescriptions;
1766 }
1767 if ((*ii).second->pAttachments) {
1768 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001769 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001770 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1771 delete[] (*ii).second->dynStateCI.pDynamicStates;
1772 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001773 delete (*ii).second;
1774 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001775 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001776}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001777
Tobin Ehliseba312c2015-04-01 08:40:34 -06001778// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001779static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001780{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001781 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001782 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001783 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001784 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001785 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001786}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001787
Tobin Ehliseba312c2015-04-01 08:40:34 -06001788// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001789static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001790{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001791 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001792 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001793 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001794 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001795 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001796 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001797 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001798 uint32_t i;
1799
Chia-I Wud50a7d72015-10-26 20:48:51 +08001800 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001801 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001802
Cody Northropa505dda2015-08-04 11:16:41 -06001803 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001804 continue;
1805
Cody Northropa505dda2015-08-04 11:16:41 -06001806 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001807 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001808 subpassNumSamples = samples;
1809 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001810 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001811 break;
1812 }
1813 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001814 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001815 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1816 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001817 subpassNumSamples = samples;
1818 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001819 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001820 }
1821
1822 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001823 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 -06001824 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001825 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001826 }
1827 } else {
1828 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1829 // Verify and flag error as appropriate
1830 }
1831 // TODO : Add more checks here
1832 } else {
1833 // TODO : Validate non-gfx pipeline updates
1834 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001835 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001836}
1837
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001838// Block of code at start here specifically for managing/tracking DSs
1839
Tobin Ehlis793ad302015-04-03 12:01:11 -06001840// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001841static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001842{
1843 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001844 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001845 loader_platform_thread_unlock_mutex(&globalLock);
1846 return NULL;
1847 }
1848 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001849 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001850}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001851
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001852static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001853 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001854 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001855 loader_platform_thread_unlock_mutex(&globalLock);
1856 return NULL;
1857 }
1858 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001859 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001860}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001861
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001862// 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 -06001863static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001864{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001865 switch (pUpdateStruct->sType)
1866 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001867 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1868 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001869 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001870 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001871 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 -06001872 "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 -06001873 }
1874}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001875
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001876// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001877// 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 -06001878static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001879{
1880 switch (pUpdateStruct->sType)
1881 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001882 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001883 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001884 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001885 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001886 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001887 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001888
1889 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001890}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001891
Tobin Ehlis793ad302015-04-03 12:01:11 -06001892// For given Layout Node and binding, return index where that binding begins
1893static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1894{
1895 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001896 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001897 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001898 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001899 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001900 }
1901 return offsetIndex;
1902}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001903
Tobin Ehlis793ad302015-04-03 12:01:11 -06001904// For given layout node and binding, return last index that is updated
1905static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1906{
1907 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001908 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001909 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1910 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001911 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001912 }
1913 return offsetIndex-1;
1914}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001915
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001916// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001917static 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 -06001918{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001919 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001920}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001921
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001922// For given layout and update, return the last overall index of the layout that is updated
1923static 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 -06001924{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001925 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001926 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001927}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001928
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001929// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001930static 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 -06001931{
1932 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001933 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001934 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001935 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001936 switch (pUpdateStruct->sType)
1937 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001938 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1939 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001940 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001941 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1942 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001943 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001944 break;
1945 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001946 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 -06001947 "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 -06001948 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001949 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001950 // Set first stageFlags as reference and verify that all other updates match it
1951 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001952 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001953 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001954 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 -06001955 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1956 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1957 }
1958 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001959 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 -06001960 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1961 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001962 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001963 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001964 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001965 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001966}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001967
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001968// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001969// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001970// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001971static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001972{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001973 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001974 VkWriteDescriptorSet* pWDS = NULL;
1975 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001976 size_t array_size = 0;
1977 size_t base_array_size = 0;
1978 size_t total_array_size = 0;
1979 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001980 switch (pUpdate->sType)
1981 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001982 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1983 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001984 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001985 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001986
1987 switch (pWDS->descriptorType) {
1988 case VK_DESCRIPTOR_TYPE_SAMPLER:
1989 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1990 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1991 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1992 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001993 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1994 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001995 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001996 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001997 break;
1998 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1999 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2000 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002001 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
2002 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002003 pWDS->pTexelBufferView = info;
2004 }
2005 break;
2006 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2007 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2008 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2009 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2010 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002011 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
2012 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002013 pWDS->pBufferInfo = info;
2014 }
2015 break;
2016 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07002017 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002018 break;
2019 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002020 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002021 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2022 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002023 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002024 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002025 break;
2026 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002027 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 -06002028 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2029 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002030 }
2031 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002032 (*pNewNode)->pNext = NULL;
2033 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002034}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002035
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002036// Verify that given sampler is valid
2037static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2038{
2039 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002040 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002041 if (sampIt == my_data->sampleMap.end()) {
2042 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002043 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 +08002044 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002045 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002046 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 +08002047 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002048 }
2049 } else {
2050 // TODO : Any further checks we want to do on the sampler?
2051 }
2052 return skipCall;
2053}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002054
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002055// Verify that given imageView is valid
2056static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2057{
2058 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002059 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002060 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002061 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 +08002062 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002063 } else {
2064 // Validate that imageLayout is compatible with aspectMask and image format
2065 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002066 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002067 // TODO : Check here in case we have a bad image
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07002068 auto imgIt = my_data->imageLayoutMap.find(image);
2069 if (imgIt == my_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002070 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 -07002071 "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 -06002072 } else {
2073 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002074 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002075 switch (imageLayout) {
2076 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2077 // Only Color bit must be set
2078 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002079 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 -06002080 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 +08002081 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002082 }
2083 // format must NOT be DS
2084 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002085 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 -06002086 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 +08002087 " 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 -06002088 }
2089 break;
2090 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2091 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2092 // Depth or stencil bit must be set, but both must NOT be set
2093 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2094 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2095 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002096 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 -06002097 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002098 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002099 }
2100 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2101 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002102 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 -06002103 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002104 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002105 }
2106 // format must be DS
2107 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002108 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 -06002109 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002110 " 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 -06002111 }
2112 break;
2113 default:
2114 // anything to check for other layouts?
2115 break;
2116 }
2117 }
2118 }
2119 return skipCall;
2120}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002121
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002122// Verify that given bufferView is valid
2123static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2124{
2125 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002126 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002127 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002128 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 +08002129 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002130 } else {
2131 // TODO : Any further checks we want to do on the bufferView?
2132 }
2133 return skipCall;
2134}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002135
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002136// Verify that given bufferInfo is valid
2137static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2138{
2139 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002140 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002141 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002142 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 +08002143 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002144 } else {
2145 // TODO : Any further checks we want to do on the bufferView?
2146 }
2147 return skipCall;
2148}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002149
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002150static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2151{
2152 VkBool32 skipCall = VK_FALSE;
2153 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2154 VkBufferView* pBufferView = NULL;
2155 const VkSampler* pSampler = NULL;
2156 VkImageView* pImageView = NULL;
2157 VkImageLayout* pImageLayout = NULL;
2158 VkDescriptorBufferInfo* pBufferInfo = NULL;
2159 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002160 uint32_t i = 0;
2161 // For given update type, verify that update contents are correct
2162 switch (pWDS->descriptorType) {
2163 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002164 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002165 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002166 }
2167 break;
2168 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002169 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002170 if (NULL == pLayoutBinding->pImmutableSamplers) {
2171 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002172 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002173 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 -06002174 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2175 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002176 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002177 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002178 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002179 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002180 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 -06002181 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2182 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2183 "use immutable or non-immutable samplers.", i);
2184 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002185 immutable = VK_TRUE;
2186 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2187 }
2188 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002189 }
2190 // Intentionally fall through here to also validate image stuff
2191 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2192 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2193 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002194 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002195 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002196 }
2197 break;
2198 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2199 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002200 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002201 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002202 }
2203 break;
2204 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2205 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2206 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2207 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002208 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002209 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002210 }
2211 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002212 }
2213 return skipCall;
2214}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002215// Validate that given set is valid and that it's not being used by an in-flight CmdBuffer
2216// func_str is the name of the calling function
2217// Return VK_FALSE if no errors occur
2218// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2219VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
2220 VkBool32 skip_call = VK_FALSE;
2221 auto set_node = my_data->setMap.find(set);
2222 if (set_node == my_data->setMap.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002223 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",
2224 "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 -07002225 } else {
2226 if (set_node->second->in_use.load()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002227 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",
2228 "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 -07002229 }
2230 }
2231 return skip_call;
2232}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002233// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002234static 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 -06002235{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002236 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002237
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002238 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002239 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002240 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002241 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002242 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002243 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002244 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002245 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002246 // Set being updated cannot be in-flight
2247 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
2248 return skipCall;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002249 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002250 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002251 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002252 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002253 break;
2254 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002255 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002256 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002257 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002258 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002259 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",
2260 "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 -06002261 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002262 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002263 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002264 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002265 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002266 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Young93ecb1d2016-01-13 13:47:16 -07002267 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 -06002268 "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 -06002269 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002270 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002271 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002272 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2273 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2274 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002275 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002276 // Update is good. Save the update info
2277 // Create new update struct for this set's shadow copy
2278 GENERIC_HEADER* pNewNode = NULL;
2279 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2280 if (NULL == pNewNode) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002281 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 -06002282 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2283 } else {
2284 // Insert shadow node into LL of updates for this set
2285 pNewNode->pNext = pSet->pUpdateStructs;
2286 pSet->pUpdateStructs = pNewNode;
2287 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002288 for (uint32_t j = startIndex; j <= endIndex; j++) {
2289 assert(j<pSet->descriptorCount);
2290 pSet->ppDescriptors[j] = pNewNode;
2291 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002292 }
2293 }
2294 }
2295 }
2296 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002297 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002298 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002299 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002300 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2301 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2302 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2303 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002304 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002305 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002306 // Set being updated cannot be in-flight
2307 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
2308 return skipCall;
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002309 pSrcLayout = pSrcSet->pLayout;
2310 pDstLayout = pDstSet->pLayout;
2311 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002312 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002313 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 -06002314 "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 +08002315 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002316 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002317 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 +08002318 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2319 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002320 } else {
2321 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2322 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 +08002323 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002324 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2325 pLayoutCI = &pSrcLayout->createInfo;
2326 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002327 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 -06002328 "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 +08002329 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002330 pLayoutCI = &pDstLayout->createInfo;
2331 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002332 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 +08002333 "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 -06002334 } else {
2335 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 +08002336 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 +08002337 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002338 // For copy just make sure that the types match and then perform the update
2339 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002340 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 -06002341 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2342 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2343 } else {
2344 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002345 // TODO : This may be a hole. I believe copy should be its own copy,
2346 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002347 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2348 }
2349 }
2350 }
2351 }
2352 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002353 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002354 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002355}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002356
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002357// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002358static 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 -06002359{
2360 VkBool32 skipCall = VK_FALSE;
2361 uint32_t i = 0, j = 0;
2362 for (i=0; i<count; ++i) {
2363 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2364 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002365 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 +08002366 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002367 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002368 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002369 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002370 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2371 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002372 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002373 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 -06002374 "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 -07002375 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002376 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002377 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002378 }
2379 }
2380 }
2381 }
2382 return skipCall;
2383}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002384
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002385// Free the shadowed update node for this Set
2386// NOTE : Calls to this function should be wrapped in mutex
2387static void freeShadowUpdateTree(SET_NODE* pSet)
2388{
2389 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2390 pSet->pUpdateStructs = NULL;
2391 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2392 // Clear the descriptor mappings as they will now be invalid
2393 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2394 while(pShadowUpdate) {
2395 pFreeUpdate = pShadowUpdate;
2396 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2397 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002398 VkWriteDescriptorSet * pWDS = NULL;
2399 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002400 void** ppToFree = NULL;
2401 switch (pFreeUpdate->sType)
2402 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002403 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2404 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002405 switch (pWDS->descriptorType) {
2406 case VK_DESCRIPTOR_TYPE_SAMPLER:
2407 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2408 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2409 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2410 {
2411 delete[] pWDS->pImageInfo;
2412 }
2413 break;
2414 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2415 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2416 {
2417 delete[] pWDS->pTexelBufferView;
2418 }
2419 break;
2420 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2421 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2422 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2423 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2424 {
2425 delete[] pWDS->pBufferInfo;
2426 }
2427 break;
2428 default:
2429 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002430 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002431 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002432 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002433 break;
2434 default:
2435 assert(0);
2436 break;
2437 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002438 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002439 }
2440}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002441
Tobin Ehlis793ad302015-04-03 12:01:11 -06002442// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002443// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002444static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002445{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002446 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002447 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002448 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002449 SET_NODE* pSet = (*ii).second->pSets;
2450 SET_NODE* pFreeSet = pSet;
2451 while (pSet) {
2452 pFreeSet = pSet;
2453 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002454 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002455 // Free Update shadow struct tree
2456 freeShadowUpdateTree(pFreeSet);
2457 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002458 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002459 }
2460 delete pFreeSet;
2461 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002462 delete (*ii).second;
2463 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002464 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002465}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002466
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002467// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
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 deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002470{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002471 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002472 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002473 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002474 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002475 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002476 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002477 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2478 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002479 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002480 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002481 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002482 delete pLayout;
2483 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002484 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002485}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002486
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002487// Currently clearing a set is removing all previous updates to that set
2488// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002489static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002491 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002492 if (!pSet) {
2493 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002494 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002495 loader_platform_thread_lock_mutex(&globalLock);
2496 freeShadowUpdateTree(pSet);
2497 loader_platform_thread_unlock_mutex(&globalLock);
2498 }
2499}
2500
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002501static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002502{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002503 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002504 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002505 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 +08002506 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002507 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002508 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002509 // For every set off of this pool, clear it
2510 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002511 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002512 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002513 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002514 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002515 // Reset available count to max count for this pool
2516 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2517 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2518 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002519 }
2520}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002521
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002522// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002523static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002524{
2525 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002526 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002527 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002528 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002529 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 -07002530 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002531 return NULL;
2532 }
2533 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002534 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002535}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002536
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002537// Free all CB Nodes
2538// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002539static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002540{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002541 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002542 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002543 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002544 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002545 delete (*ii).second;
2546 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002547 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002548}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002549
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002550static 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 -06002551{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002552 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 -07002553 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002554 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002555}
Michael Lentine3dea6512015-10-28 15:55:18 -07002556
Mark Youngb20a6a82016-01-07 15:41:43 -07002557VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2558 if (!pCB->activeRenderPass) return VK_FALSE;
2559 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002560 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2561 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2562 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2563 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2564 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2565 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2566 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002567 return skip_call;
2568}
2569
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002570// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2571// in the recording state or if there's an issue with the Cmd ordering
2572static 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 -06002573{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002574 VkBool32 skipCall = VK_FALSE;
2575 if (pCB->state != CB_RECORDING) {
2576 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2577 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002578 CMD_NODE cmdNode = {};
2579 // init cmd node and append to end of cmd LL
2580 cmdNode.cmdNumber = ++pCB->numCmds;
2581 cmdNode.type = cmd;
2582 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002583 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002584 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002585}
Tobin Ehlisef694652016-01-19 12:03:34 -07002586// Reset the command buffer state
2587// Maintain the createInfo and set state to CB_NEW, but clear all other state
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002588static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002589{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002590 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002591 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002592 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002593 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002594 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002595 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07002596 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002597 pCB->fence = 0;
2598 pCB->numCmds = 0;
2599 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2600 pCB->state = CB_NEW;
2601 pCB->submitCount = 0;
2602 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002603 pCB->lastBoundPipeline = 0;
2604 pCB->viewports.clear();
2605 pCB->scissors.clear();
2606 pCB->lineWidth = 0;
2607 pCB->depthBiasConstantFactor = 0;
2608 pCB->depthBiasClamp = 0;
2609 pCB->depthBiasSlopeFactor = 0;
2610 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2611 pCB->minDepthBounds = 0;
2612 pCB->maxDepthBounds = 0;
2613 memset(&pCB->front, 0, sizeof(stencil_data));
2614 memset(&pCB->back, 0, sizeof(stencil_data));
2615 pCB->lastBoundDescriptorSet = 0;
2616 pCB->lastBoundPipelineLayout = 0;
2617 pCB->activeRenderPass = 0;
2618 pCB->activeSubpass = 0;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002619 pCB->activeSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002620 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002621 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002622 pCB->drawData.clear();
2623 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002624 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002625 pCB->waitedEvents.clear();
2626 pCB->waitedEventsBeforeQueryReset.clear();
2627 pCB->queryToStateMap.clear();
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002628 pCB->secondaryCommandBuffers.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002629 }
2630}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002631
Tobin Ehlis963a4042015-09-29 08:18:34 -06002632// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002633static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2634{
2635 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002636 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002637 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2638 }
2639 }
2640 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002641 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2642 }
Cody Northrop82485a82015-08-18 15:21:16 -06002643 if (pPipe->dsStateCI.stencilTestEnable) {
2644 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002645 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002646 // Account for any dynamic state not set via this PSO
2647 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2648 pCB->status = CBSTATUS_ALL;
2649 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002650 // First consider all state on
2651 // Then unset any state that's noted as dynamic in PSO
2652 // Finally OR that into CB statemask
2653 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002654 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2655 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2656 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002657 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002658 break;
2659 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002660 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002661 break;
2662 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002663 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002664 break;
2665 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002666 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002667 break;
2668 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002669 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002670 break;
2671 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002672 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002673 break;
2674 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002675 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002676 break;
2677 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002678 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002679 break;
2680 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002681 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002682 break;
2683 default:
2684 // TODO : Flag error here
2685 break;
2686 }
2687 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002688 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002689 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002690}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002691
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002692// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002693static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002694{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002695 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002696 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002697 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002698 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002699 if (!pPipeTrav) {
2700 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002701 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002702 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 -08002703 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002704 }
2705 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002706 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002707}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002708
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002709// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002710static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002711{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002712 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002713 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 -06002714 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002715 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002716 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002717 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002718 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002719 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002720 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002721 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002722 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002723 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002724 // Print out set details
2725 char prefix[10];
2726 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002727 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002728 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002729 LAYOUT_NODE* pLayout = pSet->pLayout;
2730 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002731 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 -07002732 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (uint64_t)(pLayout->layout), (uint64_t)(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002733 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002734 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002735 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 -06002736 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002737 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002738 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2739 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002740 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 +08002741 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002742 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002743 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 -08002744 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002745 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002746 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002747 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002748 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 +08002749 "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 -06002750 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002751 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 +08002752 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002753 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002754 }
2755 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002756 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002757}
2758
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002759static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002760{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002761 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002762 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002763 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 -06002764 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002765 vector<CMD_NODE> cmds = pCB->cmds;
2766 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002767 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002768 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 -07002769 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002770 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002771 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002772 // Nothing to print
2773 }
2774}
2775
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002776static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002777{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002778 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002779 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002780 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002781 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002782 skipCall |= printDSConfig(my_data, cb);
2783 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002784 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002785}
2786
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002787// Flags validation error if the associated call is made inside a render pass. The apiName
2788// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002789static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002790{
2791 VkBool32 inside = VK_FALSE;
2792 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002793 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 -07002794 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002795 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002796 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002797 }
2798 return inside;
2799}
2800
2801// Flags validation error if the associated call is made outside a render pass. The apiName
2802// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002803static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002804{
2805 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002806 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2807 (!pCB->activeRenderPass)) ||
2808 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2809 (!pCB->activeRenderPass) &&
2810 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002811 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 -07002812 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002813 "%s: This call must be issued inside an active render pass.", apiName);
2814 }
2815 return outside;
2816}
2817
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002818static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002819{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002820 uint32_t report_flags = 0;
2821 uint32_t debug_action = 0;
2822 FILE *log_output = NULL;
2823 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002824 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002825 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002826 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2827 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002828
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002829 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002830 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002831 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002832 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002833 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002834 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002835 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002836 dbgInfo.pfnCallback = log_callback;
2837 dbgInfo.pUserData = log_output;
2838 dbgInfo.flags = report_flags;
2839 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002840 my_data->logging_callback.push_back(callback);
2841 }
2842
2843 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002844 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002845 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002846 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002847 dbgInfo.pfnCallback = win32_debug_output_msg;
2848 dbgInfo.pUserData = log_output;
2849 dbgInfo.flags = report_flags;
2850 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002851 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002852 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002853
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002854 if (!globalLockInitialized)
2855 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002856 loader_platform_thread_create_mutex(&globalLock);
2857 globalLockInitialized = 1;
2858 }
2859}
2860
Chia-I Wu9ab61502015-11-06 06:42:02 +08002861VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002862{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002863 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002864
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002865 assert(chain_info->u.pLayerInfo);
2866 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2867 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
2868 if (fpCreateInstance == NULL) {
2869 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002870 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002871
2872 // Advance the link info for the next element on the chain
2873 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2874
2875 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
2876 if (result != VK_SUCCESS)
2877 return result;
2878
2879 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2880 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
2881 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
2882
2883 my_data->report_data = debug_report_create_instance(
2884 my_data->instance_dispatch_table,
2885 *pInstance,
2886 pCreateInfo->enabledExtensionCount,
2887 pCreateInfo->ppEnabledExtensionNames);
2888
2889 init_draw_state(my_data, pAllocator);
2890
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002891 return result;
2892}
2893
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002894/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002895VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002896{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002897 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002898 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002899 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2900 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002901 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002902
2903 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002904 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002905 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002906 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002907 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002908 }
2909
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002910 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002911 delete my_data->instance_dispatch_table;
2912 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002913 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002914 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002915 // Release mutex when destroying last instance.
2916 loader_platform_thread_delete_mutex(&globalLock);
2917 globalLockInitialized = 0;
2918 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002919}
2920
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002921static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2922{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002923 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002924 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2925 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002926 dev_data->device_extensions.wsi_enabled = false;
2927
2928
2929 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2930 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2931
Michael Lentineabc5e922015-10-12 11:30:14 -05002932 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2933 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2934 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2935 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002936 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002937
Jon Ashburnf19916e2016-01-11 13:12:43 -07002938 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002939 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002940 dev_data->device_extensions.wsi_enabled = true;
2941 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002942 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002943 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002944 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002945 initDebugMarkerTable(device);
2946
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002947 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002948 }
2949}
2950
Chia-I Wu9ab61502015-11-06 06:42:02 +08002951VK_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 -06002952{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002953 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002954
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002955 assert(chain_info->u.pLayerInfo);
2956 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2957 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
2958 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
2959 if (fpCreateDevice == NULL) {
2960 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002961 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002962
2963 // Advance the link info for the next element on the chain
2964 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2965
2966 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
2967 if (result != VK_SUCCESS) {
2968 return result;
2969 }
2970
2971 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
2972 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
2973
2974 // Setup device dispatch table
2975 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
2976 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
2977
2978 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
2979 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
2980 // Get physical device limits for this device
2981 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002982 return result;
2983}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002984
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002985// prototype
2986static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002987VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002988{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002989 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002990 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002991 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002992 // Free all the memory
2993 loader_platform_thread_lock_mutex(&globalLock);
2994 deletePipelines(dev_data);
2995 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002996 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002997 deletePools(dev_data);
2998 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002999 dev_data->imageViewMap.clear();
3000 dev_data->imageMap.clear();
3001 dev_data->bufferViewMap.clear();
3002 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003003 loader_platform_thread_unlock_mutex(&globalLock);
3004
Chia-I Wuf7458c52015-10-26 21:10:41 +08003005 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003006 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003007 delete dev_data->device_dispatch_table;
3008 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003009}
3010
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003011static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003012 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003013 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -07003014 VK_EXT_DEBUG_REPORT_SPEC_VERSION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003015 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003016};
3017
Chia-I Wu9ab61502015-11-06 06:42:02 +08003018VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003019 const char *pLayerName,
3020 uint32_t *pCount,
3021 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003022{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003023 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003024}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003025
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003026static const VkLayerProperties ds_global_layers[] = {
3027 {
Michael Lentine03107b42015-12-11 10:49:51 -08003028 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003029 VK_API_VERSION,
3030 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003031 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003032 }
3033};
3034
Chia-I Wu9ab61502015-11-06 06:42:02 +08003035VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003036 uint32_t *pCount,
3037 VkLayerProperties* pProperties)
3038{
3039 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
3040 ds_global_layers,
3041 pCount, pProperties);
3042}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003043
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003044static const VkExtensionProperties ds_device_extensions[] = {
3045 {
3046 DEBUG_MARKER_EXTENSION_NAME,
3047 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003048 }
3049};
3050
3051static const VkLayerProperties ds_device_layers[] = {
3052 {
Michael Lentine1f8d4412016-01-19 14:19:38 -06003053 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003054 VK_API_VERSION,
3055 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003056 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003057 }
3058};
3059
Chia-I Wu9ab61502015-11-06 06:42:02 +08003060VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003061 VkPhysicalDevice physicalDevice,
3062 const char* pLayerName,
3063 uint32_t* pCount,
3064 VkExtensionProperties* pProperties)
3065{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003066 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003067 if (pLayerName == NULL) {
3068 dispatch_key key = get_dispatch_key(physicalDevice);
3069 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003070 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003071 physicalDevice,
3072 NULL,
3073 pCount,
3074 pProperties);
3075 } else {
3076 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3077 ds_device_extensions,
3078 pCount, pProperties);
3079 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003080}
3081
Chia-I Wu9ab61502015-11-06 06:42:02 +08003082VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003083 VkPhysicalDevice physicalDevice,
3084 uint32_t* pCount,
3085 VkLayerProperties* pProperties)
3086{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003087 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003088 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3089 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003090}
3091
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003092VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003093 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003094 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3095 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3096 for (auto cb_image_data : pCB->imageLayoutMap) {
3097 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3098 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003099 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 -07003100 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", (uint64_t)(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003101 } else {
3102 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003103 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 -05003104 "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);
3105 }
3106 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3107 }
3108 }
3109 return skip_call;
3110}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003111// Descriptor sets are unique vs. other resources in that they may be consumed at bind time:
3112// From spec section on vkCmdBindDescriptorSets - The descriptor set contents bound by a call
3113// to vkCmdBindDescriptorSets may be consumed during host execution of the command, or during
3114// shader execution of the resulting draws, or any time in between.
3115VkBool32 validateAndIncrementDescriptorSets(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
3116 VkBool32 skip_call = VK_FALSE;
3117 // Verify that any active sets for this CB are valid and mark them in use
3118 for (auto set : pCB->activeSets) {
3119 auto setNode = my_data->setMap.find(set);
3120 if (setNode == my_data->setMap.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07003121 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",
3122 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003123 } else {
3124 setNode->second->in_use.fetch_add(1);
3125 }
3126 }
3127 return skip_call;
3128}
Michael Lentineabc5e922015-10-12 11:30:14 -05003129
Mark Young7a69c302016-01-07 09:48:47 -07003130VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003131 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003132 for (auto drawDataElement : pCB->drawData) {
3133 for (auto buffer : drawDataElement.buffers) {
3134 auto buffer_data = my_data->bufferMap.find(buffer);
3135 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003136 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",
3137 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003138 } else {
3139 buffer_data->second.in_use.fetch_add(1);
3140 }
3141 }
3142 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003143 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003144}
3145
3146void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3147 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3148 for (auto drawDataElement : pCB->drawData) {
3149 for (auto buffer : drawDataElement.buffers) {
3150 auto buffer_data = my_data->bufferMap.find(buffer);
3151 if (buffer_data != my_data->bufferMap.end()) {
3152 buffer_data->second.in_use.fetch_sub(1);
3153 }
3154 }
3155 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003156 for (auto set : pCB->activeSets) {
3157 auto setNode = my_data->setMap.find(set);
3158 if (setNode != my_data->setMap.end()) {
3159 setNode->second->in_use.fetch_sub(1);
3160 }
3161 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003162 for (auto queryStatePair : pCB->queryToStateMap) {
3163 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3164 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003165}
3166
3167void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3168 for (uint32_t i = 0; i < fenceCount; ++i) {
3169 auto fence_data = my_data->fenceMap.find(pFences[i]);
3170 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3171 fence_data->second.needsSignaled = false;
3172 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3173 decrementResources(my_data, 1, &fence_data->second.priorFence);
3174 }
3175 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3176 decrementResources(my_data, cmdBuffer);
3177 }
3178 }
3179}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003180
Michael Lentine700b0aa2015-10-30 17:57:32 -07003181void decrementResources(layer_data* my_data, VkQueue queue) {
3182 auto queue_data = my_data->queueMap.find(queue);
3183 if (queue_data != my_data->queueMap.end()) {
3184 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3185 decrementResources(my_data, cmdBuffer);
3186 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003187 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003188 decrementResources(my_data, 1, &queue_data->second.priorFence);
3189 }
3190}
3191
3192void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3193 auto queue_data = my_data->queueMap.find(queue);
3194 if (fence != VK_NULL_HANDLE) {
3195 VkFence priorFence = VK_NULL_HANDLE;
3196 if (queue_data != my_data->queueMap.end()) {
3197 priorFence = queue_data->second.priorFence;
3198 queue_data->second.priorFence = fence;
3199 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3200 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3201 }
3202 queue_data->second.untrackedCmdBuffers.clear();
3203 }
3204 my_data->fenceMap[fence].cmdBuffers.clear();
3205 my_data->fenceMap[fence].priorFence = priorFence;
3206 my_data->fenceMap[fence].needsSignaled = true;
3207 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003208 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3209 my_data->fenceMap[fence].cmdBuffers.push_back(secondaryCmdBuffer);
3210 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003211 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3212 }
3213 } else {
3214 if (queue_data != my_data->queueMap.end()) {
3215 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003216 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3217 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
3218 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003219 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3220 }
3221 }
3222 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003223 if (queue_data != my_data->queueMap.end()) {
3224 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003225 // Add cmdBuffers to both the global set and queue set
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003226 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3227 my_data->inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003228 my_data->queueMap[queue].inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003229 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003230 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003231 my_data->queueMap[queue].inFlightCmdBuffers.insert(pCmdBuffers[i]);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003232 }
3233 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003234}
3235
Chia-I Wu9ab61502015-11-06 06:42:02 +08003236VK_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 -06003237{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003238 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003239 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003240 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003241 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003242 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003243 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3244 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3245 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3246 } else {
3247 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",
3248 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07003249 (uint64_t)(queue), (uint64_t)(submit->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06003250 }
3251 }
3252 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3253 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3254 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003255 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003256
3257#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3258 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3259#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3260
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003261 // Validate that cmd buffers have been updated
3262 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3263 loader_platform_thread_lock_mutex(&globalLock);
3264 pCB->submitCount++; // increment submit count
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003265 // Track in-use for resources off of primary and any secondary CBs
Michael Lentine700b0aa2015-10-30 17:57:32 -07003266 skipCall |= validateAndIncrementResources(dev_data, pCB);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003267 if (!pCB->secondaryCommandBuffers.empty()) {
3268 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
3269 skipCall |= validateAndIncrementResources(dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3270 }
3271 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003272 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003273 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 -05003274 "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 -07003275 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003276 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003277 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003278 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003279 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 -07003280 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003281 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003282 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003283 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003284 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing on device
3285 if (!(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3286 if (dev_data->inFlightCmdBuffers.find(pCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07003287 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",
3288 "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 -07003289 }
3290 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003291 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003292 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003293 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003294 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003295 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003296 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003297 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003298}
3299
Mark Youngb20a6a82016-01-07 15:41:43 -07003300VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3301 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003302 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003303 if (pCB) {
3304 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3305 for (auto event : queryEventsPair.second) {
3306 if (my_data->eventMap[event].needsSignaled) {
3307 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",
3308 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
3309 (uint64_t)(queryEventsPair.first.pool), queryEventsPair.first.index, (uint64_t)(event));
3310 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003311 }
3312 }
3313 }
3314 return skip_call;
3315}
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003316// Remove given cmd_buffer from inFlight set for given queue
3317// If cmd_buffer is not inFlight on any other queues, also remove it from global inFlight set
3318static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkQueue queue, VkCommandBuffer cmd_buffer)
3319{
3320 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3321 // Pull it off of global list initially, but if we find it in any other queue list, add it back in
3322 dev_data->inFlightCmdBuffers.erase(cmd_buffer);
3323 for (auto q : dev_data->queues) {
3324 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
3325 dev_data->inFlightCmdBuffers.insert(cmd_buffer);
3326 break;
3327 }
3328 }
3329}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003330
Michael Lentine700b0aa2015-10-30 17:57:32 -07003331VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3332{
3333 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3334 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003335 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003336 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003337 for (uint32_t i = 0; i < fenceCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003338 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003339 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003340 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003341 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003342 }
3343 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003344 decrementResources(dev_data, fenceCount, pFences);
3345 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003346 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003347 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003348 return result;
3349}
3350
3351
3352VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3353{
3354 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3355 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003356 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003357 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003358 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003359 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003360 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3361 removeInFlightCmdBuffer(dev_data, fence_queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003362 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003363 decrementResources(dev_data, 1, &fence);
3364 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003365 if (VK_FALSE != skip_call)
3366 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003367 return result;
3368}
3369
3370VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3371{
3372 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3373 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003374 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003375 dev_data->queueMap[*pQueue].device = device;
3376}
3377
3378VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3379{
3380 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3381 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003382 VkBool32 skip_call = VK_FALSE;
3383 // Iterate over local set since we erase set members as we go in for loop
3384 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3385 for (auto cmdBuffer : local_cb_set) {
3386 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3387 removeInFlightCmdBuffer(dev_data, queue, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003388 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003389 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3390 if (VK_FALSE != skip_call)
3391 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003392 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3393}
3394
3395VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3396{
3397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003398 for (auto queue : dev_data->queues) {
3399 decrementResources(dev_data, queue);
3400 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
3401 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003402 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003403 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3404 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3405 }
3406 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003407 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3408}
3409
Chia-I Wu9ab61502015-11-06 06:42:02 +08003410VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003411{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003412 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 -06003413 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003414}
3415
Chia-I Wu9ab61502015-11-06 06:42:02 +08003416VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003417{
Michael Lentine15a47882016-01-06 10:05:48 -06003418 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3419 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3420 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003421 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003422}
3423
Chia-I Wu9ab61502015-11-06 06:42:02 +08003424VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003425{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003426 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 -06003427 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003428}
3429
Chia-I Wu9ab61502015-11-06 06:42:02 +08003430VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003431{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003432 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 -06003433 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003434}
3435
Mark Lobodzinskice738852016-01-07 10:04:02 -07003436VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003437 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3438 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3439 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3440 GLOBAL_CB_NODE* pCB = nullptr;
3441 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3442 pCB = getCBNode(dev_data, cmdBuffer);
3443 for (auto queryStatePair : pCB->queryToStateMap) {
3444 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3445 }
3446 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003447 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003448 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003449 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003450 auto queryElement = queriesInFlight.find(query);
3451 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3452 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3453 }
3454 // Available and in flight
3455 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3456 for (auto cmdBuffer : queryElement->second) {
3457 pCB = getCBNode(dev_data, cmdBuffer);
3458 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3459 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003460 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3461 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 -07003462 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003463 } else {
3464 for (auto event : queryEventElement->second) {
3465 dev_data->eventMap[event].needsSignaled = true;
3466 }
3467 }
3468 }
3469 // Unavailable and in flight
3470 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3471 // TODO : Can there be the same query in use by multiple command buffers in flight?
3472 bool make_available = false;
3473 for (auto cmdBuffer : queryElement->second) {
3474 pCB = getCBNode(dev_data, cmdBuffer);
3475 make_available |= pCB->queryToStateMap[query];
3476 }
3477 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003478 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 -06003479 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003480 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003481 }
3482 // Unavailable
3483 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003484 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 -06003485 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003486 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003487 // Unitialized
3488 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003489 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 -06003490 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003491 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003492 }
3493 }
3494 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003495 return VK_ERROR_VALIDATION_FAILED_EXT;
3496 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003497}
3498
Mark Young7a69c302016-01-07 09:48:47 -07003499VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003500 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003501 auto buffer_data = my_data->bufferMap.find(buffer);
3502 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003503 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",
3504 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003505 } else {
3506 if (buffer_data->second.in_use.load()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003507 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",
3508 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003509 }
3510 }
3511 return skip_call;
3512}
3513
Chia-I Wu9ab61502015-11-06 06:42:02 +08003514VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003515{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003516 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003517 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003518 if (!validateIdleBuffer(dev_data, buffer)) {
3519 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3520 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003521 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003522}
3523
Chia-I Wu9ab61502015-11-06 06:42:02 +08003524VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003525{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003526 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003527 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003528 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003529}
3530
Chia-I Wu9ab61502015-11-06 06:42:02 +08003531VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003532{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003533 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003534 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003535 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003536}
3537
Chia-I Wu9ab61502015-11-06 06:42:02 +08003538VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003539{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003540 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 -06003541 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003542}
3543
Chia-I Wu9ab61502015-11-06 06:42:02 +08003544VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003545{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003546 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 -06003547 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003548}
3549
Chia-I Wu9ab61502015-11-06 06:42:02 +08003550VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003551{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003552 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 -06003553 // TODO : Clean up any internal data structures using this obj.
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 vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003557{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003558 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 -06003559 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003560}
3561
Chia-I Wu9ab61502015-11-06 06:42:02 +08003562VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003563{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003564 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 -06003565 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003566}
3567
Chia-I Wu9ab61502015-11-06 06:42:02 +08003568VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003569{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003570 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 -06003571 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003572}
3573
Chia-I Wu9ab61502015-11-06 06:42:02 +08003574VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003575{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003576 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 -06003577 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003578}
3579
Chia-I Wu9ab61502015-11-06 06:42:02 +08003580VK_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 -06003581{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003582 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3583
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003584 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003585 // Delete CB information structure, and remove from commandBufferMap
3586 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003587 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003588 if (cb != dev_data->commandBufferMap.end()) {
3589 delete (*cb).second;
3590 dev_data->commandBufferMap.erase(cb);
3591 }
3592
3593 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003594 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003595 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003596 }
3597
3598 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3599}
3600
3601VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3602{
3603 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3604
3605 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3606
3607 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003608 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003609 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003610 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003611 }
3612 return result;
3613}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003614// Destroy commandPool along with all of the commandBuffers allocated from that pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003615VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3616{
3617 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003618 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003619
3620 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3621 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003622 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003623 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3624 delete (*del_cb).second; // delete CB info structure
3625 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003626 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003627 }
3628 }
3629 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003630
3631 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003632 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003633}
3634
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003635VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3636 VkDevice device,
3637 VkCommandPool commandPool,
3638 VkCommandPoolResetFlags flags)
3639{
3640 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003641 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003642
3643 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3644 // Reset all of the CBs allocated from this pool
3645 if (VK_SUCCESS == result) {
3646 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3647 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3648 resetCB(dev_data, (*it));
3649 ++it;
3650 }
3651 }
3652 return result;
3653}
3654
Chia-I Wu9ab61502015-11-06 06:42:02 +08003655VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003656{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003657 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 -06003658 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003659}
3660
Chia-I Wu9ab61502015-11-06 06:42:02 +08003661VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003662{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003663 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 -06003664 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003665}
3666
Chia-I Wu9ab61502015-11-06 06:42:02 +08003667VK_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 -06003668{
3669 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003670 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003671 if (VK_SUCCESS == result) {
3672 loader_platform_thread_lock_mutex(&globalLock);
3673 // 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 -07003674 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3675 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003676 loader_platform_thread_unlock_mutex(&globalLock);
3677 }
3678 return result;
3679}
3680
Chia-I Wu9ab61502015-11-06 06:42:02 +08003681VK_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 -06003682{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003683 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003684 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003685 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003686 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003687 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003688 loader_platform_thread_unlock_mutex(&globalLock);
3689 }
3690 return result;
3691}
3692
Chia-I Wu9ab61502015-11-06 06:42:02 +08003693VK_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 -06003694{
3695 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003696 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003697 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003698 IMAGE_NODE* image_node = new IMAGE_NODE;
3699 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07003700 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003701 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003702 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003703 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003704 loader_platform_thread_unlock_mutex(&globalLock);
3705 }
3706 return result;
3707}
3708
Chia-I Wu9ab61502015-11-06 06:42:02 +08003709VK_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 -06003710{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003711 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003712 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003713 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003714 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003715 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003716 loader_platform_thread_unlock_mutex(&globalLock);
3717 }
3718 return result;
3719}
3720
Jon Ashburnc669cc62015-07-09 15:02:25 -06003721//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003722VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003723 VkDevice device,
3724 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003725 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003726 VkPipelineCache* pPipelineCache)
3727{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003728 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003729 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003730 return result;
3731}
3732
Chia-I Wu9ab61502015-11-06 06:42:02 +08003733VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003734 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003735 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003736 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003737{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003738 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003739 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003740}
3741
Chia-I Wu9ab61502015-11-06 06:42:02 +08003742VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003743 VkDevice device,
3744 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003745 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003746 void* pData)
3747{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003748 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003749 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003750 return result;
3751}
3752
Chia-I Wu9ab61502015-11-06 06:42:02 +08003753VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003754 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003755 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003756 uint32_t srcCacheCount,
3757 const VkPipelineCache* pSrcCaches)
3758{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003759 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003760 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003761 return result;
3762}
3763
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003764VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3765 VkDevice device,
3766 VkPipelineCache pipelineCache,
3767 uint32_t count,
3768 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3769 const VkAllocationCallbacks *pAllocator,
3770 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003771{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003772 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003773 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003774 // The order of operations here is a little convoluted but gets the job done
3775 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3776 // 2. Create state is then validated (which uses flags setup during shadowing)
3777 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003778 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003779 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3780 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003781 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003782
Tobin Ehlis11efc302015-09-16 10:33:53 -06003783 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003784 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003785
Tobin Ehlis11efc302015-09-16 10:33:53 -06003786 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003787 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003788 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003789 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003790
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003791 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003792
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003793 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003794 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3795 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003796 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003797 for (i=0; i<count; i++) {
3798 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003799 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003800 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003801 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003802 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003803 for (i=0; i<count; i++) {
3804 if (pPipeNode[i]) {
3805 // If we allocated a pipeNode, need to clean it up here
3806 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3807 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3808 delete[] pPipeNode[i]->pAttachments;
3809 delete pPipeNode[i];
3810 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003811 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003812 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003813 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003814 return result;
3815}
3816
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003817VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3818 VkDevice device,
3819 VkPipelineCache pipelineCache,
3820 uint32_t count,
3821 const VkComputePipelineCreateInfo *pCreateInfos,
3822 const VkAllocationCallbacks *pAllocator,
3823 VkPipeline *pPipelines)
3824{
3825 VkResult result = VK_SUCCESS;
3826 VkBool32 skipCall = VK_FALSE;
3827
3828 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3829 vector<PIPELINE_NODE*> pPipeNode(count);
3830 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3831
3832 uint32_t i=0;
3833 loader_platform_thread_lock_mutex(&globalLock);
3834 for (i=0; i<count; i++) {
3835 // TODO: Verify compute stage bits
3836
3837 // Create and initialize internal tracking data structure
3838 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003839 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3840
3841 // TODO: Add Compute Pipeline Verification
3842 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3843 }
3844 loader_platform_thread_unlock_mutex(&globalLock);
3845
3846 if (VK_FALSE == skipCall) {
3847 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3848 loader_platform_thread_lock_mutex(&globalLock);
3849 for (i=0; i<count; i++) {
3850 pPipeNode[i]->pipeline = pPipelines[i];
3851 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3852 }
3853 loader_platform_thread_unlock_mutex(&globalLock);
3854 } else {
3855 for (i=0; i<count; i++) {
3856 if (pPipeNode[i]) {
3857 // Clean up any locally allocated data structures
3858 delete pPipeNode[i];
3859 }
3860 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003861 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003862 }
3863 return result;
3864}
3865
Chia-I Wu9ab61502015-11-06 06:42:02 +08003866VK_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 -06003867{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003868 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003869 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003870 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003871 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003872 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003873 loader_platform_thread_unlock_mutex(&globalLock);
3874 }
3875 return result;
3876}
3877
Chia-I Wu9ab61502015-11-06 06:42:02 +08003878VK_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 -06003879{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003880 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003881 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003882 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003883 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003884 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3885 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003886 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 -06003887 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003888 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003889 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003890 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003891 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3892 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003893 // g++ does not like reserve with size 0
3894 if (pCreateInfo->bindingCount)
3895 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003896 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003897 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003898 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003899 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 +08003900 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003901 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003902 }
3903
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003904 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3905 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3906 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3907 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3908 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003909 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003910 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003911 pNewNode->layout = *pSetLayout;
3912 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003913 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003914 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003915 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003916 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003917 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003918 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003919 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003920 dType = pCreateInfo->pBindings[i].descriptorType;
3921 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003922 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003923 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003924 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3925 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3926 pNewNode->dynamicDescriptorCount++;
3927 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003928 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003929 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003930 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003931 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3932 } else { // no descriptors
3933 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003934 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003935 // Put new node at Head of global Layer list
3936 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003937 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003938 loader_platform_thread_unlock_mutex(&globalLock);
3939 }
3940 return result;
3941}
3942
Chia-I Wu9ab61502015-11-06 06:42:02 +08003943VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003944{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003945 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003946 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003947 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003948 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003949 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003950 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003951 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003952 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003953 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3954 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003955 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003956 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3957 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3958 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003959 }
3960 return result;
3961}
3962
Chia-I Wu9ab61502015-11-06 06:42:02 +08003963VK_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 -06003964{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003965 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003966 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003967 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003968 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003969 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 +08003970 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003971 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003972 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003973 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003974 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003975 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 -07003976 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003977 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003978 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003979 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003980 }
3981 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003982 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003983 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003984 }
3985 return result;
3986}
3987
Chia-I Wu9ab61502015-11-06 06:42:02 +08003988VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
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);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003991 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003992 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003993 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003994 }
3995 return result;
3996}
3997
Chia-I Wu9ab61502015-11-06 06:42:02 +08003998VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003999{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004000 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004001 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004002 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07004003 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004004 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004005 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 +08004006 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004007 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07004008 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004009 }
4010 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004011 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004012 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06004013 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004014 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004015 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004016 if (pAllocateInfo->descriptorSetCount == 0) {
4017 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 +08004018 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06004019 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004020 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004021 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 +08004022 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004023 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004024 SET_NODE* pNewNode = new SET_NODE;
4025 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004026 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 +08004027 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004028 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004029 } else {
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06004030 // TODO : Pool should store a total count of each type of Descriptor available
4031 // When descriptors are allocated, decrement the count and validate here
4032 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004033 // Insert set at head of Set LL for this pool
4034 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004035 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004036 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004037 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004038 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004039 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 +08004040 "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 -07004041 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004042 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004043 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004044 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004045 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004046 pNewNode->descriptorCount = pLayout->endIndex + 1;
4047 if (pNewNode->descriptorCount) {
4048 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4049 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
4050 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4051 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004052 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004053 }
4054 }
4055 }
4056 }
4057 return result;
4058}
4059
Chia-I Wu9ab61502015-11-06 06:42:02 +08004060VK_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 -06004061{
Tobin Ehlise735c692015-10-08 13:13:50 -06004062 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004063 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004064 // Make sure that no sets being destroyed are in-flight
4065 for (uint32_t i=0; i<count; ++i)
4066 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004067 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004068 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
4069 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004070 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 -06004071 "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 -06004072 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004073 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004074 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004075 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004076 if (VK_SUCCESS == result) {
4077 // For each freed descriptor add it back into the pool as available
4078 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08004079 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004080 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004081 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004082 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004083 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4084 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004085 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004086 }
4087 }
4088 }
4089 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004090 return result;
4091}
4092
Chia-I Wu9ab61502015-11-06 06:42:02 +08004093VK_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 -06004094{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004095 // 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 -06004096 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08004097 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4098 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004099 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004100}
4101
Chia-I Wu9ab61502015-11-06 06:42:02 +08004102VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004103{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004104 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004105 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004106 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004107 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004108 // Validate command pool
4109 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004110 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004111 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004112 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004113 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
4114 // Add command buffer to map
4115 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004116 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004117 resetCB(dev_data, pCommandBuffer[i]);
4118 pCB->commandBuffer = pCommandBuffer[i];
4119 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004120 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004121 }
4122 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004123 }
4124 return result;
4125}
4126
Chia-I Wu9ab61502015-11-06 06:42:02 +08004127VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004128{
Mark Youngb20a6a82016-01-07 15:41:43 -07004129 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004130 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004131 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004132 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004133 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004134 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4135 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004136 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4137 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4138 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004139 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004140 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004141 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004142 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 -07004143 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4144 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004145 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004146 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 -07004147 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4148 } else {
4149 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004150 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4151 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004152 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004153 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 -07004154 "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 -07004155 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004156 }
4157 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004158 }
4159 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004160 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004161 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 -07004162 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4163 } else if (CB_RECORDED == pCB->state) {
4164 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4165 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004166 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 -07004167 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004168 "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.",
4169 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4170 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004171 resetCB(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004172 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004173 // Set updated state here in case implicit reset occurs above
4174 pCB->state = CB_RECORDING;
4175 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004176
4177 if (pCB->beginInfo.pInheritanceInfo) {
4178 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4179 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4180 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004181 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004182 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 +08004183 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004184 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004185 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004186 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004187 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004188 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004189 return result;
4190}
4191
Chia-I Wu9ab61502015-11-06 06:42:02 +08004192VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004193{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004194 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004195 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004196 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4197 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004198 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004199 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004200 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004201 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004202 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004203 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004204 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004205 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004206 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004207 // Reset CB status flags
4208 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004209 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004210 }
4211 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004212 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004213 }
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 vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004218{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004219 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004220 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004221 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4222 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4223 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004224 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 -07004225 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004226 "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.",
4227 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4228 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004229 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004230 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004231 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004232 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004233 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004234 }
4235 return result;
4236}
4237
Chia-I Wu9ab61502015-11-06 06:42:02 +08004238VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004239{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004240 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004241 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4242 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004243 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004244 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4245 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4246 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 -07004247 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004248 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4249 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4250 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4251 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4252 }
4253
4254 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4255 if (pPN) {
4256 pCB->lastBoundPipeline = pipeline;
4257 loader_platform_thread_lock_mutex(&globalLock);
4258 set_cb_pso_status(pCB, pPN);
4259 loader_platform_thread_unlock_mutex(&globalLock);
4260 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004261 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004262 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 -07004263 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07004264 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004265 }
4266 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004267 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004268 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004269}
4270
Chia-I Wu9ab61502015-11-06 06:42:02 +08004271VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004272 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004273 uint32_t firstViewport,
4274 uint32_t viewportCount,
4275 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004276{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004277 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004278 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4279 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004280 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004281 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4282 loader_platform_thread_lock_mutex(&globalLock);
4283 pCB->status |= CBSTATUS_VIEWPORT_SET;
4284 pCB->viewports.resize(viewportCount);
4285 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4286 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004287 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004288 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004289 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004290}
4291
Chia-I Wu9ab61502015-11-06 06:42:02 +08004292VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004293 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004294 uint32_t firstScissor,
4295 uint32_t scissorCount,
4296 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004297{
4298 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004299 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4300 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004301 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004302 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4303 loader_platform_thread_lock_mutex(&globalLock);
4304 pCB->status |= CBSTATUS_SCISSOR_SET;
4305 pCB->scissors.resize(scissorCount);
4306 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4307 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004308 }
4309 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004310 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004311}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004312
Chia-I Wu9ab61502015-11-06 06:42:02 +08004313VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004314{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004315 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004316 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4317 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004318 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004319 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4320 /* TODO: Do we still need this lock? */
4321 loader_platform_thread_lock_mutex(&globalLock);
4322 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4323 pCB->lineWidth = lineWidth;
4324 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004325 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004326 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004327 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004328}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004329
Chia-I Wu9ab61502015-11-06 06:42:02 +08004330VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004331 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004332 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004333 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004334 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004335{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004336 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004337 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4338 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004339 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004340 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4341 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4342 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4343 pCB->depthBiasClamp = depthBiasClamp;
4344 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004345 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004346 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004347 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004348}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004349
Chia-I Wu9ab61502015-11-06 06:42:02 +08004350VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004351{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004352 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004353 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4354 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004355 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004356 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4357 pCB->status |= CBSTATUS_BLEND_SET;
4358 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004359 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004360 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004361 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004362}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004363
Chia-I Wu9ab61502015-11-06 06:42:02 +08004364VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004365 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004366 float minDepthBounds,
4367 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004368{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004369 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004370 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4371 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004372 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004373 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4374 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4375 pCB->minDepthBounds = minDepthBounds;
4376 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004377 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004378 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004379 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004380}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004381
Chia-I Wu9ab61502015-11-06 06:42:02 +08004382VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004383 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004384 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004385 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004386{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004387 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004388 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4389 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004390 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004391 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4392 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4393 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004394 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004395 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4396 pCB->back.compareMask = compareMask;
4397 }
4398 /* TODO: Do we need to track front and back separately? */
4399 /* TODO: We aren't capturing the faceMask, do we need to? */
4400 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004401 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004402 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004403 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004404}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004405
Chia-I Wu9ab61502015-11-06 06:42:02 +08004406VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004407 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004408 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004409 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004410{
4411 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004412 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4413 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004414 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004415 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4416 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4417 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004418 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004419 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4420 pCB->back.writeMask = writeMask;
4421 }
4422 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004423 }
4424 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004425 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004426}
4427
Chia-I Wu9ab61502015-11-06 06:42:02 +08004428VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004429 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004430 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004431 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004432{
4433 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004434 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4435 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004436 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004437 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4438 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4439 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004440 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004441 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4442 pCB->back.reference = reference;
4443 }
4444 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004445 }
4446 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004447 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004448}
4449
Chia-I Wu9ab61502015-11-06 06:42:02 +08004450VK_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 -06004451{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004452 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004453 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4454 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004455 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004456 if (pCB->state == CB_RECORDING) {
4457 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004458 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 -07004459 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4460 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4461 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004462 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004463 if (VK_FALSE == skipCall) {
4464 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4465 uint32_t totalDynamicDescriptors = 0;
4466 string errorString = "";
4467 uint32_t lastSetIndex = firstSet+setCount-1;
4468 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004469 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004470 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4471 for (uint32_t i=0; i<setCount; i++) {
4472 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4473 if (pSet) {
4474 loader_platform_thread_lock_mutex(&globalLock);
4475 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4476 pCB->lastBoundPipelineLayout = layout;
4477 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4478 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004479 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 -07004480 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004481 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004482 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 -07004483 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4484 }
4485 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4486 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004487 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 -07004488 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4489 }
4490 if (pSet->pLayout->dynamicDescriptorCount) {
4491 // First make sure we won't overstep bounds of pDynamicOffsets array
4492 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004493 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 -07004494 "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.",
4495 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004496 } else { // Validate and store dynamic offsets with the set
4497 // Validate Dynamic Offset Minimums
4498 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4499 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4500 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4501 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4502 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4503 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4504 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4505 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4506 }
4507 cur_dyn_offset++;
4508 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4509 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4510 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4511 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4512 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4513 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4514 }
4515 cur_dyn_offset++;
4516 }
4517 }
4518 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004519 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4520 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4521 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4522 }
4523 }
4524 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004525 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 -07004526 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4527 }
4528 }
4529 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4530 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4531 if (firstSet > 0) { // Check set #s below the first bound set
4532 for (uint32_t i=0; i<firstSet; ++i) {
4533 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 -07004534 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 -07004535 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4536 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4537 }
4538 }
4539 }
4540 // Check if newly last bound set invalidates any remaining bound sets
4541 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4542 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004543 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 -07004544 "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);
4545 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4546 }
4547 }
4548 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4549 if (totalDynamicDescriptors != dynamicOffsetCount) {
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_COMMAND_BUFFER_EXT, (uint64_t) commandBuffer, __LINE__, DRAWSTATE_INVALID_DYNAMIC_OFFSET_COUNT, "DS",
Tobin Ehlisf6585052015-12-17 11:48:42 -07004551 "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 -07004552 }
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004553 validateAndIncrementDescriptorSets(dev_data, pCB);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004554 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004555 } else {
4556 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004557 }
4558 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004559 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004560 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004561}
4562
Chia-I Wu9ab61502015-11-06 06:42:02 +08004563VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004564{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004565 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004566 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4567 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004568 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004569 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4570 VkDeviceSize offset_align = 0;
4571 switch (indexType) {
4572 case VK_INDEX_TYPE_UINT16:
4573 offset_align = 2;
4574 break;
4575 case VK_INDEX_TYPE_UINT32:
4576 offset_align = 4;
4577 break;
4578 default:
4579 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4580 break;
4581 }
4582 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004583 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 -07004584 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004585 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004586 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004587 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004588 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004589 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004590}
4591
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004592void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4593 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004594 if (pCB->currentDrawData.buffers.size() < end) {
4595 pCB->currentDrawData.buffers.resize(end);
4596 }
4597 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004598 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004599 }
4600}
4601
4602void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4603 pCB->drawData.push_back(pCB->currentDrawData);
4604}
4605
Chia-I Wu9ab61502015-11-06 06:42:02 +08004606VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004607 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004608 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004609 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004610 const VkBuffer *pBuffers,
4611 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004612{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004613 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004614 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4615 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004616 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004617 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004618 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004619 } else {
Mark Youngad779052016-01-06 14:26:04 -07004620 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004621 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004622 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004623 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004624}
4625
Chia-I Wu9ab61502015-11-06 06:42:02 +08004626VK_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 -06004627{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004628 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004629 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4630 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004631 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004632 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4633 pCB->drawCount[DRAW]++;
4634 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4635 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004636 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 -07004637 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4638 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004639 if (VK_FALSE == skipCall) {
4640 updateResourceTrackingOnDraw(pCB);
4641 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004642 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004643 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004644 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004645 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004646}
4647
Chia-I Wu9ab61502015-11-06 06:42:02 +08004648VK_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 -06004649{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004650 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4651 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004652 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004653 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004654 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4655 pCB->drawCount[DRAW_INDEXED]++;
4656 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4657 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004658 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 -07004659 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4660 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004661 if (VK_FALSE == skipCall) {
4662 updateResourceTrackingOnDraw(pCB);
4663 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004664 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004665 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004666 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004667 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004668}
4669
Chia-I Wu9ab61502015-11-06 06:42:02 +08004670VK_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 -06004671{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004672 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4673 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004674 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004675 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004676 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4677 pCB->drawCount[DRAW_INDIRECT]++;
4678 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4679 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004680 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 -07004681 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4682 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004683 if (VK_FALSE == skipCall) {
4684 updateResourceTrackingOnDraw(pCB);
4685 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004686 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004687 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004688 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004689 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004690}
4691
Chia-I Wu9ab61502015-11-06 06:42:02 +08004692VK_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 -06004693{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004694 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004695 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4696 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004697 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004698 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4699 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4700 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4701 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004702 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 -07004703 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4704 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004705 if (VK_FALSE == skipCall) {
4706 updateResourceTrackingOnDraw(pCB);
4707 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004708 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004709 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004710 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004711 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004712}
4713
Chia-I Wu9ab61502015-11-06 06:42:02 +08004714VK_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 -06004715{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004716 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004717 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4718 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004719 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004720 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004721 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004722 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004723 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004724 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004725}
4726
Chia-I Wu9ab61502015-11-06 06:42:02 +08004727VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004728{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004729 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004730 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4731 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004732 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004733 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004734 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004735 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004736 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004737 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004738}
4739
Chia-I Wu9ab61502015-11-06 06:42:02 +08004740VK_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 -06004741{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004742 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004743 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4744 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004745 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004746 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004747 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004748 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004749 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004750 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004751}
4752
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004753VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004754 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004755
4756#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4757 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4758 return skip_call;
4759#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4760
Michael Lentineabc5e922015-10-12 11:30:14 -05004761 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4762 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4763 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4764 if (src_image_element == pCB->imageLayoutMap.end()) {
4765 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4766 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004767 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004768 }
4769 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004770 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 -05004771 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4772 }
4773 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4774 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004775 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004776 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 -05004777 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004778 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004779 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 -05004780 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004781 }
4782 }
4783 return skip_call;
4784}
4785
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004786VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004787 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004788
4789#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4790 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4791 return skip_call;
4792#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4793
Michael Lentineabc5e922015-10-12 11:30:14 -05004794 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4795 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4796 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4797 if (dest_image_element == pCB->imageLayoutMap.end()) {
4798 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4799 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004800 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004801 }
4802 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004803 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 -05004804 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4805 }
4806 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4807 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004808 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004809 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 -05004810 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4811 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004812 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 -05004813 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4814 }
4815 }
4816 return skip_call;
4817}
4818
Chia-I Wu9ab61502015-11-06 06:42:02 +08004819VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004820 VkImage srcImage,
4821 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004822 VkImage dstImage,
4823 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004824 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004825{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004826 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004827 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4828 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004829 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004830 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004831 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004832 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4833 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004834 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004835 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004836 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004837}
4838
Chia-I Wu9ab61502015-11-06 06:42:02 +08004839VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004840 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004841 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004842 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004843 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004844{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004845 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004846 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4847 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004848 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004849 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004850 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004851 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004852 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004853 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004854}
4855
Chia-I Wu9ab61502015-11-06 06:42:02 +08004856VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004857 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004858 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004859 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004860{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004861 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004862 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4863 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004864 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004865 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004866 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004867 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004868 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004869 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004870 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004871}
4872
Chia-I Wu9ab61502015-11-06 06:42:02 +08004873VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004874 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004875 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004876 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004877{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004878 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004879 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4880 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004881 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004882 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004883 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004884 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004885 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004886 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004887 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004888}
4889
Chia-I Wu9ab61502015-11-06 06:42:02 +08004890VK_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 -06004891{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004892 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004893 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4894 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004895 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004896 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004897 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004898 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004899 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004900 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004901}
4902
Chia-I Wu9ab61502015-11-06 06:42:02 +08004903VK_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 -06004904{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004905 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004906 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4907 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004908 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004909 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004910 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004911 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004912 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004913 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004914}
4915
Chia-I Wu9ab61502015-11-06 06:42:02 +08004916VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004917 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004918 uint32_t attachmentCount,
4919 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004920 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004921 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004922{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004923 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004924 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4925 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004926 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004927 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4928 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4929 if (!hasDrawCmd(pCB) &&
4930 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4931 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4932 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004933 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 -07004934 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Mark Youngee3f3a22016-01-25 12:18:32 -07004935 " 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 -06004936 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004937 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4938 }
4939
4940 // Validate that attachment is in reference list of active subpass
4941 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004942 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004943 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4944
4945 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4946 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4947 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4948 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004949 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004950 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4951 found = VK_TRUE;
4952 break;
4953 }
4954 }
4955 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004956 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 -07004957 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004958 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4959 attachment->colorAttachment, pCB->activeSubpass);
4960 }
4961 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004962 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004963 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004964
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004965 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 -07004966 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004967 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4968 attachment->colorAttachment,
4969 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4970 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004971 }
4972 }
4973 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004974 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004975 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004976 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004977}
4978
Chia-I Wu9ab61502015-11-06 06:42:02 +08004979VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004980 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004981 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004982 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004983 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004984{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004985 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004986 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4987 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004988 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004989 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004990 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004991 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004992 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004993 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004994}
4995
Chia-I Wu9ab61502015-11-06 06:42:02 +08004996VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004997 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004998 VkImage image, VkImageLayout imageLayout,
4999 const VkClearDepthStencilValue *pDepthStencil,
5000 uint32_t rangeCount,
5001 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005002{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005003 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005004 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5005 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005006 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005007 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005008 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005009 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005010 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005011 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005012}
5013
Chia-I Wu9ab61502015-11-06 06:42:02 +08005014VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005015 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005016 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06005017 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005018{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005019 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005020 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5021 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005022 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005023 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005024 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005025 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005026 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005027 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005028}
5029
Chia-I Wu9ab61502015-11-06 06:42:02 +08005030VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005031{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005032 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005033 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5034 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005035 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005036 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005037 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005038 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005039 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005040 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005041}
5042
Chia-I Wu9ab61502015-11-06 06:42:02 +08005043VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005044{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005045 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005046 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5047 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005048 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005049 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005050 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005051 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005052 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005053 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005054}
5055
Jon Ashburnf19916e2016-01-11 13:12:43 -07005056VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005057 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5058 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07005059 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005060
5061#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5062 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
5063 return skip;
5064#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5065
Michael Lentineabc5e922015-10-12 11:30:14 -05005066 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005067 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005068 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005069 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005070 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005071 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5072 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005073 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005074 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005075 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 -07005076 "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 -05005077 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005078 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005079 }
5080 }
5081 }
5082 return skip;
5083}
5084
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005085// Print readable FlagBits in FlagMask
5086std::string string_VkAccessFlags(VkAccessFlags accessMask)
5087{
5088 std::string result;
5089 std::string separator;
5090
5091 if (accessMask == 0) {
5092 result = "[None]";
5093 } else {
5094 result = "[";
5095 for (auto i = 0; i < 32; i++) {
5096 if (accessMask & (1 << i)) {
5097 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
5098 separator = " | ";
5099 }
5100 }
5101 result = result + "]";
5102 }
5103 return result;
5104}
5105
Michael Lentine97eb7462015-11-20 09:48:52 -08005106// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5107// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005108// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005109VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5110 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005111 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005112
Michael Lentine97eb7462015-11-20 09:48:52 -08005113 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
5114 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005115 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005116 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 -07005117 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5118 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005119 }
5120 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005121 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005122 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 -07005123 "%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 -07005124 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5125 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005126 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005127 std::string opt_bits;
5128 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005129 std::stringstream ss;
5130 ss << optional_bits;
5131 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005132 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005133 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 -07005134 "%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 -07005135 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5136 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005137 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005138 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005139 }
5140 return skip_call;
5141}
5142
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005143VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005144 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005145 switch (layout) {
5146 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005147 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 -08005148 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005149 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005150 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005151 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 -08005152 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005153 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005154 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005155 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005156 break;
5157 }
5158 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005159 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005160 break;
5161 }
5162 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005163 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 -08005164 break;
5165 }
5166 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005167 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 -08005168 break;
5169 }
5170 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005171 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005172 break;
5173 }
5174 case VK_IMAGE_LAYOUT_UNDEFINED: {
5175 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005176 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005177 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 -07005178 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5179 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005180 }
5181 break;
5182 }
5183 case VK_IMAGE_LAYOUT_GENERAL:
5184 default: {
5185 break;
5186 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005187 }
5188 return skip_call;
5189}
5190
Jon Ashburnf19916e2016-01-11 13:12:43 -07005191VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5192{
Mark Youngb20a6a82016-01-07 15:41:43 -07005193 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005194 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5195 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5196 if (pCB->activeRenderPass && memBarrierCount) {
5197 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005198 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005199 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005200 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 -05005201 "Image or Buffers Barriers cannot be used during a render pass.");
5202 }
5203 }
5204 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005205 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 -05005206 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5207 }
5208 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005209
Jon Ashburnf19916e2016-01-11 13:12:43 -07005210 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5211 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005212 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005213 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5214 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005215 }
5216 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005217
Michael Lentine48930b82015-10-15 17:07:00 -05005218 return skip_call;
5219}
5220
Jon Ashburnf19916e2016-01-11 13:12:43 -07005221VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5222 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5223 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5224 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5225 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5226 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005227{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005228 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005229 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5230 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005231 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005232 for (uint32_t i = 0; i < eventCount; ++i) {
5233 pCB->waitedEvents.push_back(pEvents[i]);
5234 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005235 if (pCB->state == CB_RECORDING) {
5236 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005237 } else {
5238 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5239 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005240 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5241 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005242 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005243 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005244 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5245 memoryBarrierCount, pMemoryBarriers,
5246 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5247 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005248}
5249
Jon Ashburnf19916e2016-01-11 13:12:43 -07005250VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5251 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5252 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5253 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5254 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5255 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005256{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005257 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005258 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5259 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005260 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005261 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005262 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5263 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005264 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005265 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005266 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5267 memoryBarrierCount, pMemoryBarriers,
5268 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5269 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005270}
5271
Chia-I Wu9ab61502015-11-06 06:42:02 +08005272VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005273{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005274 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005275 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5276 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005277 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005278 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005279 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005280 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005281 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005282}
5283
Chia-I Wu9ab61502015-11-06 06:42:02 +08005284VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005285{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005286 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005287 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5288 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005289 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005290 QueryObject query = {queryPool, slot};
5291 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005292 if (pCB->state == CB_RECORDING) {
5293 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005294 } else {
5295 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5296 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005297 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005298 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005299 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005300}
5301
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005302VK_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 -06005303{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005304 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005305 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5306 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005307 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005308 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005309 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005310 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5311 pCB->queryToStateMap[query] = 0;
5312 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005313 if (pCB->state == CB_RECORDING) {
5314 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005315 } else {
5316 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5317 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005318 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005319 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005320 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005321 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005322}
5323
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005324VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005325 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005326 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005327{
5328 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005329 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5330 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005331 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005332 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005333 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005334 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005335 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 -07005336 "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 -06005337 }
5338 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005339 if (pCB->state == CB_RECORDING) {
5340 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005341 } else {
5342 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5343 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005344 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005345 }
5346 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005347 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005348 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005349}
5350
Chia-I Wu9ab61502015-11-06 06:42:02 +08005351VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005352{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005353 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);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005356 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005357 QueryObject query = {queryPool, slot};
5358 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005359 if (pCB->state == CB_RECORDING) {
5360 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005361 } else {
5362 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5363 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005364 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005365 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005366 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005367}
5368
Chia-I Wu9ab61502015-11-06 06:42:02 +08005369VK_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 -06005370{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005371 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005372 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005373 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005374 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005375 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005376 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005377 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5378 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005379 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005380 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005381 }
5382 return result;
5383}
5384
Michael Lentineb6986752015-10-06 14:56:18 -07005385// Store the DAG.
5386struct DAGNode {
5387 uint32_t pass;
5388 std::vector<uint32_t> prev;
5389 std::vector<uint32_t> next;
5390};
5391
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005392VkBool32 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 -07005393 // If we have already checked this node we have not found a dependency path so return false.
5394 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005395 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005396 processed_nodes.insert(index);
5397 const DAGNode& node = subpass_to_node[index];
5398 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5399 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5400 for (auto elem : node.prev) {
5401 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005402 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005403 }
5404 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005405 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005406 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005407 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005408}
5409
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005410VkBool32 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 -07005411 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005412 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5413 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5414 if (subpass == dependent_subpasses[k])
5415 continue;
5416 const DAGNode& node = subpass_to_node[subpass];
5417 // Check for a specified dependency between the two nodes. If one exists we are done.
5418 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5419 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5420 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5421 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5422 std::unordered_set<uint32_t> processed_nodes;
5423 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5424 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005425 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005426 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 -07005427 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5428 subpass, dependent_subpasses[k]);
5429 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005430 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 -07005431 "A dependency between subpasses %d and %d must exist but one is not specified.",
5432 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005433 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005434 }
5435 }
5436 }
5437 return result;
5438}
5439
Jon Ashburnf19916e2016-01-11 13:12:43 -07005440VkBool32 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 -07005441 const DAGNode& node = subpass_to_node[index];
5442 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5443 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005444 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005445 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005446 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005447 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005448 if (subpass.pDepthStencilAttachment &&
5449 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5450 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005451 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005452 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005453 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005454 // Loop through previous nodes and see if any of them write to the attachment.
5455 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005456 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005457 }
5458 // If the attachment was written to by a previous node than this node needs to preserve it.
5459 if (result && depth > 0) {
5460 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005461 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005462 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005463 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005464 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005465 break;
5466 }
5467 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005468 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005469 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 -07005470 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5471 }
5472 }
5473 return result;
5474}
5475
Michael Lentineb4979492015-12-22 11:36:14 -06005476VkBool32 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 -07005477 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005478 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5479 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005480 // Find for each attachment the subpasses that use them.
5481 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5482 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005483 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005484 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5485 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005486 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005487 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5488 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005489 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5490 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005491 }
5492 }
5493 // If there is a dependency needed make sure one exists
5494 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5495 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5496 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005497 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005498 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005499 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005500 }
5501 // 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 +08005502 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005503 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005504 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5505 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005506 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005507 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5508 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005509 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5510 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005511 }
5512 }
5513 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5514 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5515 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005516 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005517 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005518 }
5519 }
5520 return skip_call;
5521}
5522
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005523VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005524 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005525
5526#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5527 return skip;
5528#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5529
Michael Lentineabc5e922015-10-12 11:30:14 -05005530 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5531 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5532 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5533 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5534 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5535 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005536 // 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 -07005537 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 -05005538 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5539 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005540 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 -05005541 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5542 }
5543 }
5544 }
5545 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5546 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5547 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005548 // 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 -07005549 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 -05005550 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5551 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005552 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 -05005553 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5554 }
5555 }
5556 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005557 if ((subpass.pDepthStencilAttachment != NULL) &&
5558 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005559 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5560 if (subpass.pDepthStencilAttachment->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 depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_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 depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5567 }
5568 }
5569 }
5570 }
5571 return skip;
5572}
5573
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005574VkBool32 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 -07005575 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005576 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5577 DAGNode& subpass_node = subpass_to_node[i];
5578 subpass_node.pass = i;
5579 }
5580 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5581 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Michael Lentine6bd4f122016-01-19 14:00:53 -06005582 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005583 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 -05005584 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine6bd4f122016-01-19 14:00:53 -06005585 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
5586 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5587 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05005588 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5589 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005590 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06005591 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
5592 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5593 }
5594 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
5595 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5596 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005597 }
5598 return skip_call;
5599}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005600// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005601
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005602VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5603 VkDevice device,
5604 const VkShaderModuleCreateInfo *pCreateInfo,
5605 const VkAllocationCallbacks* pAllocator,
5606 VkShaderModule *pShaderModule)
5607{
5608 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005609 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005610 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005611 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 -07005612 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005613 "Shader is not SPIR-V");
5614 }
5615
Mark Youngb20a6a82016-01-07 15:41:43 -07005616 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005617 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005618
5619 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5620
5621 if (res == VK_SUCCESS) {
5622 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005623 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005624 loader_platform_thread_unlock_mutex(&globalLock);
5625 }
5626 return res;
5627}
5628
Chia-I Wu9ab61502015-11-06 06:42:02 +08005629VK_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 -06005630{
Mark Youngb20a6a82016-01-07 15:41:43 -07005631 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005632 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005633 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005634 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005635 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005636 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005637 // Validate using DAG
5638 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5639 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005640 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005641 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005642 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005643 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005644 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005645 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005646 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005647 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005648 if (pCreateInfo->pAttachments) {
5649 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5650 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005651 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005652 if (pCreateInfo->pSubpasses) {
5653 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5654 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5655
5656 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5657 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005658 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5659 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005660 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005661 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5662
Cody Northropa505dda2015-08-04 11:16:41 -06005663 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005664 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005665 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005666 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005667
Cody Northropa505dda2015-08-04 11:16:41 -06005668 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005669 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005670 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005671 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005672
Cody Northropa505dda2015-08-04 11:16:41 -06005673 if (subpass->pResolveAttachments) {
5674 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005675 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005676 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005677 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005678 }
5679
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005680 if (subpass->pDepthStencilAttachment) {
5681 memcpy(attachments, subpass->pDepthStencilAttachment,
5682 sizeof(attachments[0]) * 1);
5683 subpass->pDepthStencilAttachment = attachments;
5684 attachments += 1;
5685 }
5686
Cody Northropa505dda2015-08-04 11:16:41 -06005687 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005688 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005689 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005690 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005691 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005692 if (pCreateInfo->pDependencies) {
5693 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5694 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005695 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005696 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005697 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005698 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005699 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005700 }
5701 return result;
5702}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005703// Free the renderpass shadow
5704static void deleteRenderPasses(layer_data* my_data)
5705{
5706 if (my_data->renderPassMap.size() <= 0)
5707 return;
5708 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005709 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005710 if (pRenderPassInfo->pAttachments) {
5711 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005712 }
Michael Lentine48930b82015-10-15 17:07:00 -05005713 if (pRenderPassInfo->pSubpasses) {
5714 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005715 // Attachements are all allocated in a block, so just need to
5716 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005717 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5718 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5719 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5720 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5721 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5722 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5723 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5724 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005725 }
5726 }
Michael Lentine48930b82015-10-15 17:07:00 -05005727 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005728 }
Michael Lentine48930b82015-10-15 17:07:00 -05005729 if (pRenderPassInfo->pDependencies) {
5730 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005731 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005732 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005733 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005734 }
5735 my_data->renderPassMap.clear();
5736}
Michael Lentineabc5e922015-10-12 11:30:14 -05005737
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005738VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005739 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005740 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5741 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005742 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005743 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5744 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005745 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 -05005746 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5747 }
5748 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5749 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5750 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5751 auto image_data = pCB->imageLayoutMap.find(image);
5752 if (image_data == pCB->imageLayoutMap.end()) {
5753 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5754 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5755 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005756 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 -05005757 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5758 }
5759 }
5760 return skip_call;
5761}
5762
5763void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5764 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5765 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5766 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5767 if (render_pass_data == dev_data->renderPassMap.end()) {
5768 return;
5769 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005770 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005771 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5772 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5773 return;
5774 }
5775 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5776 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5777 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5778 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5779 auto image_view_data = dev_data->imageViewMap.find(image_view);
5780 if (image_view_data != dev_data->imageViewMap.end()) {
5781 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5782 if (image_layout != pCB->imageLayoutMap.end()) {
5783 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5784 }
5785 }
5786 }
5787 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5788 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5789 auto image_view_data = dev_data->imageViewMap.find(image_view);
5790 if (image_view_data != dev_data->imageViewMap.end()) {
5791 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5792 if (image_layout != pCB->imageLayoutMap.end()) {
5793 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5794 }
5795 }
5796 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005797 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005798 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005799 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5800 auto image_view_data = dev_data->imageViewMap.find(image_view);
5801 if (image_view_data != dev_data->imageViewMap.end()) {
5802 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5803 if (image_layout != pCB->imageLayoutMap.end()) {
5804 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5805 }
5806 }
5807 }
5808}
5809
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005810VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005811 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005812 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005813 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 -07005814 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5815 }
5816 return skip_call;
5817}
5818
Michael Lentineabc5e922015-10-12 11:30:14 -05005819void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5820 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5821 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5822 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5823 if (render_pass_data == dev_data->renderPassMap.end()) {
5824 return;
5825 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005826 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005827 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5828 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5829 return;
5830 }
5831 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5832 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5833 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5834 auto image_view_data = dev_data->imageViewMap.find(image_view);
5835 if (image_view_data != dev_data->imageViewMap.end()) {
5836 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5837 if (image_layout != pCB->imageLayoutMap.end()) {
5838 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5839 }
5840 }
5841 }
5842}
5843
Chia-I Wu9ab61502015-11-06 06:42:02 +08005844VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005845{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005846 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005847 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5848 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005849 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005850 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005851 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005852 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005853 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005854 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005855 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005856 // This is a shallow copy as that is all that is needed for now
5857 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005858 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005859 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005860 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005861 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005862 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 -06005863 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005864 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005865 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005866 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005867 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005868 // This is a shallow copy as that is all that is needed for now
5869 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5870 dev_data->currentSubpass = 0;
5871 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005872}
5873
Chia-I Wu9ab61502015-11-06 06:42:02 +08005874VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005875{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005876 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005877 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5878 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005879 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005880 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005881 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005882 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005883 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005884 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005885 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005886 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005887 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005888 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005889 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005890 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005891 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005892 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005893}
5894
Chia-I Wu9ab61502015-11-06 06:42:02 +08005895VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005896{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005897 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005898 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5899 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005900 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005901 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005902 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005903 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005904 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005905 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005906 pCB->activeRenderPass = 0;
5907 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005908 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005909 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005910 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005911}
5912
Chia-I Wu9ab61502015-11-06 06:42:02 +08005913VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005914{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005915 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005916 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5917 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005918 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005919 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5920 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5921 // 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 -06005922 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005923 for (uint32_t i=0; i<commandBuffersCount; i++) {
5924 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005925 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005926 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 +08005927 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5928 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005929 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 +08005930 "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 -07005931 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5932 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005933 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 -07005934 "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);
5935 }
5936 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005937 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005938 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 -07005939 "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 -07005940 (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 -07005941 }
5942 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5943 // 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 -07005944 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5945 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005946 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 -07005947 "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 -07005948 (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 -07005949 }
5950 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005951 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005952 // Secondary cmdBuffers are considered pending execution starting w/ being recorded
5953 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
5954 if (dev_data->inFlightCmdBuffers.find(pSubCB->commandBuffer) != dev_data->inFlightCmdBuffers.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07005955 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",
5956 "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 -07005957 }
5958 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
5959 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
Mark Youngee3f3a22016-01-25 12:18:32 -07005960 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 -07005961 "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 -07005962 (uint64_t)(pCommandBuffers[i]), (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07005963 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5964 }
5965 }
5966 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
5967 dev_data->inFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005968 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005969 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005970 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005971 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005972 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005973 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005974}
5975
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005976VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005977 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005978 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5979 auto mem_data = dev_data->memImageMap.find(mem);
5980 if (mem_data != dev_data->memImageMap.end()) {
5981 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5982 if (image_data != dev_data->imageLayoutMap.end()) {
5983 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005984 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 -07005985 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5986 }
5987 }
5988 }
5989 return skip_call;
5990}
5991
Chia-I Wu9ab61502015-11-06 06:42:02 +08005992VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005993 VkDevice device,
5994 VkDeviceMemory mem,
5995 VkDeviceSize offset,
5996 VkDeviceSize size,
5997 VkFlags flags,
5998 void **ppData)
5999{
6000 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006001
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006002 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006003#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
6004 skip_call = ValidateMapImageLayouts(device, mem);
6005#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6006
Michael Lentine7b236262015-10-23 12:41:44 -07006007 if (VK_FALSE == skip_call) {
6008 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
6009 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006010 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07006011}
6012
Chia-I Wu9ab61502015-11-06 06:42:02 +08006013VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07006014 VkDevice device,
6015 VkImage image,
6016 VkDeviceMemory mem,
6017 VkDeviceSize memOffset)
6018{
6019 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6020 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
6021 loader_platform_thread_lock_mutex(&globalLock);
6022 dev_data->memImageMap[mem] = image;
6023 loader_platform_thread_unlock_mutex(&globalLock);
6024 return result;
6025}
6026
Michael Lentineb887b0a2015-12-29 14:12:11 -06006027
6028VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
6029 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6030 dev_data->eventMap[event].needsSignaled = false;
6031 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6032 return result;
6033}
6034
Michael Lentine15a47882016-01-06 10:05:48 -06006035VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6036 VkQueue queue,
6037 uint32_t bindInfoCount,
6038 const VkBindSparseInfo* pBindInfo,
6039 VkFence fence)
6040{
6041 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006042 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006043
6044 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6045 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6046 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
6047 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6048 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6049 } else {
6050 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",
6051 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006052 (uint64_t)(queue), (uint64_t)(bindInfo.pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006053 }
6054 }
6055 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
6056 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6057 }
6058 }
6059
Mark Youngb20a6a82016-01-07 15:41:43 -07006060 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06006061 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006062 else
6063 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006064}
6065
6066VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6067 VkDevice device,
6068 const VkSemaphoreCreateInfo* pCreateInfo,
6069 const VkAllocationCallbacks* pAllocator,
6070 VkSemaphore* pSemaphore)
6071{
6072 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6073 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
6074 if (result == VK_SUCCESS) {
6075 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
6076 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006077 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006078}
6079
Chia-I Wu9ab61502015-11-06 06:42:02 +08006080VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006081 VkDevice device,
6082 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07006083 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05006084 VkSwapchainKHR *pSwapchain)
6085{
6086 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07006087 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006088
6089 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006090 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006091 loader_platform_thread_lock_mutex(&globalLock);
6092 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6093 loader_platform_thread_unlock_mutex(&globalLock);
6094 }
6095
6096 return result;
6097}
6098
Ian Elliott05846062015-11-20 14:13:17 -07006099VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006100 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07006101 VkSwapchainKHR swapchain,
6102 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05006103{
6104 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006105
6106 loader_platform_thread_lock_mutex(&globalLock);
6107 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
6108 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6109 if (swapchain_data->second->images.size() > 0) {
6110 for (auto swapchain_image : swapchain_data->second->images) {
6111 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
6112 if (image_item != dev_data->imageLayoutMap.end())
6113 dev_data->imageLayoutMap.erase(image_item);
6114 }
6115 }
6116 delete swapchain_data->second;
6117 dev_data->device_extensions.swapchainMap.erase(swapchain);
6118 }
6119 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07006120 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006121}
6122
Chia-I Wu9ab61502015-11-06 06:42:02 +08006123VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006124 VkDevice device,
6125 VkSwapchainKHR swapchain,
6126 uint32_t* pCount,
6127 VkImage* pSwapchainImages)
6128{
6129 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6130 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
6131
6132 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6133 // This should never happen and is checked by param checker.
6134 if (!pCount) return result;
6135 for (uint32_t i = 0; i < *pCount; ++i) {
6136 IMAGE_NODE* image_node = new IMAGE_NODE;
6137 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6138 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006139 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
6140 image_node->format = swapchain_node->createInfo.imageFormat;
6141 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006142 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6143 loader_platform_thread_unlock_mutex(&globalLock);
6144 }
6145 }
6146 return result;
6147}
6148
Ian Elliott05846062015-11-20 14:13:17 -07006149VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05006150{
6151 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006152 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006153
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006154#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006155 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006156 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6157 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6158 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6159 } else {
6160 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",
6161 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006162 (uint64_t)(queue), (uint64_t)(pPresentInfo->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006163 }
6164 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006165 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006166 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6167 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6168 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006169 auto image_data = dev_data->imageLayoutMap.find(image);
6170 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006171 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006172 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 -05006173 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6174 }
6175 }
6176 }
6177 }
6178 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006179#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006180
6181 if (VK_FALSE == skip_call)
6182 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006183 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006184}
6185
Michael Lentine15a47882016-01-06 10:05:48 -06006186VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6187 VkDevice device,
6188 VkSwapchainKHR swapchain,
6189 uint64_t timeout,
6190 VkSemaphore semaphore,
6191 VkFence fence,
6192 uint32_t* pImageIndex)
6193{
6194 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6195 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6196 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006197 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006198}
6199
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006200VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6201 VkInstance instance,
6202 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6203 const VkAllocationCallbacks* pAllocator,
6204 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006205{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006206 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006207 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006208 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006209 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006210 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006211 }
6212 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006213}
6214
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006215VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006216 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006217 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006218 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006219{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006220 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006221 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006222 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006223 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006224}
6225
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006226VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006227 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006228 VkDebugReportFlagsEXT flags,
6229 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006230 uint64_t object,
6231 size_t location,
6232 int32_t msgCode,
6233 const char* pLayerPrefix,
6234 const char* pMsg)
6235{
6236 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006237 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006238}
6239
Chia-I Wu9ab61502015-11-06 06:42:02 +08006240VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006241{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006242 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006243 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6244 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006245 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006246 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 -06006247 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006248 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006249 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006250 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006251 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006252 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006253 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006254}
6255
Chia-I Wu9ab61502015-11-06 06:42:02 +08006256VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006257{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006258 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006259 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6260 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006261 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006262 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 -06006263 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006264 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006265 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006266 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006267 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006268 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006269 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006270}
6271
Chia-I Wu9ab61502015-11-06 06:42:02 +08006272VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006273{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006274 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006275 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006276 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006277 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006278 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006279 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006280 if (!strcmp(funcName, "vkWaitForFences"))
6281 return (PFN_vkVoidFunction) vkWaitForFences;
6282 if (!strcmp(funcName, "vkGetFenceStatus"))
6283 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006284 if (!strcmp(funcName, "vkQueueWaitIdle"))
6285 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6286 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6287 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006288 if (!strcmp(funcName, "vkGetDeviceQueue"))
6289 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006290 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006291 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006292 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006293 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006294 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006295 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006296 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006297 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006298 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006299 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006300 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006301 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006302 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006303 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006304 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006305 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006306 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006307 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006308 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006309 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006310 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006311 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006312 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006313 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006314 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006315 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006316 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006317 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006318 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006319 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006320 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006321 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006322 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006323 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006324 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006325 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006326 if (!strcmp(funcName, "vkCreateBuffer"))
6327 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006328 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006329 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006330 if (!strcmp(funcName, "vkCreateImage"))
6331 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006332 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006333 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006334 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006335 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006336 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006337 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006338 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006339 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006340 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006341 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006342 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006343 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006344 if (!strcmp(funcName, "vkCreateComputePipelines"))
6345 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006346 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006347 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006348 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006349 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006350 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006351 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006352 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006353 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006354 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006355 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006356 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6357 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006358 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6359 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006360 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006361 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006362 if (!strcmp(funcName, "vkCreateCommandPool"))
6363 return (PFN_vkVoidFunction) vkCreateCommandPool;
6364 if (!strcmp(funcName, "vkDestroyCommandPool"))
6365 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006366 if (!strcmp(funcName, "vkResetCommandPool"))
6367 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006368 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6369 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006370 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6371 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006372 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006373 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006374 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006375 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006376 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006377 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006378 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006379 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006380 if (!strcmp(funcName, "vkCmdSetViewport"))
6381 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006382 if (!strcmp(funcName, "vkCmdSetScissor"))
6383 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006384 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6385 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6386 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6387 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6388 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6389 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6390 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6391 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6392 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6393 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6394 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6395 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6396 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6397 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006398 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006399 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006400 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006401 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006402 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006403 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006404 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006405 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006406 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006407 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006408 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006409 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006410 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006411 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006412 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006413 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006414 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006415 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006416 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006417 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006418 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006419 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006420 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006421 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006422 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006423 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006424 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006425 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006426 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006427 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006428 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006429 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006430 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006431 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006432 if (!strcmp(funcName, "vkCmdClearAttachments"))
6433 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006434 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006435 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006436 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006437 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006438 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006439 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006440 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006441 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006442 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006443 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006444 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006445 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006446 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006447 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006448 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006449 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006450 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006451 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006452 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006453 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006454 if (!strcmp(funcName, "vkCreateShaderModule"))
6455 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006456 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006457 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006458 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006459 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006460 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006461 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006462 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006463 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006464 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6465 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006466 if (!strcmp(funcName, "vkSetEvent"))
6467 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006468 if (!strcmp(funcName, "vkMapMemory"))
6469 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006470 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6471 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006472 if (!strcmp(funcName, "vkBindImageMemory"))
6473 return (PFN_vkVoidFunction) vkBindImageMemory;
6474 if (!strcmp(funcName, "vkQueueBindSparse"))
6475 return (PFN_vkVoidFunction) vkQueueBindSparse;
6476 if (!strcmp(funcName, "vkCreateSemaphore"))
6477 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006478
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006479 if (dev == NULL)
6480 return NULL;
6481
6482 layer_data *dev_data;
6483 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6484
Michael Lentineabc5e922015-10-12 11:30:14 -05006485 if (dev_data->device_extensions.wsi_enabled)
6486 {
6487 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6488 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6489 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6490 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6491 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6492 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006493 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6494 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006495 if (!strcmp(funcName, "vkQueuePresentKHR"))
6496 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6497 }
6498
Tobin Ehlis0b632332015-10-07 09:38:40 -06006499 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6500 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006501 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006502 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006503 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006504 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006505 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006506 }
6507 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006508 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006509 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006510 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006511 }
6512}
6513
Chia-I Wu9ab61502015-11-06 06:42:02 +08006514VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006515{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006516 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006517 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006518 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
6519 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006520 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006521 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006522 if (!strcmp(funcName, "vkCreateDevice"))
6523 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006524 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006525 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006526 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6527 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6528 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6529 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6530 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6531 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6532 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6533 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006534
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006535 if (instance == NULL)
6536 return NULL;
6537
6538 PFN_vkVoidFunction fptr;
6539
6540 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006541 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006542 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006543 if (fptr)
6544 return fptr;
6545
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006546 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
6547 if (pTable->GetInstanceProcAddr == NULL)
6548 return NULL;
6549 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006550}