blob: 62a3477356091cfbe96aafe19505d2824bd99346 [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;
Michael Lentineb887b0a2015-12-29 14:12:11 -060098 unordered_set<VkCommandBuffer> inFlightCmdBuffers;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -060099 // Layer specific data
Mark Lobodzinski39298632015-11-18 08:38:27 -0700100 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
101 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
102 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
103 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700104 unordered_map<VkBuffer, BUFFER_NODE> bufferMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700105 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700106 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700107 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
108 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700109 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700110 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
111 unordered_map<VkDeviceMemory, VkImage> memImageMap;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -0700112 unordered_map<VkFence, FENCE_NODE> fenceMap;
113 unordered_map<VkQueue, QUEUE_NODE> queueMap;
114 unordered_map<VkDevice, DEVICE_NODE> deviceMap;
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 Forbes79b37f82016-01-18 08:56:09 +1300138build_type_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]; }
149 uint32_t offset() { return it - zero; }
150
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
182 * trees requires jumping all over the instruction stream.
183 */
184 unordered_map<unsigned, unsigned> type_def_index;
185
186 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
187 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
188 type_def_index() {
189
Chris Forbes79b37f82016-01-18 08:56:09 +1300190 build_type_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
199 spirv_inst_iter get_type_def(unsigned type_id) const {
200 auto it = type_def_index.find(type_id);
201 if (it == type_def_index.end()) {
202 return end();
203 }
204 return at(it->second);
205 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700206};
207
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600208// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700209static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600210
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600211static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
212// TODO : This can be much smarter, using separate locks for separate global data
213static int globalLockInitialized = 0;
214static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600215#define MAX_TID 513
216static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
217static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600218
219template layer_data *get_my_data_ptr<layer_data>(
220 void *data_key,
221 std::unordered_map<void *, layer_data *> &data_map);
222
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600223// Map actual TID to an index value and return that index
224// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
225static uint32_t getTIDIndex() {
226 loader_platform_thread_id tid = loader_platform_get_thread_id();
227 for (uint32_t i = 0; i < g_maxTID; i++) {
228 if (tid == g_tidMapping[i])
229 return i;
230 }
231 // Don't yet have mapping, set it and return newly set index
232 uint32_t retVal = (uint32_t) g_maxTID;
233 g_tidMapping[g_maxTID++] = tid;
234 assert(g_maxTID < MAX_TID);
235 return retVal;
236}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700237
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600238// Return a string representation of CMD_TYPE enum
239static string cmdTypeToString(CMD_TYPE cmd)
240{
241 switch (cmd)
242 {
243 case CMD_BINDPIPELINE:
244 return "CMD_BINDPIPELINE";
245 case CMD_BINDPIPELINEDELTA:
246 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600247 case CMD_SETVIEWPORTSTATE:
248 return "CMD_SETVIEWPORTSTATE";
249 case CMD_SETLINEWIDTHSTATE:
250 return "CMD_SETLINEWIDTHSTATE";
251 case CMD_SETDEPTHBIASSTATE:
252 return "CMD_SETDEPTHBIASSTATE";
253 case CMD_SETBLENDSTATE:
254 return "CMD_SETBLENDSTATE";
255 case CMD_SETDEPTHBOUNDSSTATE:
256 return "CMD_SETDEPTHBOUNDSSTATE";
257 case CMD_SETSTENCILREADMASKSTATE:
258 return "CMD_SETSTENCILREADMASKSTATE";
259 case CMD_SETSTENCILWRITEMASKSTATE:
260 return "CMD_SETSTENCILWRITEMASKSTATE";
261 case CMD_SETSTENCILREFERENCESTATE:
262 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600263 case CMD_BINDDESCRIPTORSETS:
264 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600265 case CMD_BINDINDEXBUFFER:
266 return "CMD_BINDINDEXBUFFER";
267 case CMD_BINDVERTEXBUFFER:
268 return "CMD_BINDVERTEXBUFFER";
269 case CMD_DRAW:
270 return "CMD_DRAW";
271 case CMD_DRAWINDEXED:
272 return "CMD_DRAWINDEXED";
273 case CMD_DRAWINDIRECT:
274 return "CMD_DRAWINDIRECT";
275 case CMD_DRAWINDEXEDINDIRECT:
276 return "CMD_DRAWINDEXEDINDIRECT";
277 case CMD_DISPATCH:
278 return "CMD_DISPATCH";
279 case CMD_DISPATCHINDIRECT:
280 return "CMD_DISPATCHINDIRECT";
281 case CMD_COPYBUFFER:
282 return "CMD_COPYBUFFER";
283 case CMD_COPYIMAGE:
284 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600285 case CMD_BLITIMAGE:
286 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600287 case CMD_COPYBUFFERTOIMAGE:
288 return "CMD_COPYBUFFERTOIMAGE";
289 case CMD_COPYIMAGETOBUFFER:
290 return "CMD_COPYIMAGETOBUFFER";
291 case CMD_CLONEIMAGEDATA:
292 return "CMD_CLONEIMAGEDATA";
293 case CMD_UPDATEBUFFER:
294 return "CMD_UPDATEBUFFER";
295 case CMD_FILLBUFFER:
296 return "CMD_FILLBUFFER";
297 case CMD_CLEARCOLORIMAGE:
298 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600299 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600300 return "CMD_CLEARCOLORATTACHMENT";
301 case CMD_CLEARDEPTHSTENCILIMAGE:
302 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600303 case CMD_RESOLVEIMAGE:
304 return "CMD_RESOLVEIMAGE";
305 case CMD_SETEVENT:
306 return "CMD_SETEVENT";
307 case CMD_RESETEVENT:
308 return "CMD_RESETEVENT";
309 case CMD_WAITEVENTS:
310 return "CMD_WAITEVENTS";
311 case CMD_PIPELINEBARRIER:
312 return "CMD_PIPELINEBARRIER";
313 case CMD_BEGINQUERY:
314 return "CMD_BEGINQUERY";
315 case CMD_ENDQUERY:
316 return "CMD_ENDQUERY";
317 case CMD_RESETQUERYPOOL:
318 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600319 case CMD_COPYQUERYPOOLRESULTS:
320 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600321 case CMD_WRITETIMESTAMP:
322 return "CMD_WRITETIMESTAMP";
323 case CMD_INITATOMICCOUNTERS:
324 return "CMD_INITATOMICCOUNTERS";
325 case CMD_LOADATOMICCOUNTERS:
326 return "CMD_LOADATOMICCOUNTERS";
327 case CMD_SAVEATOMICCOUNTERS:
328 return "CMD_SAVEATOMICCOUNTERS";
329 case CMD_BEGINRENDERPASS:
330 return "CMD_BEGINRENDERPASS";
331 case CMD_ENDRENDERPASS:
332 return "CMD_ENDRENDERPASS";
333 case CMD_DBGMARKERBEGIN:
334 return "CMD_DBGMARKERBEGIN";
335 case CMD_DBGMARKEREND:
336 return "CMD_DBGMARKEREND";
337 default:
338 return "UNKNOWN";
339 }
340}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700341
342// SPIRV utility functions
343static void
Chris Forbes79b37f82016-01-18 08:56:09 +1300344build_type_def_index(shader_module *module)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700345{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300346 for (auto insn : *module) {
347 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700348 case spv::OpTypeVoid:
349 case spv::OpTypeBool:
350 case spv::OpTypeInt:
351 case spv::OpTypeFloat:
352 case spv::OpTypeVector:
353 case spv::OpTypeMatrix:
354 case spv::OpTypeImage:
355 case spv::OpTypeSampler:
356 case spv::OpTypeSampledImage:
357 case spv::OpTypeArray:
358 case spv::OpTypeRuntimeArray:
359 case spv::OpTypeStruct:
360 case spv::OpTypeOpaque:
361 case spv::OpTypePointer:
362 case spv::OpTypeFunction:
363 case spv::OpTypeEvent:
364 case spv::OpTypeDeviceEvent:
365 case spv::OpTypeReserveId:
366 case spv::OpTypeQueue:
367 case spv::OpTypePipe:
Chris Forbesc7e2e202016-01-18 08:56:40 +1300368 module->type_def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700369 break;
370
371 default:
372 /* We only care about type definitions */
373 break;
374 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700375 }
376}
377
378bool
379shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
380{
381 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
382 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
383
384 /* Just validate that the header makes sense. */
385 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
386}
387
388static char const *
389storage_class_name(unsigned sc)
390{
391 switch (sc) {
392 case spv::StorageClassInput: return "input";
393 case spv::StorageClassOutput: return "output";
394 case spv::StorageClassUniformConstant: return "const uniform";
395 case spv::StorageClassUniform: return "uniform";
396 case spv::StorageClassWorkgroup: return "workgroup local";
397 case spv::StorageClassCrossWorkgroup: return "workgroup global";
398 case spv::StorageClassPrivate: return "private global";
399 case spv::StorageClassFunction: return "function";
400 case spv::StorageClassGeneric: return "generic";
401 case spv::StorageClassAtomicCounter: return "atomic counter";
402 case spv::StorageClassImage: return "image";
403 default: return "unknown";
404 }
405}
406
407/* returns ptr to null terminator */
408static char *
409describe_type(char *dst, shader_module const *src, unsigned type)
410{
Chris Forbes1257f912016-01-18 12:07:01 +1300411 auto insn = src->get_type_def(type);
412 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700413
Chris Forbes1257f912016-01-18 12:07:01 +1300414 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700415 case spv::OpTypeBool:
416 return dst + sprintf(dst, "bool");
417 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300418 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700419 case spv::OpTypeFloat:
Chris Forbes1257f912016-01-18 12:07:01 +1300420 return dst + sprintf(dst, "float%d", insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700421 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300422 dst += sprintf(dst, "vec%d of ", insn.word(3));
423 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700424 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300425 dst += sprintf(dst, "mat%d of ", insn.word(3));
426 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700427 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300428 dst += sprintf(dst, "arr[%d] of ", insn.word(3));
429 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700430 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300431 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
432 return describe_type(dst, src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700433 case spv::OpTypeStruct:
434 {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700435 dst += sprintf(dst, "struct of (");
Chris Forbes1257f912016-01-18 12:07:01 +1300436 for (unsigned i = 2; i < insn.len(); i++) {
437 dst = describe_type(dst, src, insn.word(i));
438 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700439 }
440 return dst;
441 }
442 case spv::OpTypeSampler:
443 return dst + sprintf(dst, "sampler");
444 default:
445 return dst + sprintf(dst, "oddtype");
446 }
447}
448
449static bool
450types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
451{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700452 /* walk two type trees together, and complain about differences */
Chris Forbes1257f912016-01-18 12:07:01 +1300453 auto a_insn = a->get_type_def(a_type);
454 auto b_insn = b->get_type_def(b_type);
455 assert(a_insn != a->end());
456 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700457
Chris Forbes1257f912016-01-18 12:07:01 +1300458 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700459 /* 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 +1300460 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700461 }
462
Chris Forbes1257f912016-01-18 12:07:01 +1300463 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700464 return false;
465 }
466
Chris Forbes1257f912016-01-18 12:07:01 +1300467 switch (a_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700468 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
469 case spv::OpTypeBool:
470 return true && !b_arrayed;
471 case spv::OpTypeInt:
472 /* match on width, signedness */
Chris Forbes1257f912016-01-18 12:07:01 +1300473 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 -0700474 case spv::OpTypeFloat:
475 /* match on width */
Chris Forbes1257f912016-01-18 12:07:01 +1300476 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700477 case spv::OpTypeVector:
478 case spv::OpTypeMatrix:
479 case spv::OpTypeArray:
480 /* match on element type, count. these all have the same layout. we don't get here if
481 * b_arrayed -- that is handled above. */
Chris Forbes1257f912016-01-18 12:07:01 +1300482 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 -0700483 case spv::OpTypeStruct:
484 /* match on all element types */
485 {
486 if (b_arrayed) {
487 /* for the purposes of matching different levels of arrayness, structs are leaves. */
488 return false;
489 }
490
Chris Forbes1257f912016-01-18 12:07:01 +1300491 if (a_insn.len() != b_insn.len()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700492 return false; /* structs cannot match if member counts differ */
493 }
494
Chris Forbes1257f912016-01-18 12:07:01 +1300495 for (unsigned i = 2; i < a_insn.len(); i++) {
496 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700497 return false;
498 }
499 }
500
501 return true;
502 }
503 case spv::OpTypePointer:
504 /* match on pointee type. storage class is expected to differ */
Chris Forbes1257f912016-01-18 12:07:01 +1300505 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700506
507 default:
508 /* remaining types are CLisms, or may not appear in the interfaces we
509 * are interested in. Just claim no match.
510 */
511 return false;
512
513 }
514}
515
516static int
517value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
518{
519 auto it = map.find(id);
520 if (it == map.end())
521 return def;
522 else
523 return it->second;
524}
525
526
527static unsigned
528get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
529{
Chris Forbes1257f912016-01-18 12:07:01 +1300530 auto insn = src->get_type_def(type);
531 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700532
Chris Forbesc7e2e202016-01-18 08:56:40 +1300533 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700534 case spv::OpTypePointer:
535 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
536 * we're never actually passing pointers around. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300537 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700538 case spv::OpTypeArray:
539 if (strip_array_level) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300540 return get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700541 }
542 else {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300543 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700544 }
545 case spv::OpTypeMatrix:
546 /* num locations is the dimension * element size */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300547 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700548 default:
549 /* everything else is just 1. */
550 return 1;
551
552 /* TODO: extend to handle 64bit scalar types, whose vectors may need
553 * multiple locations. */
554 }
555}
556
557
558struct interface_var {
559 uint32_t id;
560 uint32_t type_id;
561 uint32_t offset;
562 /* TODO: collect the name, too? Isn't required to be present. */
563};
564
Chris Forbesa3e85f62016-01-15 14:53:11 +1300565
566static void
567collect_interface_block_members(layer_data *my_data, VkDevice dev,
568 shader_module const *src,
569 std::map<uint32_t, interface_var> &out,
570 std::map<uint32_t, interface_var> &builtins_out,
571 std::unordered_map<unsigned, unsigned> const &blocks,
572 bool is_array_of_verts,
573 uint32_t id,
574 uint32_t type_id)
575{
576 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes1257f912016-01-18 12:07:01 +1300577 auto type = src->get_type_def(type_id);
578
Chris Forbesa3e85f62016-01-15 14:53:11 +1300579 while (true) {
580
Chris Forbes1257f912016-01-18 12:07:01 +1300581 if (type.opcode() == spv::OpTypePointer) {
582 type = src->get_type_def(type.word(3));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300583 }
Chris Forbes1257f912016-01-18 12:07:01 +1300584 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
585 type = src->get_type_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300586 is_array_of_verts = false;
587 }
Chris Forbes1257f912016-01-18 12:07:01 +1300588 else if (type.opcode() == spv::OpTypeStruct) {
589 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300590 /* This isn't an interface block. */
591 return;
592 }
593 else {
594 /* We have found the correct type. Walk its members. */
595 break;
596 }
597 }
598 else {
599 /* not an interface block */
600 return;
601 }
602 }
603
Chris Forbes1257f912016-01-18 12:07:01 +1300604 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300605 for (auto insn : *src) {
Chris Forbes1257f912016-01-18 12:07:01 +1300606 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300607 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300608 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300609
Chris Forbesc7e2e202016-01-18 08:56:40 +1300610 if (insn.word(3) == spv::DecorationLocation) {
611 unsigned location = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300612 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
613 for (unsigned int offset = 0; offset < num_locations; offset++) {
614 interface_var v;
615 v.id = id;
616 /* TODO: member index in interface_var too? */
617 v.type_id = member_type_id;
618 v.offset = offset;
619 out[location + offset] = v;
620 }
621 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300622 else if (insn.word(3) == spv::DecorationBuiltIn) {
623 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300624 interface_var v;
625 v.id = id;
626 v.type_id = member_type_id;
627 v.offset = 0;
628 builtins_out[builtin] = v;
629 }
630 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300631 }
632}
633
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700634static void
635collect_interface_by_location(layer_data *my_data, VkDevice dev,
636 shader_module const *src, spv::StorageClass sinterface,
637 std::map<uint32_t, interface_var> &out,
638 std::map<uint32_t, interface_var> &builtins_out,
639 bool is_array_of_verts)
640{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700641 std::unordered_map<unsigned, unsigned> var_locations;
642 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300643 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700644
Chris Forbesc7e2e202016-01-18 08:56:40 +1300645 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700646
647 /* We consider two interface models: SSO rendezvous-by-location, and
648 * builtins. Complain about anything that fits neither model.
649 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300650 if (insn.opcode() == spv::OpDecorate) {
651 if (insn.word(2) == spv::DecorationLocation) {
652 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700653 }
654
Chris Forbesc7e2e202016-01-18 08:56:40 +1300655 if (insn.word(2) == spv::DecorationBuiltIn) {
656 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700657 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300658
Chris Forbesc7e2e202016-01-18 08:56:40 +1300659 if (insn.word(2) == spv::DecorationBlock) {
660 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300661 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700662 }
663
664 /* TODO: handle grouped decorations */
665 /* TODO: handle index=1 dual source outputs from FS -- two vars will
666 * have the same location, and we DONT want to clobber. */
667
Chris Forbesc7e2e202016-01-18 08:56:40 +1300668 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
669 unsigned id = insn.word(2);
670 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700671
Chris Forbesc7e2e202016-01-18 08:56:40 +1300672 int location = value_or_default(var_locations, id, -1);
673 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700674
Chris Forbesf5020cf2016-01-13 09:29:31 +1300675 /* All variables and interface block members in the Input or Output storage classes
676 * must be decorated with either a builtin or an explicit location.
677 *
678 * TODO: integrate the interface block support here. For now, don't complain --
679 * a valid SPIRV module will only hit this path for the interface block case, as the
680 * individual members of the type are decorated, rather than variable declarations.
681 */
682
683 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700684 /* A user-defined interface variable, with a location. Where a variable
685 * occupied multiple locations, emit one result for each. */
686 unsigned num_locations = get_locations_consumed_by_type(src, type,
687 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700688 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700689 interface_var v;
690 v.id = id;
691 v.type_id = type;
692 v.offset = offset;
693 out[location + offset] = v;
694 }
695 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300696 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700697 /* A builtin interface variable */
698 /* Note that since builtin interface variables do not consume numbered
699 * locations, there is no larger-than-vec4 consideration as above
700 */
701 interface_var v;
702 v.id = id;
703 v.type_id = type;
704 v.offset = 0;
705 builtins_out[builtin] = v;
706 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300707 else {
708 /* An interface block instance */
709 collect_interface_block_members(my_data, dev, src, out, builtins_out,
710 blocks, is_array_of_verts, id, type);
711 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700712 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700713 }
714}
715
716static void
717collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
718 shader_module const *src, spv::StorageClass sinterface,
719 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
720{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700721
722 std::unordered_map<unsigned, unsigned> var_sets;
723 std::unordered_map<unsigned, unsigned> var_bindings;
724
Chris Forbesc7e2e202016-01-18 08:56:40 +1300725 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700726 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
727 * DecorationDescriptorSet and DecorationBinding.
728 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300729 if (insn.opcode() == spv::OpDecorate) {
730 if (insn.word(2) == spv::DecorationDescriptorSet) {
731 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700732 }
733
Chris Forbesc7e2e202016-01-18 08:56:40 +1300734 if (insn.word(2) == spv::DecorationBinding) {
735 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700736 }
737 }
738
Chris Forbesc7e2e202016-01-18 08:56:40 +1300739 else if (insn.opcode() == spv::OpVariable &&
740 (insn.word(3) == spv::StorageClassUniform ||
741 insn.word(3) == spv::StorageClassUniformConstant)) {
742 unsigned set = value_or_default(var_sets, insn.word(2), 0);
743 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700744
745 auto existing_it = out.find(std::make_pair(set, binding));
746 if (existing_it != out.end()) {
747 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700748 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 -0700749 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
750 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
Chris Forbesc7e2e202016-01-18 08:56:40 +1300751 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700752 existing_it->first.first, existing_it->first.second);
753 }
754
755 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300756 v.id = insn.word(2);
757 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700758 out[std::make_pair(set, binding)] = v;
759 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700760 }
761}
762
763static bool
764validate_interface_between_stages(layer_data *my_data, VkDevice dev,
765 shader_module const *producer, char const *producer_name,
766 shader_module const *consumer, char const *consumer_name,
767 bool consumer_arrayed_input)
768{
769 std::map<uint32_t, interface_var> outputs;
770 std::map<uint32_t, interface_var> inputs;
771
772 std::map<uint32_t, interface_var> builtin_outputs;
773 std::map<uint32_t, interface_var> builtin_inputs;
774
775 bool pass = true;
776
777 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
778 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
779 consumer_arrayed_input);
780
781 auto a_it = outputs.begin();
782 auto b_it = inputs.begin();
783
784 /* maps sorted by key (location); walk them together to find mismatches */
785 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
786 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
787 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
788 auto a_first = a_at_end ? 0 : a_it->first;
789 auto b_first = b_at_end ? 0 : b_it->first;
790
791 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700792 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 -0700793 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
794 pass = false;
795 }
796 a_it++;
797 }
798 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700799 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 -0700800 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
801 pass = false;
802 }
803 b_it++;
804 }
805 else {
806 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
807 /* OK! */
808 }
809 else {
810 char producer_type[1024];
811 char consumer_type[1024];
812 describe_type(producer_type, producer, a_it->second.type_id);
813 describe_type(consumer_type, consumer, b_it->second.type_id);
814
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700815 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 -0700816 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
817 pass = false;
818 }
819 }
820 a_it++;
821 b_it++;
822 }
823 }
824
825 return pass;
826}
827
828enum FORMAT_TYPE {
829 FORMAT_TYPE_UNDEFINED,
830 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
831 FORMAT_TYPE_SINT,
832 FORMAT_TYPE_UINT,
833};
834
835static unsigned
836get_format_type(VkFormat fmt) {
837 switch (fmt) {
838 case VK_FORMAT_UNDEFINED:
839 return FORMAT_TYPE_UNDEFINED;
840 case VK_FORMAT_R8_SINT:
841 case VK_FORMAT_R8G8_SINT:
842 case VK_FORMAT_R8G8B8_SINT:
843 case VK_FORMAT_R8G8B8A8_SINT:
844 case VK_FORMAT_R16_SINT:
845 case VK_FORMAT_R16G16_SINT:
846 case VK_FORMAT_R16G16B16_SINT:
847 case VK_FORMAT_R16G16B16A16_SINT:
848 case VK_FORMAT_R32_SINT:
849 case VK_FORMAT_R32G32_SINT:
850 case VK_FORMAT_R32G32B32_SINT:
851 case VK_FORMAT_R32G32B32A32_SINT:
852 case VK_FORMAT_B8G8R8_SINT:
853 case VK_FORMAT_B8G8R8A8_SINT:
854 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
855 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
856 return FORMAT_TYPE_SINT;
857 case VK_FORMAT_R8_UINT:
858 case VK_FORMAT_R8G8_UINT:
859 case VK_FORMAT_R8G8B8_UINT:
860 case VK_FORMAT_R8G8B8A8_UINT:
861 case VK_FORMAT_R16_UINT:
862 case VK_FORMAT_R16G16_UINT:
863 case VK_FORMAT_R16G16B16_UINT:
864 case VK_FORMAT_R16G16B16A16_UINT:
865 case VK_FORMAT_R32_UINT:
866 case VK_FORMAT_R32G32_UINT:
867 case VK_FORMAT_R32G32B32_UINT:
868 case VK_FORMAT_R32G32B32A32_UINT:
869 case VK_FORMAT_B8G8R8_UINT:
870 case VK_FORMAT_B8G8R8A8_UINT:
871 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
872 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
873 return FORMAT_TYPE_UINT;
874 default:
875 return FORMAT_TYPE_FLOAT;
876 }
877}
878
879/* characterizes a SPIR-V type appearing in an interface to a FF stage,
880 * for comparison to a VkFormat's characterization above. */
881static unsigned
882get_fundamental_type(shader_module const *src, unsigned type)
883{
Chris Forbes1257f912016-01-18 12:07:01 +1300884 auto insn = src->get_type_def(type);
885 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700886
Chris Forbes1257f912016-01-18 12:07:01 +1300887 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700888 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300889 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700890 case spv::OpTypeFloat:
891 return FORMAT_TYPE_FLOAT;
892 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300893 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700894 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300895 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700896 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300897 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700898 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300899 return get_fundamental_type(src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700900 default:
901 return FORMAT_TYPE_UNDEFINED;
902 }
903}
904
905static bool
906validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
907{
908 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
909 * each binding should be specified only once.
910 */
911 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
912 bool pass = true;
913
914 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
915 auto desc = &vi->pVertexBindingDescriptions[i];
916 auto & binding = bindings[desc->binding];
917 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700918 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 -0700919 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
920 pass = false;
921 }
922 }
923 else {
924 binding = desc;
925 }
926 }
927
928 return pass;
929}
930
931static bool
932validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
933{
934 std::map<uint32_t, interface_var> inputs;
935 /* we collect builtin inputs, but they will never appear in the VI state --
936 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
937 */
938 std::map<uint32_t, interface_var> builtin_inputs;
939 bool pass = true;
940
941 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
942
943 /* Build index by location */
944 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
945 if (vi) {
946 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
947 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
948 }
949
950 auto it_a = attribs.begin();
951 auto it_b = inputs.begin();
952
953 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
954 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
955 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
956 auto a_first = a_at_end ? 0 : it_a->first;
957 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +1300958 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700959 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 -0700960 "Vertex attribute at location %d not consumed by VS", a_first)) {
961 pass = false;
962 }
963 it_a++;
964 }
Chris Forbes7d83cd52016-01-15 11:32:03 +1300965 else if (!b_at_end && (a_at_end || b_first < a_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700966 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 -0700967 "VS consumes input at location %d but not provided", b_first)) {
968 pass = false;
969 }
970 it_b++;
971 }
972 else {
973 unsigned attrib_type = get_format_type(it_a->second->format);
974 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
975
976 /* type checking */
977 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
978 char vs_type[1024];
979 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700980 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 -0700981 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
982 string_VkFormat(it_a->second->format), a_first, vs_type)) {
983 pass = false;
984 }
985 }
986
987 /* OK! */
988 it_a++;
989 it_b++;
990 }
991 }
992
993 return pass;
994}
995
996static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700997validate_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 -0700998{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700999 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001000 std::map<uint32_t, interface_var> outputs;
1001 std::map<uint32_t, interface_var> builtin_outputs;
1002 bool pass = true;
1003
1004 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1005
1006 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
1007
1008 auto it = outputs.begin();
1009 uint32_t attachment = 0;
1010
1011 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1012 * are currently dense, but the parallel with matching between shader stages is nice.
1013 */
1014
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001015 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1016 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001017 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 -07001018 "FS writes to output location %d with no matching attachment", it->first)) {
1019 pass = false;
1020 }
1021 it++;
1022 }
1023 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001024 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 -07001025 "Attachment %d not written by FS", attachment)) {
1026 pass = false;
1027 }
1028 attachment++;
1029 }
1030 else {
1031 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1032 unsigned att_type = get_format_type(color_formats[attachment]);
1033
1034 /* type checking */
1035 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
1036 char fs_type[1024];
1037 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001038 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 -07001039 "Attachment %d of type `%s` does not match FS output type of `%s`",
1040 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
1041 pass = false;
1042 }
1043 }
1044
1045 /* OK! */
1046 it++;
1047 attachment++;
1048 }
1049 }
1050
1051 return pass;
1052}
1053
1054
1055struct shader_stage_attributes {
1056 char const * const name;
1057 bool arrayed_input;
1058};
1059
1060
1061static shader_stage_attributes
1062shader_stage_attribs[] = {
1063 { "vertex shader", false },
1064 { "tessellation control shader", true },
1065 { "tessellation evaluation shader", false },
1066 { "geometry shader", true },
1067 { "fragment shader", false },
1068};
1069
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001070// For given pipelineLayout verify that the setLayout at slot.first
1071// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001072static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001073has_descriptor_binding(layer_data* my_data,
1074 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001075 std::pair<unsigned, unsigned> slot)
1076{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001077 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001078 return false;
1079
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001080 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001081 return false;
1082
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001083 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001084
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001085 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001086}
1087
1088static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1089{
1090 uint32_t bit_pos = u_ffs(stage);
1091 return bit_pos-1;
1092}
1093
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001094// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001095
1096static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1097
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001098// 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 -06001099// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1100// to that same cmd buffer by separate thread are not changing state from underneath us
1101// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001102
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001103// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001104static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001105
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001106static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001107{
1108 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1109 if (pCB->drawCount[i])
1110 return VK_TRUE;
1111 }
1112 return VK_FALSE;
1113}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001114
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001115// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001116static 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 -06001117{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001118 // If non-zero enable mask is present, check it against status but if enable_mask
1119 // is 0 then no enable required so we should always just check status
1120 if ((!enable_mask) || (enable_mask & pNode->status)) {
1121 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001122 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001123 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001124 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001125 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001126 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001127 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001128}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001129
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001130// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001131static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001132{
1133 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001134 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001135 loader_platform_thread_unlock_mutex(&globalLock);
1136 return NULL;
1137 }
1138 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001139 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001140}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001141
Tobin Ehlisd332f282015-10-02 11:00:56 -06001142// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1143static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1144{
1145 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1146 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1147 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1148 return VK_TRUE;
1149 }
1150 }
1151 return VK_FALSE;
1152}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001153
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001154// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001155static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001156 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001157 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");
1158 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");
1159 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");
1160 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");
1161 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");
1162 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");
1163 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");
1164 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");
1165 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 -06001166 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001167 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 -06001168 return result;
1169}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001170
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001171// Verify attachment reference compatibility according to spec
1172// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1173// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1174// to make sure that format and samples counts match.
1175// If not, they are not compatible.
1176static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1177 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1178{
1179 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1180 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1181 return false;
1182 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1183 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1184 return false;
1185 } else { // format and sample count must match
1186 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1187 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1188 return true;
1189 }
1190 // Format and sample counts didn't match
1191 return false;
1192}
1193
1194// For give primary and secondary RenderPass objects, verify that they're compatible
1195static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1196{
1197 stringstream errorStr;
1198 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1199 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1200 errorMsg = errorStr.str();
1201 return false;
1202 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1203 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1204 errorMsg = errorStr.str();
1205 return false;
1206 }
1207 // Trivial pass case is exact same RP
1208 if (primaryRP == secondaryRP)
1209 return true;
1210 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1211 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1212 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1213 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1214 errorMsg = errorStr.str();
1215 return false;
1216 }
1217 uint32_t spIndex = 0;
1218 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1219 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1220 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1221 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1222 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1223 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1224 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1225 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1226 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1227 errorMsg = errorStr.str();
1228 return false;
1229 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1230 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1231 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1232 errorMsg = errorStr.str();
1233 return false;
1234 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1235 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1236 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1237 errorMsg = errorStr.str();
1238 return false;
1239 }
1240 }
1241 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1242 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1243 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1244 for (uint32_t i = 0; i < inputMax; ++i) {
1245 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1246 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1247 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1248 errorMsg = errorStr.str();
1249 return false;
1250 }
1251 }
1252 }
1253 return true;
1254}
1255
Tobin Ehlis559c6382015-11-05 09:52:49 -07001256// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1257static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1258{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001259 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001260 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001261 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1262 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001263 return false;
1264 }
1265 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1266 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001267 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;
1268 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001269 return false;
1270 }
1271 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001272 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001273 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1274 return true;
1275 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001276 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001277 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001278 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1279 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001280 return false; // trivial fail case
1281 }
1282 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001283 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001284 // Need to verify that layouts are identically defined
1285 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1286 // do we also need to check immutable samplers?
1287 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001288 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]) << "'";
1289 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001290 return false;
1291 }
1292 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001293 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1294 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001295 return false;
1296 }
1297 }
1298 return true;
1299}
1300
Tobin Ehlis88452832015-12-03 09:40:56 -07001301// Validate that the shaders used by the given pipeline
1302// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001303static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001304validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001305{
Tobin Ehlis88452832015-12-03 09:40:56 -07001306 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001307 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1308 * before trying to do anything more: */
1309 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1310 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1311 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1312
1313 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1314 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001315 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001316 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001317 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001318
1319 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1320 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1321 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1322
1323 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1324 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001325 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 -07001326 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001327 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001328 }
1329 }
1330 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001331 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001332 shaders[get_shader_stage_id(pStage->stage)] = module;
1333
1334 /* validate descriptor set layout against what the spirv module actually uses */
1335 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1336 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1337 descriptor_uses);
1338
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001339 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1340 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001341
1342 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001343 // As a side-effect of this function, capture which sets are used by the pipeline
1344 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001345
1346 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001347 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001348
1349 if (!found) {
1350 char type_name[1024];
1351 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001352 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 -07001353 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1354 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1355 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001356 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001357 }
1358 }
1359 }
1360 }
1361 }
1362 }
1363
1364 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001365 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001366
1367 vi = pCreateInfo->pVertexInputState;
1368
1369 if (vi) {
1370 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1371 }
1372
1373 if (shaders[vertex_stage]) {
1374 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1375 }
1376
1377 /* TODO: enforce rules about present combinations of shaders */
1378 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1379 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1380
1381 while (!shaders[producer] && producer != fragment_stage) {
1382 producer++;
1383 consumer++;
1384 }
1385
1386 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1387 assert(shaders[producer]);
1388 if (shaders[consumer]) {
1389 pass = validate_interface_between_stages(my_data, dev,
1390 shaders[producer], shader_stage_attribs[producer].name,
1391 shaders[consumer], shader_stage_attribs[consumer].name,
1392 shader_stage_attribs[consumer].arrayed_input) && pass;
1393
1394 producer = consumer;
1395 }
1396 }
1397
1398 if (shaders[fragment_stage] && rp) {
1399 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1400 }
1401
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001402 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001403
1404 return pass;
1405}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001406
Tobin Ehlisf6585052015-12-17 11:48:42 -07001407// Return Set node ptr for specified set or else NULL
1408static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1409{
1410 loader_platform_thread_lock_mutex(&globalLock);
1411 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1412 loader_platform_thread_unlock_mutex(&globalLock);
1413 return NULL;
1414 }
1415 loader_platform_thread_unlock_mutex(&globalLock);
1416 return my_data->setMap[set];
1417}
1418
1419// For the given set, verify that for each dynamic descriptor in that set that its
1420// dynamic offset combined with the offet and range from its descriptor update
1421// do not overflow the size of its buffer being updated
1422static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1423{
1424 VkBool32 result = VK_FALSE;
1425 if (pSet->dynamicOffsets.empty())
1426 return result;
1427
1428 VkWriteDescriptorSet* pWDS = NULL;
1429 uint32_t dynOffsetIndex = 0;
1430 VkDeviceSize bufferSize = 0;
1431 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1432 switch (pSet->ppDescriptors[i]->sType) {
1433 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1434 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1435 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1436 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1437 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001438 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001439 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001440 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 -07001441 "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 ".",
1442 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1443 }
1444 dynOffsetIndex++;
1445 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)
1446 }
1447 }
1448 break;
1449 default: // Currently only shadowing Write update nodes so shouldn't get here
1450 assert(0);
1451 continue;
1452 }
1453 }
1454 return result;
1455}
1456
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001457// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001458static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001459 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001460 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001461 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001462 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001463 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1464 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1465 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001466 if (pPipe) {
1467 if (pCB->lastBoundPipelineLayout) {
1468 string errorString;
1469 for (auto setIndex : pPipe->active_sets) {
1470 // If valid set is not bound throw an error
1471 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001472 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 -07001473 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1474 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1475 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1476 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001477 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 -07001478 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1479 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001480 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
1481 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001482 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001483 // Make sure set has been updated
1484 if (!pSet->pUpdateStructs) {
1485 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",
1486 "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);
1487 }
1488 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001489 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001490 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001491 }
1492 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001493
Mark Lobodzinski74635932015-12-18 15:35:38 -07001494 // Verify Vtx binding
1495 if (pPipe->vtxBindingCount > 0) {
1496 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1497 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001498 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001499 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 -07001500 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1501 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001502
Mark Lobodzinski74635932015-12-18 15:35:38 -07001503 }
1504 }
1505 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001506 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001507 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 -07001508 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1509 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001510 }
1511 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001512
Mark Lobodzinski74635932015-12-18 15:35:38 -07001513 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1514 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1515 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1516 if (dynViewport) {
1517 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001518 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Mark Lobodzinski74635932015-12-18 15:35:38 -07001519 "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);
1520 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001521 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001522 if (dynScissor) {
1523 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001524 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 -07001525 "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);
1526 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001527 }
1528 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001529 return result;
1530}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001531
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001532// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001533static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001534{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001535 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001536
Tobin Ehlis88452832015-12-03 09:40:56 -07001537 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001538 skipCall = VK_TRUE;
1539 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001540 // VS is required
1541 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001542 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 -06001543 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001544 }
1545 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001546 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1547 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001548 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 -06001549 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001550 }
1551 // Compute shaders should be specified independent of Gfx shaders
1552 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001553 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1554 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001555 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001556 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 -06001557 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001558 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001559 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001560 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001561 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001562 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001563 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 +08001564 "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 -06001565 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001566 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001567 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001568 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 +08001569 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001570 }
1571 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001572 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 +08001573 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001574 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1575 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001576 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001577 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001578 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001579 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001580 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 -06001581 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1582 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001583 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 -06001584 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001585 } else {
1586 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1587 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1588 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1589 if (!dynViewport) {
1590 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
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_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001592 "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 -06001593 }
1594 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001595 if (!dynScissor) {
1596 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001597 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 -07001598 "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 -06001599 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001600 }
1601 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001602 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001603}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001604
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001605// Init the pipeline mapping info based on pipeline create info LL tree
1606// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001607// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001608static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001609{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001610 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001611
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001612 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001613 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001614 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001615
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001616 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001617 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001618
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001619 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001620 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001621 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001622
1623 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1624 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1625
Chia-I Wu28e06912015-10-31 00:31:16 +08001626 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001627 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001628 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1629 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001630 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001631 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001632 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001633 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001634 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001635 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001636 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001637 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001638 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001639 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001640 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1641 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001642 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001643 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001644 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1645 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001646 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001647 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001648 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1649 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001650 break;
1651 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001652 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001653 break;
1654 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001655 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001656 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1657 if (pCreateInfo->stageCount != 0) {
1658 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1659 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1660 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1661 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001662 if (pCreateInfo->pVertexInputState != NULL) {
1663 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1664 // Copy embedded ptrs
1665 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001666 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001667 if (pPipeline->vtxBindingCount) {
1668 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1669 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1670 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1671 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001672 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001673 if (pPipeline->vtxAttributeCount) {
1674 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1675 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1676 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1677 }
1678 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1679 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001680 if (pCreateInfo->pInputAssemblyState != NULL) {
1681 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1682 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001683 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001684 if (pCreateInfo->pTessellationState != NULL) {
1685 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1686 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001687 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001688 if (pCreateInfo->pViewportState != NULL) {
1689 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1690 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001691 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001692 if (pCreateInfo->pRasterizationState != NULL) {
1693 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1694 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001695 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001696 if (pCreateInfo->pMultisampleState != NULL) {
1697 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1698 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001699 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001700 if (pCreateInfo->pDepthStencilState != NULL) {
1701 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1702 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1703 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001704 if (pCreateInfo->pColorBlendState != NULL) {
1705 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001706 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001707 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001708 pPipeline->attachmentCount = pCBCI->attachmentCount;
1709 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001710 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1711 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001712 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1713 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001714 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001715 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001716 if (pCreateInfo->pDynamicState != NULL) {
1717 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1718 if (pPipeline->dynStateCI.dynamicStateCount) {
1719 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1720 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1721 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1722 }
1723 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001724 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001725 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001726 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001727}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001728
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001729// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001730static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001731{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001732 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001733 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001734 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001735 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1736 delete[] (*ii).second->graphicsPipelineCI.pStages;
1737 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001738 if ((*ii).second->pVertexBindingDescriptions) {
1739 delete[] (*ii).second->pVertexBindingDescriptions;
1740 }
1741 if ((*ii).second->pVertexAttributeDescriptions) {
1742 delete[] (*ii).second->pVertexAttributeDescriptions;
1743 }
1744 if ((*ii).second->pAttachments) {
1745 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001746 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001747 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1748 delete[] (*ii).second->dynStateCI.pDynamicStates;
1749 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001750 delete (*ii).second;
1751 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001752 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001753}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001754
Tobin Ehliseba312c2015-04-01 08:40:34 -06001755// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001756static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001757{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001758 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001759 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001760 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001761 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001762 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001763}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001764
Tobin Ehliseba312c2015-04-01 08:40:34 -06001765// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001766static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001767{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001768 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001769 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001770 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001771 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001772 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001773 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001774 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001775 uint32_t i;
1776
Chia-I Wud50a7d72015-10-26 20:48:51 +08001777 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001778 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001779
Cody Northropa505dda2015-08-04 11:16:41 -06001780 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001781 continue;
1782
Cody Northropa505dda2015-08-04 11:16:41 -06001783 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001784 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001785 subpassNumSamples = samples;
1786 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001787 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001788 break;
1789 }
1790 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001791 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001792 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1793 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001794 subpassNumSamples = samples;
1795 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001796 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001797 }
1798
1799 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001800 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 -06001801 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001802 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001803 }
1804 } else {
1805 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1806 // Verify and flag error as appropriate
1807 }
1808 // TODO : Add more checks here
1809 } else {
1810 // TODO : Validate non-gfx pipeline updates
1811 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001812 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001813}
1814
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001815// Block of code at start here specifically for managing/tracking DSs
1816
Tobin Ehlis793ad302015-04-03 12:01:11 -06001817// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001818static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001819{
1820 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001821 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001822 loader_platform_thread_unlock_mutex(&globalLock);
1823 return NULL;
1824 }
1825 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001826 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001827}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001828
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001829static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001830 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001831 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001832 loader_platform_thread_unlock_mutex(&globalLock);
1833 return NULL;
1834 }
1835 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001836 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001837}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001838
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001839// 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 -06001840static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001841{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001842 switch (pUpdateStruct->sType)
1843 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001844 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1845 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001846 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001847 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001848 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 -06001849 "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 -06001850 }
1851}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001852
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001853// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001854// 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 -06001855static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001856{
1857 switch (pUpdateStruct->sType)
1858 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001859 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001860 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001861 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001862 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001863 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001864 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001865
1866 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001867}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001868
Tobin Ehlis793ad302015-04-03 12:01:11 -06001869// For given Layout Node and binding, return index where that binding begins
1870static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1871{
1872 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001873 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001874 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001875 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001876 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001877 }
1878 return offsetIndex;
1879}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001880
Tobin Ehlis793ad302015-04-03 12:01:11 -06001881// For given layout node and binding, return last index that is updated
1882static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1883{
1884 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001885 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001886 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1887 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001888 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001889 }
1890 return offsetIndex-1;
1891}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001892
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001893// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001894static 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 -06001895{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001896 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001897}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001898
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001899// For given layout and update, return the last overall index of the layout that is updated
1900static 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 -06001901{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001902 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001903 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001904}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001905
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001906// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001907static 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 -06001908{
1909 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001910 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001911 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001912 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001913 switch (pUpdateStruct->sType)
1914 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001915 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1916 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001917 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001918 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1919 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001920 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001921 break;
1922 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001923 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 -06001924 "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 -06001925 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001926 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001927 // Set first stageFlags as reference and verify that all other updates match it
1928 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001929 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001930 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001931 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 -06001932 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1933 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1934 }
1935 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001936 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 -06001937 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1938 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001939 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001940 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001941 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001942 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001943}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001944
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001945// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001946// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001947// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001948static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001949{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001950 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001951 VkWriteDescriptorSet* pWDS = NULL;
1952 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001953 size_t array_size = 0;
1954 size_t base_array_size = 0;
1955 size_t total_array_size = 0;
1956 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001957 switch (pUpdate->sType)
1958 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001959 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1960 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001961 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001962 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001963
1964 switch (pWDS->descriptorType) {
1965 case VK_DESCRIPTOR_TYPE_SAMPLER:
1966 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1967 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1968 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1969 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001970 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
1971 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001972 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001973 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001974 break;
1975 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1976 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1977 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001978 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
1979 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001980 pWDS->pTexelBufferView = info;
1981 }
1982 break;
1983 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1984 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1985 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1986 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1987 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08001988 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
1989 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001990 pWDS->pBufferInfo = info;
1991 }
1992 break;
1993 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001994 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001995 break;
1996 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001997 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001998 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1999 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002000 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002001 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002002 break;
2003 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002004 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 -06002005 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2006 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002007 }
2008 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002009 (*pNewNode)->pNext = NULL;
2010 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002011}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002012
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002013// Verify that given sampler is valid
2014static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2015{
2016 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002017 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002018 if (sampIt == my_data->sampleMap.end()) {
2019 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002020 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 +08002021 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002022 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002023 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 +08002024 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002025 }
2026 } else {
2027 // TODO : Any further checks we want to do on the sampler?
2028 }
2029 return skipCall;
2030}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002031
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002032// Verify that given imageView is valid
2033static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2034{
2035 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002036 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002037 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002038 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 +08002039 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002040 } else {
2041 // Validate that imageLayout is compatible with aspectMask and image format
2042 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002043 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002044 // TODO : Check here in case we have a bad image
Chia-I Wue2fc5522015-10-26 20:04:44 +08002045 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlis47026a22016-01-19 08:36:40 -07002046 auto swapChainImageIt = my_data->imageLayoutMap.find(image);
2047 if ((imgIt == my_data->imageMap.end()) && (swapChainImageIt == my_data->imageLayoutMap.end())) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002048 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 -07002049 "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 -06002050 } else {
2051 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002052 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002053 switch (imageLayout) {
2054 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2055 // Only Color bit must be set
2056 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002057 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 -06002058 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 +08002059 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002060 }
2061 // format must NOT be DS
2062 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002063 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 -06002064 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 +08002065 " 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 -06002066 }
2067 break;
2068 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2069 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2070 // Depth or stencil bit must be set, but both must NOT be set
2071 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2072 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2073 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002074 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 -06002075 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002076 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002077 }
2078 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2079 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002080 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 -06002081 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002082 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002083 }
2084 // format must be DS
2085 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002086 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002087 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002088 " 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 -06002089 }
2090 break;
2091 default:
2092 // anything to check for other layouts?
2093 break;
2094 }
2095 }
2096 }
2097 return skipCall;
2098}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002099
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002100// Verify that given bufferView is valid
2101static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2102{
2103 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002104 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002105 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002106 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 +08002107 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002108 } else {
2109 // TODO : Any further checks we want to do on the bufferView?
2110 }
2111 return skipCall;
2112}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002113
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002114// Verify that given bufferInfo is valid
2115static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2116{
2117 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002118 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002119 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002120 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 +08002121 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002122 } else {
2123 // TODO : Any further checks we want to do on the bufferView?
2124 }
2125 return skipCall;
2126}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002127
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002128static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2129{
2130 VkBool32 skipCall = VK_FALSE;
2131 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2132 VkBufferView* pBufferView = NULL;
2133 const VkSampler* pSampler = NULL;
2134 VkImageView* pImageView = NULL;
2135 VkImageLayout* pImageLayout = NULL;
2136 VkDescriptorBufferInfo* pBufferInfo = NULL;
2137 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002138 uint32_t i = 0;
2139 // For given update type, verify that update contents are correct
2140 switch (pWDS->descriptorType) {
2141 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002142 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002143 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002144 }
2145 break;
2146 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002147 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002148 if (NULL == pLayoutBinding->pImmutableSamplers) {
2149 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002150 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002151 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 -06002152 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2153 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002154 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002155 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002156 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002157 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002158 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 -06002159 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2160 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2161 "use immutable or non-immutable samplers.", i);
2162 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002163 immutable = VK_TRUE;
2164 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2165 }
2166 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002167 }
2168 // Intentionally fall through here to also validate image stuff
2169 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2170 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2171 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002172 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002173 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002174 }
2175 break;
2176 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2177 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002178 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002179 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002180 }
2181 break;
2182 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2183 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2184 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2185 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002186 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002187 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002188 }
2189 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002190 }
2191 return skipCall;
2192}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002193
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002194// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002195static 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 -06002196{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002197 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002198
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002199 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002200 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002201 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002202 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002203 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002204 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002205 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002206 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002207 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002208 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002209 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002210 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002211 break;
2212 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002213 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002214 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002215 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002216 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002217 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",
Michael Lentine010f4692015-11-03 16:19:46 -08002218 "Descriptor Set %" PRIu64 " does not have binding to match update binding %u for update type %s!", reinterpret_cast<uint64_t>(ds), binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06002219 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002220 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002221 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002222 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002223 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002224 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002225 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 -06002226 "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 -06002227 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002228 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002229 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002230 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2231 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2232 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002233 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002234 // Update is good. Save the update info
2235 // Create new update struct for this set's shadow copy
2236 GENERIC_HEADER* pNewNode = NULL;
2237 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2238 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002239 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 -06002240 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2241 } else {
2242 // Insert shadow node into LL of updates for this set
2243 pNewNode->pNext = pSet->pUpdateStructs;
2244 pSet->pUpdateStructs = pNewNode;
2245 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002246 for (uint32_t j = startIndex; j <= endIndex; j++) {
2247 assert(j<pSet->descriptorCount);
2248 pSet->ppDescriptors[j] = pNewNode;
2249 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002250 }
2251 }
2252 }
2253 }
2254 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002255 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002256 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002257 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002258 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2259 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2260 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2261 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002262 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002263 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002264 pSrcLayout = pSrcSet->pLayout;
2265 pDstLayout = pDstSet->pLayout;
2266 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002267 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002268 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 -06002269 "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 +08002270 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002271 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002272 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 +08002273 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2274 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002275 } else {
2276 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2277 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 +08002278 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002279 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2280 pLayoutCI = &pSrcLayout->createInfo;
2281 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002282 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 -06002283 "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 +08002284 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002285 pLayoutCI = &pDstLayout->createInfo;
2286 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002287 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 +08002288 "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 -06002289 } else {
2290 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 +08002291 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 +08002292 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002293 // For copy just make sure that the types match and then perform the update
2294 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002295 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 -06002296 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2297 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2298 } else {
2299 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002300 // TODO : This may be a hole. I believe copy should be its own copy,
2301 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002302 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2303 }
2304 }
2305 }
2306 }
2307 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002308 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002309 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002310}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002311
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002312// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002313static 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 -06002314{
2315 VkBool32 skipCall = VK_FALSE;
2316 uint32_t i = 0, j = 0;
2317 for (i=0; i<count; ++i) {
2318 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2319 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002320 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 +08002321 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002322 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002323 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002324 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002325 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2326 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002327 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002328 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 -06002329 "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 -07002330 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002331 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002332 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002333 }
2334 }
2335 }
2336 }
2337 return skipCall;
2338}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002339
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002340// Free the shadowed update node for this Set
2341// NOTE : Calls to this function should be wrapped in mutex
2342static void freeShadowUpdateTree(SET_NODE* pSet)
2343{
2344 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2345 pSet->pUpdateStructs = NULL;
2346 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2347 // Clear the descriptor mappings as they will now be invalid
2348 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2349 while(pShadowUpdate) {
2350 pFreeUpdate = pShadowUpdate;
2351 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2352 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002353 VkWriteDescriptorSet * pWDS = NULL;
2354 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002355 void** ppToFree = NULL;
2356 switch (pFreeUpdate->sType)
2357 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002358 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2359 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002360 switch (pWDS->descriptorType) {
2361 case VK_DESCRIPTOR_TYPE_SAMPLER:
2362 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2363 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2364 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2365 {
2366 delete[] pWDS->pImageInfo;
2367 }
2368 break;
2369 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2370 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2371 {
2372 delete[] pWDS->pTexelBufferView;
2373 }
2374 break;
2375 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2376 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2377 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2378 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2379 {
2380 delete[] pWDS->pBufferInfo;
2381 }
2382 break;
2383 default:
2384 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002385 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002386 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002387 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002388 break;
2389 default:
2390 assert(0);
2391 break;
2392 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002393 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002394 }
2395}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002396
Tobin Ehlis793ad302015-04-03 12:01:11 -06002397// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002398// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002399static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002400{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002401 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002402 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002403 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002404 SET_NODE* pSet = (*ii).second->pSets;
2405 SET_NODE* pFreeSet = pSet;
2406 while (pSet) {
2407 pFreeSet = pSet;
2408 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002409 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002410 // Free Update shadow struct tree
2411 freeShadowUpdateTree(pFreeSet);
2412 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002413 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002414 }
2415 delete pFreeSet;
2416 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002417 delete (*ii).second;
2418 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002419 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002420}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002421
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002422// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002423// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002424static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002425{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002426 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002427 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002428 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002429 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002430 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002431 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002432 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2433 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002434 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002435 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002436 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002437 delete pLayout;
2438 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002439 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002440}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002441
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002442// Currently clearing a set is removing all previous updates to that set
2443// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002444static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002445{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002446 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002447 if (!pSet) {
2448 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002449 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002450 loader_platform_thread_lock_mutex(&globalLock);
2451 freeShadowUpdateTree(pSet);
2452 loader_platform_thread_unlock_mutex(&globalLock);
2453 }
2454}
2455
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002456static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002457{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002458 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002459 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002460 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 +08002461 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002462 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002463 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002464 // For every set off of this pool, clear it
2465 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002466 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002467 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002468 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002469 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002470 // Reset available count to max count for this pool
2471 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2472 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2473 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002474 }
2475}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002476
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002477// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002478static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002479{
2480 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002481 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002482 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002483 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002484 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",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002485 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002486 return NULL;
2487 }
2488 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002489 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002491
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002492// Free all CB Nodes
2493// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002494static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002495{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002496 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002497 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002498 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002499 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06002500 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2501 while (!cmd_node_list.empty()) {
2502 CMD_NODE* cmd_node = cmd_node_list.back();
2503 delete cmd_node;
2504 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002505 }
2506 delete (*ii).second;
2507 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002508 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002509}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002510
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002511static 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 -06002512{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002513 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 -07002514 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002515 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002516}
Michael Lentine3dea6512015-10-28 15:55:18 -07002517
Mark Youngb20a6a82016-01-07 15:41:43 -07002518VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2519 if (!pCB->activeRenderPass) return VK_FALSE;
2520 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002521 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2522 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2523 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2524 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2525 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2526 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2527 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002528 return skip_call;
2529}
2530
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002531// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2532// in the recording state or if there's an issue with the Cmd ordering
2533static 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 -06002534{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002535 VkBool32 skipCall = VK_FALSE;
2536 if (pCB->state != CB_RECORDING) {
2537 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2538 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
2539 CMD_NODE* pCmd = new CMD_NODE;
2540 if (pCmd) {
2541 // init cmd node and append to end of cmd LL
2542 memset(pCmd, 0, sizeof(CMD_NODE));
2543 pCmd->cmdNumber = ++pCB->numCmds;
2544 pCmd->type = cmd;
2545 pCB->pCmds.push_back(pCmd);
2546 } else {
2547 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002548 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002549 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
2550 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002551 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002552 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002553}
Tobin Ehlisef694652016-01-19 12:03:34 -07002554// Reset the command buffer state
2555// Maintain the createInfo and set state to CB_NEW, but clear all other state
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002556static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002557{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002558 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002559 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002560 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2561 while (!cmd_list.empty()) {
2562 delete cmd_list.back();
2563 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002564 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002565 pCB->pCmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002566 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002567 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002568 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2569 pCB->fence = 0;
2570 pCB->numCmds = 0;
2571 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2572 pCB->state = CB_NEW;
2573 pCB->submitCount = 0;
2574 pCB->status = 0;
2575 pCB->pCmds.clear();
2576 pCB->lastBoundPipeline = 0;
2577 pCB->viewports.clear();
2578 pCB->scissors.clear();
2579 pCB->lineWidth = 0;
2580 pCB->depthBiasConstantFactor = 0;
2581 pCB->depthBiasClamp = 0;
2582 pCB->depthBiasSlopeFactor = 0;
2583 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2584 pCB->minDepthBounds = 0;
2585 pCB->maxDepthBounds = 0;
2586 memset(&pCB->front, 0, sizeof(stencil_data));
2587 memset(&pCB->back, 0, sizeof(stencil_data));
2588 pCB->lastBoundDescriptorSet = 0;
2589 pCB->lastBoundPipelineLayout = 0;
2590 pCB->activeRenderPass = 0;
2591 pCB->activeSubpass = 0;
2592 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002593 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002594 pCB->drawData.clear();
2595 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002596 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002597 pCB->waitedEvents.clear();
2598 pCB->waitedEventsBeforeQueryReset.clear();
2599 pCB->queryToStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002600 }
2601}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002602
Tobin Ehlis963a4042015-09-29 08:18:34 -06002603// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002604static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2605{
2606 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002607 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002608 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2609 }
2610 }
2611 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002612 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2613 }
Cody Northrop82485a82015-08-18 15:21:16 -06002614 if (pPipe->dsStateCI.stencilTestEnable) {
2615 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002616 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002617 // Account for any dynamic state not set via this PSO
2618 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2619 pCB->status = CBSTATUS_ALL;
2620 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002621 // First consider all state on
2622 // Then unset any state that's noted as dynamic in PSO
2623 // Finally OR that into CB statemask
2624 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002625 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2626 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2627 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002628 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002629 break;
2630 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002631 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002632 break;
2633 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002634 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002635 break;
2636 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002637 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002638 break;
2639 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002640 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002641 break;
2642 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002643 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002644 break;
2645 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002646 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002647 break;
2648 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002649 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002650 break;
2651 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002652 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002653 break;
2654 default:
2655 // TODO : Flag error here
2656 break;
2657 }
2658 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002659 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002660 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002661}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002662
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002663// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002664static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002665{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002666 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002667 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002668 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002669 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002670 if (!pPipeTrav) {
2671 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002672 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002673 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 -08002674 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002675 }
2676 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002677 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002678}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002679
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002680// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002681static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002682{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002683 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002684 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 -06002685 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002686 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002687 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002688 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002689 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002690 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 +08002691 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002692 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002693 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 -06002694 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002695 // Print out set details
2696 char prefix[10];
2697 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002698 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 +08002699 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002700 LAYOUT_NODE* pLayout = pSet->pLayout;
2701 // Print layout details
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 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, reinterpret_cast<uint64_t>(pLayout->layout), reinterpret_cast<uint64_t>(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002704 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002705 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002706 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 -06002707 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002708 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002709 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2710 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002711 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 +08002712 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002713 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002714 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 -08002715 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002716 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002717 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002718 if (0 != pSet->descriptorCount) {
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 "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 -06002721 } else {
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",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002723 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002724 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002725 }
2726 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002727 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002728}
2729
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002730static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002731{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002732 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedod8f83d82015-04-27 16:36:17 -06002733 if (pCB && pCB->pCmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002734 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 -06002735 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06002736 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002737 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2738 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002739 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",
Michael Lentine010f4692015-11-03 16:19:46 -08002740 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002741 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002742 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002743 // Nothing to print
2744 }
2745}
2746
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002747static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002748{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002749 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002750 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002751 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002752 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002753 skipCall |= printDSConfig(my_data, cb);
2754 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002755 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002756}
2757
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002758// Flags validation error if the associated call is made inside a render pass. The apiName
2759// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002760static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002761{
2762 VkBool32 inside = VK_FALSE;
2763 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002764 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 -07002765 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002766 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002767 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002768 }
2769 return inside;
2770}
2771
2772// Flags validation error if the associated call is made outside a render pass. The apiName
2773// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002774static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002775{
2776 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002777 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2778 (!pCB->activeRenderPass)) ||
2779 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2780 (!pCB->activeRenderPass) &&
2781 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002782 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 -07002783 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002784 "%s: This call must be issued inside an active render pass.", apiName);
2785 }
2786 return outside;
2787}
2788
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002789static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002790{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002791 uint32_t report_flags = 0;
2792 uint32_t debug_action = 0;
2793 FILE *log_output = NULL;
2794 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002795 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002796 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002797 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2798 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002799
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002800 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002801 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002802 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002803 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002804 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002805 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002806 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002807 dbgInfo.pfnCallback = log_callback;
2808 dbgInfo.pUserData = log_output;
2809 dbgInfo.flags = report_flags;
2810 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002811 my_data->logging_callback.push_back(callback);
2812 }
2813
2814 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002815 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002816 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002817 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002818 dbgInfo.pfnCallback = win32_debug_output_msg;
2819 dbgInfo.pUserData = log_output;
2820 dbgInfo.flags = report_flags;
2821 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002822 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002823 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002824
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002825 if (!globalLockInitialized)
2826 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002827 loader_platform_thread_create_mutex(&globalLock);
2828 globalLockInitialized = 1;
2829 }
2830}
2831
Chia-I Wu9ab61502015-11-06 06:42:02 +08002832VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002833{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002834 // TODOSC : Shouldn't need any customization here
Tobin Ehlis0b632332015-10-07 09:38:40 -06002835 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2836 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002837 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002838
2839 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002840 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2841 my_data->report_data = debug_report_create_instance(
2842 pTable,
2843 *pInstance,
Jon Ashburnf19916e2016-01-11 13:12:43 -07002844 pCreateInfo->enabledExtensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002845 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06002846
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002847 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002848 }
2849 return result;
2850}
2851
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002852/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002853VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002854{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002855 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002856 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002857 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2858 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002859 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002860
2861 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002862 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002863 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002864 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002865 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002866 }
2867
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002868 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002869 delete my_data->instance_dispatch_table;
2870 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002871 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002872 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002873 // Release mutex when destroying last instance.
2874 loader_platform_thread_delete_mutex(&globalLock);
2875 globalLockInitialized = 0;
2876 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002877}
2878
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002879static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2880{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002881 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002882 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2883 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002884 dev_data->device_extensions.wsi_enabled = false;
2885
2886
2887 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2888 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2889
Michael Lentineabc5e922015-10-12 11:30:14 -05002890 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2891 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2892 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2893 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002894 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002895
Jon Ashburnf19916e2016-01-11 13:12:43 -07002896 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002897 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002898 dev_data->device_extensions.wsi_enabled = true;
2899 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002900 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002901 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002902 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002903 initDebugMarkerTable(device);
2904
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002905 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002906 }
2907}
2908
Chia-I Wu9ab61502015-11-06 06:42:02 +08002909VK_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 -06002910{
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002911 layer_data *instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
2912 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
2913 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
2914
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002915 if (result == VK_SUCCESS) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002916 dev_data->report_data = layer_debug_report_create_device(instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06002917 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002918 // Get physical device limits for this device
2919 instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002920 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002921 return result;
2922}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002923
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002924// prototype
2925static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002926VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002927{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002928 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002929 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002930 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002931 // Free all the memory
2932 loader_platform_thread_lock_mutex(&globalLock);
2933 deletePipelines(dev_data);
2934 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002935 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002936 deletePools(dev_data);
2937 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002938 dev_data->imageViewMap.clear();
2939 dev_data->imageMap.clear();
2940 dev_data->bufferViewMap.clear();
2941 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002942 loader_platform_thread_unlock_mutex(&globalLock);
2943
Chia-I Wuf7458c52015-10-26 21:10:41 +08002944 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002945 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002946 delete dev_data->device_dispatch_table;
2947 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002948}
2949
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002950static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002951 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002952 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2953 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002954 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002955};
2956
Chia-I Wu9ab61502015-11-06 06:42:02 +08002957VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002958 const char *pLayerName,
2959 uint32_t *pCount,
2960 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002961{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002962 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002963}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002964
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002965static const VkLayerProperties ds_global_layers[] = {
2966 {
Michael Lentine03107b42015-12-11 10:49:51 -08002967 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002968 VK_API_VERSION,
2969 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002970 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002971 }
2972};
2973
Chia-I Wu9ab61502015-11-06 06:42:02 +08002974VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002975 uint32_t *pCount,
2976 VkLayerProperties* pProperties)
2977{
2978 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2979 ds_global_layers,
2980 pCount, pProperties);
2981}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002982
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002983static const VkExtensionProperties ds_device_extensions[] = {
2984 {
2985 DEBUG_MARKER_EXTENSION_NAME,
2986 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002987 }
2988};
2989
2990static const VkLayerProperties ds_device_layers[] = {
2991 {
Michael Lentine1f8d4412016-01-19 14:19:38 -06002992 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002993 VK_API_VERSION,
2994 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002995 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002996 }
2997};
2998
Chia-I Wu9ab61502015-11-06 06:42:02 +08002999VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003000 VkPhysicalDevice physicalDevice,
3001 const char* pLayerName,
3002 uint32_t* pCount,
3003 VkExtensionProperties* pProperties)
3004{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003005 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003006 if (pLayerName == NULL) {
3007 dispatch_key key = get_dispatch_key(physicalDevice);
3008 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003009 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003010 physicalDevice,
3011 NULL,
3012 pCount,
3013 pProperties);
3014 } else {
3015 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3016 ds_device_extensions,
3017 pCount, pProperties);
3018 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003019}
3020
Chia-I Wu9ab61502015-11-06 06:42:02 +08003021VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003022 VkPhysicalDevice physicalDevice,
3023 uint32_t* pCount,
3024 VkLayerProperties* pProperties)
3025{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003026 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003027 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3028 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003029}
3030
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003031VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003032 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003033 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3034 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3035 for (auto cb_image_data : pCB->imageLayoutMap) {
3036 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3037 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003038 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 Lentine010f4692015-11-03 16:19:46 -08003039 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003040 } else {
3041 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003042 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 -05003043 "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);
3044 }
3045 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3046 }
3047 }
3048 return skip_call;
3049}
3050
Mark Young7a69c302016-01-07 09:48:47 -07003051VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003052 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003053 for (auto drawDataElement : pCB->drawData) {
3054 for (auto buffer : drawDataElement.buffers) {
3055 auto buffer_data = my_data->bufferMap.find(buffer);
3056 if (buffer_data == my_data->bufferMap.end()) {
3057 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, 0, DRAWSTATE_INVALID_BUFFER, "DS",
3058 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
3059 } else {
3060 buffer_data->second.in_use.fetch_add(1);
3061 }
3062 }
3063 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003064 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003065}
3066
3067void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3068 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3069 for (auto drawDataElement : pCB->drawData) {
3070 for (auto buffer : drawDataElement.buffers) {
3071 auto buffer_data = my_data->bufferMap.find(buffer);
3072 if (buffer_data != my_data->bufferMap.end()) {
3073 buffer_data->second.in_use.fetch_sub(1);
3074 }
3075 }
3076 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003077 for (auto queryStatePair : pCB->queryToStateMap) {
3078 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3079 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003080}
3081
3082void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3083 for (uint32_t i = 0; i < fenceCount; ++i) {
3084 auto fence_data = my_data->fenceMap.find(pFences[i]);
3085 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3086 fence_data->second.needsSignaled = false;
3087 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3088 decrementResources(my_data, 1, &fence_data->second.priorFence);
3089 }
3090 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3091 decrementResources(my_data, cmdBuffer);
3092 }
3093 }
3094}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003095
Michael Lentine700b0aa2015-10-30 17:57:32 -07003096void decrementResources(layer_data* my_data, VkQueue queue) {
3097 auto queue_data = my_data->queueMap.find(queue);
3098 if (queue_data != my_data->queueMap.end()) {
3099 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3100 decrementResources(my_data, cmdBuffer);
3101 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003102 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003103 decrementResources(my_data, 1, &queue_data->second.priorFence);
3104 }
3105}
3106
3107void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3108 auto queue_data = my_data->queueMap.find(queue);
3109 if (fence != VK_NULL_HANDLE) {
3110 VkFence priorFence = VK_NULL_HANDLE;
3111 if (queue_data != my_data->queueMap.end()) {
3112 priorFence = queue_data->second.priorFence;
3113 queue_data->second.priorFence = fence;
3114 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3115 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3116 }
3117 queue_data->second.untrackedCmdBuffers.clear();
3118 }
3119 my_data->fenceMap[fence].cmdBuffers.clear();
3120 my_data->fenceMap[fence].priorFence = priorFence;
3121 my_data->fenceMap[fence].needsSignaled = true;
3122 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3123 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3124 }
3125 } else {
3126 if (queue_data != my_data->queueMap.end()) {
3127 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3128 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3129 }
3130 }
3131 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003132 if (queue_data != my_data->queueMap.end()) {
3133 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3134 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
3135 }
3136 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003137}
3138
Chia-I Wu9ab61502015-11-06 06:42:02 +08003139VK_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 -06003140{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003141 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003142 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003143 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003144 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
3145 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003146 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003147 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003148 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3149 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3150 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3151 } else {
3152 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",
3153 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3154 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3155 }
3156 }
3157 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3158 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3159 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003160 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003161
3162#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3163 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3164#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3165
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003166 // Validate that cmd buffers have been updated
3167 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3168 loader_platform_thread_lock_mutex(&globalLock);
3169 pCB->submitCount++; // increment submit count
Michael Lentine700b0aa2015-10-30 17:57:32 -07003170 skipCall |= validateAndIncrementResources(dev_data, pCB);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003171 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003172 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 -05003173 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3174 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003175 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003176 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003177 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003178 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",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003179 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->commandBuffer));
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003180 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003181 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003182 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003183 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003184 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003185 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003186 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003187 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003188 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003189 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003190}
3191
Mark Youngb20a6a82016-01-07 15:41:43 -07003192VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3193 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003194 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3195 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3196 for (auto event : queryEventsPair.second) {
3197 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003198 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",
3199 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003200 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3201 }
3202 }
3203 }
3204 return skip_call;
3205}
3206
Michael Lentine700b0aa2015-10-30 17:57:32 -07003207VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3208{
3209 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3210 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003211 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003212 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003213 for (uint32_t i = 0; i < fenceCount; ++i) {
3214 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3215 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3216 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3217 }
3218 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003219 decrementResources(dev_data, fenceCount, pFences);
3220 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003221 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003222 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003223 return result;
3224}
3225
3226
3227VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3228{
3229 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3230 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
3231 if (result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003232 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
3233 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3234 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3235 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003236 decrementResources(dev_data, 1, &fence);
3237 }
3238 return result;
3239}
3240
3241VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3242{
3243 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3244 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
3245 dev_data->deviceMap[device].queues.push_back(*pQueue);
3246 dev_data->queueMap[*pQueue].device = device;
3247}
3248
3249VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3250{
3251 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3252 decrementResources(dev_data, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003253 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3254 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3255 }
3256 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003257 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3258}
3259
3260VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3261{
3262 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3263 auto device_data = dev_data->deviceMap.find(device);
3264 if (device_data != dev_data->deviceMap.end()) {
3265 for (auto queue : device_data->second.queues) {
3266 decrementResources(dev_data, queue);
3267 }
3268 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003269 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3270 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3271 }
3272 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003273 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3274}
3275
Chia-I Wu9ab61502015-11-06 06:42:02 +08003276VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003277{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003278 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 -06003279 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003280}
3281
Chia-I Wu9ab61502015-11-06 06:42:02 +08003282VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003283{
Michael Lentine15a47882016-01-06 10:05:48 -06003284 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3285 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3286 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003287 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003288}
3289
Chia-I Wu9ab61502015-11-06 06:42:02 +08003290VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003291{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003292 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 -06003293 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003294}
3295
Chia-I Wu9ab61502015-11-06 06:42:02 +08003296VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003297{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003298 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 -06003299 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003300}
3301
Mark Lobodzinskice738852016-01-07 10:04:02 -07003302VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003303 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3304 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3305 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3306 GLOBAL_CB_NODE* pCB = nullptr;
3307 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3308 pCB = getCBNode(dev_data, cmdBuffer);
3309 for (auto queryStatePair : pCB->queryToStateMap) {
3310 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3311 }
3312 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003313 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003314 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003315 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003316 auto queryElement = queriesInFlight.find(query);
3317 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3318 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3319 }
3320 // Available and in flight
3321 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3322 for (auto cmdBuffer : queryElement->second) {
3323 pCB = getCBNode(dev_data, cmdBuffer);
3324 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3325 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003326 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3327 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3328 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003329 } else {
3330 for (auto event : queryEventElement->second) {
3331 dev_data->eventMap[event].needsSignaled = true;
3332 }
3333 }
3334 }
3335 // Unavailable and in flight
3336 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3337 // TODO : Can there be the same query in use by multiple command buffers in flight?
3338 bool make_available = false;
3339 for (auto cmdBuffer : queryElement->second) {
3340 pCB = getCBNode(dev_data, cmdBuffer);
3341 make_available |= pCB->queryToStateMap[query];
3342 }
3343 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003344 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 -06003345 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003346 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003347 }
3348 // Unavailable
3349 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003350 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 -06003351 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003352 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003353 // Unitialized
3354 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003355 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 -06003356 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003357 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003358 }
3359 }
3360 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003361 return VK_ERROR_VALIDATION_FAILED_EXT;
3362 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003363}
3364
Mark Young7a69c302016-01-07 09:48:47 -07003365VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003366 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003367 auto buffer_data = my_data->bufferMap.find(buffer);
3368 if (buffer_data == my_data->bufferMap.end()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003369 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003370 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3371 } else {
3372 if (buffer_data->second.in_use.load()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003373 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
Michael Lentine700b0aa2015-10-30 17:57:32 -07003374 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
3375
3376 }
3377 }
3378 return skip_call;
3379}
3380
Chia-I Wu9ab61502015-11-06 06:42:02 +08003381VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003382{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003383 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003384 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003385 if (!validateIdleBuffer(dev_data, buffer)) {
3386 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3387 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003388 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003389}
3390
Chia-I Wu9ab61502015-11-06 06:42:02 +08003391VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003392{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003393 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003394 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003395 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003396}
3397
Chia-I Wu9ab61502015-11-06 06:42:02 +08003398VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003399{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003400 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003401 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003402 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003403}
3404
Chia-I Wu9ab61502015-11-06 06:42:02 +08003405VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003406{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003407 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 -06003408 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003409}
3410
Chia-I Wu9ab61502015-11-06 06:42:02 +08003411VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003412{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003413 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 -06003414 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003415}
3416
Chia-I Wu9ab61502015-11-06 06:42:02 +08003417VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003418{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003419 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 -06003420 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003421}
3422
Chia-I Wu9ab61502015-11-06 06:42:02 +08003423VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003424{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003425 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 -06003426 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003427}
3428
Chia-I Wu9ab61502015-11-06 06:42:02 +08003429VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003430{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003431 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 -06003432 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003433}
3434
Chia-I Wu9ab61502015-11-06 06:42:02 +08003435VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003436{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003437 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 -06003438 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003439}
3440
Chia-I Wu9ab61502015-11-06 06:42:02 +08003441VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003442{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003443 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 -06003444 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003445}
3446
Chia-I Wu9ab61502015-11-06 06:42:02 +08003447VK_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 -06003448{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003449 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3450
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003451 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003452 // Delete CB information structure, and remove from commandBufferMap
3453 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003454 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003455 if (cb != dev_data->commandBufferMap.end()) {
3456 delete (*cb).second;
3457 dev_data->commandBufferMap.erase(cb);
3458 }
3459
3460 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003461 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003462 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003463 }
3464
3465 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3466}
3467
3468VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3469{
3470 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3471
3472 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3473
3474 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003475 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003476 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003477 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003478 }
3479 return result;
3480}
3481
3482VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3483{
3484 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003485 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003486
3487 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3488 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003489 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003490 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3491 delete (*del_cb).second; // delete CB info structure
3492 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003493 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003494 }
3495 }
3496 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003497
3498 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003499 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003500}
3501
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003502VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3503 VkDevice device,
3504 VkCommandPool commandPool,
3505 VkCommandPoolResetFlags flags)
3506{
3507 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003508 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003509
3510 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3511 // Reset all of the CBs allocated from this pool
3512 if (VK_SUCCESS == result) {
3513 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3514 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3515 resetCB(dev_data, (*it));
3516 ++it;
3517 }
3518 }
3519 return result;
3520}
3521
Chia-I Wu9ab61502015-11-06 06:42:02 +08003522VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003523{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003524 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 -06003525 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003526}
3527
Chia-I Wu9ab61502015-11-06 06:42:02 +08003528VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003529{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003530 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 -06003531 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003532}
3533
Chia-I Wu9ab61502015-11-06 06:42:02 +08003534VK_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 -06003535{
3536 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003537 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003538 if (VK_SUCCESS == result) {
3539 loader_platform_thread_lock_mutex(&globalLock);
3540 // 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 -07003541 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3542 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003543 loader_platform_thread_unlock_mutex(&globalLock);
3544 }
3545 return result;
3546}
3547
Chia-I Wu9ab61502015-11-06 06:42:02 +08003548VK_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 -06003549{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003550 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003551 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003552 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003553 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003554 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003555 loader_platform_thread_unlock_mutex(&globalLock);
3556 }
3557 return result;
3558}
3559
Chia-I Wu9ab61502015-11-06 06:42:02 +08003560VK_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 -06003561{
3562 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003563 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003564 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003565 IMAGE_NODE* image_node = new IMAGE_NODE;
3566 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003567 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003568 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003569 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003570 loader_platform_thread_unlock_mutex(&globalLock);
3571 }
3572 return result;
3573}
3574
Chia-I Wu9ab61502015-11-06 06:42:02 +08003575VK_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 -06003576{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003577 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003578 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003579 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003580 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003581 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003582 loader_platform_thread_unlock_mutex(&globalLock);
3583 }
3584 return result;
3585}
3586
Jon Ashburnc669cc62015-07-09 15:02:25 -06003587//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003588VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003589 VkDevice device,
3590 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003591 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003592 VkPipelineCache* pPipelineCache)
3593{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003594 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003595 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003596 return result;
3597}
3598
Chia-I Wu9ab61502015-11-06 06:42:02 +08003599VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003600 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003601 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003602 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003603{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003604 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003605 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003606}
3607
Chia-I Wu9ab61502015-11-06 06:42:02 +08003608VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003609 VkDevice device,
3610 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003611 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003612 void* pData)
3613{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003614 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003615 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003616 return result;
3617}
3618
Chia-I Wu9ab61502015-11-06 06:42:02 +08003619VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003620 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003621 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003622 uint32_t srcCacheCount,
3623 const VkPipelineCache* pSrcCaches)
3624{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003625 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003626 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003627 return result;
3628}
3629
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003630VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3631 VkDevice device,
3632 VkPipelineCache pipelineCache,
3633 uint32_t count,
3634 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3635 const VkAllocationCallbacks *pAllocator,
3636 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003637{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003638 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003639 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003640 // The order of operations here is a little convoluted but gets the job done
3641 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3642 // 2. Create state is then validated (which uses flags setup during shadowing)
3643 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003644 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003645 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3646 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003647 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003648
Tobin Ehlis11efc302015-09-16 10:33:53 -06003649 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003650 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003651
Tobin Ehlis11efc302015-09-16 10:33:53 -06003652 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003653 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003654 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003655 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003656
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003657 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003658
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003659 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003660 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3661 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003662 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003663 for (i=0; i<count; i++) {
3664 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003665 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003666 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003667 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003668 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003669 for (i=0; i<count; i++) {
3670 if (pPipeNode[i]) {
3671 // If we allocated a pipeNode, need to clean it up here
3672 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3673 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3674 delete[] pPipeNode[i]->pAttachments;
3675 delete pPipeNode[i];
3676 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003677 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003678 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003679 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003680 return result;
3681}
3682
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003683VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3684 VkDevice device,
3685 VkPipelineCache pipelineCache,
3686 uint32_t count,
3687 const VkComputePipelineCreateInfo *pCreateInfos,
3688 const VkAllocationCallbacks *pAllocator,
3689 VkPipeline *pPipelines)
3690{
3691 VkResult result = VK_SUCCESS;
3692 VkBool32 skipCall = VK_FALSE;
3693
3694 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3695 vector<PIPELINE_NODE*> pPipeNode(count);
3696 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3697
3698 uint32_t i=0;
3699 loader_platform_thread_lock_mutex(&globalLock);
3700 for (i=0; i<count; i++) {
3701 // TODO: Verify compute stage bits
3702
3703 // Create and initialize internal tracking data structure
3704 pPipeNode[i] = new PIPELINE_NODE;
3705 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3706 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3707
3708 // TODO: Add Compute Pipeline Verification
3709 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3710 }
3711 loader_platform_thread_unlock_mutex(&globalLock);
3712
3713 if (VK_FALSE == skipCall) {
3714 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3715 loader_platform_thread_lock_mutex(&globalLock);
3716 for (i=0; i<count; i++) {
3717 pPipeNode[i]->pipeline = pPipelines[i];
3718 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3719 }
3720 loader_platform_thread_unlock_mutex(&globalLock);
3721 } else {
3722 for (i=0; i<count; i++) {
3723 if (pPipeNode[i]) {
3724 // Clean up any locally allocated data structures
3725 delete pPipeNode[i];
3726 }
3727 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003728 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003729 }
3730 return result;
3731}
3732
Chia-I Wu9ab61502015-11-06 06:42:02 +08003733VK_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 -06003734{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003735 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003736 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003737 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003738 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003739 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003740 loader_platform_thread_unlock_mutex(&globalLock);
3741 }
3742 return result;
3743}
3744
Chia-I Wu9ab61502015-11-06 06:42:02 +08003745VK_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 -06003746{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003747 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003748 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003749 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003750 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003751 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3752 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003753 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 -06003754 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003755 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003756 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003757 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003758 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3759 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003760 // g++ does not like reserve with size 0
3761 if (pCreateInfo->bindingCount)
3762 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003763 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003764 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003765 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003766 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 +08003767 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003768 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003769 }
3770
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003771 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3772 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3773 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3774 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3775 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003776 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003777 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003778 pNewNode->layout = *pSetLayout;
3779 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003780 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003781 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003782 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003783 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003784 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003785 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003786 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003787 dType = pCreateInfo->pBindings[i].descriptorType;
3788 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003789 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003790 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003791 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3792 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3793 pNewNode->dynamicDescriptorCount++;
3794 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003795 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003796 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003797 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003798 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3799 } else { // no descriptors
3800 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003801 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003802 // Put new node at Head of global Layer list
3803 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003804 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003805 loader_platform_thread_unlock_mutex(&globalLock);
3806 }
3807 return result;
3808}
3809
Chia-I Wu9ab61502015-11-06 06:42:02 +08003810VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003811{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003812 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003813 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003814 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003815 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003816 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003817 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003818 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003819 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003820 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3821 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003822 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003823 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3824 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3825 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003826 }
3827 return result;
3828}
3829
Chia-I Wu9ab61502015-11-06 06:42:02 +08003830VK_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 -06003831{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003832 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003833 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003834 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003835 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003836 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 +08003837 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003838 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003839 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003840 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003841 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003842 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 -07003843 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003844 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003845 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003846 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003847 }
3848 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003849 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003850 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003851 }
3852 return result;
3853}
3854
Chia-I Wu9ab61502015-11-06 06:42:02 +08003855VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003856{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003857 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003858 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003859 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003860 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003861 }
3862 return result;
3863}
3864
Chia-I Wu9ab61502015-11-06 06:42:02 +08003865VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003866{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003867 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003868 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003869 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003870 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003871 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003872 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 +08003873 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003874 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003875 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003876 }
3877 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003878 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003879 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003880 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003881 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003882 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003883 if (pAllocateInfo->descriptorSetCount == 0) {
3884 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 +08003885 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003886 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003887 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003888 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 +08003889 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003890 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003891 SET_NODE* pNewNode = new SET_NODE;
3892 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003893 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 +08003894 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003895 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003896 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003897 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003898 // TODO : Pool should store a total count of each type of Descriptor available
3899 // When descriptors are allocated, decrement the count and validate here
3900 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003901 // Insert set at head of Set LL for this pool
3902 pNewNode->pNext = pPoolNode->pSets;
3903 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003904 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003905 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003906 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 +08003907 "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 -07003908 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003909 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003910 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003911 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003912 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003913 pNewNode->descriptorCount = pLayout->endIndex + 1;
3914 if (pNewNode->descriptorCount) {
3915 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3916 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3917 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3918 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003919 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003920 }
3921 }
3922 }
3923 }
3924 return result;
3925}
3926
Chia-I Wu9ab61502015-11-06 06:42:02 +08003927VK_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 -06003928{
Tobin Ehlise735c692015-10-08 13:13:50 -06003929 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003930 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003931 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003932 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3933 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003934 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 -06003935 "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 -06003936 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003937 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003938 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003939 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003940 if (VK_SUCCESS == result) {
3941 // For each freed descriptor add it back into the pool as available
3942 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003943 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003944 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003945 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003946 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003947 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
3948 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003949 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003950 }
3951 }
3952 }
3953 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06003954 return result;
3955}
3956
Chia-I Wu9ab61502015-11-06 06:42:02 +08003957VK_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 -06003958{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003959 // 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 -06003960 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003961 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3962 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003963 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003964}
3965
Chia-I Wu9ab61502015-11-06 06:42:02 +08003966VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003967{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003968 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003969 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003970 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003971 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003972 // Validate command pool
3973 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003974 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003975 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003976 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003977 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3978 // Add command buffer to map
3979 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003980 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003981 resetCB(dev_data, pCommandBuffer[i]);
3982 pCB->commandBuffer = pCommandBuffer[i];
3983 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07003984 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07003985 }
3986 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003987 }
3988 return result;
3989}
3990
Chia-I Wu9ab61502015-11-06 06:42:02 +08003991VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003992{
Mark Youngb20a6a82016-01-07 15:41:43 -07003993 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003994 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003995 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003996 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06003997 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003998 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
3999 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004000 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4001 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4002 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004003 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004004 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004005 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004006 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 -07004007 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4008 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004009 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004010 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 -07004011 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4012 } else {
4013 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004014 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4015 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004016 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004017 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 -07004018 "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 -07004019 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004020 }
4021 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004022 }
4023 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004024 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004025 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 -07004026 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4027 } else if (CB_RECORDED == pCB->state) {
4028 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4029 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004030 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 -07004031 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004032 "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.",
4033 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4034 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004035 resetCB(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004036 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004037 // Set updated state here in case implicit reset occurs above
4038 pCB->state = CB_RECORDING;
4039 pCB->beginInfo = *pBeginInfo;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004040 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004041 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 +08004042 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004043 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004044 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004045 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004046 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004047 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004048 return result;
4049}
4050
Chia-I Wu9ab61502015-11-06 06:42:02 +08004051VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004052{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004053 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004054 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004055 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4056 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004057 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004058 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004059 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004060 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004061 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004062 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004063 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004064 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004065 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004066 // Reset CB status flags
4067 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004068 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004069 }
4070 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004071 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004072 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004073 return result;
4074}
4075
Chia-I Wu9ab61502015-11-06 06:42:02 +08004076VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004077{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004078 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004079 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004080 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4081 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4082 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004083 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 -07004084 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004085 "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.",
4086 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4087 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004088 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004089 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004090 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004091 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004092 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004093 }
4094 return result;
4095}
4096
Chia-I Wu9ab61502015-11-06 06:42:02 +08004097VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004098{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004099 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004100 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4101 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004102 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004103 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4104 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4105 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 -07004106 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004107 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4108 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4109 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4110 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4111 }
4112
4113 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4114 if (pPN) {
4115 pCB->lastBoundPipeline = pipeline;
4116 loader_platform_thread_lock_mutex(&globalLock);
4117 set_cb_pso_status(pCB, pPN);
4118 loader_platform_thread_unlock_mutex(&globalLock);
4119 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004120 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004121 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 -07004122 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004123 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004124 }
4125 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004126 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004127 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004128}
4129
Chia-I Wu9ab61502015-11-06 06:42:02 +08004130VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004131 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004132 uint32_t firstViewport,
4133 uint32_t viewportCount,
4134 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004135{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004136 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004137 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4138 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004139 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004140 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4141 loader_platform_thread_lock_mutex(&globalLock);
4142 pCB->status |= CBSTATUS_VIEWPORT_SET;
4143 pCB->viewports.resize(viewportCount);
4144 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4145 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004146 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004147 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004148 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004149}
4150
Chia-I Wu9ab61502015-11-06 06:42:02 +08004151VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004152 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004153 uint32_t firstScissor,
4154 uint32_t scissorCount,
4155 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004156{
4157 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004158 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4159 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004160 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004161 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4162 loader_platform_thread_lock_mutex(&globalLock);
4163 pCB->status |= CBSTATUS_SCISSOR_SET;
4164 pCB->scissors.resize(scissorCount);
4165 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4166 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004167 }
4168 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004169 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004170}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004171
Chia-I Wu9ab61502015-11-06 06:42:02 +08004172VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004173{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004174 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004175 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4176 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004177 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004178 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4179 /* TODO: Do we still need this lock? */
4180 loader_platform_thread_lock_mutex(&globalLock);
4181 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4182 pCB->lineWidth = lineWidth;
4183 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004184 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004185 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004186 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004187}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004188
Chia-I Wu9ab61502015-11-06 06:42:02 +08004189VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004190 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004191 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004192 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004193 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004194{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004195 VkBool32 skipCall = VK_FALSE;
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);
Cody Northrop12365112015-08-17 11:10:49 -06004198 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004199 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4200 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4201 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4202 pCB->depthBiasClamp = depthBiasClamp;
4203 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004204 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004205 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004206 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004207}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004208
Chia-I Wu9ab61502015-11-06 06:42:02 +08004209VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004210{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004211 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004212 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4213 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004214 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004215 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4216 pCB->status |= CBSTATUS_BLEND_SET;
4217 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004218 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004219 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004220 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004221}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004222
Chia-I Wu9ab61502015-11-06 06:42:02 +08004223VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004224 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004225 float minDepthBounds,
4226 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004227{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004228 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004229 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4230 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004231 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004232 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4233 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4234 pCB->minDepthBounds = minDepthBounds;
4235 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004236 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004237 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004238 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004239}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004240
Chia-I Wu9ab61502015-11-06 06:42:02 +08004241VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004242 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004243 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004244 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004245{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004246 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004247 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4248 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004249 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004250 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4251 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4252 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004253 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004254 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4255 pCB->back.compareMask = compareMask;
4256 }
4257 /* TODO: Do we need to track front and back separately? */
4258 /* TODO: We aren't capturing the faceMask, do we need to? */
4259 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004260 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004261 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004262 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004263}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004264
Chia-I Wu9ab61502015-11-06 06:42:02 +08004265VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004266 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004267 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004268 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004269{
4270 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004271 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4272 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004273 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004274 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4275 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4276 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004277 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004278 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4279 pCB->back.writeMask = writeMask;
4280 }
4281 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004282 }
4283 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004284 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004285}
4286
Chia-I Wu9ab61502015-11-06 06:42:02 +08004287VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004288 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004289 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004290 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004291{
4292 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004293 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4294 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004295 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004296 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4297 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4298 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004299 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004300 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4301 pCB->back.reference = reference;
4302 }
4303 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004304 }
4305 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004306 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004307}
4308
Chia-I Wu9ab61502015-11-06 06:42:02 +08004309VK_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 -06004310{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004311 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004312 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4313 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004314 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004315 if (pCB->state == CB_RECORDING) {
4316 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004317 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 -07004318 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4319 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4320 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004321 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004322 if (VK_FALSE == skipCall) {
4323 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4324 uint32_t totalDynamicDescriptors = 0;
4325 string errorString = "";
4326 uint32_t lastSetIndex = firstSet+setCount-1;
4327 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004328 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004329 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4330 for (uint32_t i=0; i<setCount; i++) {
4331 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4332 if (pSet) {
4333 loader_platform_thread_lock_mutex(&globalLock);
4334 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4335 pCB->lastBoundPipelineLayout = layout;
4336 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4337 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004338 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 -07004339 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004340 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004341 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 -07004342 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4343 }
4344 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4345 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004346 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 -07004347 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4348 }
4349 if (pSet->pLayout->dynamicDescriptorCount) {
4350 // First make sure we won't overstep bounds of pDynamicOffsets array
4351 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004352 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 -07004353 "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.",
4354 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004355 } else { // Validate and store dynamic offsets with the set
4356 // Validate Dynamic Offset Minimums
4357 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4358 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4359 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4360 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4361 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4362 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4363 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4364 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4365 }
4366 cur_dyn_offset++;
4367 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4368 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4369 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4370 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4371 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4372 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4373 }
4374 cur_dyn_offset++;
4375 }
4376 }
4377 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004378 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4379 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4380 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4381 }
4382 }
4383 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004384 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 -07004385 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4386 }
4387 }
4388 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4389 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4390 if (firstSet > 0) { // Check set #s below the first bound set
4391 for (uint32_t i=0; i<firstSet; ++i) {
4392 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 -07004393 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 -07004394 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4395 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4396 }
4397 }
4398 }
4399 // Check if newly last bound set invalidates any remaining bound sets
4400 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4401 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004402 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 -07004403 "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);
4404 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4405 }
4406 }
4407 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4408 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004409 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 -07004410 "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 -07004411 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004412 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004413 } else {
4414 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004415 }
4416 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004417 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004418 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004419}
4420
Chia-I Wu9ab61502015-11-06 06:42:02 +08004421VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004422{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004423 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004424 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4425 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004426 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004427 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4428 VkDeviceSize offset_align = 0;
4429 switch (indexType) {
4430 case VK_INDEX_TYPE_UINT16:
4431 offset_align = 2;
4432 break;
4433 case VK_INDEX_TYPE_UINT32:
4434 offset_align = 4;
4435 break;
4436 default:
4437 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4438 break;
4439 }
4440 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004441 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 -07004442 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004443 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004444 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004445 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004446 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004447 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004448}
4449
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004450void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4451 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004452 if (pCB->currentDrawData.buffers.size() < end) {
4453 pCB->currentDrawData.buffers.resize(end);
4454 }
4455 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004456 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004457 }
4458}
4459
4460void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4461 pCB->drawData.push_back(pCB->currentDrawData);
4462}
4463
Chia-I Wu9ab61502015-11-06 06:42:02 +08004464VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004465 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004466 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004467 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004468 const VkBuffer *pBuffers,
4469 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004470{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004471 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004472 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4473 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004474 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004475 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004476 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004477 } else {
Mark Youngad779052016-01-06 14:26:04 -07004478 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004479 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004480 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004481 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004482}
4483
Chia-I Wu9ab61502015-11-06 06:42:02 +08004484VK_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 -06004485{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004486 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004487 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4488 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004489 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004490 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4491 pCB->drawCount[DRAW]++;
4492 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4493 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004494 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 -07004495 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4496 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004497 if (VK_FALSE == skipCall) {
4498 updateResourceTrackingOnDraw(pCB);
4499 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004500 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004501 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004502 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004503 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004504}
4505
Chia-I Wu9ab61502015-11-06 06:42:02 +08004506VK_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 -06004507{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004508 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4509 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004510 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004511 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004512 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4513 pCB->drawCount[DRAW_INDEXED]++;
4514 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4515 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004516 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 -07004517 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4518 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004519 if (VK_FALSE == skipCall) {
4520 updateResourceTrackingOnDraw(pCB);
4521 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004522 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004523 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004524 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004525 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004526}
4527
Chia-I Wu9ab61502015-11-06 06:42:02 +08004528VK_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 -06004529{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004530 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4531 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004532 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004533 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004534 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4535 pCB->drawCount[DRAW_INDIRECT]++;
4536 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4537 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004538 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 -07004539 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4540 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004541 if (VK_FALSE == skipCall) {
4542 updateResourceTrackingOnDraw(pCB);
4543 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004544 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004545 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004546 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004547 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004548}
4549
Chia-I Wu9ab61502015-11-06 06:42:02 +08004550VK_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 -06004551{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004552 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004553 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4554 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004555 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004556 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4557 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4558 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4559 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004560 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 -07004561 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4562 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004563 if (VK_FALSE == skipCall) {
4564 updateResourceTrackingOnDraw(pCB);
4565 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004566 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004567 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004568 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004569 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004570}
4571
Chia-I Wu9ab61502015-11-06 06:42:02 +08004572VK_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 -06004573{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004574 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004575 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4576 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004577 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004578 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004579 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004580 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004581 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004582 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004583}
4584
Chia-I Wu9ab61502015-11-06 06:42:02 +08004585VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004586{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004587 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004588 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4589 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004590 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004591 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004592 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004593 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004594 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004595 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004596}
4597
Chia-I Wu9ab61502015-11-06 06:42:02 +08004598VK_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 -06004599{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004600 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004601 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4602 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004603 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004604 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004605 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004606 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004607 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004608 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004609}
4610
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004611VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004612 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004613
4614#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4615 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4616 return skip_call;
4617#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4618
Michael Lentineabc5e922015-10-12 11:30:14 -05004619 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4620 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4621 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4622 if (src_image_element == pCB->imageLayoutMap.end()) {
4623 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4624 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004625 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004626 }
4627 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004628 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 -05004629 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4630 }
4631 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4632 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004633 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004634 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 -05004635 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004636 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004637 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 -05004638 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004639 }
4640 }
4641 return skip_call;
4642}
4643
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004644VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004645 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004646
4647#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4648 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4649 return skip_call;
4650#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4651
Michael Lentineabc5e922015-10-12 11:30:14 -05004652 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4653 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4654 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4655 if (dest_image_element == pCB->imageLayoutMap.end()) {
4656 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4657 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004658 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004659 }
4660 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004661 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 -05004662 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4663 }
4664 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4665 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004666 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004667 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 -05004668 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4669 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004670 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 -05004671 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4672 }
4673 }
4674 return skip_call;
4675}
4676
Chia-I Wu9ab61502015-11-06 06:42:02 +08004677VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004678 VkImage srcImage,
4679 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004680 VkImage dstImage,
4681 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004682 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004683{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004684 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004685 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4686 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004687 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004688 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004689 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004690 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4691 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004692 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004693 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004694 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004695}
4696
Chia-I Wu9ab61502015-11-06 06:42:02 +08004697VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004698 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004699 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004700 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004701 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004702{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004703 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004704 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4705 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004706 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004707 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004708 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -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->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004712}
4713
Chia-I Wu9ab61502015-11-06 06:42:02 +08004714VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004715 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004716 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004717 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004718{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004719 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004720 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4721 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004722 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004723 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004724 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004725 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004726 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004727 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004728 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004729}
4730
Chia-I Wu9ab61502015-11-06 06:42:02 +08004731VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004732 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004733 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004734 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004735{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004736 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004737 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4738 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004739 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004740 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004741 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004742 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004743 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004744 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004745 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004746}
4747
Chia-I Wu9ab61502015-11-06 06:42:02 +08004748VK_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 -06004749{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004750 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004751 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4752 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004753 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004754 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004755 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004756 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004757 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004758 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004759}
4760
Chia-I Wu9ab61502015-11-06 06:42:02 +08004761VK_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 -06004762{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004763 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004764 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4765 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004766 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004767 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004768 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004769 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004770 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004771 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004772}
4773
Chia-I Wu9ab61502015-11-06 06:42:02 +08004774VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004775 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004776 uint32_t attachmentCount,
4777 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004778 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004779 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004780{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004781 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004782 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4783 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004784 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004785 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4786 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4787 if (!hasDrawCmd(pCB) &&
4788 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4789 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4790 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004791 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 -07004792 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4793 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", reinterpret_cast<uint64_t>(commandBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004794 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004795 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4796 }
4797
4798 // Validate that attachment is in reference list of active subpass
4799 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004800 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004801 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4802
4803 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4804 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4805 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4806 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004807 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004808 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4809 found = VK_TRUE;
4810 break;
4811 }
4812 }
4813 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004814 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 -07004815 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004816 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4817 attachment->colorAttachment, pCB->activeSubpass);
4818 }
4819 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004820 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004821 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004822
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004823 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 -07004824 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004825 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4826 attachment->colorAttachment,
4827 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4828 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004829 }
4830 }
4831 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004832 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004833 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004834 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004835}
4836
Chia-I Wu9ab61502015-11-06 06:42:02 +08004837VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004838 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004839 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004840 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004841 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004842{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004843 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004844 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4845 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004846 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004847 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004848 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004849 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004850 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004851 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004852}
4853
Chia-I Wu9ab61502015-11-06 06:42:02 +08004854VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004855 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004856 VkImage image, VkImageLayout imageLayout,
4857 const VkClearDepthStencilValue *pDepthStencil,
4858 uint32_t rangeCount,
4859 const VkImageSubresourceRange* pRanges)
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_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004866 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004867 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004868 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004869 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004870}
4871
Chia-I Wu9ab61502015-11-06 06:42:02 +08004872VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004873 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004874 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004875 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004876{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004877 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004878 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4879 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004880 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004881 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004882 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004883 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004884 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004885 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004886}
4887
Chia-I Wu9ab61502015-11-06 06:42:02 +08004888VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004889{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004890 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004891 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4892 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004893 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004894 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004895 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004896 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004897 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004898 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004899}
4900
Chia-I Wu9ab61502015-11-06 06:42:02 +08004901VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004902{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004903 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004904 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4905 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004906 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004907 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004908 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004909 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004910 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004911 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004912}
4913
Jon Ashburnf19916e2016-01-11 13:12:43 -07004914VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004915 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4916 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07004917 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004918
4919#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4920 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4921 return skip;
4922#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4923
Michael Lentineabc5e922015-10-12 11:30:14 -05004924 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004925 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05004926 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004927 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05004928 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004929 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
4930 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004931 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004932 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004933 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 -07004934 "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 -05004935 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004936 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004937 }
4938 }
4939 }
4940 return skip;
4941}
4942
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07004943// Print readable FlagBits in FlagMask
4944std::string string_VkAccessFlags(VkAccessFlags accessMask)
4945{
4946 std::string result;
4947 std::string separator;
4948
4949 if (accessMask == 0) {
4950 result = "[None]";
4951 } else {
4952 result = "[";
4953 for (auto i = 0; i < 32; i++) {
4954 if (accessMask & (1 << i)) {
4955 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
4956 separator = " | ";
4957 }
4958 }
4959 result = result + "]";
4960 }
4961 return result;
4962}
4963
Michael Lentine97eb7462015-11-20 09:48:52 -08004964// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4965// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004966// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004967VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
4968 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004969 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004970
Michael Lentine97eb7462015-11-20 09:48:52 -08004971 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4972 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004973 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004974 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 -07004975 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
4976 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05004977 }
4978 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08004979 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004980 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 -07004981 "%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 -07004982 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
4983 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004984 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004985 std::string opt_bits;
4986 if (optional_bits != 0) {
4987 opt_bits = "and may have optional bits " + std::to_string(optional_bits) + ' ' + string_VkAccessFlags(optional_bits);
4988 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004989 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 -07004990 "%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 -07004991 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
4992 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07004993 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08004994 }
Michael Lentineecc32b72015-10-16 18:08:09 -05004995 }
4996 return skip_call;
4997}
4998
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004999VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005000 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005001 switch (layout) {
5002 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005003 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 -08005004 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005005 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005006 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005007 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 -08005008 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005009 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005010 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005011 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005012 break;
5013 }
5014 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005015 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005016 break;
5017 }
5018 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005019 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 -08005020 break;
5021 }
5022 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005023 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 -08005024 break;
5025 }
5026 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005027 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005028 break;
5029 }
5030 case VK_IMAGE_LAYOUT_UNDEFINED: {
5031 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005032 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005033 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 -07005034 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5035 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005036 }
5037 break;
5038 }
5039 case VK_IMAGE_LAYOUT_GENERAL:
5040 default: {
5041 break;
5042 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005043 }
5044 return skip_call;
5045}
5046
Jon Ashburnf19916e2016-01-11 13:12:43 -07005047VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5048{
Mark Youngb20a6a82016-01-07 15:41:43 -07005049 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005050 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5051 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5052 if (pCB->activeRenderPass && memBarrierCount) {
5053 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005054 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005055 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005056 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 -05005057 "Image or Buffers Barriers cannot be used during a render pass.");
5058 }
5059 }
5060 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005061 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 -05005062 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5063 }
5064 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005065
Jon Ashburnf19916e2016-01-11 13:12:43 -07005066 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5067 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005068 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005069 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5070 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005071 }
5072 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005073
Michael Lentine48930b82015-10-15 17:07:00 -05005074 return skip_call;
5075}
5076
Jon Ashburnf19916e2016-01-11 13:12:43 -07005077VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5078 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5079 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5080 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5081 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5082 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005083{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005084 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005085 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5086 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005087 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005088 for (uint32_t i = 0; i < eventCount; ++i) {
5089 pCB->waitedEvents.push_back(pEvents[i]);
5090 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005091 if (pCB->state == CB_RECORDING) {
5092 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005093 } else {
5094 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5095 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005096 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5097 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005098 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005099 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005100 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5101 memoryBarrierCount, pMemoryBarriers,
5102 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5103 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005104}
5105
Jon Ashburnf19916e2016-01-11 13:12:43 -07005106VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5107 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5108 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5109 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5110 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5111 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005112{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005113 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005114 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5115 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005116 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005117 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005118 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5119 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005120 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005121 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005122 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5123 memoryBarrierCount, pMemoryBarriers,
5124 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5125 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005126}
5127
Chia-I Wu9ab61502015-11-06 06:42:02 +08005128VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005129{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005130 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005131 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5132 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005133 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005134 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005135 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005136 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005137 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005138}
5139
Chia-I Wu9ab61502015-11-06 06:42:02 +08005140VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005141{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005142 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005143 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5144 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005145 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005146 QueryObject query = {queryPool, slot};
5147 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005148 if (pCB->state == CB_RECORDING) {
5149 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005150 } else {
5151 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5152 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005153 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005154 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005155 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005156}
5157
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005158VK_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 -06005159{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005160 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005161 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5162 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005163 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005164 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005165 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005166 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5167 pCB->queryToStateMap[query] = 0;
5168 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005169 if (pCB->state == CB_RECORDING) {
5170 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005171 } else {
5172 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5173 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005174 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005175 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005176 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005177 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005178}
5179
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005180VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005181 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005182 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005183{
5184 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005185 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5186 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005187 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005188 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005189 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005190 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005191 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5192 "Requesting a copy from query to buffer with invalid query: queryPool %" PRIu64 ", index %d", reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06005193 }
5194 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005195 if (pCB->state == CB_RECORDING) {
5196 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005197 } else {
5198 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5199 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005200 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005201 }
5202 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005203 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005204 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005205}
5206
Chia-I Wu9ab61502015-11-06 06:42:02 +08005207VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005208{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005209 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005210 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5211 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005212 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005213 QueryObject query = {queryPool, slot};
5214 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005215 if (pCB->state == CB_RECORDING) {
5216 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005217 } else {
5218 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5219 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005220 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005221 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005222 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005223}
5224
Chia-I Wu9ab61502015-11-06 06:42:02 +08005225VK_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 -06005226{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005227 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005228 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005229 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005230 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005231 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005232 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005233 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5234 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005235 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005236 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005237 }
5238 return result;
5239}
5240
Michael Lentineb6986752015-10-06 14:56:18 -07005241// Store the DAG.
5242struct DAGNode {
5243 uint32_t pass;
5244 std::vector<uint32_t> prev;
5245 std::vector<uint32_t> next;
5246};
5247
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005248VkBool32 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 -07005249 // If we have already checked this node we have not found a dependency path so return false.
5250 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005251 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005252 processed_nodes.insert(index);
5253 const DAGNode& node = subpass_to_node[index];
5254 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5255 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5256 for (auto elem : node.prev) {
5257 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005258 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005259 }
5260 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005261 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005262 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005263 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005264}
5265
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005266VkBool32 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 -07005267 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005268 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5269 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5270 if (subpass == dependent_subpasses[k])
5271 continue;
5272 const DAGNode& node = subpass_to_node[subpass];
5273 // Check for a specified dependency between the two nodes. If one exists we are done.
5274 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5275 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5276 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5277 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5278 std::unordered_set<uint32_t> processed_nodes;
5279 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5280 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005281 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005282 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 -07005283 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5284 subpass, dependent_subpasses[k]);
5285 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005286 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 -07005287 "A dependency between subpasses %d and %d must exist but one is not specified.",
5288 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005289 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005290 }
5291 }
5292 }
5293 return result;
5294}
5295
Jon Ashburnf19916e2016-01-11 13:12:43 -07005296VkBool32 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 -07005297 const DAGNode& node = subpass_to_node[index];
5298 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5299 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005300 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005301 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005302 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005303 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005304 if (subpass.pDepthStencilAttachment &&
5305 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5306 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005307 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005308 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005309 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005310 // Loop through previous nodes and see if any of them write to the attachment.
5311 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005312 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005313 }
5314 // If the attachment was written to by a previous node than this node needs to preserve it.
5315 if (result && depth > 0) {
5316 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005317 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005318 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005319 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005320 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005321 break;
5322 }
5323 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005324 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005325 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 -07005326 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5327 }
5328 }
5329 return result;
5330}
5331
Michael Lentineb4979492015-12-22 11:36:14 -06005332VkBool32 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 -07005333 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005334 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5335 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005336 // Find for each attachment the subpasses that use them.
5337 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5338 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005339 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005340 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5341 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005342 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005343 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5344 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005345 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5346 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005347 }
5348 }
5349 // If there is a dependency needed make sure one exists
5350 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5351 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5352 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005353 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005354 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005355 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005356 }
5357 // 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 +08005358 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005359 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005360 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5361 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005362 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005363 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5364 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005365 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5366 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005367 }
5368 }
5369 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5370 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5371 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005372 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005373 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005374 }
5375 }
5376 return skip_call;
5377}
5378
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005379VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005380 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005381
5382#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5383 return skip;
5384#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5385
Michael Lentineabc5e922015-10-12 11:30:14 -05005386 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5387 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5388 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5389 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5390 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5391 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005392 // 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 -07005393 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 -05005394 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5395 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005396 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 -05005397 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5398 }
5399 }
5400 }
5401 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5402 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5403 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005404 // 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 -07005405 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 -05005406 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5407 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005408 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 -05005409 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5410 }
5411 }
5412 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005413 if ((subpass.pDepthStencilAttachment != NULL) &&
5414 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005415 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5416 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005417 // 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 -07005418 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 -05005419 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5420 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005421 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 -05005422 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5423 }
5424 }
5425 }
5426 }
5427 return skip;
5428}
5429
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005430VkBool32 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 -07005431 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005432 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5433 DAGNode& subpass_node = subpass_to_node[i];
5434 subpass_node.pass = i;
5435 }
5436 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5437 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5438 if (dependency.srcSubpass > dependency.dstSubpass) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005439 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 -05005440 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005441 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5442 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005443 }
5444 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5445 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5446 }
5447 return skip_call;
5448}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005449// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005450
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005451VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5452 VkDevice device,
5453 const VkShaderModuleCreateInfo *pCreateInfo,
5454 const VkAllocationCallbacks* pAllocator,
5455 VkShaderModule *pShaderModule)
5456{
5457 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005458 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005459 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005460 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 -07005461 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005462 "Shader is not SPIR-V");
5463 }
5464
Mark Youngb20a6a82016-01-07 15:41:43 -07005465 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005466 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005467
5468 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5469
5470 if (res == VK_SUCCESS) {
5471 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005472 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005473 loader_platform_thread_unlock_mutex(&globalLock);
5474 }
5475 return res;
5476}
5477
Chia-I Wu9ab61502015-11-06 06:42:02 +08005478VK_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 -06005479{
Mark Youngb20a6a82016-01-07 15:41:43 -07005480 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005481 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005482 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005483 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005484 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005485 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005486 // Validate using DAG
5487 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5488 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005489 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005490 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005491 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005492 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005493 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005494 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005495 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005496 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005497 if (pCreateInfo->pAttachments) {
5498 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5499 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005500 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005501 if (pCreateInfo->pSubpasses) {
5502 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5503 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5504
5505 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5506 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005507 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5508 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005509 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005510 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5511
Cody Northropa505dda2015-08-04 11:16:41 -06005512 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005513 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005514 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005515 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005516
Cody Northropa505dda2015-08-04 11:16:41 -06005517 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005518 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005519 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005520 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005521
Cody Northropa505dda2015-08-04 11:16:41 -06005522 if (subpass->pResolveAttachments) {
5523 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005524 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005525 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005526 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005527 }
5528
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005529 if (subpass->pDepthStencilAttachment) {
5530 memcpy(attachments, subpass->pDepthStencilAttachment,
5531 sizeof(attachments[0]) * 1);
5532 subpass->pDepthStencilAttachment = attachments;
5533 attachments += 1;
5534 }
5535
Cody Northropa505dda2015-08-04 11:16:41 -06005536 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005537 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005538 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005539 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005540 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005541 if (pCreateInfo->pDependencies) {
5542 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5543 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005544 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005545 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005546 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005547 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005548 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005549 }
5550 return result;
5551}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005552// Free the renderpass shadow
5553static void deleteRenderPasses(layer_data* my_data)
5554{
5555 if (my_data->renderPassMap.size() <= 0)
5556 return;
5557 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005558 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005559 if (pRenderPassInfo->pAttachments) {
5560 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005561 }
Michael Lentine48930b82015-10-15 17:07:00 -05005562 if (pRenderPassInfo->pSubpasses) {
5563 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005564 // Attachements are all allocated in a block, so just need to
5565 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005566 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5567 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5568 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5569 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5570 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5571 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5572 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5573 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005574 }
5575 }
Michael Lentine48930b82015-10-15 17:07:00 -05005576 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005577 }
Michael Lentine48930b82015-10-15 17:07:00 -05005578 if (pRenderPassInfo->pDependencies) {
5579 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005580 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005581 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005582 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005583 }
5584 my_data->renderPassMap.clear();
5585}
Michael Lentineabc5e922015-10-12 11:30:14 -05005586
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005587VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005588 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005589 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5590 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005591 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005592 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5593 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005594 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 -05005595 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5596 }
5597 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5598 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5599 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5600 auto image_data = pCB->imageLayoutMap.find(image);
5601 if (image_data == pCB->imageLayoutMap.end()) {
5602 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5603 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5604 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005605 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 -05005606 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5607 }
5608 }
5609 return skip_call;
5610}
5611
5612void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5613 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5614 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5615 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5616 if (render_pass_data == dev_data->renderPassMap.end()) {
5617 return;
5618 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005619 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005620 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5621 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5622 return;
5623 }
5624 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5625 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5626 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5627 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5628 auto image_view_data = dev_data->imageViewMap.find(image_view);
5629 if (image_view_data != dev_data->imageViewMap.end()) {
5630 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5631 if (image_layout != pCB->imageLayoutMap.end()) {
5632 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5633 }
5634 }
5635 }
5636 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5637 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5638 auto image_view_data = dev_data->imageViewMap.find(image_view);
5639 if (image_view_data != dev_data->imageViewMap.end()) {
5640 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5641 if (image_layout != pCB->imageLayoutMap.end()) {
5642 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5643 }
5644 }
5645 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005646 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005647 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005648 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5649 auto image_view_data = dev_data->imageViewMap.find(image_view);
5650 if (image_view_data != dev_data->imageViewMap.end()) {
5651 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5652 if (image_layout != pCB->imageLayoutMap.end()) {
5653 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5654 }
5655 }
5656 }
5657}
5658
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005659VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005660 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005661 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005662 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 -07005663 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5664 }
5665 return skip_call;
5666}
5667
Michael Lentineabc5e922015-10-12 11:30:14 -05005668void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5669 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5670 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5671 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5672 if (render_pass_data == dev_data->renderPassMap.end()) {
5673 return;
5674 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005675 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005676 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5677 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5678 return;
5679 }
5680 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5681 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5682 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5683 auto image_view_data = dev_data->imageViewMap.find(image_view);
5684 if (image_view_data != dev_data->imageViewMap.end()) {
5685 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5686 if (image_layout != pCB->imageLayoutMap.end()) {
5687 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5688 }
5689 }
5690 }
5691}
5692
Chia-I Wu9ab61502015-11-06 06:42:02 +08005693VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005694{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005695 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005696 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5697 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005698 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005699 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005700 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005701 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005702 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005703 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005704 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005705 // This is a shallow copy as that is all that is needed for now
5706 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005707 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005708 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005709 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005710 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005711 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 -06005712 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005713 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005714 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005715 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005716 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005717 // This is a shallow copy as that is all that is needed for now
5718 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5719 dev_data->currentSubpass = 0;
5720 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005721}
5722
Chia-I Wu9ab61502015-11-06 06:42:02 +08005723VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005724{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005725 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005726 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5727 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005728 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005729 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005730 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005731 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005732 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005733 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005734 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005735 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005736 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005737 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005738 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005739 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005740 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005741 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005742}
5743
Chia-I Wu9ab61502015-11-06 06:42:02 +08005744VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005745{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005746 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005747 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5748 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005749 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005750 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005751 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005752 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005753 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005754 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005755 pCB->activeRenderPass = 0;
5756 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005757 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005758 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005759 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005760}
5761
Chia-I Wu9ab61502015-11-06 06:42:02 +08005762VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005763{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005764 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005765 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5766 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005767 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005768 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5769 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5770 // 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 -06005771 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005772 for (uint32_t i=0; i<commandBuffersCount; i++) {
5773 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005774 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005775 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 +08005776 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5777 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005778 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 +08005779 "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 -07005780 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5781 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005782 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 -07005783 "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);
5784 }
5785 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005786 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005787 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 -07005788 "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 -07005789 (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 -07005790 }
5791 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5792 // 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 -07005793 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5794 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005795 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 -07005796 "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 -07005797 (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 -07005798 }
5799 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005800 }
5801 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005802 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005803 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005804 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005805 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005806 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005807}
5808
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005809VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005810 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005811 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5812 auto mem_data = dev_data->memImageMap.find(mem);
5813 if (mem_data != dev_data->memImageMap.end()) {
5814 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5815 if (image_data != dev_data->imageLayoutMap.end()) {
5816 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005817 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 -07005818 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5819 }
5820 }
5821 }
5822 return skip_call;
5823}
5824
Chia-I Wu9ab61502015-11-06 06:42:02 +08005825VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005826 VkDevice device,
5827 VkDeviceMemory mem,
5828 VkDeviceSize offset,
5829 VkDeviceSize size,
5830 VkFlags flags,
5831 void **ppData)
5832{
5833 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005834
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005835 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005836#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5837 skip_call = ValidateMapImageLayouts(device, mem);
5838#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5839
Michael Lentine7b236262015-10-23 12:41:44 -07005840 if (VK_FALSE == skip_call) {
5841 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5842 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005843 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005844}
5845
Chia-I Wu9ab61502015-11-06 06:42:02 +08005846VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005847 VkDevice device,
5848 VkImage image,
5849 VkDeviceMemory mem,
5850 VkDeviceSize memOffset)
5851{
5852 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5853 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5854 loader_platform_thread_lock_mutex(&globalLock);
5855 dev_data->memImageMap[mem] = image;
5856 loader_platform_thread_unlock_mutex(&globalLock);
5857 return result;
5858}
5859
Michael Lentineb887b0a2015-12-29 14:12:11 -06005860
5861VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
5862 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5863 dev_data->eventMap[event].needsSignaled = false;
5864 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
5865 return result;
5866}
5867
Michael Lentine15a47882016-01-06 10:05:48 -06005868VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
5869 VkQueue queue,
5870 uint32_t bindInfoCount,
5871 const VkBindSparseInfo* pBindInfo,
5872 VkFence fence)
5873{
5874 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005875 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06005876
5877 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
5878 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
5879 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
5880 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
5881 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
5882 } else {
5883 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",
5884 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5885 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
5886 }
5887 }
5888 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
5889 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
5890 }
5891 }
5892
Mark Youngb20a6a82016-01-07 15:41:43 -07005893 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06005894 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07005895 else
5896 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06005897}
5898
5899VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
5900 VkDevice device,
5901 const VkSemaphoreCreateInfo* pCreateInfo,
5902 const VkAllocationCallbacks* pAllocator,
5903 VkSemaphore* pSemaphore)
5904{
5905 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5906 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
5907 if (result == VK_SUCCESS) {
5908 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
5909 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07005910 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06005911}
5912
Chia-I Wu9ab61502015-11-06 06:42:02 +08005913VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005914 VkDevice device,
5915 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07005916 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05005917 VkSwapchainKHR *pSwapchain)
5918{
5919 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07005920 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05005921
5922 if (VK_SUCCESS == result) {
5923 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5924 loader_platform_thread_lock_mutex(&globalLock);
5925 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5926 loader_platform_thread_unlock_mutex(&globalLock);
5927 }
5928
5929 return result;
5930}
5931
Ian Elliott05846062015-11-20 14:13:17 -07005932VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005933 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07005934 VkSwapchainKHR swapchain,
5935 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05005936{
5937 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005938
5939 loader_platform_thread_lock_mutex(&globalLock);
5940 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5941 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5942 if (swapchain_data->second->images.size() > 0) {
5943 for (auto swapchain_image : swapchain_data->second->images) {
5944 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5945 if (image_item != dev_data->imageLayoutMap.end())
5946 dev_data->imageLayoutMap.erase(image_item);
5947 }
5948 }
5949 delete swapchain_data->second;
5950 dev_data->device_extensions.swapchainMap.erase(swapchain);
5951 }
5952 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07005953 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05005954}
5955
Chia-I Wu9ab61502015-11-06 06:42:02 +08005956VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005957 VkDevice device,
5958 VkSwapchainKHR swapchain,
5959 uint32_t* pCount,
5960 VkImage* pSwapchainImages)
5961{
5962 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5963 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5964
5965 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5966 // This should never happen and is checked by param checker.
5967 if (!pCount) return result;
5968 for (uint32_t i = 0; i < *pCount; ++i) {
5969 IMAGE_NODE* image_node = new IMAGE_NODE;
5970 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5971 loader_platform_thread_lock_mutex(&globalLock);
5972 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5973 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5974 loader_platform_thread_unlock_mutex(&globalLock);
5975 }
5976 }
5977 return result;
5978}
5979
Ian Elliott05846062015-11-20 14:13:17 -07005980VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05005981{
5982 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005983 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005984
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005985#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05005986 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06005987 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
5988 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
5989 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
5990 } else {
5991 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",
5992 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5993 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
5994 }
5995 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005996 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07005997 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
5998 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
5999 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006000 auto image_data = dev_data->imageLayoutMap.find(image);
6001 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006002 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006003 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 -05006004 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6005 }
6006 }
6007 }
6008 }
6009 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006010#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006011
6012 if (VK_FALSE == skip_call)
6013 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006014 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006015}
6016
Michael Lentine15a47882016-01-06 10:05:48 -06006017VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6018 VkDevice device,
6019 VkSwapchainKHR swapchain,
6020 uint64_t timeout,
6021 VkSemaphore semaphore,
6022 VkFence fence,
6023 uint32_t* pImageIndex)
6024{
6025 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6026 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6027 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006028 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006029}
6030
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006031VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6032 VkInstance instance,
6033 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6034 const VkAllocationCallbacks* pAllocator,
6035 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006036{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006037 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006038 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006039 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006040 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006041 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006042 }
6043 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006044}
6045
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006046VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006047 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006048 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006049 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006050{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006051 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006052 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006053 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006054 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006055}
6056
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006057VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006058 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006059 VkDebugReportFlagsEXT flags,
6060 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006061 uint64_t object,
6062 size_t location,
6063 int32_t msgCode,
6064 const char* pLayerPrefix,
6065 const char* pMsg)
6066{
6067 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006068 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006069}
6070
Chia-I Wu9ab61502015-11-06 06:42:02 +08006071VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006072{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006073 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006074 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6075 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006076 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006077 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 -06006078 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006079 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006080 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006081 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006082 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006083 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006084 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006085}
6086
Chia-I Wu9ab61502015-11-06 06:42:02 +08006087VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006088{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006089 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006090 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6091 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006092 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006093 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 -06006094 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006095 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006096 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006097 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006098 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006099 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006100 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006101}
6102
Chia-I Wu9ab61502015-11-06 06:42:02 +08006103VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006104{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06006105 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006106 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006107
Tobin Ehlis0b632332015-10-07 09:38:40 -06006108 layer_data *dev_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006109 /* loader uses this to force layer initialization; device object is wrapped */
6110 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006111 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
6112 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006113 dev_data->device_dispatch_table = new VkLayerDispatchTable;
6114 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006115 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006116 }
Tobin Ehlis0b632332015-10-07 09:38:40 -06006117 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06006118 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006119 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006120 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006121 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006122 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006123 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006124 if (!strcmp(funcName, "vkWaitForFences"))
6125 return (PFN_vkVoidFunction) vkWaitForFences;
6126 if (!strcmp(funcName, "vkGetFenceStatus"))
6127 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006128 if (!strcmp(funcName, "vkQueueWaitIdle"))
6129 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6130 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6131 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006132 if (!strcmp(funcName, "vkGetDeviceQueue"))
6133 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006134 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006135 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006136 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006137 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006138 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006139 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006140 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006141 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006142 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006143 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006144 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006145 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006146 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006147 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006148 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006149 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006150 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006151 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006152 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006153 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006154 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006155 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006156 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006157 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006158 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006159 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006160 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006161 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006162 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006163 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006164 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006165 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006166 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006167 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006168 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006169 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006170 if (!strcmp(funcName, "vkCreateBuffer"))
6171 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006172 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006173 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006174 if (!strcmp(funcName, "vkCreateImage"))
6175 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006176 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006177 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006178 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006179 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006180 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006181 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006182 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006183 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006184 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006185 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006186 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006187 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006188 if (!strcmp(funcName, "vkCreateComputePipelines"))
6189 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006190 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006191 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006192 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006193 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006194 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006195 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006196 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006197 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006198 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006199 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006200 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6201 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006202 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6203 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006204 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006205 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006206 if (!strcmp(funcName, "vkCreateCommandPool"))
6207 return (PFN_vkVoidFunction) vkCreateCommandPool;
6208 if (!strcmp(funcName, "vkDestroyCommandPool"))
6209 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006210 if (!strcmp(funcName, "vkResetCommandPool"))
6211 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006212 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6213 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006214 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6215 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006216 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006217 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006218 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006219 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006220 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006221 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006222 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006223 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006224 if (!strcmp(funcName, "vkCmdSetViewport"))
6225 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006226 if (!strcmp(funcName, "vkCmdSetScissor"))
6227 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006228 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6229 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6230 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6231 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6232 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6233 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6234 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6235 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6236 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6237 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6238 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6239 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6240 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6241 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006242 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006243 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006244 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006245 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006246 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006247 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006248 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006249 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006250 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006251 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006252 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006253 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006254 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006255 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006256 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006257 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006258 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006259 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006260 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006261 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006262 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006263 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006264 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006265 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006266 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006267 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006268 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006269 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006270 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006271 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006272 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006273 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006274 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006275 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006276 if (!strcmp(funcName, "vkCmdClearAttachments"))
6277 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006278 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006279 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006280 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006281 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006282 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006283 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006284 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006285 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006286 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006287 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006288 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006289 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006290 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006291 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006292 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006293 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006294 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006295 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006296 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006297 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006298 if (!strcmp(funcName, "vkCreateShaderModule"))
6299 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006300 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006301 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006302 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006303 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006304 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006305 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006306 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006307 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006308 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6309 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006310 if (!strcmp(funcName, "vkSetEvent"))
6311 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006312 if (!strcmp(funcName, "vkMapMemory"))
6313 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006314 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6315 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006316 if (!strcmp(funcName, "vkBindImageMemory"))
6317 return (PFN_vkVoidFunction) vkBindImageMemory;
6318 if (!strcmp(funcName, "vkQueueBindSparse"))
6319 return (PFN_vkVoidFunction) vkQueueBindSparse;
6320 if (!strcmp(funcName, "vkCreateSemaphore"))
6321 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006322
Michael Lentineabc5e922015-10-12 11:30:14 -05006323 if (dev_data->device_extensions.wsi_enabled)
6324 {
6325 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6326 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6327 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6328 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6329 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6330 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006331 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6332 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006333 if (!strcmp(funcName, "vkQueuePresentKHR"))
6334 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6335 }
6336
Tobin Ehlis0b632332015-10-07 09:38:40 -06006337 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6338 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006339 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006340 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006341 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006342 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006343 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006344 }
6345 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006346 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006347 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006348 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006349 }
6350}
6351
Chia-I Wu9ab61502015-11-06 06:42:02 +08006352VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006353{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006354 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006355 if (instance == NULL)
6356 return NULL;
6357
Tobin Ehlis0b632332015-10-07 09:38:40 -06006358 layer_data* my_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006359 /* loader uses this to force layer initialization; instance object is wrapped */
6360 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006361 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
6362 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006363 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
6364 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006365 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006366 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006367 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006368 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006369 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006370 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006371 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6372 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6373 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6374 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6375 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6376 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6377 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6378 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006379
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006380 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006381 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006382 if (fptr)
6383 return fptr;
6384
Jon Ashburn8fd08252015-05-28 16:25:02 -06006385 {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006386 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006387 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006388 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006389 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006390 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006391}