blob: 90285ae312d9f7e22ee05b50dbfcaf99ccf5d248 [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); }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700198};
199
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600200// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700201static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600202
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600203static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
204// TODO : This can be much smarter, using separate locks for separate global data
205static int globalLockInitialized = 0;
206static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600207#define MAX_TID 513
208static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
209static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600210
211template layer_data *get_my_data_ptr<layer_data>(
212 void *data_key,
213 std::unordered_map<void *, layer_data *> &data_map);
214
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600215// Map actual TID to an index value and return that index
216// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
217static uint32_t getTIDIndex() {
218 loader_platform_thread_id tid = loader_platform_get_thread_id();
219 for (uint32_t i = 0; i < g_maxTID; i++) {
220 if (tid == g_tidMapping[i])
221 return i;
222 }
223 // Don't yet have mapping, set it and return newly set index
224 uint32_t retVal = (uint32_t) g_maxTID;
225 g_tidMapping[g_maxTID++] = tid;
226 assert(g_maxTID < MAX_TID);
227 return retVal;
228}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700229
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600230// Return a string representation of CMD_TYPE enum
231static string cmdTypeToString(CMD_TYPE cmd)
232{
233 switch (cmd)
234 {
235 case CMD_BINDPIPELINE:
236 return "CMD_BINDPIPELINE";
237 case CMD_BINDPIPELINEDELTA:
238 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600239 case CMD_SETVIEWPORTSTATE:
240 return "CMD_SETVIEWPORTSTATE";
241 case CMD_SETLINEWIDTHSTATE:
242 return "CMD_SETLINEWIDTHSTATE";
243 case CMD_SETDEPTHBIASSTATE:
244 return "CMD_SETDEPTHBIASSTATE";
245 case CMD_SETBLENDSTATE:
246 return "CMD_SETBLENDSTATE";
247 case CMD_SETDEPTHBOUNDSSTATE:
248 return "CMD_SETDEPTHBOUNDSSTATE";
249 case CMD_SETSTENCILREADMASKSTATE:
250 return "CMD_SETSTENCILREADMASKSTATE";
251 case CMD_SETSTENCILWRITEMASKSTATE:
252 return "CMD_SETSTENCILWRITEMASKSTATE";
253 case CMD_SETSTENCILREFERENCESTATE:
254 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600255 case CMD_BINDDESCRIPTORSETS:
256 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600257 case CMD_BINDINDEXBUFFER:
258 return "CMD_BINDINDEXBUFFER";
259 case CMD_BINDVERTEXBUFFER:
260 return "CMD_BINDVERTEXBUFFER";
261 case CMD_DRAW:
262 return "CMD_DRAW";
263 case CMD_DRAWINDEXED:
264 return "CMD_DRAWINDEXED";
265 case CMD_DRAWINDIRECT:
266 return "CMD_DRAWINDIRECT";
267 case CMD_DRAWINDEXEDINDIRECT:
268 return "CMD_DRAWINDEXEDINDIRECT";
269 case CMD_DISPATCH:
270 return "CMD_DISPATCH";
271 case CMD_DISPATCHINDIRECT:
272 return "CMD_DISPATCHINDIRECT";
273 case CMD_COPYBUFFER:
274 return "CMD_COPYBUFFER";
275 case CMD_COPYIMAGE:
276 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600277 case CMD_BLITIMAGE:
278 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600279 case CMD_COPYBUFFERTOIMAGE:
280 return "CMD_COPYBUFFERTOIMAGE";
281 case CMD_COPYIMAGETOBUFFER:
282 return "CMD_COPYIMAGETOBUFFER";
283 case CMD_CLONEIMAGEDATA:
284 return "CMD_CLONEIMAGEDATA";
285 case CMD_UPDATEBUFFER:
286 return "CMD_UPDATEBUFFER";
287 case CMD_FILLBUFFER:
288 return "CMD_FILLBUFFER";
289 case CMD_CLEARCOLORIMAGE:
290 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600291 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600292 return "CMD_CLEARCOLORATTACHMENT";
293 case CMD_CLEARDEPTHSTENCILIMAGE:
294 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600295 case CMD_RESOLVEIMAGE:
296 return "CMD_RESOLVEIMAGE";
297 case CMD_SETEVENT:
298 return "CMD_SETEVENT";
299 case CMD_RESETEVENT:
300 return "CMD_RESETEVENT";
301 case CMD_WAITEVENTS:
302 return "CMD_WAITEVENTS";
303 case CMD_PIPELINEBARRIER:
304 return "CMD_PIPELINEBARRIER";
305 case CMD_BEGINQUERY:
306 return "CMD_BEGINQUERY";
307 case CMD_ENDQUERY:
308 return "CMD_ENDQUERY";
309 case CMD_RESETQUERYPOOL:
310 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600311 case CMD_COPYQUERYPOOLRESULTS:
312 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600313 case CMD_WRITETIMESTAMP:
314 return "CMD_WRITETIMESTAMP";
315 case CMD_INITATOMICCOUNTERS:
316 return "CMD_INITATOMICCOUNTERS";
317 case CMD_LOADATOMICCOUNTERS:
318 return "CMD_LOADATOMICCOUNTERS";
319 case CMD_SAVEATOMICCOUNTERS:
320 return "CMD_SAVEATOMICCOUNTERS";
321 case CMD_BEGINRENDERPASS:
322 return "CMD_BEGINRENDERPASS";
323 case CMD_ENDRENDERPASS:
324 return "CMD_ENDRENDERPASS";
325 case CMD_DBGMARKERBEGIN:
326 return "CMD_DBGMARKERBEGIN";
327 case CMD_DBGMARKEREND:
328 return "CMD_DBGMARKEREND";
329 default:
330 return "UNKNOWN";
331 }
332}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700333
334// SPIRV utility functions
335static void
Chris Forbes79b37f82016-01-18 08:56:09 +1300336build_type_def_index(shader_module *module)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700337{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300338 for (auto insn : *module) {
339 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700340 case spv::OpTypeVoid:
341 case spv::OpTypeBool:
342 case spv::OpTypeInt:
343 case spv::OpTypeFloat:
344 case spv::OpTypeVector:
345 case spv::OpTypeMatrix:
346 case spv::OpTypeImage:
347 case spv::OpTypeSampler:
348 case spv::OpTypeSampledImage:
349 case spv::OpTypeArray:
350 case spv::OpTypeRuntimeArray:
351 case spv::OpTypeStruct:
352 case spv::OpTypeOpaque:
353 case spv::OpTypePointer:
354 case spv::OpTypeFunction:
355 case spv::OpTypeEvent:
356 case spv::OpTypeDeviceEvent:
357 case spv::OpTypeReserveId:
358 case spv::OpTypeQueue:
359 case spv::OpTypePipe:
Chris Forbesc7e2e202016-01-18 08:56:40 +1300360 module->type_def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700361 break;
362
363 default:
364 /* We only care about type definitions */
365 break;
366 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700367 }
368}
369
370bool
371shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
372{
373 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
374 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
375
376 /* Just validate that the header makes sense. */
377 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
378}
379
380static char const *
381storage_class_name(unsigned sc)
382{
383 switch (sc) {
384 case spv::StorageClassInput: return "input";
385 case spv::StorageClassOutput: return "output";
386 case spv::StorageClassUniformConstant: return "const uniform";
387 case spv::StorageClassUniform: return "uniform";
388 case spv::StorageClassWorkgroup: return "workgroup local";
389 case spv::StorageClassCrossWorkgroup: return "workgroup global";
390 case spv::StorageClassPrivate: return "private global";
391 case spv::StorageClassFunction: return "function";
392 case spv::StorageClassGeneric: return "generic";
393 case spv::StorageClassAtomicCounter: return "atomic counter";
394 case spv::StorageClassImage: return "image";
395 default: return "unknown";
396 }
397}
398
399/* returns ptr to null terminator */
400static char *
401describe_type(char *dst, shader_module const *src, unsigned type)
402{
403 auto type_def_it = src->type_def_index.find(type);
404
405 if (type_def_it == src->type_def_index.end()) {
406 return dst + sprintf(dst, "undef");
407 }
408
409 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
410 unsigned opcode = code[0] & 0x0ffffu;
411 switch (opcode) {
412 case spv::OpTypeBool:
413 return dst + sprintf(dst, "bool");
414 case spv::OpTypeInt:
415 return dst + sprintf(dst, "%cint%d", code[3] ? 's' : 'u', code[2]);
416 case spv::OpTypeFloat:
417 return dst + sprintf(dst, "float%d", code[2]);
418 case spv::OpTypeVector:
419 dst += sprintf(dst, "vec%d of ", code[3]);
420 return describe_type(dst, src, code[2]);
421 case spv::OpTypeMatrix:
422 dst += sprintf(dst, "mat%d of ", code[3]);
423 return describe_type(dst, src, code[2]);
424 case spv::OpTypeArray:
425 dst += sprintf(dst, "arr[%d] of ", code[3]);
426 return describe_type(dst, src, code[2]);
427 case spv::OpTypePointer:
428 dst += sprintf(dst, "ptr to %s ", storage_class_name(code[2]));
429 return describe_type(dst, src, code[3]);
430 case spv::OpTypeStruct:
431 {
432 unsigned oplen = code[0] >> 16;
433 dst += sprintf(dst, "struct of (");
434 for (unsigned i = 2; i < oplen; i++) {
435 dst = describe_type(dst, src, code[i]);
436 dst += sprintf(dst, i == oplen-1 ? ")" : ", ");
437 }
438 return dst;
439 }
440 case spv::OpTypeSampler:
441 return dst + sprintf(dst, "sampler");
442 default:
443 return dst + sprintf(dst, "oddtype");
444 }
445}
446
447static bool
448types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
449{
450 auto a_type_def_it = a->type_def_index.find(a_type);
451 auto b_type_def_it = b->type_def_index.find(b_type);
452
453 if (a_type_def_it == a->type_def_index.end()) {
454 return false;
455 }
456
457 if (b_type_def_it == b->type_def_index.end()) {
458 return false;
459 }
460
461 /* walk two type trees together, and complain about differences */
462 unsigned int const *a_code = (unsigned int const *)&a->words[a_type_def_it->second];
463 unsigned int const *b_code = (unsigned int const *)&b->words[b_type_def_it->second];
464
465 unsigned a_opcode = a_code[0] & 0x0ffffu;
466 unsigned b_opcode = b_code[0] & 0x0ffffu;
467
468 if (b_arrayed && b_opcode == spv::OpTypeArray) {
469 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
470 return types_match(a, b, a_type, b_code[2], false);
471 }
472
473 if (a_opcode != b_opcode) {
474 return false;
475 }
476
477 switch (a_opcode) {
478 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
479 case spv::OpTypeBool:
480 return true && !b_arrayed;
481 case spv::OpTypeInt:
482 /* match on width, signedness */
483 return a_code[2] == b_code[2] && a_code[3] == b_code[3] && !b_arrayed;
484 case spv::OpTypeFloat:
485 /* match on width */
486 return a_code[2] == b_code[2] && !b_arrayed;
487 case spv::OpTypeVector:
488 case spv::OpTypeMatrix:
489 case spv::OpTypeArray:
490 /* match on element type, count. these all have the same layout. we don't get here if
491 * b_arrayed -- that is handled above. */
492 return !b_arrayed && types_match(a, b, a_code[2], b_code[2], b_arrayed) && a_code[3] == b_code[3];
493 case spv::OpTypeStruct:
494 /* match on all element types */
495 {
496 if (b_arrayed) {
497 /* for the purposes of matching different levels of arrayness, structs are leaves. */
498 return false;
499 }
500
501 unsigned a_len = a_code[0] >> 16;
502 unsigned b_len = b_code[0] >> 16;
503
504 if (a_len != b_len) {
505 return false; /* structs cannot match if member counts differ */
506 }
507
508 for (unsigned i = 2; i < a_len; i++) {
509 if (!types_match(a, b, a_code[i], b_code[i], b_arrayed)) {
510 return false;
511 }
512 }
513
514 return true;
515 }
516 case spv::OpTypePointer:
517 /* match on pointee type. storage class is expected to differ */
518 return types_match(a, b, a_code[3], b_code[3], b_arrayed);
519
520 default:
521 /* remaining types are CLisms, or may not appear in the interfaces we
522 * are interested in. Just claim no match.
523 */
524 return false;
525
526 }
527}
528
529static int
530value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
531{
532 auto it = map.find(id);
533 if (it == map.end())
534 return def;
535 else
536 return it->second;
537}
538
539
540static unsigned
541get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
542{
543 auto type_def_it = src->type_def_index.find(type);
544
545 if (type_def_it == src->type_def_index.end()) {
546 return 1; /* This is actually broken SPIR-V... */
547 }
548
Chris Forbesc7e2e202016-01-18 08:56:40 +1300549 auto insn = src->at(type_def_it->second);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700550
Chris Forbesc7e2e202016-01-18 08:56:40 +1300551 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700552 case spv::OpTypePointer:
553 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
554 * we're never actually passing pointers around. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300555 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700556 case spv::OpTypeArray:
557 if (strip_array_level) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300558 return get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700559 }
560 else {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300561 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700562 }
563 case spv::OpTypeMatrix:
564 /* num locations is the dimension * element size */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300565 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700566 default:
567 /* everything else is just 1. */
568 return 1;
569
570 /* TODO: extend to handle 64bit scalar types, whose vectors may need
571 * multiple locations. */
572 }
573}
574
575
576struct interface_var {
577 uint32_t id;
578 uint32_t type_id;
579 uint32_t offset;
580 /* TODO: collect the name, too? Isn't required to be present. */
581};
582
Chris Forbesa3e85f62016-01-15 14:53:11 +1300583
584static void
585collect_interface_block_members(layer_data *my_data, VkDevice dev,
586 shader_module const *src,
587 std::map<uint32_t, interface_var> &out,
588 std::map<uint32_t, interface_var> &builtins_out,
589 std::unordered_map<unsigned, unsigned> const &blocks,
590 bool is_array_of_verts,
591 uint32_t id,
592 uint32_t type_id)
593{
594 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
595 std::unordered_map<unsigned, unsigned>::const_iterator type_def_it;
596 while (true) {
597
598 type_def_it = src->type_def_index.find(type_id);
599 if (type_def_it == src->type_def_index.end()) {
600 return; /* this is actually broken SPIR-V */
601 }
602
603 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
604 unsigned opcode = code[0] & 0x0ffffu;
605
606 if (opcode == spv::OpTypePointer) {
607 type_id = code[3];
608 }
609 else if (opcode == spv::OpTypeArray && is_array_of_verts) {
610 type_id = code[2];
611 is_array_of_verts = false;
612 }
613 else if (opcode == spv::OpTypeStruct) {
614 if (blocks.find(type_id) == blocks.end()) {
615 /* This isn't an interface block. */
616 return;
617 }
618 else {
619 /* We have found the correct type. Walk its members. */
620 break;
621 }
622 }
623 else {
624 /* not an interface block */
625 return;
626 }
627 }
628
629 /* Walk OpMemberDecorate for type_id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300630 for (auto insn : *src) {
631 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type_id) {
632 unsigned member_index = insn.word(2);
633 unsigned member_type_id = src->at(type_def_it->second).word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300634
Chris Forbesc7e2e202016-01-18 08:56:40 +1300635 if (insn.word(3) == spv::DecorationLocation) {
636 unsigned location = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300637 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
638 for (unsigned int offset = 0; offset < num_locations; offset++) {
639 interface_var v;
640 v.id = id;
641 /* TODO: member index in interface_var too? */
642 v.type_id = member_type_id;
643 v.offset = offset;
644 out[location + offset] = v;
645 }
646 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300647 else if (insn.word(3) == spv::DecorationBuiltIn) {
648 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300649 interface_var v;
650 v.id = id;
651 v.type_id = member_type_id;
652 v.offset = 0;
653 builtins_out[builtin] = v;
654 }
655 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300656 }
657}
658
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700659static void
660collect_interface_by_location(layer_data *my_data, VkDevice dev,
661 shader_module const *src, spv::StorageClass sinterface,
662 std::map<uint32_t, interface_var> &out,
663 std::map<uint32_t, interface_var> &builtins_out,
664 bool is_array_of_verts)
665{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700666 std::unordered_map<unsigned, unsigned> var_locations;
667 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300668 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700669
Chris Forbesc7e2e202016-01-18 08:56:40 +1300670 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700671
672 /* We consider two interface models: SSO rendezvous-by-location, and
673 * builtins. Complain about anything that fits neither model.
674 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300675 if (insn.opcode() == spv::OpDecorate) {
676 if (insn.word(2) == spv::DecorationLocation) {
677 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700678 }
679
Chris Forbesc7e2e202016-01-18 08:56:40 +1300680 if (insn.word(2) == spv::DecorationBuiltIn) {
681 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700682 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300683
Chris Forbesc7e2e202016-01-18 08:56:40 +1300684 if (insn.word(2) == spv::DecorationBlock) {
685 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300686 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700687 }
688
689 /* TODO: handle grouped decorations */
690 /* TODO: handle index=1 dual source outputs from FS -- two vars will
691 * have the same location, and we DONT want to clobber. */
692
Chris Forbesc7e2e202016-01-18 08:56:40 +1300693 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
694 unsigned id = insn.word(2);
695 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700696
Chris Forbesc7e2e202016-01-18 08:56:40 +1300697 int location = value_or_default(var_locations, id, -1);
698 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700699
Chris Forbesf5020cf2016-01-13 09:29:31 +1300700 /* All variables and interface block members in the Input or Output storage classes
701 * must be decorated with either a builtin or an explicit location.
702 *
703 * TODO: integrate the interface block support here. For now, don't complain --
704 * a valid SPIRV module will only hit this path for the interface block case, as the
705 * individual members of the type are decorated, rather than variable declarations.
706 */
707
708 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700709 /* A user-defined interface variable, with a location. Where a variable
710 * occupied multiple locations, emit one result for each. */
711 unsigned num_locations = get_locations_consumed_by_type(src, type,
712 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700713 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700714 interface_var v;
715 v.id = id;
716 v.type_id = type;
717 v.offset = offset;
718 out[location + offset] = v;
719 }
720 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300721 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700722 /* A builtin interface variable */
723 /* Note that since builtin interface variables do not consume numbered
724 * locations, there is no larger-than-vec4 consideration as above
725 */
726 interface_var v;
727 v.id = id;
728 v.type_id = type;
729 v.offset = 0;
730 builtins_out[builtin] = v;
731 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300732 else {
733 /* An interface block instance */
734 collect_interface_block_members(my_data, dev, src, out, builtins_out,
735 blocks, is_array_of_verts, id, type);
736 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700737 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700738 }
739}
740
741static void
742collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
743 shader_module const *src, spv::StorageClass sinterface,
744 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
745{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700746
747 std::unordered_map<unsigned, unsigned> var_sets;
748 std::unordered_map<unsigned, unsigned> var_bindings;
749
Chris Forbesc7e2e202016-01-18 08:56:40 +1300750 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700751 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
752 * DecorationDescriptorSet and DecorationBinding.
753 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300754 if (insn.opcode() == spv::OpDecorate) {
755 if (insn.word(2) == spv::DecorationDescriptorSet) {
756 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700757 }
758
Chris Forbesc7e2e202016-01-18 08:56:40 +1300759 if (insn.word(2) == spv::DecorationBinding) {
760 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700761 }
762 }
763
Chris Forbesc7e2e202016-01-18 08:56:40 +1300764 else if (insn.opcode() == spv::OpVariable &&
765 (insn.word(3) == spv::StorageClassUniform ||
766 insn.word(3) == spv::StorageClassUniformConstant)) {
767 unsigned set = value_or_default(var_sets, insn.word(2), 0);
768 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700769
770 auto existing_it = out.find(std::make_pair(set, binding));
771 if (existing_it != out.end()) {
772 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700773 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 -0700774 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
775 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
Chris Forbesc7e2e202016-01-18 08:56:40 +1300776 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700777 existing_it->first.first, existing_it->first.second);
778 }
779
780 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300781 v.id = insn.word(2);
782 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700783 out[std::make_pair(set, binding)] = v;
784 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700785 }
786}
787
788static bool
789validate_interface_between_stages(layer_data *my_data, VkDevice dev,
790 shader_module const *producer, char const *producer_name,
791 shader_module const *consumer, char const *consumer_name,
792 bool consumer_arrayed_input)
793{
794 std::map<uint32_t, interface_var> outputs;
795 std::map<uint32_t, interface_var> inputs;
796
797 std::map<uint32_t, interface_var> builtin_outputs;
798 std::map<uint32_t, interface_var> builtin_inputs;
799
800 bool pass = true;
801
802 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
803 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
804 consumer_arrayed_input);
805
806 auto a_it = outputs.begin();
807 auto b_it = inputs.begin();
808
809 /* maps sorted by key (location); walk them together to find mismatches */
810 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
811 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
812 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
813 auto a_first = a_at_end ? 0 : a_it->first;
814 auto b_first = b_at_end ? 0 : b_it->first;
815
816 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700817 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 -0700818 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
819 pass = false;
820 }
821 a_it++;
822 }
823 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700824 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 -0700825 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
826 pass = false;
827 }
828 b_it++;
829 }
830 else {
831 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
832 /* OK! */
833 }
834 else {
835 char producer_type[1024];
836 char consumer_type[1024];
837 describe_type(producer_type, producer, a_it->second.type_id);
838 describe_type(consumer_type, consumer, b_it->second.type_id);
839
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700840 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 -0700841 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
842 pass = false;
843 }
844 }
845 a_it++;
846 b_it++;
847 }
848 }
849
850 return pass;
851}
852
853enum FORMAT_TYPE {
854 FORMAT_TYPE_UNDEFINED,
855 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
856 FORMAT_TYPE_SINT,
857 FORMAT_TYPE_UINT,
858};
859
860static unsigned
861get_format_type(VkFormat fmt) {
862 switch (fmt) {
863 case VK_FORMAT_UNDEFINED:
864 return FORMAT_TYPE_UNDEFINED;
865 case VK_FORMAT_R8_SINT:
866 case VK_FORMAT_R8G8_SINT:
867 case VK_FORMAT_R8G8B8_SINT:
868 case VK_FORMAT_R8G8B8A8_SINT:
869 case VK_FORMAT_R16_SINT:
870 case VK_FORMAT_R16G16_SINT:
871 case VK_FORMAT_R16G16B16_SINT:
872 case VK_FORMAT_R16G16B16A16_SINT:
873 case VK_FORMAT_R32_SINT:
874 case VK_FORMAT_R32G32_SINT:
875 case VK_FORMAT_R32G32B32_SINT:
876 case VK_FORMAT_R32G32B32A32_SINT:
877 case VK_FORMAT_B8G8R8_SINT:
878 case VK_FORMAT_B8G8R8A8_SINT:
879 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
880 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
881 return FORMAT_TYPE_SINT;
882 case VK_FORMAT_R8_UINT:
883 case VK_FORMAT_R8G8_UINT:
884 case VK_FORMAT_R8G8B8_UINT:
885 case VK_FORMAT_R8G8B8A8_UINT:
886 case VK_FORMAT_R16_UINT:
887 case VK_FORMAT_R16G16_UINT:
888 case VK_FORMAT_R16G16B16_UINT:
889 case VK_FORMAT_R16G16B16A16_UINT:
890 case VK_FORMAT_R32_UINT:
891 case VK_FORMAT_R32G32_UINT:
892 case VK_FORMAT_R32G32B32_UINT:
893 case VK_FORMAT_R32G32B32A32_UINT:
894 case VK_FORMAT_B8G8R8_UINT:
895 case VK_FORMAT_B8G8R8A8_UINT:
896 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
897 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
898 return FORMAT_TYPE_UINT;
899 default:
900 return FORMAT_TYPE_FLOAT;
901 }
902}
903
904/* characterizes a SPIR-V type appearing in an interface to a FF stage,
905 * for comparison to a VkFormat's characterization above. */
906static unsigned
907get_fundamental_type(shader_module const *src, unsigned type)
908{
909 auto type_def_it = src->type_def_index.find(type);
910
911 if (type_def_it == src->type_def_index.end()) {
912 return FORMAT_TYPE_UNDEFINED;
913 }
914
915 unsigned int const *code = (unsigned int const *)&src->words[type_def_it->second];
916 unsigned opcode = code[0] & 0x0ffffu;
917 switch (opcode) {
918 case spv::OpTypeInt:
919 return code[3] ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
920 case spv::OpTypeFloat:
921 return FORMAT_TYPE_FLOAT;
922 case spv::OpTypeVector:
923 return get_fundamental_type(src, code[2]);
924 case spv::OpTypeMatrix:
925 return get_fundamental_type(src, code[2]);
926 case spv::OpTypeArray:
927 return get_fundamental_type(src, code[2]);
928 case spv::OpTypePointer:
929 return get_fundamental_type(src, code[3]);
930 default:
931 return FORMAT_TYPE_UNDEFINED;
932 }
933}
934
935static bool
936validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
937{
938 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
939 * each binding should be specified only once.
940 */
941 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
942 bool pass = true;
943
944 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
945 auto desc = &vi->pVertexBindingDescriptions[i];
946 auto & binding = bindings[desc->binding];
947 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700948 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 -0700949 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
950 pass = false;
951 }
952 }
953 else {
954 binding = desc;
955 }
956 }
957
958 return pass;
959}
960
961static bool
962validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
963{
964 std::map<uint32_t, interface_var> inputs;
965 /* we collect builtin inputs, but they will never appear in the VI state --
966 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
967 */
968 std::map<uint32_t, interface_var> builtin_inputs;
969 bool pass = true;
970
971 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
972
973 /* Build index by location */
974 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
975 if (vi) {
976 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
977 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
978 }
979
980 auto it_a = attribs.begin();
981 auto it_b = inputs.begin();
982
983 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
984 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
985 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
986 auto a_first = a_at_end ? 0 : it_a->first;
987 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +1300988 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700989 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 -0700990 "Vertex attribute at location %d not consumed by VS", a_first)) {
991 pass = false;
992 }
993 it_a++;
994 }
Chris Forbes7d83cd52016-01-15 11:32:03 +1300995 else if (!b_at_end && (a_at_end || b_first < a_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700996 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 -0700997 "VS consumes input at location %d but not provided", b_first)) {
998 pass = false;
999 }
1000 it_b++;
1001 }
1002 else {
1003 unsigned attrib_type = get_format_type(it_a->second->format);
1004 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
1005
1006 /* type checking */
1007 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
1008 char vs_type[1024];
1009 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001010 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 -07001011 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
1012 string_VkFormat(it_a->second->format), a_first, vs_type)) {
1013 pass = false;
1014 }
1015 }
1016
1017 /* OK! */
1018 it_a++;
1019 it_b++;
1020 }
1021 }
1022
1023 return pass;
1024}
1025
1026static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001027validate_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 -07001028{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001029 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001030 std::map<uint32_t, interface_var> outputs;
1031 std::map<uint32_t, interface_var> builtin_outputs;
1032 bool pass = true;
1033
1034 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1035
1036 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
1037
1038 auto it = outputs.begin();
1039 uint32_t attachment = 0;
1040
1041 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1042 * are currently dense, but the parallel with matching between shader stages is nice.
1043 */
1044
1045 /* TODO: Figure out compile error with cb->attachmentCount */
1046 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1047 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001048 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 -07001049 "FS writes to output location %d with no matching attachment", it->first)) {
1050 pass = false;
1051 }
1052 it++;
1053 }
1054 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001055 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 -07001056 "Attachment %d not written by FS", attachment)) {
1057 pass = false;
1058 }
1059 attachment++;
1060 }
1061 else {
1062 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1063 unsigned att_type = get_format_type(color_formats[attachment]);
1064
1065 /* type checking */
1066 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
1067 char fs_type[1024];
1068 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001069 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 -07001070 "Attachment %d of type `%s` does not match FS output type of `%s`",
1071 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
1072 pass = false;
1073 }
1074 }
1075
1076 /* OK! */
1077 it++;
1078 attachment++;
1079 }
1080 }
1081
1082 return pass;
1083}
1084
1085
1086struct shader_stage_attributes {
1087 char const * const name;
1088 bool arrayed_input;
1089};
1090
1091
1092static shader_stage_attributes
1093shader_stage_attribs[] = {
1094 { "vertex shader", false },
1095 { "tessellation control shader", true },
1096 { "tessellation evaluation shader", false },
1097 { "geometry shader", true },
1098 { "fragment shader", false },
1099};
1100
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001101// For given pipelineLayout verify that the setLayout at slot.first
1102// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001103static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001104has_descriptor_binding(layer_data* my_data,
1105 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001106 std::pair<unsigned, unsigned> slot)
1107{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001108 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001109 return false;
1110
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001111 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001112 return false;
1113
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001114 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001115
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001116 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001117}
1118
1119static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1120{
1121 uint32_t bit_pos = u_ffs(stage);
1122 return bit_pos-1;
1123}
1124
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001125// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001126
1127static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1128
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001129// 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 -06001130// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1131// to that same cmd buffer by separate thread are not changing state from underneath us
1132// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001133
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001134// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001135static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001136
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001137static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001138{
1139 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1140 if (pCB->drawCount[i])
1141 return VK_TRUE;
1142 }
1143 return VK_FALSE;
1144}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001145
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001146// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001147static 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 -06001148{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001149 // If non-zero enable mask is present, check it against status but if enable_mask
1150 // is 0 then no enable required so we should always just check status
1151 if ((!enable_mask) || (enable_mask & pNode->status)) {
1152 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001153 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001154 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 +08001155 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001156 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001157 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001158 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001159}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001160
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001161// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001162static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001163{
1164 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001165 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001166 loader_platform_thread_unlock_mutex(&globalLock);
1167 return NULL;
1168 }
1169 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001170 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001171}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001172
Tobin Ehlisd332f282015-10-02 11:00:56 -06001173// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1174static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1175{
1176 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1177 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1178 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1179 return VK_TRUE;
1180 }
1181 }
1182 return VK_FALSE;
1183}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001184
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001185// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001186static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001187 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001188 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");
1189 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");
1190 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");
1191 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");
1192 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");
1193 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");
1194 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");
1195 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");
1196 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 -06001197 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001198 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 -06001199 return result;
1200}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001201
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001202// Verify attachment reference compatibility according to spec
1203// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1204// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1205// to make sure that format and samples counts match.
1206// If not, they are not compatible.
1207static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1208 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1209{
1210 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1211 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1212 return false;
1213 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1214 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1215 return false;
1216 } else { // format and sample count must match
1217 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1218 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1219 return true;
1220 }
1221 // Format and sample counts didn't match
1222 return false;
1223}
1224
1225// For give primary and secondary RenderPass objects, verify that they're compatible
1226static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1227{
1228 stringstream errorStr;
1229 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1230 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1231 errorMsg = errorStr.str();
1232 return false;
1233 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1234 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1235 errorMsg = errorStr.str();
1236 return false;
1237 }
1238 // Trivial pass case is exact same RP
1239 if (primaryRP == secondaryRP)
1240 return true;
1241 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1242 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1243 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1244 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1245 errorMsg = errorStr.str();
1246 return false;
1247 }
1248 uint32_t spIndex = 0;
1249 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1250 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1251 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1252 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1253 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1254 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1255 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1256 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1257 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1258 errorMsg = errorStr.str();
1259 return false;
1260 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1261 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1262 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1263 errorMsg = errorStr.str();
1264 return false;
1265 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1266 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1267 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1268 errorMsg = errorStr.str();
1269 return false;
1270 }
1271 }
1272 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1273 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1274 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1275 for (uint32_t i = 0; i < inputMax; ++i) {
1276 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1277 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1278 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1279 errorMsg = errorStr.str();
1280 return false;
1281 }
1282 }
1283 }
1284 return true;
1285}
1286
Tobin Ehlis559c6382015-11-05 09:52:49 -07001287// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1288static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1289{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001290 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001291 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001292 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1293 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001294 return false;
1295 }
1296 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1297 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001298 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;
1299 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001300 return false;
1301 }
1302 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001303 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001304 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1305 return true;
1306 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001307 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001308 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001309 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1310 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001311 return false; // trivial fail case
1312 }
1313 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001314 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001315 // Need to verify that layouts are identically defined
1316 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1317 // do we also need to check immutable samplers?
1318 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001319 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]) << "'";
1320 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001321 return false;
1322 }
1323 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001324 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1325 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001326 return false;
1327 }
1328 }
1329 return true;
1330}
1331
Tobin Ehlis88452832015-12-03 09:40:56 -07001332// Validate that the shaders used by the given pipeline
1333// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001334static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001335validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001336{
Tobin Ehlis88452832015-12-03 09:40:56 -07001337 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001338 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1339 * before trying to do anything more: */
1340 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1341 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1342 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1343
1344 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1345 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001346 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001347 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001348 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001349
1350 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1351 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1352 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1353
1354 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1355 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001356 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 -07001357 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001358 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001359 }
1360 }
1361 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001362 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001363 shaders[get_shader_stage_id(pStage->stage)] = module;
1364
1365 /* validate descriptor set layout against what the spirv module actually uses */
1366 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1367 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1368 descriptor_uses);
1369
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001370 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1371 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001372
1373 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001374 // As a side-effect of this function, capture which sets are used by the pipeline
1375 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001376
1377 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001378 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001379
1380 if (!found) {
1381 char type_name[1024];
1382 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001383 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 -07001384 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1385 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1386 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001387 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001388 }
1389 }
1390 }
1391 }
1392 }
1393 }
1394
1395 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001396 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001397
1398 vi = pCreateInfo->pVertexInputState;
1399
1400 if (vi) {
1401 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1402 }
1403
1404 if (shaders[vertex_stage]) {
1405 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1406 }
1407
1408 /* TODO: enforce rules about present combinations of shaders */
1409 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1410 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1411
1412 while (!shaders[producer] && producer != fragment_stage) {
1413 producer++;
1414 consumer++;
1415 }
1416
1417 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1418 assert(shaders[producer]);
1419 if (shaders[consumer]) {
1420 pass = validate_interface_between_stages(my_data, dev,
1421 shaders[producer], shader_stage_attribs[producer].name,
1422 shaders[consumer], shader_stage_attribs[consumer].name,
1423 shader_stage_attribs[consumer].arrayed_input) && pass;
1424
1425 producer = consumer;
1426 }
1427 }
1428
1429 if (shaders[fragment_stage] && rp) {
1430 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1431 }
1432
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001433 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001434
1435 return pass;
1436}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001437
Tobin Ehlisf6585052015-12-17 11:48:42 -07001438// Return Set node ptr for specified set or else NULL
1439static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1440{
1441 loader_platform_thread_lock_mutex(&globalLock);
1442 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1443 loader_platform_thread_unlock_mutex(&globalLock);
1444 return NULL;
1445 }
1446 loader_platform_thread_unlock_mutex(&globalLock);
1447 return my_data->setMap[set];
1448}
1449
1450// For the given set, verify that for each dynamic descriptor in that set that its
1451// dynamic offset combined with the offet and range from its descriptor update
1452// do not overflow the size of its buffer being updated
1453static VkBool32 validate_dynamic_offsets(layer_data* my_data, const SET_NODE* pSet)
1454{
1455 VkBool32 result = VK_FALSE;
1456 if (pSet->dynamicOffsets.empty())
1457 return result;
1458
1459 VkWriteDescriptorSet* pWDS = NULL;
1460 uint32_t dynOffsetIndex = 0;
1461 VkDeviceSize bufferSize = 0;
1462 for (uint32_t i=0; i < pSet->descriptorCount; ++i) {
1463 switch (pSet->ppDescriptors[i]->sType) {
1464 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1465 pWDS = (VkWriteDescriptorSet*)pSet->ppDescriptors[i];
1466 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1467 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1468 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001469 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001470 if ((pSet->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001471 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 -07001472 "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 ".",
1473 (uint64_t)pSet->set, i, pSet->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1474 }
1475 dynOffsetIndex++;
1476 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)
1477 }
1478 }
1479 break;
1480 default: // Currently only shadowing Write update nodes so shouldn't get here
1481 assert(0);
1482 continue;
1483 }
1484 }
1485 return result;
1486}
1487
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001488// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001489static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001490 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001491 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001492 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001493 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001494 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1495 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1496 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001497 if (pPipe) {
1498 if (pCB->lastBoundPipelineLayout) {
1499 string errorString;
1500 for (auto setIndex : pPipe->active_sets) {
1501 // If valid set is not bound throw an error
1502 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001503 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 -07001504 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1505 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1506 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1507 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001508 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 -07001509 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1510 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001511 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
1512 // Pull the set node
Tobin Ehlisf6585052015-12-17 11:48:42 -07001513 SET_NODE* pSet = getSetNode(my_data, pCB->boundDescriptorSets[setIndex]);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001514 // Make sure set has been updated
1515 if (!pSet->pUpdateStructs) {
1516 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",
1517 "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);
1518 }
1519 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
Tobin Ehlisf6585052015-12-17 11:48:42 -07001520 result |= validate_dynamic_offsets(my_data, pSet);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001521 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001522 }
1523 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001524
Mark Lobodzinski74635932015-12-18 15:35:38 -07001525 // Verify Vtx binding
1526 if (pPipe->vtxBindingCount > 0) {
1527 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1528 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001529 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001530 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 -07001531 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1532 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001533
Mark Lobodzinski74635932015-12-18 15:35:38 -07001534 }
1535 }
1536 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001537 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001538 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 -07001539 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1540 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001541 }
1542 }
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07001543
Mark Lobodzinski74635932015-12-18 15:35:38 -07001544 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1545 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1546 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1547 if (dynViewport) {
1548 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001549 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 -07001550 "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);
1551 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001552 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001553 if (dynScissor) {
1554 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001555 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 -07001556 "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);
1557 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001558 }
1559 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001560 return result;
1561}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001562
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001563// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001564static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001565{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001566 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001567
Tobin Ehlis88452832015-12-03 09:40:56 -07001568 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001569 skipCall = VK_TRUE;
1570 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001571 // VS is required
1572 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001573 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 -06001574 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001575 }
1576 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001577 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1578 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001579 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001580 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001581 }
1582 // Compute shaders should be specified independent of Gfx shaders
1583 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001584 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1585 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001586 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001587 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 -06001588 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001589 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001590 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001591 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001592 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001593 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001594 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 +08001595 "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 -06001596 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001597 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001598 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001599 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 +08001600 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001601 }
1602 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001603 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001604 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001605 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1606 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001607 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001608 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001609 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001610 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001611 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlisd332f282015-10-02 11:00:56 -06001612 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1613 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001614 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Tobin Ehlise68360f2015-10-01 11:15:13 -06001615 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001616 } else {
1617 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1618 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1619 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1620 if (!dynViewport) {
1621 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001622 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 -07001623 "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 -06001624 }
1625 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001626 if (!dynScissor) {
1627 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001628 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_VIEWPORT_SCISSOR_MISMATCH, "DS",
Courtney Goeltzenleuchterb19042e2015-11-25 11:38:54 -07001629 "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 -06001630 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001631 }
1632 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001633 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001634}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001635
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001636// Init the pipeline mapping info based on pipeline create info LL tree
1637// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001638// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001639static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001640{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001641 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001642
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001643 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001644 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001645 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001646
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001647 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001648 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001649
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001650 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001651 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001652 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001653
1654 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1655 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1656
Chia-I Wu28e06912015-10-31 00:31:16 +08001657 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001658 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001659 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1660 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001661 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001662 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001663 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001664 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001665 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001666 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001667 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001668 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001669 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001670 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001671 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1672 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001673 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001674 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001675 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1676 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001677 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001678 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001679 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1680 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001681 break;
1682 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001683 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001684 break;
1685 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001686 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001687 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1688 if (pCreateInfo->stageCount != 0) {
1689 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1690 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1691 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1692 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001693 if (pCreateInfo->pVertexInputState != NULL) {
1694 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1695 // Copy embedded ptrs
1696 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001697 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001698 if (pPipeline->vtxBindingCount) {
1699 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1700 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1701 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1702 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001703 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001704 if (pPipeline->vtxAttributeCount) {
1705 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1706 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1707 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1708 }
1709 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1710 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001711 if (pCreateInfo->pInputAssemblyState != NULL) {
1712 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1713 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001714 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001715 if (pCreateInfo->pTessellationState != NULL) {
1716 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1717 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001718 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001719 if (pCreateInfo->pViewportState != NULL) {
1720 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1721 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001722 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001723 if (pCreateInfo->pRasterizationState != NULL) {
1724 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1725 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001726 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001727 if (pCreateInfo->pMultisampleState != NULL) {
1728 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1729 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001730 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001731 if (pCreateInfo->pDepthStencilState != NULL) {
1732 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1733 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1734 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001735 if (pCreateInfo->pColorBlendState != NULL) {
1736 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001737 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001738 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001739 pPipeline->attachmentCount = pCBCI->attachmentCount;
1740 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001741 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1742 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001743 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1744 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001745 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001746 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001747 if (pCreateInfo->pDynamicState != NULL) {
1748 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1749 if (pPipeline->dynStateCI.dynamicStateCount) {
1750 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1751 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1752 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1753 }
1754 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001755 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001756 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001757 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001758}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001759
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001760// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001761static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001762{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001763 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001764 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001765 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001766 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1767 delete[] (*ii).second->graphicsPipelineCI.pStages;
1768 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001769 if ((*ii).second->pVertexBindingDescriptions) {
1770 delete[] (*ii).second->pVertexBindingDescriptions;
1771 }
1772 if ((*ii).second->pVertexAttributeDescriptions) {
1773 delete[] (*ii).second->pVertexAttributeDescriptions;
1774 }
1775 if ((*ii).second->pAttachments) {
1776 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001777 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001778 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1779 delete[] (*ii).second->dynStateCI.pDynamicStates;
1780 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001781 delete (*ii).second;
1782 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001783 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001784}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001785
Tobin Ehliseba312c2015-04-01 08:40:34 -06001786// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001787static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001788{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001789 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001790 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001791 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001792 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001793 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001794}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001795
Tobin Ehliseba312c2015-04-01 08:40:34 -06001796// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001797static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001798{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001799 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001800 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001801 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001802 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001803 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001804 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001805 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001806 uint32_t i;
1807
Chia-I Wud50a7d72015-10-26 20:48:51 +08001808 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001809 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001810
Cody Northropa505dda2015-08-04 11:16:41 -06001811 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001812 continue;
1813
Cody Northropa505dda2015-08-04 11:16:41 -06001814 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001815 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001816 subpassNumSamples = samples;
1817 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001818 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001819 break;
1820 }
1821 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001822 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001823 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1824 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001825 subpassNumSamples = samples;
1826 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001827 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001828 }
1829
1830 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001831 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 -06001832 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001833 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001834 }
1835 } else {
1836 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1837 // Verify and flag error as appropriate
1838 }
1839 // TODO : Add more checks here
1840 } else {
1841 // TODO : Validate non-gfx pipeline updates
1842 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001843 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001844}
1845
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001846// Block of code at start here specifically for managing/tracking DSs
1847
Tobin Ehlis793ad302015-04-03 12:01:11 -06001848// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001849static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001850{
1851 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001852 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001853 loader_platform_thread_unlock_mutex(&globalLock);
1854 return NULL;
1855 }
1856 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001857 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001858}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001859
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001860static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001861 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001862 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001863 loader_platform_thread_unlock_mutex(&globalLock);
1864 return NULL;
1865 }
1866 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001867 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001868}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001869
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001870// 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 -06001871static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001872{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001873 switch (pUpdateStruct->sType)
1874 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001875 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1876 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001877 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001878 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001879 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 -06001880 "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 -06001881 }
1882}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001883
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001884// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001885// 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 -06001886static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001887{
1888 switch (pUpdateStruct->sType)
1889 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001890 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001891 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001892 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001893 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001894 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001895 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001896
1897 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001898}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001899
Tobin Ehlis793ad302015-04-03 12:01:11 -06001900// For given Layout Node and binding, return index where that binding begins
1901static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1902{
1903 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001904 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001905 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001906 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001907 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001908 }
1909 return offsetIndex;
1910}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001911
Tobin Ehlis793ad302015-04-03 12:01:11 -06001912// For given layout node and binding, return last index that is updated
1913static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1914{
1915 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001916 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001917 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1918 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001919 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001920 }
1921 return offsetIndex-1;
1922}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001923
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001924// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001925static 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 -06001926{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001927 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001928}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001929
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001930// For given layout and update, return the last overall index of the layout that is updated
1931static 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 -06001932{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001933 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001934 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001935}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001936
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001937// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001938static 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 -06001939{
1940 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001941 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001942 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001943 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001944 switch (pUpdateStruct->sType)
1945 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001946 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1947 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001948 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001949 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1950 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001951 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001952 break;
1953 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001954 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001955 "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 -06001956 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001957 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001958 // Set first stageFlags as reference and verify that all other updates match it
1959 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001960 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001961 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001962 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 -06001963 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1964 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1965 }
1966 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001967 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 -06001968 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1969 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001970 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001971 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001972 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001973 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001974}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001975
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001976// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001977// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001978// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001979static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001980{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001981 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001982 VkWriteDescriptorSet* pWDS = NULL;
1983 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001984 size_t array_size = 0;
1985 size_t base_array_size = 0;
1986 size_t total_array_size = 0;
1987 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001988 switch (pUpdate->sType)
1989 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001990 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1991 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001992 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001993 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06001994
1995 switch (pWDS->descriptorType) {
1996 case VK_DESCRIPTOR_TYPE_SAMPLER:
1997 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1998 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1999 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2000 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002001 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
2002 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002003 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002004 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002005 break;
2006 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2007 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2008 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002009 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
2010 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002011 pWDS->pTexelBufferView = info;
2012 }
2013 break;
2014 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2015 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2016 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2017 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2018 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002019 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
2020 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002021 pWDS->pBufferInfo = info;
2022 }
2023 break;
2024 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07002025 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002026 break;
2027 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002028 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002029 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2030 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002031 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002032 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002033 break;
2034 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002035 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 -06002036 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2037 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002038 }
2039 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002040 (*pNewNode)->pNext = NULL;
2041 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002042}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002043
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002044// Verify that given sampler is valid
2045static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2046{
2047 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002048 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002049 if (sampIt == my_data->sampleMap.end()) {
2050 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002051 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 +08002052 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002053 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002054 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 +08002055 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002056 }
2057 } else {
2058 // TODO : Any further checks we want to do on the sampler?
2059 }
2060 return skipCall;
2061}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002062
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002063// Verify that given imageView is valid
2064static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2065{
2066 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002067 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002068 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002069 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 +08002070 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002071 } else {
2072 // Validate that imageLayout is compatible with aspectMask and image format
2073 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002074 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002075 // TODO : Check here in case we have a bad image
Chia-I Wue2fc5522015-10-26 20:04:44 +08002076 auto imgIt = my_data->imageMap.find(image);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002077 if (imgIt == my_data->imageMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002078 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 -07002079 "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 -06002080 } else {
2081 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002082 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002083 switch (imageLayout) {
2084 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2085 // Only Color bit must be set
2086 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002087 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 -06002088 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 +08002089 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002090 }
2091 // format must NOT be DS
2092 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002093 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 -06002094 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 +08002095 " 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 -06002096 }
2097 break;
2098 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2099 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2100 // Depth or stencil bit must be set, but both must NOT be set
2101 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2102 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2103 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002104 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002105 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002106 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002107 }
2108 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2109 // Neither were set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002110 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002111 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002112 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002113 }
2114 // format must be DS
2115 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002116 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 -06002117 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002118 " 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 -06002119 }
2120 break;
2121 default:
2122 // anything to check for other layouts?
2123 break;
2124 }
2125 }
2126 }
2127 return skipCall;
2128}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002129
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002130// Verify that given bufferView is valid
2131static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2132{
2133 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002134 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002135 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002136 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 +08002137 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002138 } else {
2139 // TODO : Any further checks we want to do on the bufferView?
2140 }
2141 return skipCall;
2142}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002143
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002144// Verify that given bufferInfo is valid
2145static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2146{
2147 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002148 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002149 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002150 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 +08002151 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002152 } else {
2153 // TODO : Any further checks we want to do on the bufferView?
2154 }
2155 return skipCall;
2156}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002157
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002158static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2159{
2160 VkBool32 skipCall = VK_FALSE;
2161 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2162 VkBufferView* pBufferView = NULL;
2163 const VkSampler* pSampler = NULL;
2164 VkImageView* pImageView = NULL;
2165 VkImageLayout* pImageLayout = NULL;
2166 VkDescriptorBufferInfo* pBufferInfo = NULL;
2167 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002168 uint32_t i = 0;
2169 // For given update type, verify that update contents are correct
2170 switch (pWDS->descriptorType) {
2171 case VK_DESCRIPTOR_TYPE_SAMPLER:
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 |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002174 }
2175 break;
2176 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002177 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002178 if (NULL == pLayoutBinding->pImmutableSamplers) {
2179 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002180 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002181 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 -06002182 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2183 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002184 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002185 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002186 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002187 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002188 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 -06002189 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2190 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2191 "use immutable or non-immutable samplers.", i);
2192 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002193 immutable = VK_TRUE;
2194 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2195 }
2196 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002197 }
2198 // Intentionally fall through here to also validate image stuff
2199 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2200 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2201 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002202 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002203 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002204 }
2205 break;
2206 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2207 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002208 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002209 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002210 }
2211 break;
2212 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2213 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2214 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2215 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002216 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002217 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002218 }
2219 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002220 }
2221 return skipCall;
2222}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002223
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002224// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002225static 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 -06002226{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002227 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002228
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002229 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002230 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002231 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002232 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002233 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002234 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002235 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002236 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002237 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002238 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002239 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002240 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002241 break;
2242 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002243 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002244 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002245 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002246 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002247 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 -08002248 "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 -06002249 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002250 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002251 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002252 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002253 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002254 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002255 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 -06002256 "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 -06002257 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002258 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002259 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002260 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2261 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2262 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002263 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002264 // Update is good. Save the update info
2265 // Create new update struct for this set's shadow copy
2266 GENERIC_HEADER* pNewNode = NULL;
2267 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2268 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002269 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 -06002270 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2271 } else {
2272 // Insert shadow node into LL of updates for this set
2273 pNewNode->pNext = pSet->pUpdateStructs;
2274 pSet->pUpdateStructs = pNewNode;
2275 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002276 for (uint32_t j = startIndex; j <= endIndex; j++) {
2277 assert(j<pSet->descriptorCount);
2278 pSet->ppDescriptors[j] = pNewNode;
2279 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002280 }
2281 }
2282 }
2283 }
2284 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002285 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002286 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002287 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002288 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2289 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2290 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2291 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002292 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002293 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002294 pSrcLayout = pSrcSet->pLayout;
2295 pDstLayout = pDstSet->pLayout;
2296 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002297 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002298 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 -06002299 "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 +08002300 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002301 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002302 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 +08002303 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2304 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002305 } else {
2306 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2307 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 +08002308 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002309 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2310 pLayoutCI = &pSrcLayout->createInfo;
2311 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002312 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 -06002313 "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 +08002314 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002315 pLayoutCI = &pDstLayout->createInfo;
2316 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002317 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDstSet->set, __LINE__, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002318 "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 -06002319 } else {
2320 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 +08002321 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 +08002322 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002323 // For copy just make sure that the types match and then perform the update
2324 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002325 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 -06002326 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2327 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2328 } else {
2329 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002330 // TODO : This may be a hole. I believe copy should be its own copy,
2331 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002332 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2333 }
2334 }
2335 }
2336 }
2337 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002338 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002339 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002340}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002341
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002342// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002343static 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 -06002344{
2345 VkBool32 skipCall = VK_FALSE;
2346 uint32_t i = 0, j = 0;
2347 for (i=0; i<count; ++i) {
2348 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2349 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002350 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 +08002351 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002352 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002353 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002354 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002355 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2356 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002357 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002358 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 -06002359 "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 -07002360 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002361 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002362 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002363 }
2364 }
2365 }
2366 }
2367 return skipCall;
2368}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002369
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002370// Free the shadowed update node for this Set
2371// NOTE : Calls to this function should be wrapped in mutex
2372static void freeShadowUpdateTree(SET_NODE* pSet)
2373{
2374 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2375 pSet->pUpdateStructs = NULL;
2376 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2377 // Clear the descriptor mappings as they will now be invalid
2378 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2379 while(pShadowUpdate) {
2380 pFreeUpdate = pShadowUpdate;
2381 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2382 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002383 VkWriteDescriptorSet * pWDS = NULL;
2384 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002385 void** ppToFree = NULL;
2386 switch (pFreeUpdate->sType)
2387 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002388 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2389 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002390 switch (pWDS->descriptorType) {
2391 case VK_DESCRIPTOR_TYPE_SAMPLER:
2392 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2393 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2394 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2395 {
2396 delete[] pWDS->pImageInfo;
2397 }
2398 break;
2399 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2400 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2401 {
2402 delete[] pWDS->pTexelBufferView;
2403 }
2404 break;
2405 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2406 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2407 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2408 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2409 {
2410 delete[] pWDS->pBufferInfo;
2411 }
2412 break;
2413 default:
2414 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002415 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002416 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002417 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002418 break;
2419 default:
2420 assert(0);
2421 break;
2422 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002423 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002424 }
2425}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002426
Tobin Ehlis793ad302015-04-03 12:01:11 -06002427// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002428// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002429static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002430{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002431 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002432 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002433 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002434 SET_NODE* pSet = (*ii).second->pSets;
2435 SET_NODE* pFreeSet = pSet;
2436 while (pSet) {
2437 pFreeSet = pSet;
2438 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002439 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002440 // Free Update shadow struct tree
2441 freeShadowUpdateTree(pFreeSet);
2442 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002443 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002444 }
2445 delete pFreeSet;
2446 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002447 delete (*ii).second;
2448 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002449 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002450}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002451
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002452// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002453// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002454static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002455{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002456 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002457 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002458 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002459 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002460 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002461 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002462 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2463 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002464 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002465 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002466 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002467 delete pLayout;
2468 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002469 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002470}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002471
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002472// Currently clearing a set is removing all previous updates to that set
2473// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002474static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002475{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002476 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002477 if (!pSet) {
2478 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002479 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002480 loader_platform_thread_lock_mutex(&globalLock);
2481 freeShadowUpdateTree(pSet);
2482 loader_platform_thread_unlock_mutex(&globalLock);
2483 }
2484}
2485
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002486static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002487{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002488 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002489 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002490 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 +08002491 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002492 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002493 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002494 // For every set off of this pool, clear it
2495 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002496 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002497 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002498 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002499 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002500 // Reset available count to max count for this pool
2501 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2502 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2503 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002504 }
2505}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002506
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002507// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002508static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002509{
2510 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002511 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002512 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002513 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002514 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 +08002515 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002516 return NULL;
2517 }
2518 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002519 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002520}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002521
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002522// Free all CB Nodes
2523// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002524static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002525{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002526 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002527 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002528 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002529 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06002530 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
2531 while (!cmd_node_list.empty()) {
2532 CMD_NODE* cmd_node = cmd_node_list.back();
2533 delete cmd_node;
2534 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002535 }
2536 delete (*ii).second;
2537 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002538 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002539}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002540
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002541static 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 -06002542{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002543 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 -07002544 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002545 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002546}
Michael Lentine3dea6512015-10-28 15:55:18 -07002547
Mark Youngb20a6a82016-01-07 15:41:43 -07002548VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2549 if (!pCB->activeRenderPass) return VK_FALSE;
2550 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002551 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2552 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2553 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2554 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2555 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2556 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2557 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002558 return skip_call;
2559}
2560
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002561// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2562// in the recording state or if there's an issue with the Cmd ordering
2563static 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 -06002564{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002565 VkBool32 skipCall = VK_FALSE;
2566 if (pCB->state != CB_RECORDING) {
2567 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2568 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
2569 CMD_NODE* pCmd = new CMD_NODE;
2570 if (pCmd) {
2571 // init cmd node and append to end of cmd LL
2572 memset(pCmd, 0, sizeof(CMD_NODE));
2573 pCmd->cmdNumber = ++pCB->numCmds;
2574 pCmd->type = cmd;
2575 pCB->pCmds.push_back(pCmd);
2576 } else {
2577 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002578 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002579 "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->commandBuffer));
2580 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002581 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002582 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002583}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002584
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002585static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002586{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002587 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002588 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002589 vector<CMD_NODE*> cmd_list = pCB->pCmds;
2590 while (!cmd_list.empty()) {
2591 delete cmd_list.back();
2592 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002593 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06002594 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002595 // Reset CB state (need to save createInfo)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002596 VkCommandBufferAllocateInfo saveCBCI = pCB->createInfo;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002597 pCB->commandBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002598 pCB->createInfo = saveCBCI;
Michael Lentineabc5e922015-10-12 11:30:14 -05002599 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
2600 pCB->fence = 0;
2601 pCB->numCmds = 0;
2602 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2603 pCB->state = CB_NEW;
2604 pCB->submitCount = 0;
2605 pCB->status = 0;
2606 pCB->pCmds.clear();
2607 pCB->lastBoundPipeline = 0;
2608 pCB->viewports.clear();
2609 pCB->scissors.clear();
2610 pCB->lineWidth = 0;
2611 pCB->depthBiasConstantFactor = 0;
2612 pCB->depthBiasClamp = 0;
2613 pCB->depthBiasSlopeFactor = 0;
2614 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2615 pCB->minDepthBounds = 0;
2616 pCB->maxDepthBounds = 0;
2617 memset(&pCB->front, 0, sizeof(stencil_data));
2618 memset(&pCB->back, 0, sizeof(stencil_data));
2619 pCB->lastBoundDescriptorSet = 0;
2620 pCB->lastBoundPipelineLayout = 0;
2621 pCB->activeRenderPass = 0;
2622 pCB->activeSubpass = 0;
2623 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002624 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002625 pCB->drawData.clear();
2626 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002627 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002628 pCB->waitedEvents.clear();
2629 pCB->waitedEventsBeforeQueryReset.clear();
2630 pCB->queryToStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002631 }
2632}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002633
Tobin Ehlis963a4042015-09-29 08:18:34 -06002634// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002635static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2636{
2637 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002638 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002639 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2640 }
2641 }
2642 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002643 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2644 }
Cody Northrop82485a82015-08-18 15:21:16 -06002645 if (pPipe->dsStateCI.stencilTestEnable) {
2646 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002647 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002648 // Account for any dynamic state not set via this PSO
2649 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2650 pCB->status = CBSTATUS_ALL;
2651 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002652 // First consider all state on
2653 // Then unset any state that's noted as dynamic in PSO
2654 // Finally OR that into CB statemask
2655 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002656 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2657 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2658 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002659 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002660 break;
2661 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002662 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002663 break;
2664 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002665 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002666 break;
2667 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002668 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002669 break;
2670 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002671 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002672 break;
2673 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002674 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002675 break;
2676 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002677 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002678 break;
2679 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002680 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002681 break;
2682 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002683 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002684 break;
2685 default:
2686 // TODO : Flag error here
2687 break;
2688 }
2689 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002690 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002691 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002692}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002693
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002694// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002695static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002696{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002697 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002698 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002699 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002700 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002701 if (!pPipeTrav) {
2702 // nothing to print
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",
Michael Lentine010f4692015-11-03 16:19:46 -08002705 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002706 }
2707 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002708 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002709}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002710
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002711// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002712static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002713{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002714 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002715 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 -06002716 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002717 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002718 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002719 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002720 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002721 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 +08002722 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002723 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002724 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 -06002725 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002726 // Print out set details
2727 char prefix[10];
2728 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002729 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 +08002730 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002731 LAYOUT_NODE* pLayout = pSet->pLayout;
2732 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002733 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 -08002734 "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 -06002735 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002736 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002737 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 -06002738 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002739 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002740 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2741 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002742 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 +08002743 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002744 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002745 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 -08002746 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002747 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002748 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002749 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002750 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 +08002751 "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 -06002752 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002753 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 +08002754 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002755 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002756 }
2757 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002758 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002759}
2760
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002761static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002762{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002763 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
David Pinedod8f83d82015-04-27 16:36:17 -06002764 if (pCB && pCB->pCmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002765 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 -06002766 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06002767 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002768 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
2769 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002770 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002771 " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002772 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002773 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002774 // Nothing to print
2775 }
2776}
2777
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002778static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002779{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002780 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002781 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002782 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002783 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002784 skipCall |= printDSConfig(my_data, cb);
2785 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002786 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002787}
2788
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002789// Flags validation error if the associated call is made inside a render pass. The apiName
2790// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002791static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002792{
2793 VkBool32 inside = VK_FALSE;
2794 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002795 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 -07002796 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002797 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002798 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002799 }
2800 return inside;
2801}
2802
2803// Flags validation error if the associated call is made outside a render pass. The apiName
2804// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002805static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002806{
2807 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002808 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2809 (!pCB->activeRenderPass)) ||
2810 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2811 (!pCB->activeRenderPass) &&
2812 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002813 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 -07002814 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002815 "%s: This call must be issued inside an active render pass.", apiName);
2816 }
2817 return outside;
2818}
2819
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002820static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002821{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002822 uint32_t report_flags = 0;
2823 uint32_t debug_action = 0;
2824 FILE *log_output = NULL;
2825 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002826 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002827 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002828 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2829 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002830
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002831 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002832 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002833 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002834 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002835 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002836 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002837 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002838 dbgInfo.pfnCallback = log_callback;
2839 dbgInfo.pUserData = log_output;
2840 dbgInfo.flags = report_flags;
2841 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002842 my_data->logging_callback.push_back(callback);
2843 }
2844
2845 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002846 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002847 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002848 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002849 dbgInfo.pfnCallback = win32_debug_output_msg;
2850 dbgInfo.pUserData = log_output;
2851 dbgInfo.flags = report_flags;
2852 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002853 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002854 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002855
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002856 if (!globalLockInitialized)
2857 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002858 loader_platform_thread_create_mutex(&globalLock);
2859 globalLockInitialized = 1;
2860 }
2861}
2862
Chia-I Wu9ab61502015-11-06 06:42:02 +08002863VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002864{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002865 // TODOSC : Shouldn't need any customization here
Tobin Ehlis0b632332015-10-07 09:38:40 -06002866 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2867 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002868 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002869
2870 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002871 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2872 my_data->report_data = debug_report_create_instance(
2873 pTable,
2874 *pInstance,
Jon Ashburnf19916e2016-01-11 13:12:43 -07002875 pCreateInfo->enabledExtensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002876 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06002877
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002878 init_draw_state(my_data, pAllocator);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002879 }
2880 return result;
2881}
2882
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002883/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002884VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002885{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002886 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002887 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002888 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2889 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002890 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002891
2892 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002893 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002894 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002895 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002896 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002897 }
2898
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002899 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002900 delete my_data->instance_dispatch_table;
2901 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002902 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002903 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002904 // Release mutex when destroying last instance.
2905 loader_platform_thread_delete_mutex(&globalLock);
2906 globalLockInitialized = 0;
2907 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002908}
2909
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002910static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2911{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002912 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002913 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2914 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002915 dev_data->device_extensions.wsi_enabled = false;
2916
2917
2918 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2919 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2920
Michael Lentineabc5e922015-10-12 11:30:14 -05002921 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2922 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2923 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2924 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002925 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002926
Jon Ashburnf19916e2016-01-11 13:12:43 -07002927 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002928 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002929 dev_data->device_extensions.wsi_enabled = true;
2930 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002931 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002932 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002933 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002934 initDebugMarkerTable(device);
2935
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002936 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002937 }
2938}
2939
Chia-I Wu9ab61502015-11-06 06:42:02 +08002940VK_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 -06002941{
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002942 layer_data *instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
2943 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
2944 VkResult result = dev_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
2945
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002946 if (result == VK_SUCCESS) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002947 dev_data->report_data = layer_debug_report_create_device(instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06002948 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07002949 // Get physical device limits for this device
2950 instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002951 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002952 return result;
2953}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002954
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002955// prototype
2956static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08002957VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002958{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002959 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06002960 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002961 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002962 // Free all the memory
2963 loader_platform_thread_lock_mutex(&globalLock);
2964 deletePipelines(dev_data);
2965 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002966 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002967 deletePools(dev_data);
2968 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002969 dev_data->imageViewMap.clear();
2970 dev_data->imageMap.clear();
2971 dev_data->bufferViewMap.clear();
2972 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002973 loader_platform_thread_unlock_mutex(&globalLock);
2974
Chia-I Wuf7458c52015-10-26 21:10:41 +08002975 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002976 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002977 delete dev_data->device_dispatch_table;
2978 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002979}
2980
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002981static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002982 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002983 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
2984 VK_EXT_DEBUG_REPORT_REVISION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002985 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002986};
2987
Chia-I Wu9ab61502015-11-06 06:42:02 +08002988VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002989 const char *pLayerName,
2990 uint32_t *pCount,
2991 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002992{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002993 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002994}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06002995
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002996static const VkLayerProperties ds_global_layers[] = {
2997 {
Michael Lentine03107b42015-12-11 10:49:51 -08002998 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07002999 VK_API_VERSION,
3000 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003001 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003002 }
3003};
3004
Chia-I Wu9ab61502015-11-06 06:42:02 +08003005VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003006 uint32_t *pCount,
3007 VkLayerProperties* pProperties)
3008{
3009 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
3010 ds_global_layers,
3011 pCount, pProperties);
3012}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003013
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003014static const VkExtensionProperties ds_device_extensions[] = {
3015 {
3016 DEBUG_MARKER_EXTENSION_NAME,
3017 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003018 }
3019};
3020
3021static const VkLayerProperties ds_device_layers[] = {
3022 {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003023 "draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003024 VK_API_VERSION,
3025 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003026 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003027 }
3028};
3029
Chia-I Wu9ab61502015-11-06 06:42:02 +08003030VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003031 VkPhysicalDevice physicalDevice,
3032 const char* pLayerName,
3033 uint32_t* pCount,
3034 VkExtensionProperties* pProperties)
3035{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003036 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003037 if (pLayerName == NULL) {
3038 dispatch_key key = get_dispatch_key(physicalDevice);
3039 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003040 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003041 physicalDevice,
3042 NULL,
3043 pCount,
3044 pProperties);
3045 } else {
3046 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3047 ds_device_extensions,
3048 pCount, pProperties);
3049 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003050}
3051
Chia-I Wu9ab61502015-11-06 06:42:02 +08003052VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003053 VkPhysicalDevice physicalDevice,
3054 uint32_t* pCount,
3055 VkLayerProperties* pProperties)
3056{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003057 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003058 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3059 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003060}
3061
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003062VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003063 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003064 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3065 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3066 for (auto cb_image_data : pCB->imageLayoutMap) {
3067 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3068 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003069 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 -08003070 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", reinterpret_cast<uint64_t>(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003071 } else {
3072 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003073 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 -05003074 "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);
3075 }
3076 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3077 }
3078 }
3079 return skip_call;
3080}
3081
Mark Young7a69c302016-01-07 09:48:47 -07003082VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003083 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003084 for (auto drawDataElement : pCB->drawData) {
3085 for (auto buffer : drawDataElement.buffers) {
3086 auto buffer_data = my_data->bufferMap.find(buffer);
3087 if (buffer_data == my_data->bufferMap.end()) {
3088 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",
3089 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", reinterpret_cast<uint64_t>(buffer));
3090 } else {
3091 buffer_data->second.in_use.fetch_add(1);
3092 }
3093 }
3094 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003095 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003096}
3097
3098void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3099 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3100 for (auto drawDataElement : pCB->drawData) {
3101 for (auto buffer : drawDataElement.buffers) {
3102 auto buffer_data = my_data->bufferMap.find(buffer);
3103 if (buffer_data != my_data->bufferMap.end()) {
3104 buffer_data->second.in_use.fetch_sub(1);
3105 }
3106 }
3107 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003108 for (auto queryStatePair : pCB->queryToStateMap) {
3109 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3110 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003111}
3112
3113void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3114 for (uint32_t i = 0; i < fenceCount; ++i) {
3115 auto fence_data = my_data->fenceMap.find(pFences[i]);
3116 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3117 fence_data->second.needsSignaled = false;
3118 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3119 decrementResources(my_data, 1, &fence_data->second.priorFence);
3120 }
3121 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3122 decrementResources(my_data, cmdBuffer);
3123 }
3124 }
3125}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003126
Michael Lentine700b0aa2015-10-30 17:57:32 -07003127void decrementResources(layer_data* my_data, VkQueue queue) {
3128 auto queue_data = my_data->queueMap.find(queue);
3129 if (queue_data != my_data->queueMap.end()) {
3130 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3131 decrementResources(my_data, cmdBuffer);
3132 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003133 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003134 decrementResources(my_data, 1, &queue_data->second.priorFence);
3135 }
3136}
3137
3138void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3139 auto queue_data = my_data->queueMap.find(queue);
3140 if (fence != VK_NULL_HANDLE) {
3141 VkFence priorFence = VK_NULL_HANDLE;
3142 if (queue_data != my_data->queueMap.end()) {
3143 priorFence = queue_data->second.priorFence;
3144 queue_data->second.priorFence = fence;
3145 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3146 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3147 }
3148 queue_data->second.untrackedCmdBuffers.clear();
3149 }
3150 my_data->fenceMap[fence].cmdBuffers.clear();
3151 my_data->fenceMap[fence].priorFence = priorFence;
3152 my_data->fenceMap[fence].needsSignaled = true;
3153 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3154 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3155 }
3156 } else {
3157 if (queue_data != my_data->queueMap.end()) {
3158 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3159 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3160 }
3161 }
3162 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003163 if (queue_data != my_data->queueMap.end()) {
3164 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
3165 my_data->inFlightCmdBuffers.insert(pCmdBuffers[i]);
3166 }
3167 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003168}
3169
Chia-I Wu9ab61502015-11-06 06:42:02 +08003170VK_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 -06003171{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003172 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003173 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003174 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Tobin Ehlis651d9b02015-12-16 05:01:22 -07003175 // TODO : Any pCommandBuffers must have USAGE_SIMULTANEOUS_USE_BIT set or cannot already be executing on device
3176 // Same goes for any secondary CBs under the primary CB
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003177 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003178 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003179 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3180 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3181 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3182 } else {
3183 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",
3184 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
3185 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(submit->pWaitSemaphores[i]));
3186 }
3187 }
3188 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3189 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3190 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003191 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003192
3193#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3194 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3195#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3196
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003197 // Validate that cmd buffers have been updated
3198 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3199 loader_platform_thread_lock_mutex(&globalLock);
3200 pCB->submitCount++; // increment submit count
Michael Lentine700b0aa2015-10-30 17:57:32 -07003201 skipCall |= validateAndIncrementResources(dev_data, pCB);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003202 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003203 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 -05003204 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3205 reinterpret_cast<uint64_t>(pCB->commandBuffer), pCB->submitCount);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003206 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003207 if (CB_RECORDED != pCB->state) {
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003208 // Flag error for using CB w/o vkEndCommandBuffer() called
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003209 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 +08003210 "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 -06003211 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003212 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003213 }
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003214 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003215 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003216 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003217 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003218 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003219 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003220 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003221}
3222
Mark Youngb20a6a82016-01-07 15:41:43 -07003223VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3224 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003225 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3226 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3227 for (auto event : queryEventsPair.second) {
3228 if (my_data->eventMap[event].needsSignaled) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003229 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",
3230 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
Michael Lentineb887b0a2015-12-29 14:12:11 -06003231 reinterpret_cast<uint64_t>(queryEventsPair.first.pool), queryEventsPair.first.index, reinterpret_cast<uint64_t>(event));
3232 }
3233 }
3234 }
3235 return skip_call;
3236}
3237
Michael Lentine700b0aa2015-10-30 17:57:32 -07003238VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3239{
3240 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3241 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003242 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003243 if ((waitAll || fenceCount == 1) && result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003244 for (uint32_t i = 0; i < fenceCount; ++i) {
3245 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3246 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3247 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3248 }
3249 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003250 decrementResources(dev_data, fenceCount, pFences);
3251 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003252 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003253 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003254 return result;
3255}
3256
3257
3258VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3259{
3260 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3261 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
3262 if (result == VK_SUCCESS) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003263 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
3264 dev_data->inFlightCmdBuffers.erase(cmdBuffer);
3265 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3266 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003267 decrementResources(dev_data, 1, &fence);
3268 }
3269 return result;
3270}
3271
3272VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3273{
3274 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3275 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
3276 dev_data->deviceMap[device].queues.push_back(*pQueue);
3277 dev_data->queueMap[*pQueue].device = device;
3278}
3279
3280VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3281{
3282 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3283 decrementResources(dev_data, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003284 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3285 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3286 }
3287 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003288 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3289}
3290
3291VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3292{
3293 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3294 auto device_data = dev_data->deviceMap.find(device);
3295 if (device_data != dev_data->deviceMap.end()) {
3296 for (auto queue : device_data->second.queues) {
3297 decrementResources(dev_data, queue);
3298 }
3299 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003300 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3301 cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3302 }
3303 dev_data->inFlightCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003304 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3305}
3306
Chia-I Wu9ab61502015-11-06 06:42:02 +08003307VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003308{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003309 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 -06003310 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003311}
3312
Chia-I Wu9ab61502015-11-06 06:42:02 +08003313VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003314{
Michael Lentine15a47882016-01-06 10:05:48 -06003315 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3316 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3317 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003318 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003319}
3320
Chia-I Wu9ab61502015-11-06 06:42:02 +08003321VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003322{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003323 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 -06003324 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003325}
3326
Chia-I Wu9ab61502015-11-06 06:42:02 +08003327VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003328{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003329 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 -06003330 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003331}
3332
Mark Lobodzinskice738852016-01-07 10:04:02 -07003333VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003334 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3335 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3336 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3337 GLOBAL_CB_NODE* pCB = nullptr;
3338 for (auto cmdBuffer : dev_data->inFlightCmdBuffers) {
3339 pCB = getCBNode(dev_data, cmdBuffer);
3340 for (auto queryStatePair : pCB->queryToStateMap) {
3341 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3342 }
3343 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003344 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003345 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003346 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003347 auto queryElement = queriesInFlight.find(query);
3348 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3349 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3350 }
3351 // Available and in flight
3352 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3353 for (auto cmdBuffer : queryElement->second) {
3354 pCB = getCBNode(dev_data, cmdBuffer);
3355 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3356 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003357 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3358 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
3359 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003360 } else {
3361 for (auto event : queryEventElement->second) {
3362 dev_data->eventMap[event].needsSignaled = true;
3363 }
3364 }
3365 }
3366 // Unavailable and in flight
3367 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3368 // TODO : Can there be the same query in use by multiple command buffers in flight?
3369 bool make_available = false;
3370 for (auto cmdBuffer : queryElement->second) {
3371 pCB = getCBNode(dev_data, cmdBuffer);
3372 make_available |= pCB->queryToStateMap[query];
3373 }
3374 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003375 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 -06003376 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003377 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003378 }
3379 // Unavailable
3380 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003381 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 -06003382 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003383 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003384 // Unitialized
3385 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003386 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 -06003387 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Lobodzinskice738852016-01-07 10:04:02 -07003388 reinterpret_cast<uint64_t>(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003389 }
3390 }
3391 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003392 return VK_ERROR_VALIDATION_FAILED_EXT;
3393 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003394}
3395
Mark Young7a69c302016-01-07 09:48:47 -07003396VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003397 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003398 auto buffer_data = my_data->bufferMap.find(buffer);
3399 if (buffer_data == my_data->bufferMap.end()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003400 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 -07003401 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", reinterpret_cast<uint64_t>(buffer));
3402 } else {
3403 if (buffer_data->second.in_use.load()) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003404 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 -07003405 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", reinterpret_cast<uint64_t>(buffer));
3406
3407 }
3408 }
3409 return skip_call;
3410}
3411
Chia-I Wu9ab61502015-11-06 06:42:02 +08003412VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, 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);
Mark Youngb20a6a82016-01-07 15:41:43 -07003415 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003416 if (!validateIdleBuffer(dev_data, buffer)) {
3417 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3418 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003419 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003420}
3421
Chia-I Wu9ab61502015-11-06 06:42:02 +08003422VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003423{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003424 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003425 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003426 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003427}
3428
Chia-I Wu9ab61502015-11-06 06:42:02 +08003429VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003430{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003431 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003432 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003433 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003434}
3435
Chia-I Wu9ab61502015-11-06 06:42:02 +08003436VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003437{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003438 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 -06003439 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003440}
3441
Chia-I Wu9ab61502015-11-06 06:42:02 +08003442VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003443{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003444 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 -06003445 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003446}
3447
Chia-I Wu9ab61502015-11-06 06:42:02 +08003448VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003449{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003450 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 -06003451 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003452}
3453
Chia-I Wu9ab61502015-11-06 06:42:02 +08003454VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003455{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003456 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 -06003457 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003458}
3459
Chia-I Wu9ab61502015-11-06 06:42:02 +08003460VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003461{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003462 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 -06003463 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003464}
3465
Chia-I Wu9ab61502015-11-06 06:42:02 +08003466VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003467{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003468 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 -06003469 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003470}
3471
Chia-I Wu9ab61502015-11-06 06:42:02 +08003472VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003473{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003474 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 -06003475 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003476}
3477
Chia-I Wu9ab61502015-11-06 06:42:02 +08003478VK_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 -06003479{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003480 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3481
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003482 for (uint32_t i = 0; i < count; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003483 // Delete CB information structure, and remove from commandBufferMap
3484 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003485 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003486 if (cb != dev_data->commandBufferMap.end()) {
3487 delete (*cb).second;
3488 dev_data->commandBufferMap.erase(cb);
3489 }
3490
3491 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003492 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003493 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003494 }
3495
3496 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3497}
3498
3499VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3500{
3501 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3502
3503 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3504
3505 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003506 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003507 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003508 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003509 }
3510 return result;
3511}
3512
3513VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3514{
3515 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003516 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003517
3518 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3519 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003520 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003521 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3522 delete (*del_cb).second; // delete CB info structure
3523 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003524 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003525 }
3526 }
3527 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003528
3529 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003530 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003531}
3532
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003533VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3534 VkDevice device,
3535 VkCommandPool commandPool,
3536 VkCommandPoolResetFlags flags)
3537{
3538 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003539 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003540
3541 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3542 // Reset all of the CBs allocated from this pool
3543 if (VK_SUCCESS == result) {
3544 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3545 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3546 resetCB(dev_data, (*it));
3547 ++it;
3548 }
3549 }
3550 return result;
3551}
3552
Chia-I Wu9ab61502015-11-06 06:42:02 +08003553VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003554{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003555 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 -06003556 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003557}
3558
Chia-I Wu9ab61502015-11-06 06:42:02 +08003559VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003560{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003561 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 -06003562 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003563}
3564
Chia-I Wu9ab61502015-11-06 06:42:02 +08003565VK_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 -06003566{
3567 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003568 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003569 if (VK_SUCCESS == result) {
3570 loader_platform_thread_lock_mutex(&globalLock);
3571 // 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 -07003572 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3573 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003574 loader_platform_thread_unlock_mutex(&globalLock);
3575 }
3576 return result;
3577}
3578
Chia-I Wu9ab61502015-11-06 06:42:02 +08003579VK_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 -06003580{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003581 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003582 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003583 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003584 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003585 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003586 loader_platform_thread_unlock_mutex(&globalLock);
3587 }
3588 return result;
3589}
3590
Chia-I Wu9ab61502015-11-06 06:42:02 +08003591VK_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 -06003592{
3593 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003594 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003595 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003596 IMAGE_NODE* image_node = new IMAGE_NODE;
3597 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003598 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003599 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003600 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003601 loader_platform_thread_unlock_mutex(&globalLock);
3602 }
3603 return result;
3604}
3605
Chia-I Wu9ab61502015-11-06 06:42:02 +08003606VK_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 -06003607{
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->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003610 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003611 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003612 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003613 loader_platform_thread_unlock_mutex(&globalLock);
3614 }
3615 return result;
3616}
3617
Jon Ashburnc669cc62015-07-09 15:02:25 -06003618//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003619VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003620 VkDevice device,
3621 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003622 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003623 VkPipelineCache* pPipelineCache)
3624{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003625 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003626 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003627 return result;
3628}
3629
Chia-I Wu9ab61502015-11-06 06:42:02 +08003630VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003631 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003632 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003633 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003634{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003635 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003636 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003637}
3638
Chia-I Wu9ab61502015-11-06 06:42:02 +08003639VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003640 VkDevice device,
3641 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003642 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003643 void* pData)
3644{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003645 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003646 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003647 return result;
3648}
3649
Chia-I Wu9ab61502015-11-06 06:42:02 +08003650VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003651 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003652 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003653 uint32_t srcCacheCount,
3654 const VkPipelineCache* pSrcCaches)
3655{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003656 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003657 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003658 return result;
3659}
3660
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003661VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3662 VkDevice device,
3663 VkPipelineCache pipelineCache,
3664 uint32_t count,
3665 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3666 const VkAllocationCallbacks *pAllocator,
3667 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003668{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003669 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003670 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003671 // The order of operations here is a little convoluted but gets the job done
3672 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3673 // 2. Create state is then validated (which uses flags setup during shadowing)
3674 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003675 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003676 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3677 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003678 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003679
Tobin Ehlis11efc302015-09-16 10:33:53 -06003680 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003681 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003682
Tobin Ehlis11efc302015-09-16 10:33:53 -06003683 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003684 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003685 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003686 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003687
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003688 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003689
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003690 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003691 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3692 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003693 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003694 for (i=0; i<count; i++) {
3695 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003696 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003697 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003698 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003699 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003700 for (i=0; i<count; i++) {
3701 if (pPipeNode[i]) {
3702 // If we allocated a pipeNode, need to clean it up here
3703 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3704 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3705 delete[] pPipeNode[i]->pAttachments;
3706 delete pPipeNode[i];
3707 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003708 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003709 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003710 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003711 return result;
3712}
3713
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003714VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3715 VkDevice device,
3716 VkPipelineCache pipelineCache,
3717 uint32_t count,
3718 const VkComputePipelineCreateInfo *pCreateInfos,
3719 const VkAllocationCallbacks *pAllocator,
3720 VkPipeline *pPipelines)
3721{
3722 VkResult result = VK_SUCCESS;
3723 VkBool32 skipCall = VK_FALSE;
3724
3725 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3726 vector<PIPELINE_NODE*> pPipeNode(count);
3727 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3728
3729 uint32_t i=0;
3730 loader_platform_thread_lock_mutex(&globalLock);
3731 for (i=0; i<count; i++) {
3732 // TODO: Verify compute stage bits
3733
3734 // Create and initialize internal tracking data structure
3735 pPipeNode[i] = new PIPELINE_NODE;
3736 memset((void*)pPipeNode[i], 0, sizeof(PIPELINE_NODE));
3737 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3738
3739 // TODO: Add Compute Pipeline Verification
3740 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3741 }
3742 loader_platform_thread_unlock_mutex(&globalLock);
3743
3744 if (VK_FALSE == skipCall) {
3745 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3746 loader_platform_thread_lock_mutex(&globalLock);
3747 for (i=0; i<count; i++) {
3748 pPipeNode[i]->pipeline = pPipelines[i];
3749 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3750 }
3751 loader_platform_thread_unlock_mutex(&globalLock);
3752 } else {
3753 for (i=0; i<count; i++) {
3754 if (pPipeNode[i]) {
3755 // Clean up any locally allocated data structures
3756 delete pPipeNode[i];
3757 }
3758 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003759 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003760 }
3761 return result;
3762}
3763
Chia-I Wu9ab61502015-11-06 06:42:02 +08003764VK_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 -06003765{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003766 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003767 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003768 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003769 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003770 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003771 loader_platform_thread_unlock_mutex(&globalLock);
3772 }
3773 return result;
3774}
3775
Chia-I Wu9ab61502015-11-06 06:42:02 +08003776VK_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 -06003777{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003778 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003779 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003780 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003781 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003782 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3783 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003784 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 -06003785 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003786 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003787 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003788 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003789 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
3790 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003791 // g++ does not like reserve with size 0
3792 if (pCreateInfo->bindingCount)
3793 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003794 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003795 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003796 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003797 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 +08003798 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003799 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08003800 }
3801
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003802 totalCount += pCreateInfo->pBindings[i].descriptorCount;
3803 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
3804 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
3805 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
3806 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06003807 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003808 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003809 pNewNode->layout = *pSetLayout;
3810 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003811 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06003812 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003813 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003814 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06003815 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003816 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003817 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003818 dType = pCreateInfo->pBindings[i].descriptorType;
3819 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003820 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003821 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07003822 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3823 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3824 pNewNode->dynamicDescriptorCount++;
3825 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003826 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003827 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003828 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07003829 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
3830 } else { // no descriptors
3831 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003832 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003833 // Put new node at Head of global Layer list
3834 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003835 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003836 loader_platform_thread_unlock_mutex(&globalLock);
3837 }
3838 return result;
3839}
3840
Chia-I Wu9ab61502015-11-06 06:42:02 +08003841VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003842{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003843 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003844 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003845 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003846 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07003847 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08003848 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003849 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003850 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06003851 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
3852 }
Cody Northrop43751cc2015-10-26 14:07:35 -06003853 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06003854 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
3855 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
3856 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003857 }
3858 return result;
3859}
3860
Chia-I Wu9ab61502015-11-06 06:42:02 +08003861VK_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 -06003862{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003863 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003864 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003865 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003866 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003867 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 +08003868 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003869 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003870 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003871 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003872 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003873 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 -07003874 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003875 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003876 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003877 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003878 }
3879 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003880 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06003881 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003882 }
3883 return result;
3884}
3885
Chia-I Wu9ab61502015-11-06 06:42:02 +08003886VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003887{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003888 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003889 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003890 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003891 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003892 }
3893 return result;
3894}
3895
Chia-I Wu9ab61502015-11-06 06:42:02 +08003896VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003897{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003898 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003899 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003900 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003901 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003902 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003903 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 +08003904 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003905 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07003906 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003907 }
3908 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003909 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003910 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06003911 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003912 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003913 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07003914 if (pAllocateInfo->descriptorSetCount == 0) {
3915 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 +08003916 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06003917 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07003918 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003919 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 +08003920 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06003921 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003922 SET_NODE* pNewNode = new SET_NODE;
3923 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003924 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t) pDescriptorSets[i], __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003925 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003926 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003927 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003928 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06003929 // TODO : Pool should store a total count of each type of Descriptor available
3930 // When descriptors are allocated, decrement the count and validate here
3931 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06003932 // Insert set at head of Set LL for this pool
3933 pNewNode->pNext = pPoolNode->pSets;
3934 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003935 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003936 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003937 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 +08003938 "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 -07003939 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003940 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06003941 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003942 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003943 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003944 pNewNode->descriptorCount = pLayout->endIndex + 1;
3945 if (pNewNode->descriptorCount) {
3946 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
3947 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
3948 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
3949 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003950 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003951 }
3952 }
3953 }
3954 }
3955 return result;
3956}
3957
Chia-I Wu9ab61502015-11-06 06:42:02 +08003958VK_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 -06003959{
Tobin Ehlise735c692015-10-08 13:13:50 -06003960 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003961 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003962 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003963 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
3964 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003965 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 -06003966 "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 -06003967 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003968 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003969 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003970 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003971 if (VK_SUCCESS == result) {
3972 // For each freed descriptor add it back into the pool as available
3973 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08003974 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003975 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003976 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003977 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07003978 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
3979 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003980 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003981 }
3982 }
3983 }
3984 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06003985 return result;
3986}
3987
Chia-I Wu9ab61502015-11-06 06:42:02 +08003988VK_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 -06003989{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06003990 // 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 -06003991 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003992 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
3993 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003994 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003995}
3996
Chia-I Wu9ab61502015-11-06 06:42:02 +08003997VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003998{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003999 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004000 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004001 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004002 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004003 // Validate command pool
4004 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004005 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004006 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004007 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004008 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
4009 // Add command buffer to map
4010 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004011 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004012 resetCB(dev_data, pCommandBuffer[i]);
4013 pCB->commandBuffer = pCommandBuffer[i];
4014 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004015 pCB->device = device;
Mark Lobodzinski39298632015-11-18 08:38:27 -07004016 }
4017 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004018 }
4019 return result;
4020}
4021
Chia-I Wu9ab61502015-11-06 06:42:02 +08004022VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004023{
Mark Youngb20a6a82016-01-07 15:41:43 -07004024 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004025 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004026 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004027 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004028 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004029 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4030 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004031 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4032 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4033 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004034 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004035 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004036 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004037 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 -07004038 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4039 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004040 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004041 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 -07004042 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4043 } else {
4044 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004045 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4046 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004047 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004048 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 -07004049 "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 -07004050 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004051 }
4052 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004053 }
4054 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004055 pCB->beginInfo = *pBeginInfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004056 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004057 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 -07004058 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4059 } else if (CB_RECORDED == pCB->state) {
4060 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4061 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004062 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 -07004063 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004064 "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.",
4065 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4066 }
4067 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004068 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004069 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 +08004070 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004071 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004072 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004073 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004074 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004075 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Mark Lobodzinski29b8d5a2015-11-12 16:14:04 -07004076 if ((VK_SUCCESS == result) && (pCB != NULL)) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004077 if (CB_RECORDED == pCB->state) { resetCB(dev_data, commandBuffer); } pCB->state = CB_RECORDING; }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004078 return result;
4079}
4080
Chia-I Wu9ab61502015-11-06 06:42:02 +08004081VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004082{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004083 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004084 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004085 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4086 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004087 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004088 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004089 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004090 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004091 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004092 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004093 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004094 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004095 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004096 // Reset CB status flags
4097 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004098 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004099 }
4100 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004101 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004102 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004103 return result;
4104}
4105
Chia-I Wu9ab61502015-11-06 06:42:02 +08004106VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004107{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004108 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004109 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004110 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4111 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4112 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004113 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 -07004114 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004115 "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.",
4116 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4117 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004118 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004119 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004120 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004121 if (VK_SUCCESS == result) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004122 resetCB(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004123 }
4124 return result;
4125}
4126
Chia-I Wu9ab61502015-11-06 06:42:02 +08004127VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004128{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004129 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004130 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4131 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004132 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004133 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4134 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4135 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 -07004136 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004137 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4138 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4139 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4140 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4141 }
4142
4143 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4144 if (pPN) {
4145 pCB->lastBoundPipeline = pipeline;
4146 loader_platform_thread_lock_mutex(&globalLock);
4147 set_cb_pso_status(pCB, pPN);
4148 loader_platform_thread_unlock_mutex(&globalLock);
4149 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004150 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004151 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 -07004152 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004153 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004154 }
4155 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004156 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004157 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004158}
4159
Chia-I Wu9ab61502015-11-06 06:42:02 +08004160VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004161 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004162 uint32_t firstViewport,
4163 uint32_t viewportCount,
4164 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004165{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004166 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004167 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4168 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004169 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004170 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4171 loader_platform_thread_lock_mutex(&globalLock);
4172 pCB->status |= CBSTATUS_VIEWPORT_SET;
4173 pCB->viewports.resize(viewportCount);
4174 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4175 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004176 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004177 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004178 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004179}
4180
Chia-I Wu9ab61502015-11-06 06:42:02 +08004181VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004182 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004183 uint32_t firstScissor,
4184 uint32_t scissorCount,
4185 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004186{
4187 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004188 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4189 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004190 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004191 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4192 loader_platform_thread_lock_mutex(&globalLock);
4193 pCB->status |= CBSTATUS_SCISSOR_SET;
4194 pCB->scissors.resize(scissorCount);
4195 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4196 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004197 }
4198 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004199 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004200}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004201
Chia-I Wu9ab61502015-11-06 06:42:02 +08004202VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004203{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004204 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004205 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4206 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004207 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004208 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4209 /* TODO: Do we still need this lock? */
4210 loader_platform_thread_lock_mutex(&globalLock);
4211 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4212 pCB->lineWidth = lineWidth;
4213 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004214 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004215 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004216 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004217}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004218
Chia-I Wu9ab61502015-11-06 06:42:02 +08004219VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004220 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004221 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004222 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004223 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004224{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004225 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004226 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4227 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004228 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004229 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4230 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4231 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4232 pCB->depthBiasClamp = depthBiasClamp;
4233 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004234 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004235 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004236 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004237}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004238
Chia-I Wu9ab61502015-11-06 06:42:02 +08004239VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004240{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004241 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004242 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4243 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004244 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004245 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4246 pCB->status |= CBSTATUS_BLEND_SET;
4247 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004248 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004249 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004250 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004251}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004252
Chia-I Wu9ab61502015-11-06 06:42:02 +08004253VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004254 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004255 float minDepthBounds,
4256 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004257{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004258 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004259 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4260 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004261 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004262 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4263 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4264 pCB->minDepthBounds = minDepthBounds;
4265 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004266 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004267 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004268 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004269}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004270
Chia-I Wu9ab61502015-11-06 06:42:02 +08004271VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004272 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004273 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004274 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004275{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004276 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004277 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4278 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004279 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004280 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4281 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4282 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004283 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004284 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4285 pCB->back.compareMask = compareMask;
4286 }
4287 /* TODO: Do we need to track front and back separately? */
4288 /* TODO: We aren't capturing the faceMask, do we need to? */
4289 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004290 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004291 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004292 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004293}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004294
Chia-I Wu9ab61502015-11-06 06:42:02 +08004295VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004296 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004297 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004298 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004299{
4300 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004301 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4302 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004303 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004304 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4305 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4306 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004307 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004308 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4309 pCB->back.writeMask = writeMask;
4310 }
4311 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004312 }
4313 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004314 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004315}
4316
Chia-I Wu9ab61502015-11-06 06:42:02 +08004317VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004318 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004319 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004320 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004321{
4322 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004323 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4324 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004325 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004326 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4327 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4328 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004329 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004330 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4331 pCB->back.reference = reference;
4332 }
4333 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004334 }
4335 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004336 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004337}
4338
Chia-I Wu9ab61502015-11-06 06:42:02 +08004339VK_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 -06004340{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004341 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004342 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4343 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004344 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004345 if (pCB->state == CB_RECORDING) {
4346 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004347 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 -07004348 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4349 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4350 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004351 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004352 if (VK_FALSE == skipCall) {
4353 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4354 uint32_t totalDynamicDescriptors = 0;
4355 string errorString = "";
4356 uint32_t lastSetIndex = firstSet+setCount-1;
4357 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004358 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004359 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4360 for (uint32_t i=0; i<setCount; i++) {
4361 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4362 if (pSet) {
4363 loader_platform_thread_lock_mutex(&globalLock);
4364 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4365 pCB->lastBoundPipelineLayout = layout;
4366 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4367 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004368 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 -07004369 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004370 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004371 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 -07004372 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4373 }
4374 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4375 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004376 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 -07004377 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4378 }
4379 if (pSet->pLayout->dynamicDescriptorCount) {
4380 // First make sure we won't overstep bounds of pDynamicOffsets array
4381 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004382 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 -07004383 "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.",
4384 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004385 } else { // Validate and store dynamic offsets with the set
4386 // Validate Dynamic Offset Minimums
4387 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4388 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4389 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4390 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4391 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4392 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4393 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4394 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4395 }
4396 cur_dyn_offset++;
4397 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4398 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4399 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4400 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4401 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4402 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4403 }
4404 cur_dyn_offset++;
4405 }
4406 }
4407 // Store offsets
Tobin Ehlisf6585052015-12-17 11:48:42 -07004408 const uint32_t* pStartDynOffset = pDynamicOffsets + totalDynamicDescriptors;
4409 pSet->dynamicOffsets.assign(pStartDynOffset, pStartDynOffset + pSet->pLayout->dynamicDescriptorCount);
4410 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4411 }
4412 }
4413 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004414 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 -07004415 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4416 }
4417 }
4418 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4419 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4420 if (firstSet > 0) { // Check set #s below the first bound set
4421 for (uint32_t i=0; i<firstSet; ++i) {
4422 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 -07004423 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 -07004424 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4425 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4426 }
4427 }
4428 }
4429 // Check if newly last bound set invalidates any remaining bound sets
4430 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4431 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004432 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 -07004433 "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);
4434 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4435 }
4436 }
4437 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4438 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004439 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 -07004440 "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 -07004441 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004442 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004443 } else {
4444 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004445 }
4446 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004447 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004448 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004449}
4450
Chia-I Wu9ab61502015-11-06 06:42:02 +08004451VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004452{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004453 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004454 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4455 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004456 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004457 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4458 VkDeviceSize offset_align = 0;
4459 switch (indexType) {
4460 case VK_INDEX_TYPE_UINT16:
4461 offset_align = 2;
4462 break;
4463 case VK_INDEX_TYPE_UINT32:
4464 offset_align = 4;
4465 break;
4466 default:
4467 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4468 break;
4469 }
4470 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004471 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 -07004472 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004473 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004474 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004475 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004476 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004477 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004478}
4479
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004480void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4481 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004482 if (pCB->currentDrawData.buffers.size() < end) {
4483 pCB->currentDrawData.buffers.resize(end);
4484 }
4485 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004486 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004487 }
4488}
4489
4490void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4491 pCB->drawData.push_back(pCB->currentDrawData);
4492}
4493
Chia-I Wu9ab61502015-11-06 06:42:02 +08004494VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004495 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004496 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004497 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004498 const VkBuffer *pBuffers,
4499 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004500{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004501 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004502 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4503 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004504 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004505 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004506 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004507 } else {
Mark Youngad779052016-01-06 14:26:04 -07004508 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004509 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004510 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004511 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004512}
4513
Chia-I Wu9ab61502015-11-06 06:42:02 +08004514VK_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 -06004515{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004516 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004517 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4518 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004519 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004520 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4521 pCB->drawCount[DRAW]++;
4522 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4523 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004524 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 -07004525 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4526 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004527 if (VK_FALSE == skipCall) {
4528 updateResourceTrackingOnDraw(pCB);
4529 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004530 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004531 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004532 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004533 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004534}
4535
Chia-I Wu9ab61502015-11-06 06:42:02 +08004536VK_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 -06004537{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004538 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4539 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004540 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004541 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004542 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4543 pCB->drawCount[DRAW_INDEXED]++;
4544 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4545 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004546 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 -07004547 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4548 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004549 if (VK_FALSE == skipCall) {
4550 updateResourceTrackingOnDraw(pCB);
4551 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004552 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004553 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004554 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004555 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004556}
4557
Chia-I Wu9ab61502015-11-06 06:42:02 +08004558VK_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 -06004559{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004560 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4561 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004562 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004563 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004564 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4565 pCB->drawCount[DRAW_INDIRECT]++;
4566 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4567 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004568 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 -07004569 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4570 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004571 if (VK_FALSE == skipCall) {
4572 updateResourceTrackingOnDraw(pCB);
4573 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004574 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004575 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004576 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004577 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004578}
4579
Chia-I Wu9ab61502015-11-06 06:42:02 +08004580VK_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 -06004581{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004582 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004583 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4584 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004585 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004586 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4587 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4588 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4589 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004590 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 -07004591 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4592 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004593 if (VK_FALSE == skipCall) {
4594 updateResourceTrackingOnDraw(pCB);
4595 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004596 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004597 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004598 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004599 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004600}
4601
Chia-I Wu9ab61502015-11-06 06:42:02 +08004602VK_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 -06004603{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004604 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004605 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4606 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004607 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004608 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004609 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004610 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004611 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004612 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004613}
4614
Chia-I Wu9ab61502015-11-06 06:42:02 +08004615VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004616{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004617 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004618 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4619 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004620 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004621 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004622 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004623 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004624 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004625 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004626}
4627
Chia-I Wu9ab61502015-11-06 06:42:02 +08004628VK_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 -06004629{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004630 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004631 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4632 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004633 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004634 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004635 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004636 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004637 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004638 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004639}
4640
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004641VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004642 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004643
4644#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4645 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4646 return skip_call;
4647#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4648
Michael Lentineabc5e922015-10-12 11:30:14 -05004649 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4650 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4651 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4652 if (src_image_element == pCB->imageLayoutMap.end()) {
4653 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4654 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004655 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004656 }
4657 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004658 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 -05004659 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4660 }
4661 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4662 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004663 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004664 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 -05004665 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004666 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004667 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 -05004668 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004669 }
4670 }
4671 return skip_call;
4672}
4673
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004674VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004675 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004676
4677#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4678 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4679 return skip_call;
4680#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4681
Michael Lentineabc5e922015-10-12 11:30:14 -05004682 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4683 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4684 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4685 if (dest_image_element == pCB->imageLayoutMap.end()) {
4686 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4687 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004688 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004689 }
4690 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004691 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 -05004692 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4693 }
4694 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4695 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004696 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004697 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 -05004698 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4699 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004700 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 -05004701 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4702 }
4703 }
4704 return skip_call;
4705}
4706
Chia-I Wu9ab61502015-11-06 06:42:02 +08004707VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004708 VkImage srcImage,
4709 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004710 VkImage dstImage,
4711 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004712 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004713{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004714 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004715 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4716 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004717 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004718 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004719 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004720 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4721 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004722 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004723 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004724 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004725}
4726
Chia-I Wu9ab61502015-11-06 06:42:02 +08004727VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004728 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004729 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004730 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004731 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004732{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004733 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004734 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4735 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004736 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004737 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004738 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004739 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004740 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004741 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004742}
4743
Chia-I Wu9ab61502015-11-06 06:42:02 +08004744VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004745 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004746 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004747 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004748{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004749 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004750 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4751 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004752 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004753 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004754 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004755 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004756 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004757 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004758 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004759}
4760
Chia-I Wu9ab61502015-11-06 06:42:02 +08004761VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004762 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004763 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004764 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004765{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004766 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004767 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4768 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004769 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004770 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004771 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05004772 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004773 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004774 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004775 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004776}
4777
Chia-I Wu9ab61502015-11-06 06:42:02 +08004778VK_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 -06004779{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004780 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004781 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4782 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004783 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004784 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004785 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004786 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004787 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004788 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004789}
4790
Chia-I Wu9ab61502015-11-06 06:42:02 +08004791VK_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 -06004792{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004793 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004794 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4795 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004796 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004797 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004798 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004799 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004800 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004801 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004802}
4803
Chia-I Wu9ab61502015-11-06 06:42:02 +08004804VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004805 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004806 uint32_t attachmentCount,
4807 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004808 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06004809 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004810{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004811 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004812 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4813 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004814 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004815 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
4816 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
4817 if (!hasDrawCmd(pCB) &&
4818 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
4819 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
4820 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004821 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 -07004822 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
4823 " 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 -06004824 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004825 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
4826 }
4827
4828 // Validate that attachment is in reference list of active subpass
4829 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004830 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004831 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
4832
4833 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
4834 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
4835 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
4836 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004837 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004838 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
4839 found = VK_TRUE;
4840 break;
4841 }
4842 }
4843 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004844 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 -07004845 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004846 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
4847 attachment->colorAttachment, pCB->activeSubpass);
4848 }
4849 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004850 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07004851 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004852
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004853 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 -07004854 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07004855 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
4856 attachment->colorAttachment,
4857 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
4858 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06004859 }
4860 }
4861 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004862 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004863 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004864 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06004865}
4866
Chia-I Wu9ab61502015-11-06 06:42:02 +08004867VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004868 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004869 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12004870 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06004871 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004872{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004873 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004874 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4875 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004876 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004877 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004878 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004879 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004880 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004881 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004882}
4883
Chia-I Wu9ab61502015-11-06 06:42:02 +08004884VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004885 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06004886 VkImage image, VkImageLayout imageLayout,
4887 const VkClearDepthStencilValue *pDepthStencil,
4888 uint32_t rangeCount,
4889 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004890{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004891 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004892 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4893 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004894 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004895 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004896 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004897 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004898 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004899 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004900}
4901
Chia-I Wu9ab61502015-11-06 06:42:02 +08004902VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004903 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004904 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06004905 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004906{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004907 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004908 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4909 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004910 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004911 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004912 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004913 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004914 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004915 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004916}
4917
Chia-I Wu9ab61502015-11-06 06:42:02 +08004918VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004919{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004920 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004921 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4922 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004923 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004924 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004925 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004926 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004927 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004928 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004929}
4930
Chia-I Wu9ab61502015-11-06 06:42:02 +08004931VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004932{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004933 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004934 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4935 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004936 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004937 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004938 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004939 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004940 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004941 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004942}
4943
Jon Ashburnf19916e2016-01-11 13:12:43 -07004944VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05004945 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4946 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07004947 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004948
4949#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4950 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
4951 return skip;
4952#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4953
Michael Lentineabc5e922015-10-12 11:30:14 -05004954 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004955 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05004956 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004957 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05004958 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004959 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
4960 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004961 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004962 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004963 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 -07004964 "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 -05004965 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004966 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05004967 }
4968 }
4969 }
4970 return skip;
4971}
4972
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07004973// Print readable FlagBits in FlagMask
4974std::string string_VkAccessFlags(VkAccessFlags accessMask)
4975{
4976 std::string result;
4977 std::string separator;
4978
4979 if (accessMask == 0) {
4980 result = "[None]";
4981 } else {
4982 result = "[";
4983 for (auto i = 0; i < 32; i++) {
4984 if (accessMask & (1 << i)) {
4985 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
4986 separator = " | ";
4987 }
4988 }
4989 result = result + "]";
4990 }
4991 return result;
4992}
4993
Michael Lentine97eb7462015-11-20 09:48:52 -08004994// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
4995// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07004996// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07004997VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
4998 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004999 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005000
Michael Lentine97eb7462015-11-20 09:48:52 -08005001 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
5002 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005003 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005004 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 -07005005 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5006 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005007 }
5008 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005009 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005010 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 -07005011 "%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 -07005012 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5013 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005014 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005015 std::string opt_bits;
5016 if (optional_bits != 0) {
5017 opt_bits = "and may have optional bits " + std::to_string(optional_bits) + ' ' + string_VkAccessFlags(optional_bits);
5018 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005019 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 -07005020 "%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 -07005021 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5022 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005023 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005024 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005025 }
5026 return skip_call;
5027}
5028
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005029VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005030 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005031 switch (layout) {
5032 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005033 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 -08005034 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005035 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005036 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005037 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 -08005038 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005039 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005040 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005041 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005042 break;
5043 }
5044 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005045 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005046 break;
5047 }
5048 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005049 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 -08005050 break;
5051 }
5052 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005053 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 -08005054 break;
5055 }
5056 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005057 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005058 break;
5059 }
5060 case VK_IMAGE_LAYOUT_UNDEFINED: {
5061 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005062 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005063 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 -07005064 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5065 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005066 }
5067 break;
5068 }
5069 case VK_IMAGE_LAYOUT_GENERAL:
5070 default: {
5071 break;
5072 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005073 }
5074 return skip_call;
5075}
5076
Jon Ashburnf19916e2016-01-11 13:12:43 -07005077VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5078{
Mark Youngb20a6a82016-01-07 15:41:43 -07005079 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005080 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5081 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5082 if (pCB->activeRenderPass && memBarrierCount) {
5083 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005084 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005085 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005086 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 -05005087 "Image or Buffers Barriers cannot be used during a render pass.");
5088 }
5089 }
5090 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005091 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 -05005092 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5093 }
5094 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005095
Jon Ashburnf19916e2016-01-11 13:12:43 -07005096 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5097 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005098 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005099 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5100 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005101 }
5102 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005103
Michael Lentine48930b82015-10-15 17:07:00 -05005104 return skip_call;
5105}
5106
Jon Ashburnf19916e2016-01-11 13:12:43 -07005107VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5108 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5109 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5110 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5111 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5112 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005113{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005114 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005115 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5116 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005117 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005118 for (uint32_t i = 0; i < eventCount; ++i) {
5119 pCB->waitedEvents.push_back(pEvents[i]);
5120 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005121 if (pCB->state == CB_RECORDING) {
5122 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005123 } else {
5124 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5125 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005126 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5127 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005128 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005129 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005130 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5131 memoryBarrierCount, pMemoryBarriers,
5132 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5133 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005134}
5135
Jon Ashburnf19916e2016-01-11 13:12:43 -07005136VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5137 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5138 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5139 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5140 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5141 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005142{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005143 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005144 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5145 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005146 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005147 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005148 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5149 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005150 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005151 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005152 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5153 memoryBarrierCount, pMemoryBarriers,
5154 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5155 imageMemoryBarrierCount, pImageMemoryBarriers);
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 vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
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) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005164 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005165 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005166 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005167 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005168}
5169
Chia-I Wu9ab61502015-11-06 06:42:02 +08005170VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005171{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005172 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005173 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5174 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005175 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005176 QueryObject query = {queryPool, slot};
5177 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005178 if (pCB->state == CB_RECORDING) {
5179 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005180 } else {
5181 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5182 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005183 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005184 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005185 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005186}
5187
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005188VK_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 -06005189{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005190 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005191 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5192 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005193 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005194 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005195 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005196 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5197 pCB->queryToStateMap[query] = 0;
5198 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005199 if (pCB->state == CB_RECORDING) {
5200 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005201 } else {
5202 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5203 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005204 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005205 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005206 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005207 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005208}
5209
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005210VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005211 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005212 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005213{
5214 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005215 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5216 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005217 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005218 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005219 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005220 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005221 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
5222 "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 -06005223 }
5224 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005225 if (pCB->state == CB_RECORDING) {
5226 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005227 } else {
5228 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5229 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005230 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005231 }
5232 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005233 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005234 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005235}
5236
Chia-I Wu9ab61502015-11-06 06:42:02 +08005237VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005238{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005239 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005240 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5241 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005242 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005243 QueryObject query = {queryPool, slot};
5244 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005245 if (pCB->state == CB_RECORDING) {
5246 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005247 } else {
5248 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5249 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005250 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005251 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005252 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005253}
5254
Chia-I Wu9ab61502015-11-06 06:42:02 +08005255VK_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 -06005256{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005257 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005258 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005259 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005260 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005261 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005262 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005263 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5264 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005265 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005266 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005267 }
5268 return result;
5269}
5270
Michael Lentineb6986752015-10-06 14:56:18 -07005271// Store the DAG.
5272struct DAGNode {
5273 uint32_t pass;
5274 std::vector<uint32_t> prev;
5275 std::vector<uint32_t> next;
5276};
5277
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005278VkBool32 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 -07005279 // If we have already checked this node we have not found a dependency path so return false.
5280 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005281 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005282 processed_nodes.insert(index);
5283 const DAGNode& node = subpass_to_node[index];
5284 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5285 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5286 for (auto elem : node.prev) {
5287 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005288 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005289 }
5290 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005291 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005292 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005293 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005294}
5295
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005296VkBool32 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 -07005297 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005298 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5299 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5300 if (subpass == dependent_subpasses[k])
5301 continue;
5302 const DAGNode& node = subpass_to_node[subpass];
5303 // Check for a specified dependency between the two nodes. If one exists we are done.
5304 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5305 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5306 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5307 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5308 std::unordered_set<uint32_t> processed_nodes;
5309 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5310 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005311 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005312 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 -07005313 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5314 subpass, dependent_subpasses[k]);
5315 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005316 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 -07005317 "A dependency between subpasses %d and %d must exist but one is not specified.",
5318 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005319 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005320 }
5321 }
5322 }
5323 return result;
5324}
5325
Jon Ashburnf19916e2016-01-11 13:12:43 -07005326VkBool32 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 -07005327 const DAGNode& node = subpass_to_node[index];
5328 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5329 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005330 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005331 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005332 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005333 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005334 if (subpass.pDepthStencilAttachment &&
5335 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5336 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005337 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005338 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005339 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005340 // Loop through previous nodes and see if any of them write to the attachment.
5341 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005342 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005343 }
5344 // If the attachment was written to by a previous node than this node needs to preserve it.
5345 if (result && depth > 0) {
5346 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005347 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005348 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005349 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005350 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005351 break;
5352 }
5353 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005354 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005355 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 -07005356 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5357 }
5358 }
5359 return result;
5360}
5361
Michael Lentineb4979492015-12-22 11:36:14 -06005362VkBool32 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 -07005363 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005364 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5365 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005366 // Find for each attachment the subpasses that use them.
5367 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5368 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005369 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005370 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5371 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005372 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005373 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5374 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005375 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5376 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005377 }
5378 }
5379 // If there is a dependency needed make sure one exists
5380 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5381 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5382 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005383 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005384 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005385 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005386 }
5387 // 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 +08005388 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005389 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005390 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5391 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005392 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005393 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5394 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005395 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5396 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005397 }
5398 }
5399 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5400 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5401 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005402 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005403 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005404 }
5405 }
5406 return skip_call;
5407}
5408
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005409VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005410 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005411
5412#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5413 return skip;
5414#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5415
Michael Lentineabc5e922015-10-12 11:30:14 -05005416 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5417 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5418 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5419 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5420 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5421 if (subpass.pInputAttachments[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 input attachment is GENERAL but should be READ_ONLY_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 input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5428 }
5429 }
5430 }
5431 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5432 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5433 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005434 // 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 -07005435 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 -05005436 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5437 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005438 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 -05005439 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5440 }
5441 }
5442 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005443 if ((subpass.pDepthStencilAttachment != NULL) &&
5444 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005445 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5446 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005447 // 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 -07005448 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 -05005449 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5450 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005451 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 -05005452 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5453 }
5454 }
5455 }
5456 }
5457 return skip;
5458}
5459
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005460VkBool32 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 -07005461 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005462 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5463 DAGNode& subpass_node = subpass_to_node[i];
5464 subpass_node.pass = i;
5465 }
5466 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5467 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
5468 if (dependency.srcSubpass > dependency.dstSubpass) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005469 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
Michael Lentineabc5e922015-10-12 11:30:14 -05005470 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine48930b82015-10-15 17:07:00 -05005471 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5472 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005473 }
5474 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5475 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5476 }
5477 return skip_call;
5478}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005479// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005480
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005481VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5482 VkDevice device,
5483 const VkShaderModuleCreateInfo *pCreateInfo,
5484 const VkAllocationCallbacks* pAllocator,
5485 VkShaderModule *pShaderModule)
5486{
5487 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005488 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005489 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005490 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 -07005491 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005492 "Shader is not SPIR-V");
5493 }
5494
Mark Youngb20a6a82016-01-07 15:41:43 -07005495 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005496 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005497
5498 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5499
5500 if (res == VK_SUCCESS) {
5501 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005502 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005503 loader_platform_thread_unlock_mutex(&globalLock);
5504 }
5505 return res;
5506}
5507
Chia-I Wu9ab61502015-11-06 06:42:02 +08005508VK_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 -06005509{
Mark Youngb20a6a82016-01-07 15:41:43 -07005510 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005511 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005512 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005513 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005514 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005515 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005516 // Validate using DAG
5517 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5518 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005519 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005520 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005521 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005522 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005523 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005524 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005525 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005526 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005527 if (pCreateInfo->pAttachments) {
5528 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5529 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005530 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005531 if (pCreateInfo->pSubpasses) {
5532 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5533 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5534
5535 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5536 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005537 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5538 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005539 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005540 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5541
Cody Northropa505dda2015-08-04 11:16:41 -06005542 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005543 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005544 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005545 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005546
Cody Northropa505dda2015-08-04 11:16:41 -06005547 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005548 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005549 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005550 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005551
Cody Northropa505dda2015-08-04 11:16:41 -06005552 if (subpass->pResolveAttachments) {
5553 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005554 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005555 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005556 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005557 }
5558
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005559 if (subpass->pDepthStencilAttachment) {
5560 memcpy(attachments, subpass->pDepthStencilAttachment,
5561 sizeof(attachments[0]) * 1);
5562 subpass->pDepthStencilAttachment = attachments;
5563 attachments += 1;
5564 }
5565
Cody Northropa505dda2015-08-04 11:16:41 -06005566 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005567 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005568 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005569 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005570 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005571 if (pCreateInfo->pDependencies) {
5572 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5573 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005574 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005575 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005576 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005577 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005578 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005579 }
5580 return result;
5581}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005582// Free the renderpass shadow
5583static void deleteRenderPasses(layer_data* my_data)
5584{
5585 if (my_data->renderPassMap.size() <= 0)
5586 return;
5587 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005588 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005589 if (pRenderPassInfo->pAttachments) {
5590 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005591 }
Michael Lentine48930b82015-10-15 17:07:00 -05005592 if (pRenderPassInfo->pSubpasses) {
5593 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005594 // Attachements are all allocated in a block, so just need to
5595 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005596 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5597 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5598 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5599 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5600 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5601 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5602 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5603 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005604 }
5605 }
Michael Lentine48930b82015-10-15 17:07:00 -05005606 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005607 }
Michael Lentine48930b82015-10-15 17:07:00 -05005608 if (pRenderPassInfo->pDependencies) {
5609 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005610 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005611 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005612 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005613 }
5614 my_data->renderPassMap.clear();
5615}
Michael Lentineabc5e922015-10-12 11:30:14 -05005616
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005617VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005618 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005619 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5620 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005621 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005622 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5623 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005624 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 -05005625 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5626 }
5627 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5628 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5629 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5630 auto image_data = pCB->imageLayoutMap.find(image);
5631 if (image_data == pCB->imageLayoutMap.end()) {
5632 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5633 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5634 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005635 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 -05005636 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5637 }
5638 }
5639 return skip_call;
5640}
5641
5642void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5643 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5644 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5645 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5646 if (render_pass_data == dev_data->renderPassMap.end()) {
5647 return;
5648 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005649 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005650 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5651 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5652 return;
5653 }
5654 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5655 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5656 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5657 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5658 auto image_view_data = dev_data->imageViewMap.find(image_view);
5659 if (image_view_data != dev_data->imageViewMap.end()) {
5660 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5661 if (image_layout != pCB->imageLayoutMap.end()) {
5662 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5663 }
5664 }
5665 }
5666 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5667 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5668 auto image_view_data = dev_data->imageViewMap.find(image_view);
5669 if (image_view_data != dev_data->imageViewMap.end()) {
5670 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5671 if (image_layout != pCB->imageLayoutMap.end()) {
5672 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5673 }
5674 }
5675 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005676 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005677 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005678 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5679 auto image_view_data = dev_data->imageViewMap.find(image_view);
5680 if (image_view_data != dev_data->imageViewMap.end()) {
5681 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5682 if (image_layout != pCB->imageLayoutMap.end()) {
5683 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5684 }
5685 }
5686 }
5687}
5688
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005689VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005690 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005691 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005692 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 -07005693 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5694 }
5695 return skip_call;
5696}
5697
Michael Lentineabc5e922015-10-12 11:30:14 -05005698void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5699 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5700 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5701 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5702 if (render_pass_data == dev_data->renderPassMap.end()) {
5703 return;
5704 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005705 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005706 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5707 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5708 return;
5709 }
5710 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5711 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5712 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5713 auto image_view_data = dev_data->imageViewMap.find(image_view);
5714 if (image_view_data != dev_data->imageViewMap.end()) {
5715 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5716 if (image_layout != pCB->imageLayoutMap.end()) {
5717 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5718 }
5719 }
5720 }
5721}
5722
Chia-I Wu9ab61502015-11-06 06:42:02 +08005723VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005724{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005725 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005726 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5727 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005728 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005729 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005730 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005731 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005732 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005733 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005734 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005735 // This is a shallow copy as that is all that is needed for now
5736 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005737 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005738 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005739 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005740 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005741 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 -06005742 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005743 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005744 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005745 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005746 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005747 // This is a shallow copy as that is all that is needed for now
5748 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5749 dev_data->currentSubpass = 0;
5750 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005751}
5752
Chia-I Wu9ab61502015-11-06 06:42:02 +08005753VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005754{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005755 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005756 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5757 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005758 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08005759 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005760 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005761 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005762 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06005763 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07005764 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005765 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005766 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08005767 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005768 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08005769 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005770 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005771 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08005772}
5773
Chia-I Wu9ab61502015-11-06 06:42:02 +08005774VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005775{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005776 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005777 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5778 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05005779 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005780 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07005781 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005782 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005783 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05005784 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005785 pCB->activeRenderPass = 0;
5786 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005787 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005788 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005789 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005790}
5791
Chia-I Wu9ab61502015-11-06 06:42:02 +08005792VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005793{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005794 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005795 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5796 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08005797 if (pCB) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07005798 // TODO : If secondary CB was not created w/ *_USAGE_SIMULTANEOUS_USE_BIT it cannot be used more than once in given primary CB
5799 // ALSO if secondary w/o this flag is set in primary, then primary must not be pending execution more than once at a time
5800 // 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 -06005801 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005802 for (uint32_t i=0; i<commandBuffersCount; i++) {
5803 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005804 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005805 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 +08005806 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
5807 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005808 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 +08005809 "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 -07005810 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
5811 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005812 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 -07005813 "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);
5814 }
5815 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07005816 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005817 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 -07005818 "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 -07005819 (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 -07005820 }
5821 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
5822 // 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 -07005823 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
5824 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005825 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 -07005826 "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 -07005827 (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 -07005828 }
5829 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06005830 }
5831 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005832 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005833 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005834 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005835 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005836 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005837}
5838
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005839VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005840 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07005841 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5842 auto mem_data = dev_data->memImageMap.find(mem);
5843 if (mem_data != dev_data->memImageMap.end()) {
5844 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
5845 if (image_data != dev_data->imageLayoutMap.end()) {
5846 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005847 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 -07005848 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
5849 }
5850 }
5851 }
5852 return skip_call;
5853}
5854
Chia-I Wu9ab61502015-11-06 06:42:02 +08005855VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005856 VkDevice device,
5857 VkDeviceMemory mem,
5858 VkDeviceSize offset,
5859 VkDeviceSize size,
5860 VkFlags flags,
5861 void **ppData)
5862{
5863 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005864
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005865 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005866#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
5867 skip_call = ValidateMapImageLayouts(device, mem);
5868#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5869
Michael Lentine7b236262015-10-23 12:41:44 -07005870 if (VK_FALSE == skip_call) {
5871 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
5872 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005873 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07005874}
5875
Chia-I Wu9ab61502015-11-06 06:42:02 +08005876VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07005877 VkDevice device,
5878 VkImage image,
5879 VkDeviceMemory mem,
5880 VkDeviceSize memOffset)
5881{
5882 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5883 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
5884 loader_platform_thread_lock_mutex(&globalLock);
5885 dev_data->memImageMap[mem] = image;
5886 loader_platform_thread_unlock_mutex(&globalLock);
5887 return result;
5888}
5889
Michael Lentineb887b0a2015-12-29 14:12:11 -06005890
5891VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
5892 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5893 dev_data->eventMap[event].needsSignaled = false;
5894 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
5895 return result;
5896}
5897
Michael Lentine15a47882016-01-06 10:05:48 -06005898VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
5899 VkQueue queue,
5900 uint32_t bindInfoCount,
5901 const VkBindSparseInfo* pBindInfo,
5902 VkFence fence)
5903{
5904 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005905 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06005906
5907 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
5908 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
5909 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
5910 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
5911 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
5912 } else {
5913 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",
5914 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
5915 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(bindInfo.pWaitSemaphores[i]));
5916 }
5917 }
5918 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
5919 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
5920 }
5921 }
5922
Mark Youngb20a6a82016-01-07 15:41:43 -07005923 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06005924 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07005925 else
5926 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06005927}
5928
5929VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
5930 VkDevice device,
5931 const VkSemaphoreCreateInfo* pCreateInfo,
5932 const VkAllocationCallbacks* pAllocator,
5933 VkSemaphore* pSemaphore)
5934{
5935 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5936 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
5937 if (result == VK_SUCCESS) {
5938 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
5939 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07005940 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06005941}
5942
Chia-I Wu9ab61502015-11-06 06:42:02 +08005943VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005944 VkDevice device,
5945 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07005946 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05005947 VkSwapchainKHR *pSwapchain)
5948{
5949 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07005950 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05005951
5952 if (VK_SUCCESS == result) {
5953 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE;
5954 loader_platform_thread_lock_mutex(&globalLock);
5955 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
5956 loader_platform_thread_unlock_mutex(&globalLock);
5957 }
5958
5959 return result;
5960}
5961
Ian Elliott05846062015-11-20 14:13:17 -07005962VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005963 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07005964 VkSwapchainKHR swapchain,
5965 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05005966{
5967 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005968
5969 loader_platform_thread_lock_mutex(&globalLock);
5970 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
5971 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
5972 if (swapchain_data->second->images.size() > 0) {
5973 for (auto swapchain_image : swapchain_data->second->images) {
5974 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
5975 if (image_item != dev_data->imageLayoutMap.end())
5976 dev_data->imageLayoutMap.erase(image_item);
5977 }
5978 }
5979 delete swapchain_data->second;
5980 dev_data->device_extensions.swapchainMap.erase(swapchain);
5981 }
5982 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07005983 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05005984}
5985
Chia-I Wu9ab61502015-11-06 06:42:02 +08005986VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05005987 VkDevice device,
5988 VkSwapchainKHR swapchain,
5989 uint32_t* pCount,
5990 VkImage* pSwapchainImages)
5991{
5992 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
5993 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
5994
5995 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
5996 // This should never happen and is checked by param checker.
5997 if (!pCount) return result;
5998 for (uint32_t i = 0; i < *pCount; ++i) {
5999 IMAGE_NODE* image_node = new IMAGE_NODE;
6000 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6001 loader_platform_thread_lock_mutex(&globalLock);
6002 dev_data->device_extensions.swapchainMap[swapchain]->images.push_back(pSwapchainImages[i]);
6003 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6004 loader_platform_thread_unlock_mutex(&globalLock);
6005 }
6006 }
6007 return result;
6008}
6009
Ian Elliott05846062015-11-20 14:13:17 -07006010VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05006011{
6012 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006013 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006014
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006015#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006016 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006017 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6018 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6019 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6020 } else {
6021 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",
6022 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
6023 reinterpret_cast<uint64_t>(queue), reinterpret_cast<uint64_t>(pPresentInfo->pWaitSemaphores[i]));
6024 }
6025 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006026 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006027 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6028 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6029 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006030 auto image_data = dev_data->imageLayoutMap.find(image);
6031 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006032 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006033 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 -05006034 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6035 }
6036 }
6037 }
6038 }
6039 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006040#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006041
6042 if (VK_FALSE == skip_call)
6043 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006044 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006045}
6046
Michael Lentine15a47882016-01-06 10:05:48 -06006047VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6048 VkDevice device,
6049 VkSwapchainKHR swapchain,
6050 uint64_t timeout,
6051 VkSemaphore semaphore,
6052 VkFence fence,
6053 uint32_t* pImageIndex)
6054{
6055 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6056 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6057 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006058 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006059}
6060
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006061VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6062 VkInstance instance,
6063 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6064 const VkAllocationCallbacks* pAllocator,
6065 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006066{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006067 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006068 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006069 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006070 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006071 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006072 }
6073 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006074}
6075
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006076VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006077 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006078 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006079 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006080{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006081 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006082 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006083 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006084 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006085}
6086
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006087VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006088 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006089 VkDebugReportFlagsEXT flags,
6090 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006091 uint64_t object,
6092 size_t location,
6093 int32_t msgCode,
6094 const char* pLayerPrefix,
6095 const char* pMsg)
6096{
6097 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006098 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006099}
6100
Chia-I Wu9ab61502015-11-06 06:42:02 +08006101VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006102{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006103 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006104 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6105 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006106 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006107 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 -06006108 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006109 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006110 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006111 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006112 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006113 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006114 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006115}
6116
Chia-I Wu9ab61502015-11-06 06:42:02 +08006117VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006118{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006119 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006120 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6121 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006122 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006123 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 -06006124 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006125 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006126 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006127 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006128 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006129 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006130 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006131}
6132
Chia-I Wu9ab61502015-11-06 06:42:02 +08006133VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006134{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06006135 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006136 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006137
Tobin Ehlis0b632332015-10-07 09:38:40 -06006138 layer_data *dev_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006139 /* loader uses this to force layer initialization; device object is wrapped */
6140 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006141 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
6142 dev_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006143 dev_data->device_dispatch_table = new VkLayerDispatchTable;
6144 layer_initialize_dispatch_table(dev_data->device_dispatch_table, wrapped_dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006145 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006146 }
Tobin Ehlis0b632332015-10-07 09:38:40 -06006147 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06006148 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006149 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006150 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006151 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006152 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006153 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006154 if (!strcmp(funcName, "vkWaitForFences"))
6155 return (PFN_vkVoidFunction) vkWaitForFences;
6156 if (!strcmp(funcName, "vkGetFenceStatus"))
6157 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006158 if (!strcmp(funcName, "vkQueueWaitIdle"))
6159 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6160 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6161 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006162 if (!strcmp(funcName, "vkGetDeviceQueue"))
6163 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006164 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006165 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006166 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006167 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006168 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006169 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006170 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006171 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006172 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006173 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006174 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006175 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006176 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006177 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006178 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006179 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006180 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006181 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006182 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006183 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006184 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006185 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006186 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006187 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006188 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006189 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006190 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006191 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006192 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006193 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006194 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006195 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006196 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006197 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006198 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006199 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006200 if (!strcmp(funcName, "vkCreateBuffer"))
6201 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006202 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006203 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006204 if (!strcmp(funcName, "vkCreateImage"))
6205 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006206 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006207 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006208 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006209 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006210 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006211 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006212 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006213 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006214 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006215 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006216 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006217 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006218 if (!strcmp(funcName, "vkCreateComputePipelines"))
6219 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006220 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006221 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006222 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006223 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006224 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006225 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006226 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006227 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006228 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006229 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006230 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6231 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006232 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6233 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006234 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006235 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006236 if (!strcmp(funcName, "vkCreateCommandPool"))
6237 return (PFN_vkVoidFunction) vkCreateCommandPool;
6238 if (!strcmp(funcName, "vkDestroyCommandPool"))
6239 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006240 if (!strcmp(funcName, "vkResetCommandPool"))
6241 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006242 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6243 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006244 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6245 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006246 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006247 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006248 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006249 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006250 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006251 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006252 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006253 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006254 if (!strcmp(funcName, "vkCmdSetViewport"))
6255 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006256 if (!strcmp(funcName, "vkCmdSetScissor"))
6257 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006258 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6259 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6260 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6261 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6262 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6263 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6264 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6265 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6266 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6267 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6268 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6269 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6270 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6271 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006272 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006273 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006274 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006275 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006276 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006277 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006278 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006279 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006280 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006281 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006282 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006283 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006284 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006285 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006286 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006287 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006288 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006289 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006290 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006291 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006292 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006293 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006294 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006295 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006296 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006297 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006298 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006299 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006300 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006301 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006302 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006303 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006304 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006305 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006306 if (!strcmp(funcName, "vkCmdClearAttachments"))
6307 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006308 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006309 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006310 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006311 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006312 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006313 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006314 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006315 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006316 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006317 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006318 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006319 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006320 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006321 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006322 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006323 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006324 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006325 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006326 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006327 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006328 if (!strcmp(funcName, "vkCreateShaderModule"))
6329 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006330 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006331 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006332 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006333 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006334 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006335 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006336 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006337 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006338 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6339 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006340 if (!strcmp(funcName, "vkSetEvent"))
6341 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006342 if (!strcmp(funcName, "vkMapMemory"))
6343 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006344 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6345 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006346 if (!strcmp(funcName, "vkBindImageMemory"))
6347 return (PFN_vkVoidFunction) vkBindImageMemory;
6348 if (!strcmp(funcName, "vkQueueBindSparse"))
6349 return (PFN_vkVoidFunction) vkQueueBindSparse;
6350 if (!strcmp(funcName, "vkCreateSemaphore"))
6351 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006352
Michael Lentineabc5e922015-10-12 11:30:14 -05006353 if (dev_data->device_extensions.wsi_enabled)
6354 {
6355 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6356 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6357 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6358 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6359 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6360 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006361 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6362 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006363 if (!strcmp(funcName, "vkQueuePresentKHR"))
6364 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6365 }
6366
Tobin Ehlis0b632332015-10-07 09:38:40 -06006367 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6368 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006369 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006370 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006371 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006372 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006373 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006374 }
6375 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006376 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006377 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006378 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006379 }
6380}
6381
Chia-I Wu9ab61502015-11-06 06:42:02 +08006382VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006383{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006384 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006385 if (instance == NULL)
6386 return NULL;
6387
Tobin Ehlis0b632332015-10-07 09:38:40 -06006388 layer_data* my_data;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006389 /* loader uses this to force layer initialization; instance object is wrapped */
6390 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006391 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
6392 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006393 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
6394 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006395 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006396 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006397 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006398 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006399 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006400 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006401 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6402 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6403 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6404 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6405 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6406 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6407 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6408 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006409
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006410 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006411 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006412 if (fptr)
6413 return fptr;
6414
Jon Ashburn8fd08252015-05-28 16:25:02 -06006415 {
Tobin Ehlis0b632332015-10-07 09:38:40 -06006416 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006417 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006418 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006419 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006420 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006421}