blob: 8d6ac6588415cdc37095d002ebddb7f64961dc70 [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) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002500 delete (*ii).second;
2501 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002502 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002503}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002504
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002505static 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 -06002506{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002507 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 -07002508 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002509 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002510}
Michael Lentine3dea6512015-10-28 15:55:18 -07002511
Mark Youngb20a6a82016-01-07 15:41:43 -07002512VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2513 if (!pCB->activeRenderPass) return VK_FALSE;
2514 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002515 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2516 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2517 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2518 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2519 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2520 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2521 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002522 return skip_call;
2523}
2524
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002525// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2526// in the recording state or if there's an issue with the Cmd ordering
2527static 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 -06002528{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002529 VkBool32 skipCall = VK_FALSE;
2530 if (pCB->state != CB_RECORDING) {
2531 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2532 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002533 CMD_NODE cmdNode = {};
2534 // init cmd node and append to end of cmd LL
2535 cmdNode.cmdNumber = ++pCB->numCmds;
2536 cmdNode.type = cmd;
2537 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002538 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002539 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002540}
Tobin Ehlisef694652016-01-19 12:03:34 -07002541// Reset the command buffer state
2542// Maintain the createInfo and set state to CB_NEW, but clear all other state
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002543static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002544{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002545 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002546 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002547 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002548 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002549 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002550 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07002551 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002552 pCB->fence = 0;
2553 pCB->numCmds = 0;
2554 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2555 pCB->state = CB_NEW;
2556 pCB->submitCount = 0;
2557 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002558 pCB->lastBoundPipeline = 0;
2559 pCB->viewports.clear();
2560 pCB->scissors.clear();
2561 pCB->lineWidth = 0;
2562 pCB->depthBiasConstantFactor = 0;
2563 pCB->depthBiasClamp = 0;
2564 pCB->depthBiasSlopeFactor = 0;
2565 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2566 pCB->minDepthBounds = 0;
2567 pCB->maxDepthBounds = 0;
2568 memset(&pCB->front, 0, sizeof(stencil_data));
2569 memset(&pCB->back, 0, sizeof(stencil_data));
2570 pCB->lastBoundDescriptorSet = 0;
2571 pCB->lastBoundPipelineLayout = 0;
2572 pCB->activeRenderPass = 0;
2573 pCB->activeSubpass = 0;
2574 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002575 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002576 pCB->drawData.clear();
2577 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002578 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002579 pCB->waitedEvents.clear();
2580 pCB->waitedEventsBeforeQueryReset.clear();
2581 pCB->queryToStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002582 }
2583}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002584
Tobin Ehlis963a4042015-09-29 08:18:34 -06002585// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002586static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2587{
2588 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002589 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002590 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2591 }
2592 }
2593 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002594 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2595 }
Cody Northrop82485a82015-08-18 15:21:16 -06002596 if (pPipe->dsStateCI.stencilTestEnable) {
2597 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002598 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002599 // Account for any dynamic state not set via this PSO
2600 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2601 pCB->status = CBSTATUS_ALL;
2602 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002603 // First consider all state on
2604 // Then unset any state that's noted as dynamic in PSO
2605 // Finally OR that into CB statemask
2606 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002607 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2608 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2609 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002610 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002611 break;
2612 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002613 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002614 break;
2615 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002616 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002617 break;
2618 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002619 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002620 break;
2621 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002622 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002623 break;
2624 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002625 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002626 break;
2627 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002628 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002629 break;
2630 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002631 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002632 break;
2633 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002634 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002635 break;
2636 default:
2637 // TODO : Flag error here
2638 break;
2639 }
2640 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002641 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002642 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002643}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002644
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002645// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002646static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002647{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002648 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002649 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002650 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002651 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002652 if (!pPipeTrav) {
2653 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002654 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002655 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 -08002656 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002657 }
2658 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002659 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002660}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002661
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002662// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002663static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002664{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002665 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002666 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 -06002667 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002668 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002669 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002670 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002671 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002672 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 +08002673 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002674 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002675 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 -06002676 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002677 // Print out set details
2678 char prefix[10];
2679 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002680 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 +08002681 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002682 LAYOUT_NODE* pLayout = pSet->pLayout;
2683 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002684 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 -08002685 "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 -06002686 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002687 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002688 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 -06002689 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002690 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002691 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2692 if (pUpdate) {
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",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002694 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002695 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002696 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 -08002697 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002698 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002699 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002700 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002701 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 +08002702 "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 -06002703 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002704 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 +08002705 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002706 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002707 }
2708 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002709 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002710}
2711
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002712static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002713{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002714 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002715 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002716 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 -06002717 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002718 vector<CMD_NODE> cmds = pCB->cmds;
2719 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002720 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002721 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis9a874302016-01-20 10:25:29 -07002722 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002723 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002724 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002725 // Nothing to print
2726 }
2727}
2728
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002729static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002730{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002731 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002732 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002733 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002734 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002735 skipCall |= printDSConfig(my_data, cb);
2736 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002737 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002738}
2739
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002740// Flags validation error if the associated call is made inside a render pass. The apiName
2741// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002742static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002743{
2744 VkBool32 inside = VK_FALSE;
2745 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002746 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 -07002747 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002748 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002749 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002750 }
2751 return inside;
2752}
2753
2754// Flags validation error if the associated call is made outside a render pass. The apiName
2755// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002756static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002757{
2758 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002759 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2760 (!pCB->activeRenderPass)) ||
2761 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2762 (!pCB->activeRenderPass) &&
2763 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002764 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 -07002765 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002766 "%s: This call must be issued inside an active render pass.", apiName);
2767 }
2768 return outside;
2769}
2770
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002771static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002772{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002773 uint32_t report_flags = 0;
2774 uint32_t debug_action = 0;
2775 FILE *log_output = NULL;
2776 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002777 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002778 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002779 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2780 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002781
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002782 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002783 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002784 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002785 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002786 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002787 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002788 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002789 dbgInfo.pfnCallback = log_callback;
2790 dbgInfo.pUserData = log_output;
2791 dbgInfo.flags = report_flags;
2792 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002793 my_data->logging_callback.push_back(callback);
2794 }
2795
2796 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002797 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002798 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002799 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002800 dbgInfo.pfnCallback = win32_debug_output_msg;
2801 dbgInfo.pUserData = log_output;
2802 dbgInfo.flags = report_flags;
2803 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002804 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002805 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002806
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002807 if (!globalLockInitialized)
2808 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002809 loader_platform_thread_create_mutex(&globalLock);
2810 globalLockInitialized = 1;
2811 }
2812}
2813
Chia-I Wu9ab61502015-11-06 06:42:02 +08002814VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002815{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002816 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002817
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002818 assert(chain_info->u.pLayerInfo);
2819 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2820 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
2821 if (fpCreateInstance == NULL) {
2822 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002823 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002824
2825 // Advance the link info for the next element on the chain
2826 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2827
2828 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
2829 if (result != VK_SUCCESS)
2830 return result;
2831
2832 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2833 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
2834 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
2835
2836 my_data->report_data = debug_report_create_instance(
2837 my_data->instance_dispatch_table,
2838 *pInstance,
2839 pCreateInfo->enabledExtensionCount,
2840 pCreateInfo->ppEnabledExtensionNames);
2841
2842 init_draw_state(my_data, pAllocator);
2843
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002844 return result;
2845}
2846
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002847/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002848VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002849{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002850 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002851 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002852 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2853 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002854 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002855
2856 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002857 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002858 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002859 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002860 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002861 }
2862
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002863 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002864 delete my_data->instance_dispatch_table;
2865 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002866 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002867 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002868 // Release mutex when destroying last instance.
2869 loader_platform_thread_delete_mutex(&globalLock);
2870 globalLockInitialized = 0;
2871 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002872}
2873
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002874static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2875{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002876 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002877 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2878 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002879 dev_data->device_extensions.wsi_enabled = false;
2880
2881
2882 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2883 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2884
Michael Lentineabc5e922015-10-12 11:30:14 -05002885 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2886 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2887 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2888 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002889 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002890
Jon Ashburnf19916e2016-01-11 13:12:43 -07002891 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002892 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002893 dev_data->device_extensions.wsi_enabled = true;
2894 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002895 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002896 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002897 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002898 initDebugMarkerTable(device);
2899
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002900 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002901 }
2902}
2903
Chia-I Wu9ab61502015-11-06 06:42:02 +08002904VK_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 -06002905{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002906 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002907
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002908 assert(chain_info->u.pLayerInfo);
2909 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2910 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
2911 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
2912 if (fpCreateDevice == NULL) {
2913 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002914 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002915
2916 // Advance the link info for the next element on the chain
2917 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2918
2919 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
2920 if (result != VK_SUCCESS) {
2921 return result;
2922 }
2923
2924 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
2925 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
2926
2927 // Setup device dispatch table
2928 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
2929 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
2930
2931 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
2932 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
2933 // Get physical device limits for this device
2934 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002935 return result;
2936}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002937
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002938// prototype
2939static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002940VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002941{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002942 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002943 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002944 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002945 // Free all the memory
2946 loader_platform_thread_lock_mutex(&globalLock);
2947 deletePipelines(dev_data);
2948 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002949 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002950 deletePools(dev_data);
2951 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002952 dev_data->imageViewMap.clear();
2953 dev_data->imageMap.clear();
2954 dev_data->bufferViewMap.clear();
2955 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002956 loader_platform_thread_unlock_mutex(&globalLock);
2957
Chia-I Wuf7458c52015-10-26 21:10:41 +08002958 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002959 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002960 delete dev_data->device_dispatch_table;
2961 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002962}
2963
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002964static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002965 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002966 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2967 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002968 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002969};
2970
Chia-I Wu9ab61502015-11-06 06:42:02 +08002971VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002972 const char *pLayerName,
2973 uint32_t *pCount,
2974 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002975{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002976 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002977}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002978
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002979static const VkLayerProperties ds_global_layers[] = {
2980 {
Michael Lentine03107b42015-12-11 10:49:51 -08002981 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002982 VK_API_VERSION,
2983 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07002984 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002985 }
2986};
2987
Chia-I Wu9ab61502015-11-06 06:42:02 +08002988VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002989 uint32_t *pCount,
2990 VkLayerProperties* pProperties)
2991{
2992 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
2993 ds_global_layers,
2994 pCount, pProperties);
2995}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002996
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002997static const VkExtensionProperties ds_device_extensions[] = {
2998 {
2999 DEBUG_MARKER_EXTENSION_NAME,
3000 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003001 }
3002};
3003
3004static const VkLayerProperties ds_device_layers[] = {
3005 {
Michael Lentine1f8d4412016-01-19 14:19:38 -06003006 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003007 VK_API_VERSION,
3008 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003009 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003010 }
3011};
3012
Chia-I Wu9ab61502015-11-06 06:42:02 +08003013VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003014 VkPhysicalDevice physicalDevice,
3015 const char* pLayerName,
3016 uint32_t* pCount,
3017 VkExtensionProperties* pProperties)
3018{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003019 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003020 if (pLayerName == NULL) {
3021 dispatch_key key = get_dispatch_key(physicalDevice);
3022 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003023 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003024 physicalDevice,
3025 NULL,
3026 pCount,
3027 pProperties);
3028 } else {
3029 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3030 ds_device_extensions,
3031 pCount, pProperties);
3032 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003033}
3034
Chia-I Wu9ab61502015-11-06 06:42:02 +08003035VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003036 VkPhysicalDevice physicalDevice,
3037 uint32_t* pCount,
3038 VkLayerProperties* pProperties)
3039{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003040 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003041 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3042 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003043}
3044
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003045VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003046 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003047 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3048 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3049 for (auto cb_image_data : pCB->imageLayoutMap) {
3050 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3051 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003052 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 -08003053 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003054 } else {
3055 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003056 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 -05003057 "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);
3058 }
3059 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3060 }
3061 }
3062 return skip_call;
3063}
3064
Mark Young7a69c302016-01-07 09:48:47 -07003065VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003066 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003067 for (auto drawDataElement : pCB->drawData) {
3068 for (auto buffer : drawDataElement.buffers) {
3069 auto buffer_data = my_data->bufferMap.find(buffer);
3070 if (buffer_data == my_data->bufferMap.end()) {
3071 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",
3072 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
3073 } else {
3074 buffer_data->second.in_use.fetch_add(1);
3075 }
3076 }
3077 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003078 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003079}
3080
3081void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3082 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3083 for (auto drawDataElement : pCB->drawData) {
3084 for (auto buffer : drawDataElement.buffers) {
3085 auto buffer_data = my_data->bufferMap.find(buffer);
3086 if (buffer_data != my_data->bufferMap.end()) {
3087 buffer_data->second.in_use.fetch_sub(1);
3088 }
3089 }
3090 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003091 for (auto queryStatePair : pCB->queryToStateMap) {
3092 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3093 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003094}
3095
3096void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3097 for (uint32_t i = 0; i < fenceCount; ++i) {
3098 auto fence_data = my_data->fenceMap.find(pFences[i]);
3099 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3100 fence_data->second.needsSignaled = false;
3101 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3102 decrementResources(my_data, 1, &fence_data->second.priorFence);
3103 }
3104 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3105 decrementResources(my_data, cmdBuffer);
3106 }
3107 }
3108}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003109
Michael Lentine700b0aa2015-10-30 17:57:32 -07003110void decrementResources(layer_data* my_data, VkQueue queue) {
3111 auto queue_data = my_data->queueMap.find(queue);
3112 if (queue_data != my_data->queueMap.end()) {
3113 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3114 decrementResources(my_data, cmdBuffer);
3115 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003116 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003117 decrementResources(my_data, 1, &queue_data->second.priorFence);
3118 }
3119}
3120
3121void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3122 auto queue_data = my_data->queueMap.find(queue);
3123 if (fence != VK_NULL_HANDLE) {
3124 VkFence priorFence = VK_NULL_HANDLE;
3125 if (queue_data != my_data->queueMap.end()) {
3126 priorFence = queue_data->second.priorFence;
3127 queue_data->second.priorFence = fence;
3128 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3129 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3130 }
3131 queue_data->second.untrackedCmdBuffers.clear();
3132 }
3133 my_data->fenceMap[fence].cmdBuffers.clear();
3134 my_data->fenceMap[fence].priorFence = priorFence;
3135 my_data->fenceMap[fence].needsSignaled = true;
3136 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3137 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3138 }
3139 } else {
3140 if (queue_data != my_data->queueMap.end()) {
3141 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3142 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3143 }
3144 }
3145 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003146 if (queue_data != my_data->queueMap.end()) {
3147 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3148 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
3149 }
3150 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003151}
3152
Chia-I Wu9ab61502015-11-06 06:42:02 +08003153VK_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 -06003154{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003155 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003156 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003157 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003158 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
3159 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003160 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003161 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003162 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3163 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3164 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3165 } else {
3166 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",
3167 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3168 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3169 }
3170 }
3171 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3172 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3173 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003174 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003175
3176#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3177 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3178#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3179
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003180 // Validate that cmd buffers have been updated
3181 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3182 loader_platform_thread_lock_mutex(&globalLock);
3183 pCB->submitCount++; // increment submit count
Michael Lentine700b0aa2015-10-30 17:57:32 -07003184 skipCall |= validateAndIncrementResources(dev_data, pCB);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003185 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003186 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 -05003187 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3188 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003189 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003190 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003191 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003192 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 +08003193 "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 -06003194 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003195 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003196 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003197 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003198 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003199 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003200 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003201 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003202 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003203 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003204}
3205
Mark Youngb20a6a82016-01-07 15:41:43 -07003206VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3207 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003208 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3209 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3210 for (auto event : queryEventsPair.second) {
3211 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003212 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",
3213 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003214 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3215 }
3216 }
3217 }
3218 return skip_call;
3219}
3220
Michael Lentine700b0aa2015-10-30 17:57:32 -07003221VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3222{
3223 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3224 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003225 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003226 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003227 for (uint32_t i = 0; i < fenceCount; ++i) {
3228 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3229 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3230 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3231 }
3232 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003233 decrementResources(dev_data, fenceCount, pFences);
3234 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003235 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003236 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003237 return result;
3238}
3239
3240
3241VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3242{
3243 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3244 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
3245 if (result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003246 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
3247 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3248 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3249 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003250 decrementResources(dev_data, 1, &fence);
3251 }
3252 return result;
3253}
3254
3255VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3256{
3257 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3258 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
3259 dev_data->deviceMap[device].queues.push_back(*pQueue);
3260 dev_data->queueMap[*pQueue].device = device;
3261}
3262
3263VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3264{
3265 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3266 decrementResources(dev_data, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003267 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3268 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3269 }
3270 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003271 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3272}
3273
3274VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3275{
3276 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3277 auto device_data = dev_data->deviceMap.find(device);
3278 if (device_data != dev_data->deviceMap.end()) {
3279 for (auto queue : device_data->second.queues) {
3280 decrementResources(dev_data, queue);
3281 }
3282 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003283 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3284 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3285 }
3286 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003287 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3288}
3289
Chia-I Wu9ab61502015-11-06 06:42:02 +08003290VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003291{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003292 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 -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 vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003297{
Michael Lentine15a47882016-01-06 10:05:48 -06003298 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3299 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3300 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003301 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003302}
3303
Chia-I Wu9ab61502015-11-06 06:42:02 +08003304VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003305{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003306 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 -06003307 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003308}
3309
Chia-I Wu9ab61502015-11-06 06:42:02 +08003310VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003311{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003312 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 -06003313 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003314}
3315
Mark Lobodzinskice738852016-01-07 10:04:02 -07003316VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003317 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3318 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3319 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3320 GLOBAL_CB_NODE* pCB = nullptr;
3321 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3322 pCB = getCBNode(dev_data, cmdBuffer);
3323 for (auto queryStatePair : pCB->queryToStateMap) {
3324 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3325 }
3326 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003327 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003328 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003329 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003330 auto queryElement = queriesInFlight.find(query);
3331 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3332 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3333 }
3334 // Available and in flight
3335 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3336 for (auto cmdBuffer : queryElement->second) {
3337 pCB = getCBNode(dev_data, cmdBuffer);
3338 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3339 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003340 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3341 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3342 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003343 } else {
3344 for (auto event : queryEventElement->second) {
3345 dev_data->eventMap[event].needsSignaled = true;
3346 }
3347 }
3348 }
3349 // Unavailable and in flight
3350 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3351 // TODO : Can there be the same query in use by multiple command buffers in flight?
3352 bool make_available = false;
3353 for (auto cmdBuffer : queryElement->second) {
3354 pCB = getCBNode(dev_data, cmdBuffer);
3355 make_available |= pCB->queryToStateMap[query];
3356 }
3357 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003358 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 -06003359 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003360 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003361 }
3362 // Unavailable
3363 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003364 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 -06003365 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003366 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003367 // Unitialized
3368 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003369 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 -06003370 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003371 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003372 }
3373 }
3374 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003375 return VK_ERROR_VALIDATION_FAILED_EXT;
3376 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003377}
3378
Mark Young7a69c302016-01-07 09:48:47 -07003379VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003380 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003381 auto buffer_data = my_data->bufferMap.find(buffer);
3382 if (buffer_data == my_data->bufferMap.end()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003383 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 -07003384 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3385 } else {
3386 if (buffer_data->second.in_use.load()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003387 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 -07003388 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
3389
3390 }
3391 }
3392 return skip_call;
3393}
3394
Chia-I Wu9ab61502015-11-06 06:42:02 +08003395VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003396{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003397 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003398 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003399 if (!validateIdleBuffer(dev_data, buffer)) {
3400 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3401 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003402 dev_data->bufferMap.erase(buffer);
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 vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003406{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003407 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003408 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003409 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003410}
3411
Chia-I Wu9ab61502015-11-06 06:42:02 +08003412VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003413{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003414 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003415 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003416 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003417}
3418
Chia-I Wu9ab61502015-11-06 06:42:02 +08003419VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003420{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003421 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 -06003422 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003423}
3424
Chia-I Wu9ab61502015-11-06 06:42:02 +08003425VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003426{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003427 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 -06003428 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003429}
3430
Chia-I Wu9ab61502015-11-06 06:42:02 +08003431VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003432{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003433 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 -06003434 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003435}
3436
Chia-I Wu9ab61502015-11-06 06:42:02 +08003437VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003438{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003439 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 -06003440 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003441}
3442
Chia-I Wu9ab61502015-11-06 06:42:02 +08003443VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003444{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003445 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 -06003446 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003447}
3448
Chia-I Wu9ab61502015-11-06 06:42:02 +08003449VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003450{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003451 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyDescriptorSetLayout(device, descriptorSetLayout, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003452 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003453}
3454
Chia-I Wu9ab61502015-11-06 06:42:02 +08003455VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003456{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003457 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyDescriptorPool(device, descriptorPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003458 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003459}
3460
Chia-I Wu9ab61502015-11-06 06:42:02 +08003461VK_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 -06003462{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003463 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3464
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003465 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003466 // Delete CB information structure, and remove from commandBufferMap
3467 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003468 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003469 if (cb != dev_data->commandBufferMap.end()) {
3470 delete (*cb).second;
3471 dev_data->commandBufferMap.erase(cb);
3472 }
3473
3474 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003475 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003476 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003477 }
3478
3479 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3480}
3481
3482VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3483{
3484 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3485
3486 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3487
3488 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003489 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003490 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003491 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003492 }
3493 return result;
3494}
3495
3496VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3497{
3498 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003499 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003500
3501 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3502 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003503 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003504 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3505 delete (*del_cb).second; // delete CB info structure
3506 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003507 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003508 }
3509 }
3510 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003511
3512 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003513 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003514}
3515
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003516VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3517 VkDevice device,
3518 VkCommandPool commandPool,
3519 VkCommandPoolResetFlags flags)
3520{
3521 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003522 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003523
3524 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3525 // Reset all of the CBs allocated from this pool
3526 if (VK_SUCCESS == result) {
3527 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3528 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3529 resetCB(dev_data, (*it));
3530 ++it;
3531 }
3532 }
3533 return result;
3534}
3535
Chia-I Wu9ab61502015-11-06 06:42:02 +08003536VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003537{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003538 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 -06003539 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003540}
3541
Chia-I Wu9ab61502015-11-06 06:42:02 +08003542VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003543{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003544 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 -06003545 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003546}
3547
Chia-I Wu9ab61502015-11-06 06:42:02 +08003548VK_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 -06003549{
3550 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->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003552 if (VK_SUCCESS == result) {
3553 loader_platform_thread_lock_mutex(&globalLock);
3554 // 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 -07003555 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3556 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003557 loader_platform_thread_unlock_mutex(&globalLock);
3558 }
3559 return result;
3560}
3561
Chia-I Wu9ab61502015-11-06 06:42:02 +08003562VK_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 -06003563{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003564 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003565 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003566 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003567 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003568 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003569 loader_platform_thread_unlock_mutex(&globalLock);
3570 }
3571 return result;
3572}
3573
Chia-I Wu9ab61502015-11-06 06:42:02 +08003574VK_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 -06003575{
3576 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003577 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003578 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003579 IMAGE_NODE* image_node = new IMAGE_NODE;
3580 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003581 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003582 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003583 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003584 loader_platform_thread_unlock_mutex(&globalLock);
3585 }
3586 return result;
3587}
3588
Chia-I Wu9ab61502015-11-06 06:42:02 +08003589VK_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 -06003590{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003591 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003592 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003593 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003594 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003595 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003596 loader_platform_thread_unlock_mutex(&globalLock);
3597 }
3598 return result;
3599}
3600
Jon Ashburnc669cc62015-07-09 15:02:25 -06003601//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003602VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003603 VkDevice device,
3604 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003605 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003606 VkPipelineCache* pPipelineCache)
3607{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003608 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003609 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003610 return result;
3611}
3612
Chia-I Wu9ab61502015-11-06 06:42:02 +08003613VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003614 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003615 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003616 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003617{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003618 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003619 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003620}
3621
Chia-I Wu9ab61502015-11-06 06:42:02 +08003622VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003623 VkDevice device,
3624 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003625 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003626 void* pData)
3627{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003628 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003629 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003630 return result;
3631}
3632
Chia-I Wu9ab61502015-11-06 06:42:02 +08003633VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003634 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003635 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003636 uint32_t srcCacheCount,
3637 const VkPipelineCache* pSrcCaches)
3638{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003639 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003640 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003641 return result;
3642}
3643
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003644VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3645 VkDevice device,
3646 VkPipelineCache pipelineCache,
3647 uint32_t count,
3648 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3649 const VkAllocationCallbacks *pAllocator,
3650 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003651{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003652 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003653 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003654 // The order of operations here is a little convoluted but gets the job done
3655 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3656 // 2. Create state is then validated (which uses flags setup during shadowing)
3657 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003658 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003659 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3660 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003661 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003662
Tobin Ehlis11efc302015-09-16 10:33:53 -06003663 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003664 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003665
Tobin Ehlis11efc302015-09-16 10:33:53 -06003666 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003667 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003668 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003669 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003670
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003671 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003672
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003673 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003674 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3675 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003676 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003677 for (i=0; i<count; i++) {
3678 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003679 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003680 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003681 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003682 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003683 for (i=0; i<count; i++) {
3684 if (pPipeNode[i]) {
3685 // If we allocated a pipeNode, need to clean it up here
3686 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3687 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3688 delete[] pPipeNode[i]->pAttachments;
3689 delete pPipeNode[i];
3690 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003691 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003692 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003693 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003694 return result;
3695}
3696
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003697VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3698 VkDevice device,
3699 VkPipelineCache pipelineCache,
3700 uint32_t count,
3701 const VkComputePipelineCreateInfo *pCreateInfos,
3702 const VkAllocationCallbacks *pAllocator,
3703 VkPipeline *pPipelines)
3704{
3705 VkResult result = VK_SUCCESS;
3706 VkBool32 skipCall = VK_FALSE;
3707
3708 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3709 vector<PIPELINE_NODE*> pPipeNode(count);
3710 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3711
3712 uint32_t i=0;
3713 loader_platform_thread_lock_mutex(&globalLock);
3714 for (i=0; i<count; i++) {
3715 // TODO: Verify compute stage bits
3716
3717 // Create and initialize internal tracking data structure
3718 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003719 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3720
3721 // TODO: Add Compute Pipeline Verification
3722 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3723 }
3724 loader_platform_thread_unlock_mutex(&globalLock);
3725
3726 if (VK_FALSE == skipCall) {
3727 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3728 loader_platform_thread_lock_mutex(&globalLock);
3729 for (i=0; i<count; i++) {
3730 pPipeNode[i]->pipeline = pPipelines[i];
3731 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3732 }
3733 loader_platform_thread_unlock_mutex(&globalLock);
3734 } else {
3735 for (i=0; i<count; i++) {
3736 if (pPipeNode[i]) {
3737 // Clean up any locally allocated data structures
3738 delete pPipeNode[i];
3739 }
3740 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003741 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003742 }
3743 return result;
3744}
3745
Chia-I Wu9ab61502015-11-06 06:42:02 +08003746VK_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 -06003747{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003748 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003749 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003750 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003751 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003752 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003753 loader_platform_thread_unlock_mutex(&globalLock);
3754 }
3755 return result;
3756}
3757
Chia-I Wu9ab61502015-11-06 06:42:02 +08003758VK_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 -06003759{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003760 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003761 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003762 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003763 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003764 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3765 if (NULL == pNewNode) {
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_OUT_OF_MEMORY, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003767 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003768 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003769 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003770 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003771 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3772 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003773 // g++ does not like reserve with size 0
3774 if (pCreateInfo->bindingCount)
3775 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003776 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003777 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003778 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003779 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 +08003780 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003781 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003782 }
3783
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003784 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3785 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3786 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3787 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3788 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003789 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003790 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003791 pNewNode->layout = *pSetLayout;
3792 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003793 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003794 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003795 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003796 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003797 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003798 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003799 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003800 dType = pCreateInfo->pBindings[i].descriptorType;
3801 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003802 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003803 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003804 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3805 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3806 pNewNode->dynamicDescriptorCount++;
3807 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003808 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003809 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003810 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003811 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3812 } else { // no descriptors
3813 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003814 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003815 // Put new node at Head of global Layer list
3816 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003817 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003818 loader_platform_thread_unlock_mutex(&globalLock);
3819 }
3820 return result;
3821}
3822
Chia-I Wu9ab61502015-11-06 06:42:02 +08003823VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003824{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003825 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003826 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003827 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003828 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003829 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003830 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003831 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003832 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003833 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3834 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003835 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003836 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3837 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3838 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003839 }
3840 return result;
3841}
3842
Chia-I Wu9ab61502015-11-06 06:42:02 +08003843VK_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 -06003844{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003845 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003846 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003847 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003848 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003849 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 +08003850 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003851 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003852 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003853 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003854 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003855 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 -07003856 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003857 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003858 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003859 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003860 }
3861 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003862 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003863 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003864 }
3865 return result;
3866}
3867
Chia-I Wu9ab61502015-11-06 06:42:02 +08003868VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003869{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003870 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003871 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003872 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003873 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003874 }
3875 return result;
3876}
3877
Chia-I Wu9ab61502015-11-06 06:42:02 +08003878VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003879{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003880 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003881 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003882 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003883 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003884 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003885 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 +08003886 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003887 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003888 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003889 }
3890 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003891 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003892 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003893 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003894 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003895 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003896 if (pAllocateInfo->descriptorSetCount == 0) {
3897 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 +08003898 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003899 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003900 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003901 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 +08003902 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003903 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003904 SET_NODE* pNewNode = new SET_NODE;
3905 if (NULL == pNewNode) {
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_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003907 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003908 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003909 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003910 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003911 // TODO : Pool should store a total count of each type of Descriptor available
3912 // When descriptors are allocated, decrement the count and validate here
3913 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003914 // Insert set at head of Set LL for this pool
3915 pNewNode->pNext = pPoolNode->pSets;
3916 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003917 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003918 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003919 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 +08003920 "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 -07003921 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003922 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003923 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003924 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003925 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003926 pNewNode->descriptorCount = pLayout->endIndex + 1;
3927 if (pNewNode->descriptorCount) {
3928 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3929 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3930 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3931 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003932 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003933 }
3934 }
3935 }
3936 }
3937 return result;
3938}
3939
Chia-I Wu9ab61502015-11-06 06:42:02 +08003940VK_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 -06003941{
Tobin Ehlise735c692015-10-08 13:13:50 -06003942 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003943 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003944 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003945 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3946 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003947 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 -06003948 "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 -06003949 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003950 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003951 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003952 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003953 if (VK_SUCCESS == result) {
3954 // For each freed descriptor add it back into the pool as available
3955 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003956 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003957 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003958 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003959 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003960 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
3961 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003962 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003963 }
3964 }
3965 }
3966 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06003967 return result;
3968}
3969
Chia-I Wu9ab61502015-11-06 06:42:02 +08003970VK_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 -06003971{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003972 // 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 -06003973 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003974 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3975 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003976 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003977}
3978
Chia-I Wu9ab61502015-11-06 06:42:02 +08003979VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003980{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003981 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003982 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003983 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003984 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003985 // Validate command pool
3986 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003987 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003988 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003989 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003990 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
3991 // Add command buffer to map
3992 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003993 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003994 resetCB(dev_data, pCommandBuffer[i]);
3995 pCB->commandBuffer = pCommandBuffer[i];
3996 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07003997 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07003998 }
3999 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004000 }
4001 return result;
4002}
4003
Chia-I Wu9ab61502015-11-06 06:42:02 +08004004VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004005{
Mark Youngb20a6a82016-01-07 15:41:43 -07004006 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004007 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004008 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004009 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004010 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004011 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4012 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004013 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4014 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4015 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004016 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004017 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004018 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004019 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 -07004020 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4021 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004022 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004023 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 -07004024 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4025 } else {
4026 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004027 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4028 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004029 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004030 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)commandBuffer, __LINE__, DRAWSTATE_RENDERPASS_INCOMPATIBLE, "DS",
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004031 "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 -07004032 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004033 }
4034 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004035 }
4036 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004037 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004038 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 -07004039 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4040 } else if (CB_RECORDED == pCB->state) {
4041 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4042 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004043 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 -07004044 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004045 "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.",
4046 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4047 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004048 resetCB(dev_data, commandBuffer);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004049 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004050 // Set updated state here in case implicit reset occurs above
4051 pCB->state = CB_RECORDING;
4052 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004053
4054 if (pCB->beginInfo.pInheritanceInfo) {
4055 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4056 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4057 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004058 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004059 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 +08004060 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004061 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004062 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004063 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004064 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004065 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004066 return result;
4067}
4068
Chia-I Wu9ab61502015-11-06 06:42:02 +08004069VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004070{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004071 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004072 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004073 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4074 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004075 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004076 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004077 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004078 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004079 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004080 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004081 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004082 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004083 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004084 // Reset CB status flags
4085 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004086 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004087 }
4088 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004089 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004090 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004091 return result;
4092}
4093
Chia-I Wu9ab61502015-11-06 06:42:02 +08004094VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004095{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004096 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004097 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004098 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4099 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4100 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004101 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 -07004102 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004103 "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.",
4104 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4105 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004106 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004107 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004108 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004109 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004110 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004111 }
4112 return result;
4113}
4114
Chia-I Wu9ab61502015-11-06 06:42:02 +08004115VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004116{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004117 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004118 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4119 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004120 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004121 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4122 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4123 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 -07004124 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004125 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4126 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4127 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4128 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4129 }
4130
4131 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4132 if (pPN) {
4133 pCB->lastBoundPipeline = pipeline;
4134 loader_platform_thread_lock_mutex(&globalLock);
4135 set_cb_pso_status(pCB, pPN);
4136 loader_platform_thread_unlock_mutex(&globalLock);
4137 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004138 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004139 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 -07004140 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004141 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004142 }
4143 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004144 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004145 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004146}
4147
Chia-I Wu9ab61502015-11-06 06:42:02 +08004148VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004149 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004150 uint32_t firstViewport,
4151 uint32_t viewportCount,
4152 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004153{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004154 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004155 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4156 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004157 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004158 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4159 loader_platform_thread_lock_mutex(&globalLock);
4160 pCB->status |= CBSTATUS_VIEWPORT_SET;
4161 pCB->viewports.resize(viewportCount);
4162 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4163 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004164 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004165 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004166 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004167}
4168
Chia-I Wu9ab61502015-11-06 06:42:02 +08004169VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004170 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004171 uint32_t firstScissor,
4172 uint32_t scissorCount,
4173 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004174{
4175 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004176 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4177 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004178 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004179 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4180 loader_platform_thread_lock_mutex(&globalLock);
4181 pCB->status |= CBSTATUS_SCISSOR_SET;
4182 pCB->scissors.resize(scissorCount);
4183 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4184 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004185 }
4186 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004187 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004188}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004189
Chia-I Wu9ab61502015-11-06 06:42:02 +08004190VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004191{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004192 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004193 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4194 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004195 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004196 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4197 /* TODO: Do we still need this lock? */
4198 loader_platform_thread_lock_mutex(&globalLock);
4199 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4200 pCB->lineWidth = lineWidth;
4201 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004202 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004203 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004204 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004205}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004206
Chia-I Wu9ab61502015-11-06 06:42:02 +08004207VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004208 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004209 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004210 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004211 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004212{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004213 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004214 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4215 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004216 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004217 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4218 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4219 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4220 pCB->depthBiasClamp = depthBiasClamp;
4221 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004222 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004223 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004224 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004225}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004226
Chia-I Wu9ab61502015-11-06 06:42:02 +08004227VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004228{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004229 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004230 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4231 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004232 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004233 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4234 pCB->status |= CBSTATUS_BLEND_SET;
4235 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -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->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -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 vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004242 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004243 float minDepthBounds,
4244 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -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);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004249 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004250 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4251 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4252 pCB->minDepthBounds = minDepthBounds;
4253 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004254 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004255 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004256 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004257}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004258
Chia-I Wu9ab61502015-11-06 06:42:02 +08004259VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004260 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004261 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004262 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004263{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004264 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004265 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4266 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004267 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004268 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4269 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4270 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004271 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004272 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4273 pCB->back.compareMask = compareMask;
4274 }
4275 /* TODO: Do we need to track front and back separately? */
4276 /* TODO: We aren't capturing the faceMask, do we need to? */
4277 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004278 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004279 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004280 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004281}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004282
Chia-I Wu9ab61502015-11-06 06:42:02 +08004283VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004284 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004285 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004286 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004287{
4288 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004289 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4290 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004291 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004292 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4293 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4294 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004295 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004296 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4297 pCB->back.writeMask = writeMask;
4298 }
4299 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004300 }
4301 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004302 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004303}
4304
Chia-I Wu9ab61502015-11-06 06:42:02 +08004305VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004306 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004307 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004308 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004309{
4310 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004311 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4312 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004313 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004314 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4315 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4316 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004317 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004318 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4319 pCB->back.reference = reference;
4320 }
4321 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004322 }
4323 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004324 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004325}
4326
Chia-I Wu9ab61502015-11-06 06:42:02 +08004327VK_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 -06004328{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004329 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004330 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4331 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004332 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004333 if (pCB->state == CB_RECORDING) {
4334 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004335 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 -07004336 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4337 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4338 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004339 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004340 if (VK_FALSE == skipCall) {
4341 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4342 uint32_t totalDynamicDescriptors = 0;
4343 string errorString = "";
4344 uint32_t lastSetIndex = firstSet+setCount-1;
4345 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004346 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004347 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4348 for (uint32_t i=0; i<setCount; i++) {
4349 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4350 if (pSet) {
4351 loader_platform_thread_lock_mutex(&globalLock);
4352 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4353 pCB->lastBoundPipelineLayout = layout;
4354 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4355 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004356 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 -07004357 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004358 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004359 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 -07004360 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4361 }
4362 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4363 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004364 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 -07004365 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4366 }
4367 if (pSet->pLayout->dynamicDescriptorCount) {
4368 // First make sure we won't overstep bounds of pDynamicOffsets array
4369 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004370 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 -07004371 "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.",
4372 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004373 } else { // Validate and store dynamic offsets with the set
4374 // Validate Dynamic Offset Minimums
4375 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4376 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4377 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4378 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4379 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4380 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4381 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4382 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4383 }
4384 cur_dyn_offset++;
4385 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4386 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4387 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4388 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4389 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4390 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4391 }
4392 cur_dyn_offset++;
4393 }
4394 }
4395 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004396 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4397 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4398 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4399 }
4400 }
4401 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004402 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 -07004403 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4404 }
4405 }
4406 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4407 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4408 if (firstSet > 0) { // Check set #s below the first bound set
4409 for (uint32_t i=0; i<firstSet; ++i) {
4410 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 -07004411 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 -07004412 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4413 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4414 }
4415 }
4416 }
4417 // Check if newly last bound set invalidates any remaining bound sets
4418 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4419 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004420 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 -07004421 "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);
4422 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4423 }
4424 }
4425 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4426 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004427 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 -07004428 "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 -07004429 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004430 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004431 } else {
4432 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004433 }
4434 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004435 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004436 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004437}
4438
Chia-I Wu9ab61502015-11-06 06:42:02 +08004439VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004440{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004441 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004442 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4443 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004444 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004445 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4446 VkDeviceSize offset_align = 0;
4447 switch (indexType) {
4448 case VK_INDEX_TYPE_UINT16:
4449 offset_align = 2;
4450 break;
4451 case VK_INDEX_TYPE_UINT32:
4452 offset_align = 4;
4453 break;
4454 default:
4455 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4456 break;
4457 }
4458 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004459 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 -07004460 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004461 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004462 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004463 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004464 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004465 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004466}
4467
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004468void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4469 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004470 if (pCB->currentDrawData.buffers.size() < end) {
4471 pCB->currentDrawData.buffers.resize(end);
4472 }
4473 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004474 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004475 }
4476}
4477
4478void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4479 pCB->drawData.push_back(pCB->currentDrawData);
4480}
4481
Chia-I Wu9ab61502015-11-06 06:42:02 +08004482VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004483 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004484 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004485 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004486 const VkBuffer *pBuffers,
4487 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004488{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004489 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004490 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4491 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004492 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004493 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004494 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004495 } else {
Mark Youngad779052016-01-06 14:26:04 -07004496 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004497 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004498 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004499 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004500}
4501
Chia-I Wu9ab61502015-11-06 06:42:02 +08004502VK_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 -06004503{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004504 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004505 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4506 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004507 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004508 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4509 pCB->drawCount[DRAW]++;
4510 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4511 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004512 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 -07004513 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4514 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004515 if (VK_FALSE == skipCall) {
4516 updateResourceTrackingOnDraw(pCB);
4517 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004518 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004519 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004520 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004521 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004522}
4523
Chia-I Wu9ab61502015-11-06 06:42:02 +08004524VK_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 -06004525{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004526 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4527 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004528 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004529 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004530 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4531 pCB->drawCount[DRAW_INDEXED]++;
4532 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4533 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004534 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 -07004535 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4536 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004537 if (VK_FALSE == skipCall) {
4538 updateResourceTrackingOnDraw(pCB);
4539 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004540 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004541 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004542 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004543 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004544}
4545
Chia-I Wu9ab61502015-11-06 06:42:02 +08004546VK_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 -06004547{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004548 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4549 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004550 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004551 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004552 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4553 pCB->drawCount[DRAW_INDIRECT]++;
4554 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4555 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004556 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 -07004557 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4558 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004559 if (VK_FALSE == skipCall) {
4560 updateResourceTrackingOnDraw(pCB);
4561 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004562 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004563 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004564 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004565 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004566}
4567
Chia-I Wu9ab61502015-11-06 06:42:02 +08004568VK_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 -06004569{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004570 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004571 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4572 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004573 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004574 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4575 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4576 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4577 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004578 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 -07004579 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4580 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004581 if (VK_FALSE == skipCall) {
4582 updateResourceTrackingOnDraw(pCB);
4583 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004584 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004585 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004586 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004587 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004588}
4589
Chia-I Wu9ab61502015-11-06 06:42:02 +08004590VK_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 -06004591{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004592 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004593 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4594 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004595 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004596 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004597 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004598 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004599 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004600 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004601}
4602
Chia-I Wu9ab61502015-11-06 06:42:02 +08004603VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004604{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004605 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004606 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4607 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004608 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004609 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004610 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004611 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004612 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004613 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004614}
4615
Chia-I Wu9ab61502015-11-06 06:42:02 +08004616VK_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 -06004617{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004618 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004619 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4620 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004621 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004622 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004623 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004624 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004625 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004626 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004627}
4628
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004629VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004630 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004631
4632#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4633 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4634 return skip_call;
4635#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4636
Michael Lentineabc5e922015-10-12 11:30:14 -05004637 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4638 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4639 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4640 if (src_image_element == pCB->imageLayoutMap.end()) {
4641 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4642 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004643 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004644 }
4645 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004646 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 -05004647 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4648 }
4649 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4650 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004651 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004652 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 -05004653 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004654 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004655 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 -05004656 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004657 }
4658 }
4659 return skip_call;
4660}
4661
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004662VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004663 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004664
4665#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4666 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4667 return skip_call;
4668#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4669
Michael Lentineabc5e922015-10-12 11:30:14 -05004670 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4671 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4672 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4673 if (dest_image_element == pCB->imageLayoutMap.end()) {
4674 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4675 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004676 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004677 }
4678 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004679 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 -05004680 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4681 }
4682 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4683 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004684 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004685 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 -05004686 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4687 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004688 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 -05004689 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4690 }
4691 }
4692 return skip_call;
4693}
4694
Chia-I Wu9ab61502015-11-06 06:42:02 +08004695VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004696 VkImage srcImage,
4697 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004698 VkImage dstImage,
4699 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004700 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004701{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004702 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004703 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4704 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004705 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004706 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004707 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004708 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4709 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004710 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004711 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004712 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004713}
4714
Chia-I Wu9ab61502015-11-06 06:42:02 +08004715VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004716 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004717 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004718 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004719 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004720{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004721 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004722 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4723 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004724 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004725 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004726 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004727 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004728 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004729 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004730}
4731
Chia-I Wu9ab61502015-11-06 06:42:02 +08004732VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004733 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004734 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004735 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004736{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004737 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004738 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4739 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004740 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004741 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004742 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004743 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004744 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004745 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004746 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004747}
4748
Chia-I Wu9ab61502015-11-06 06:42:02 +08004749VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004750 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004751 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004752 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004753{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004754 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004755 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4756 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004757 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004758 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004759 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004760 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004761 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004762 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004763 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004764}
4765
Chia-I Wu9ab61502015-11-06 06:42:02 +08004766VK_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 -06004767{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004768 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004769 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4770 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004771 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004772 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004773 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004774 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004775 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004776 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004777}
4778
Chia-I Wu9ab61502015-11-06 06:42:02 +08004779VK_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 -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 Ehlis10ae8c12015-03-17 16:24:32 -06004784 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004785 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004786 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004787 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004788 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004789 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004790}
4791
Chia-I Wu9ab61502015-11-06 06:42:02 +08004792VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004793 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004794 uint32_t attachmentCount,
4795 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004796 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004797 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004798{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004799 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004800 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4801 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004802 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004803 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4804 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4805 if (!hasDrawCmd(pCB) &&
4806 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4807 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4808 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004809 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 -07004810 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4811 " 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 -06004812 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004813 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4814 }
4815
4816 // Validate that attachment is in reference list of active subpass
4817 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004818 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004819 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4820
4821 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4822 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4823 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4824 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004825 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004826 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4827 found = VK_TRUE;
4828 break;
4829 }
4830 }
4831 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004832 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 -07004833 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004834 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4835 attachment->colorAttachment, pCB->activeSubpass);
4836 }
4837 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004838 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004839 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004840
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004841 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 -07004842 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004843 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4844 attachment->colorAttachment,
4845 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4846 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004847 }
4848 }
4849 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004850 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004851 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004852 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004853}
4854
Chia-I Wu9ab61502015-11-06 06:42:02 +08004855VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004856 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004857 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004858 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004859 uint32_t rangeCount, 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_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004866 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
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->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, 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 vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004873 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004874 VkImage image, VkImageLayout imageLayout,
4875 const VkClearDepthStencilValue *pDepthStencil,
4876 uint32_t rangeCount,
4877 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004878{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004879 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004880 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4881 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004882 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004883 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004884 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004885 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004886 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004887 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004888}
4889
Chia-I Wu9ab61502015-11-06 06:42:02 +08004890VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004891 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004892 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004893 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004894{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004895 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004896 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4897 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004898 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004899 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004900 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004901 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004902 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004903 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004904}
4905
Chia-I Wu9ab61502015-11-06 06:42:02 +08004906VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004907{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004908 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004909 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4910 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004911 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004912 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004913 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004914 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004915 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004916 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004917}
4918
Chia-I Wu9ab61502015-11-06 06:42:02 +08004919VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004920{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004921 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004922 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4923 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004924 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004925 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004926 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004927 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004928 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004929 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004930}
4931
Jon Ashburnf19916e2016-01-11 13:12:43 -07004932VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004933 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4934 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07004935 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004936
4937#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4938 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4939 return skip;
4940#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4941
Michael Lentineabc5e922015-10-12 11:30:14 -05004942 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004943 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05004944 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004945 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05004946 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004947 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
4948 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004949 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004950 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004951 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 -07004952 "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 -05004953 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004954 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004955 }
4956 }
4957 }
4958 return skip;
4959}
4960
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07004961// Print readable FlagBits in FlagMask
4962std::string string_VkAccessFlags(VkAccessFlags accessMask)
4963{
4964 std::string result;
4965 std::string separator;
4966
4967 if (accessMask == 0) {
4968 result = "[None]";
4969 } else {
4970 result = "[";
4971 for (auto i = 0; i < 32; i++) {
4972 if (accessMask & (1 << i)) {
4973 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
4974 separator = " | ";
4975 }
4976 }
4977 result = result + "]";
4978 }
4979 return result;
4980}
4981
Michael Lentine97eb7462015-11-20 09:48:52 -08004982// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4983// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004984// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004985VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
4986 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004987 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004988
Michael Lentine97eb7462015-11-20 09:48:52 -08004989 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
4990 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004991 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004992 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 -07004993 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
4994 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05004995 }
4996 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08004997 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004998 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 -07004999 "%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 -07005000 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5001 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005002 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005003 std::string opt_bits;
5004 if (optional_bits != 0) {
5005 opt_bits = "and may have optional bits " + std::to_string(optional_bits) + ' ' + string_VkAccessFlags(optional_bits);
5006 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005007 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 -07005008 "%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 -07005009 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5010 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005011 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005012 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005013 }
5014 return skip_call;
5015}
5016
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005017VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005018 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005019 switch (layout) {
5020 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005021 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 -08005022 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005023 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005024 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005025 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 -08005026 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005027 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005028 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005029 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005030 break;
5031 }
5032 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005033 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005034 break;
5035 }
5036 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005037 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 -08005038 break;
5039 }
5040 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005041 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 -08005042 break;
5043 }
5044 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005045 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005046 break;
5047 }
5048 case VK_IMAGE_LAYOUT_UNDEFINED: {
5049 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005050 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005051 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 -07005052 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5053 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005054 }
5055 break;
5056 }
5057 case VK_IMAGE_LAYOUT_GENERAL:
5058 default: {
5059 break;
5060 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005061 }
5062 return skip_call;
5063}
5064
Jon Ashburnf19916e2016-01-11 13:12:43 -07005065VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5066{
Mark Youngb20a6a82016-01-07 15:41:43 -07005067 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005068 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5069 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5070 if (pCB->activeRenderPass && memBarrierCount) {
5071 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005072 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005073 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005074 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 -05005075 "Image or Buffers Barriers cannot be used during a render pass.");
5076 }
5077 }
5078 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005079 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 -05005080 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5081 }
5082 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005083
Jon Ashburnf19916e2016-01-11 13:12:43 -07005084 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5085 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005086 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005087 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5088 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005089 }
5090 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005091
Michael Lentine48930b82015-10-15 17:07:00 -05005092 return skip_call;
5093}
5094
Jon Ashburnf19916e2016-01-11 13:12:43 -07005095VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5096 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5097 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5098 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5099 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5100 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005101{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005102 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005103 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5104 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005105 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005106 for (uint32_t i = 0; i < eventCount; ++i) {
5107 pCB->waitedEvents.push_back(pEvents[i]);
5108 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005109 if (pCB->state == CB_RECORDING) {
5110 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005111 } else {
5112 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5113 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005114 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5115 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005116 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005117 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005118 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5119 memoryBarrierCount, pMemoryBarriers,
5120 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5121 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005122}
5123
Jon Ashburnf19916e2016-01-11 13:12:43 -07005124VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5125 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5126 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5127 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5128 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5129 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005130{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005131 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005132 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5133 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005134 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005135 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005136 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5137 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005138 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005139 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005140 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5141 memoryBarrierCount, pMemoryBarriers,
5142 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5143 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005144}
5145
Chia-I Wu9ab61502015-11-06 06:42:02 +08005146VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005147{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005148 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005149 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5150 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005151 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005152 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
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->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005156}
5157
Chia-I Wu9ab61502015-11-06 06:42:02 +08005158VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
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 QueryObject query = {queryPool, slot};
5165 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005166 if (pCB->state == CB_RECORDING) {
5167 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005168 } else {
5169 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5170 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005171 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005172 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005173 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005174}
5175
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005176VK_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 -06005177{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005178 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005179 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5180 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005181 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005182 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005183 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005184 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5185 pCB->queryToStateMap[query] = 0;
5186 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005187 if (pCB->state == CB_RECORDING) {
5188 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005189 } else {
5190 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5191 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005192 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005193 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005194 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005195 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005196}
5197
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005198VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005199 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005200 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005201{
5202 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005203 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5204 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005205 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005206 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005207 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005208 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005209 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5210 "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 -06005211 }
5212 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005213 if (pCB->state == CB_RECORDING) {
5214 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005215 } else {
5216 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5217 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005218 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005219 }
5220 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005221 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005222 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005223}
5224
Chia-I Wu9ab61502015-11-06 06:42:02 +08005225VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005226{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005227 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005228 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5229 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005230 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005231 QueryObject query = {queryPool, slot};
5232 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005233 if (pCB->state == CB_RECORDING) {
5234 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005235 } else {
5236 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5237 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005238 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005239 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005240 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005241}
5242
Chia-I Wu9ab61502015-11-06 06:42:02 +08005243VK_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 -06005244{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005245 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005246 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005247 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005248 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005249 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005250 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005251 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5252 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005253 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005254 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005255 }
5256 return result;
5257}
5258
Michael Lentineb6986752015-10-06 14:56:18 -07005259// Store the DAG.
5260struct DAGNode {
5261 uint32_t pass;
5262 std::vector<uint32_t> prev;
5263 std::vector<uint32_t> next;
5264};
5265
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005266VkBool32 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 -07005267 // If we have already checked this node we have not found a dependency path so return false.
5268 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005269 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005270 processed_nodes.insert(index);
5271 const DAGNode& node = subpass_to_node[index];
5272 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5273 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5274 for (auto elem : node.prev) {
5275 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005276 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005277 }
5278 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005279 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005280 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005281 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005282}
5283
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005284VkBool32 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 -07005285 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005286 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5287 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5288 if (subpass == dependent_subpasses[k])
5289 continue;
5290 const DAGNode& node = subpass_to_node[subpass];
5291 // Check for a specified dependency between the two nodes. If one exists we are done.
5292 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5293 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5294 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5295 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5296 std::unordered_set<uint32_t> processed_nodes;
5297 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5298 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005299 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005300 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 -07005301 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5302 subpass, dependent_subpasses[k]);
5303 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005304 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 -07005305 "A dependency between subpasses %d and %d must exist but one is not specified.",
5306 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005307 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005308 }
5309 }
5310 }
5311 return result;
5312}
5313
Jon Ashburnf19916e2016-01-11 13:12:43 -07005314VkBool32 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 -07005315 const DAGNode& node = subpass_to_node[index];
5316 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5317 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005318 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005319 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005320 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005321 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005322 if (subpass.pDepthStencilAttachment &&
5323 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5324 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005325 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005326 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005327 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005328 // Loop through previous nodes and see if any of them write to the attachment.
5329 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005330 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005331 }
5332 // If the attachment was written to by a previous node than this node needs to preserve it.
5333 if (result && depth > 0) {
5334 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005335 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005336 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005337 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005338 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005339 break;
5340 }
5341 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005342 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005343 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 -07005344 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5345 }
5346 }
5347 return result;
5348}
5349
Michael Lentineb4979492015-12-22 11:36:14 -06005350VkBool32 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 -07005351 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005352 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5353 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005354 // Find for each attachment the subpasses that use them.
5355 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5356 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005357 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005358 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5359 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005360 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005361 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5362 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005363 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5364 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005365 }
5366 }
5367 // If there is a dependency needed make sure one exists
5368 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5369 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5370 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005371 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005372 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005373 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005374 }
5375 // 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 +08005376 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005377 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005378 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5379 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005380 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005381 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5382 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005383 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5384 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005385 }
5386 }
5387 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5388 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5389 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005390 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005391 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005392 }
5393 }
5394 return skip_call;
5395}
5396
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005397VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005398 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005399
5400#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5401 return skip;
5402#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5403
Michael Lentineabc5e922015-10-12 11:30:14 -05005404 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5405 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5406 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5407 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5408 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5409 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005410 // 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 -07005411 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 -05005412 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5413 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005414 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 -05005415 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5416 }
5417 }
5418 }
5419 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5420 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5421 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005422 // 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 -07005423 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 -05005424 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5425 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005426 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 -05005427 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5428 }
5429 }
5430 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005431 if ((subpass.pDepthStencilAttachment != NULL) &&
5432 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005433 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5434 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005435 // 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 -07005436 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 -05005437 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5438 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005439 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 -05005440 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5441 }
5442 }
5443 }
5444 }
5445 return skip;
5446}
5447
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005448VkBool32 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 -07005449 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005450 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5451 DAGNode& subpass_node = subpass_to_node[i];
5452 subpass_node.pass = i;
5453 }
5454 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5455 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5456 if (dependency.srcSubpass > dependency.dstSubpass) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005457 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 -05005458 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005459 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5460 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005461 }
5462 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5463 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5464 }
5465 return skip_call;
5466}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005467// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005468
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005469VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5470 VkDevice device,
5471 const VkShaderModuleCreateInfo *pCreateInfo,
5472 const VkAllocationCallbacks* pAllocator,
5473 VkShaderModule *pShaderModule)
5474{
5475 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005476 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005477 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005478 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 -07005479 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005480 "Shader is not SPIR-V");
5481 }
5482
Mark Youngb20a6a82016-01-07 15:41:43 -07005483 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005484 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005485
5486 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5487
5488 if (res == VK_SUCCESS) {
5489 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005490 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005491 loader_platform_thread_unlock_mutex(&globalLock);
5492 }
5493 return res;
5494}
5495
Chia-I Wu9ab61502015-11-06 06:42:02 +08005496VK_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 -06005497{
Mark Youngb20a6a82016-01-07 15:41:43 -07005498 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005499 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005500 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005501 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005502 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005503 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005504 // Validate using DAG
5505 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5506 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005507 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005508 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005509 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005510 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005511 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005512 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005513 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005514 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005515 if (pCreateInfo->pAttachments) {
5516 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5517 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005518 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005519 if (pCreateInfo->pSubpasses) {
5520 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5521 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5522
5523 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5524 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005525 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5526 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005527 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005528 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5529
Cody Northropa505dda2015-08-04 11:16:41 -06005530 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005531 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005532 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005533 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005534
Cody Northropa505dda2015-08-04 11:16:41 -06005535 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005536 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005537 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005538 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005539
Cody Northropa505dda2015-08-04 11:16:41 -06005540 if (subpass->pResolveAttachments) {
5541 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005542 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005543 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005544 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005545 }
5546
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005547 if (subpass->pDepthStencilAttachment) {
5548 memcpy(attachments, subpass->pDepthStencilAttachment,
5549 sizeof(attachments[0]) * 1);
5550 subpass->pDepthStencilAttachment = attachments;
5551 attachments += 1;
5552 }
5553
Cody Northropa505dda2015-08-04 11:16:41 -06005554 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005555 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005556 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005557 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005558 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005559 if (pCreateInfo->pDependencies) {
5560 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5561 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005562 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005563 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005564 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005565 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005566 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005567 }
5568 return result;
5569}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005570// Free the renderpass shadow
5571static void deleteRenderPasses(layer_data* my_data)
5572{
5573 if (my_data->renderPassMap.size() <= 0)
5574 return;
5575 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005576 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005577 if (pRenderPassInfo->pAttachments) {
5578 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005579 }
Michael Lentine48930b82015-10-15 17:07:00 -05005580 if (pRenderPassInfo->pSubpasses) {
5581 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005582 // Attachements are all allocated in a block, so just need to
5583 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005584 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5585 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5586 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5587 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5588 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5589 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5590 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5591 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005592 }
5593 }
Michael Lentine48930b82015-10-15 17:07:00 -05005594 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005595 }
Michael Lentine48930b82015-10-15 17:07:00 -05005596 if (pRenderPassInfo->pDependencies) {
5597 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005598 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005599 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005600 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005601 }
5602 my_data->renderPassMap.clear();
5603}
Michael Lentineabc5e922015-10-12 11:30:14 -05005604
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005605VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005606 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005607 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5608 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005609 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005610 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5611 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005612 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 -05005613 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5614 }
5615 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5616 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5617 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5618 auto image_data = pCB->imageLayoutMap.find(image);
5619 if (image_data == pCB->imageLayoutMap.end()) {
5620 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5621 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5622 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005623 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 -05005624 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5625 }
5626 }
5627 return skip_call;
5628}
5629
5630void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5631 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5632 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5633 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5634 if (render_pass_data == dev_data->renderPassMap.end()) {
5635 return;
5636 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005637 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005638 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5639 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5640 return;
5641 }
5642 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5643 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5644 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5645 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5646 auto image_view_data = dev_data->imageViewMap.find(image_view);
5647 if (image_view_data != dev_data->imageViewMap.end()) {
5648 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5649 if (image_layout != pCB->imageLayoutMap.end()) {
5650 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5651 }
5652 }
5653 }
5654 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5655 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5656 auto image_view_data = dev_data->imageViewMap.find(image_view);
5657 if (image_view_data != dev_data->imageViewMap.end()) {
5658 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5659 if (image_layout != pCB->imageLayoutMap.end()) {
5660 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5661 }
5662 }
5663 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005664 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005665 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005666 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5667 auto image_view_data = dev_data->imageViewMap.find(image_view);
5668 if (image_view_data != dev_data->imageViewMap.end()) {
5669 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5670 if (image_layout != pCB->imageLayoutMap.end()) {
5671 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5672 }
5673 }
5674 }
5675}
5676
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005677VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005678 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005679 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005680 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 -07005681 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5682 }
5683 return skip_call;
5684}
5685
Michael Lentineabc5e922015-10-12 11:30:14 -05005686void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5687 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5688 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5689 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5690 if (render_pass_data == dev_data->renderPassMap.end()) {
5691 return;
5692 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005693 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005694 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5695 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5696 return;
5697 }
5698 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5699 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5700 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5701 auto image_view_data = dev_data->imageViewMap.find(image_view);
5702 if (image_view_data != dev_data->imageViewMap.end()) {
5703 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5704 if (image_layout != pCB->imageLayoutMap.end()) {
5705 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5706 }
5707 }
5708 }
5709}
5710
Chia-I Wu9ab61502015-11-06 06:42:02 +08005711VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005712{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005713 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005714 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5715 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005716 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005717 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005718 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005719 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005720 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005721 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005722 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005723 // This is a shallow copy as that is all that is needed for now
5724 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005725 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005726 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005727 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005728 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005729 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 -06005730 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005731 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005732 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005733 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005734 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005735 // This is a shallow copy as that is all that is needed for now
5736 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5737 dev_data->currentSubpass = 0;
5738 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005739}
5740
Chia-I Wu9ab61502015-11-06 06:42:02 +08005741VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005742{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005743 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005744 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5745 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005746 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005747 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005748 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005749 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005750 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005751 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005752 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005753 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005754 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005755 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005756 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +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->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005760}
5761
Chia-I Wu9ab61502015-11-06 06:42:02 +08005762VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005763{
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);
Michael Lentineabc5e922015-10-12 11:30:14 -05005767 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005768 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005769 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005770 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005771 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005772 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005773 pCB->activeRenderPass = 0;
5774 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005775 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005776 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005777 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005778}
5779
Chia-I Wu9ab61502015-11-06 06:42:02 +08005780VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005781{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005782 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005783 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5784 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005785 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005786 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5787 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5788 // 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 -06005789 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005790 for (uint32_t i=0; i<commandBuffersCount; i++) {
5791 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005792 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005793 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 +08005794 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5795 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005796 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 +08005797 "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 -07005798 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5799 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005800 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 -07005801 "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);
5802 }
5803 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005804 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005805 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 -07005806 "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 -07005807 (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 -07005808 }
5809 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5810 // 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 -07005811 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5812 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005813 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 -07005814 "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 -07005815 (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 -07005816 }
5817 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005818 }
5819 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005820 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005821 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005822 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005823 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005824 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005825}
5826
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005827VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005828 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005829 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5830 auto mem_data = dev_data->memImageMap.find(mem);
5831 if (mem_data != dev_data->memImageMap.end()) {
5832 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5833 if (image_data != dev_data->imageLayoutMap.end()) {
5834 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005835 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 -07005836 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5837 }
5838 }
5839 }
5840 return skip_call;
5841}
5842
Chia-I Wu9ab61502015-11-06 06:42:02 +08005843VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005844 VkDevice device,
5845 VkDeviceMemory mem,
5846 VkDeviceSize offset,
5847 VkDeviceSize size,
5848 VkFlags flags,
5849 void **ppData)
5850{
5851 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005852
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005853 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005854#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5855 skip_call = ValidateMapImageLayouts(device, mem);
5856#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5857
Michael Lentine7b236262015-10-23 12:41:44 -07005858 if (VK_FALSE == skip_call) {
5859 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5860 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005861 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005862}
5863
Chia-I Wu9ab61502015-11-06 06:42:02 +08005864VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005865 VkDevice device,
5866 VkImage image,
5867 VkDeviceMemory mem,
5868 VkDeviceSize memOffset)
5869{
5870 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5871 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5872 loader_platform_thread_lock_mutex(&globalLock);
5873 dev_data->memImageMap[mem] = image;
5874 loader_platform_thread_unlock_mutex(&globalLock);
5875 return result;
5876}
5877
Michael Lentineb887b0a2015-12-29 14:12:11 -06005878
5879VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
5880 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5881 dev_data->eventMap[event].needsSignaled = false;
5882 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
5883 return result;
5884}
5885
Michael Lentine15a47882016-01-06 10:05:48 -06005886VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
5887 VkQueue queue,
5888 uint32_t bindInfoCount,
5889 const VkBindSparseInfo* pBindInfo,
5890 VkFence fence)
5891{
5892 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005893 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06005894
5895 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
5896 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
5897 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
5898 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
5899 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
5900 } else {
5901 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",
5902 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5903 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
5904 }
5905 }
5906 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
5907 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
5908 }
5909 }
5910
Mark Youngb20a6a82016-01-07 15:41:43 -07005911 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06005912 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07005913 else
5914 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06005915}
5916
5917VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
5918 VkDevice device,
5919 const VkSemaphoreCreateInfo* pCreateInfo,
5920 const VkAllocationCallbacks* pAllocator,
5921 VkSemaphore* pSemaphore)
5922{
5923 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5924 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
5925 if (result == VK_SUCCESS) {
5926 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
5927 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07005928 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06005929}
5930
Chia-I Wu9ab61502015-11-06 06:42:02 +08005931VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005932 VkDevice device,
5933 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07005934 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05005935 VkSwapchainKHR *pSwapchain)
5936{
5937 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07005938 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05005939
5940 if (VK_SUCCESS == result) {
5941 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5942 loader_platform_thread_lock_mutex(&globalLock);
5943 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5944 loader_platform_thread_unlock_mutex(&globalLock);
5945 }
5946
5947 return result;
5948}
5949
Ian Elliott05846062015-11-20 14:13:17 -07005950VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005951 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07005952 VkSwapchainKHR swapchain,
5953 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05005954{
5955 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005956
5957 loader_platform_thread_lock_mutex(&globalLock);
5958 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5959 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5960 if (swapchain_data->second->images.size() > 0) {
5961 for (auto swapchain_image : swapchain_data->second->images) {
5962 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5963 if (image_item != dev_data->imageLayoutMap.end())
5964 dev_data->imageLayoutMap.erase(image_item);
5965 }
5966 }
5967 delete swapchain_data->second;
5968 dev_data->device_extensions.swapchainMap.erase(swapchain);
5969 }
5970 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07005971 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05005972}
5973
Chia-I Wu9ab61502015-11-06 06:42:02 +08005974VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005975 VkDevice device,
5976 VkSwapchainKHR swapchain,
5977 uint32_t* pCount,
5978 VkImage* pSwapchainImages)
5979{
5980 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5981 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5982
5983 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5984 // This should never happen and is checked by param checker.
5985 if (!pCount) return result;
5986 for (uint32_t i = 0; i < *pCount; ++i) {
5987 IMAGE_NODE* image_node = new IMAGE_NODE;
5988 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
5989 loader_platform_thread_lock_mutex(&globalLock);
5990 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
5991 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
5992 loader_platform_thread_unlock_mutex(&globalLock);
5993 }
5994 }
5995 return result;
5996}
5997
Ian Elliott05846062015-11-20 14:13:17 -07005998VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05005999{
6000 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006001 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006002
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006003#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006004 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006005 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6006 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6007 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6008 } else {
6009 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",
6010 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6011 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
6012 }
6013 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006014 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006015 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6016 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6017 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006018 auto image_data = dev_data->imageLayoutMap.find(image);
6019 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006020 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006021 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 -05006022 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6023 }
6024 }
6025 }
6026 }
6027 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006028#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006029
6030 if (VK_FALSE == skip_call)
6031 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006032 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006033}
6034
Michael Lentine15a47882016-01-06 10:05:48 -06006035VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6036 VkDevice device,
6037 VkSwapchainKHR swapchain,
6038 uint64_t timeout,
6039 VkSemaphore semaphore,
6040 VkFence fence,
6041 uint32_t* pImageIndex)
6042{
6043 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6044 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6045 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006046 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006047}
6048
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006049VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6050 VkInstance instance,
6051 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6052 const VkAllocationCallbacks* pAllocator,
6053 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006054{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006055 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006056 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006057 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006058 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006059 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006060 }
6061 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006062}
6063
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006064VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006065 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006066 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006067 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006068{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006069 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006070 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006071 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006072 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006073}
6074
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006075VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006076 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006077 VkDebugReportFlagsEXT flags,
6078 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006079 uint64_t object,
6080 size_t location,
6081 int32_t msgCode,
6082 const char* pLayerPrefix,
6083 const char* pMsg)
6084{
6085 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006086 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006087}
6088
Chia-I Wu9ab61502015-11-06 06:42:02 +08006089VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006090{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006091 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006092 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6093 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006094 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006095 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 -06006096 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006097 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006098 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006099 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006100 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006101 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006102 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006103}
6104
Chia-I Wu9ab61502015-11-06 06:42:02 +08006105VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006106{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006107 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006108 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6109 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006110 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006111 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 -06006112 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006113 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006114 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006115 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006116 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006117 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006118 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006119}
6120
Chia-I Wu9ab61502015-11-06 06:42:02 +08006121VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006122{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006123 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006124 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006125 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006126 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006127 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006128 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006129 if (!strcmp(funcName, "vkWaitForFences"))
6130 return (PFN_vkVoidFunction) vkWaitForFences;
6131 if (!strcmp(funcName, "vkGetFenceStatus"))
6132 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006133 if (!strcmp(funcName, "vkQueueWaitIdle"))
6134 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6135 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6136 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006137 if (!strcmp(funcName, "vkGetDeviceQueue"))
6138 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006139 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006140 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006141 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006142 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006143 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006144 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006145 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006146 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006147 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006148 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006149 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006150 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006151 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006152 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006153 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006154 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006155 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006156 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006157 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006158 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006159 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006160 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006161 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006162 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006163 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006164 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006165 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006166 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006167 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006168 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006169 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006170 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006171 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006172 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006173 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006174 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006175 if (!strcmp(funcName, "vkCreateBuffer"))
6176 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006177 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006178 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006179 if (!strcmp(funcName, "vkCreateImage"))
6180 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006181 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006182 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006183 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006184 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006185 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006186 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006187 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006188 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006189 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006190 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006191 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006192 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006193 if (!strcmp(funcName, "vkCreateComputePipelines"))
6194 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006195 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006196 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006197 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006198 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006199 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006200 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006201 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006202 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006203 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006204 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006205 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6206 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006207 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6208 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006209 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006210 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006211 if (!strcmp(funcName, "vkCreateCommandPool"))
6212 return (PFN_vkVoidFunction) vkCreateCommandPool;
6213 if (!strcmp(funcName, "vkDestroyCommandPool"))
6214 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006215 if (!strcmp(funcName, "vkResetCommandPool"))
6216 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006217 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6218 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006219 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6220 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006221 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006222 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006223 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006224 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006225 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006226 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006227 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006228 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006229 if (!strcmp(funcName, "vkCmdSetViewport"))
6230 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006231 if (!strcmp(funcName, "vkCmdSetScissor"))
6232 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006233 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6234 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6235 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6236 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6237 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6238 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6239 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6240 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6241 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6242 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6243 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6244 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6245 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6246 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006247 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006248 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006249 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006250 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006251 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006252 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006253 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006254 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006255 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006256 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006257 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006258 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006259 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006260 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006261 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006262 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006263 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006264 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006265 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006266 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006267 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006268 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006269 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006270 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006271 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006272 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006273 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006274 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006275 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006276 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006277 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006278 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006279 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006280 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006281 if (!strcmp(funcName, "vkCmdClearAttachments"))
6282 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006283 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006284 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006285 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006286 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006287 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006288 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006289 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006290 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006291 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006292 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006293 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006294 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006295 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006296 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006297 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006298 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006299 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006300 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006301 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006302 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006303 if (!strcmp(funcName, "vkCreateShaderModule"))
6304 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006305 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006306 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006307 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006308 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006309 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006310 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006311 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006312 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006313 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6314 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006315 if (!strcmp(funcName, "vkSetEvent"))
6316 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006317 if (!strcmp(funcName, "vkMapMemory"))
6318 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006319 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6320 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006321 if (!strcmp(funcName, "vkBindImageMemory"))
6322 return (PFN_vkVoidFunction) vkBindImageMemory;
6323 if (!strcmp(funcName, "vkQueueBindSparse"))
6324 return (PFN_vkVoidFunction) vkQueueBindSparse;
6325 if (!strcmp(funcName, "vkCreateSemaphore"))
6326 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006327
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006328 if (dev == NULL)
6329 return NULL;
6330
6331 layer_data *dev_data;
6332 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6333
Michael Lentineabc5e922015-10-12 11:30:14 -05006334 if (dev_data->device_extensions.wsi_enabled)
6335 {
6336 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6337 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6338 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6339 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6340 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6341 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006342 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6343 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006344 if (!strcmp(funcName, "vkQueuePresentKHR"))
6345 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6346 }
6347
Tobin Ehlis0b632332015-10-07 09:38:40 -06006348 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6349 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006350 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006351 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006352 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006353 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006354 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006355 }
6356 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006357 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006358 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006359 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006360 }
6361}
6362
Chia-I Wu9ab61502015-11-06 06:42:02 +08006363VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006364{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006365 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006366 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006367 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
6368 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006369 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006370 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006371 if (!strcmp(funcName, "vkCreateDevice"))
6372 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006373 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006374 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006375 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6376 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6377 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6378 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6379 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6380 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6381 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6382 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006383
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006384 if (instance == NULL)
6385 return NULL;
6386
6387 PFN_vkVoidFunction fptr;
6388
6389 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006390 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006391 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006392 if (fptr)
6393 return fptr;
6394
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006395 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
6396 if (pTable->GetInstanceProcAddr == NULL)
6397 return NULL;
6398 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006399}