blob: 5434afcc97906ff2de974d4a811b6e105c9d7dd6 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials
11 * are furnished to do so, subject to the following conditions:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060012 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070013 * The above copyright notice(s) and this permission notice shall be included
14 * in all copies or substantial portions of the Materials.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060015 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070016 * The Materials are Confidential Information as defined by the Khronos
17 * Membership Agreement until designated non-confidential by Khronos, at which
18 * point this condition clause shall be removed.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060019 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070020 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 *
24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
26 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
27 * USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060028 *
Tobin Ehlis88452832015-12-03 09:40:56 -070029 * Author: Cody Northrop <cnorthrop@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060030 * Author: Michael Lentine <mlentine@google.com>
Tobin Ehlis88452832015-12-03 09:40:56 -070031 * Author: Tobin Ehlis <tobine@google.com>
32 * Author: Chia-I Wu <olv@google.com>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070033 * Author: Chris Forbes <chrisf@ijw.co.nz>
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070034 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060035 */
36
Mark Lobodzinski78da8cb2015-12-28 15:51:07 -070037// Allow use of STL min and max functions in Windows
38#define NOMINMAX
39
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060040#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070043#include <assert.h>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060044#include <unordered_map>
Michael Lentineb6986752015-10-06 14:56:18 -070045#include <unordered_set>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070046#include <map>
47#include <string>
48#include <iostream>
49#include <algorithm>
Mark Lobodzinski39298632015-11-18 08:38:27 -070050#include <list>
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070051#include <spirv.hpp>
Tobin Ehlis88452832015-12-03 09:40:56 -070052#include <set>
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060053
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060054#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060055#include "vk_dispatch_table_helper.h"
56#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060057#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060058#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060059#endif
Tony Barbour18f71552015-04-22 11:36:22 -060060#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060061#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060062#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060063#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060064#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060065#include "vk_layer_config.h"
Michael Lentine97eb7462015-11-20 09:48:52 -080066#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060067#include "vk_layer_table.h"
68#include "vk_layer_debug_marker_table.h"
69#include "vk_layer_data.h"
70#include "vk_layer_logging.h"
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060071#include "vk_layer_extension_utils.h"
Tobin Ehlisa1c28562015-10-23 16:00:08 -060072#include "vk_layer_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060073
Mark Lobodzinski31e5f282015-11-30 16:48:53 -070074// This definition controls whether image layout transitions are enabled/disabled.
75// disable until corner cases are fixed
76#define DISABLE_IMAGE_LAYOUT_VALIDATION
77
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070078using std::unordered_map;
79using std::unordered_set;
80
Tobin Ehlisac0ef842015-12-14 13:46:38 -070081// Track command pools and their command buffers
82struct CMD_POOL_INFO {
83 VkCommandPoolCreateFlags createFlags;
84 list<VkCommandBuffer> commandBuffers; // list container of cmd buffers allocated from this pool
85};
86
Tobin Ehlis0b632332015-10-07 09:38:40 -060087struct devExts {
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -070088 VkBool32 debug_marker_enabled;
Michael Lentineabc5e922015-10-12 11:30:14 -050089 VkBool32 wsi_enabled;
90 unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE*> swapchainMap;
Tobin Ehlis0b632332015-10-07 09:38:40 -060091};
92
Tobin Ehlis7e2ad752015-12-01 09:48:58 -070093// fwd decls
94struct shader_module;
95struct render_pass;
96
Cody Northrop55443ef2015-09-28 15:09:32 -060097struct layer_data {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -070098 debug_report_data* report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070099 std::vector<VkDebugReportCallbackEXT> logging_callback;
Tobin Ehlis0b632332015-10-07 09:38:40 -0600100 VkLayerDispatchTable* device_dispatch_table;
101 VkLayerInstanceDispatchTable* instance_dispatch_table;
102 devExts device_extensions;
Tobin Ehlisae82e7f2016-01-20 16:23:37 -0700103 vector<VkQueue> queues; // all queues under given device
Tobin Ehlis74714d22016-01-25 15:24:34 -0800104 // Global set of all cmdBuffers that are inFlight on this device
105 unordered_set<VkCommandBuffer> globalInFlightCmdBuffers;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600106 // Layer specific data
Mark Lobodzinski39298632015-11-18 08:38:27 -0700107 unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> sampleMap;
108 unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap;
109 unordered_map<VkImage, unique_ptr<VkImageCreateInfo>> imageMap;
110 unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap;
Michael Lentine700b0aa2015-10-30 17:57:32 -0700111 unordered_map<VkBuffer, BUFFER_NODE> bufferMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700112 unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
Tobin Ehlisac0ef842015-12-14 13:46:38 -0700113 unordered_map<VkCommandPool, CMD_POOL_INFO> commandPoolMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700114 unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE*> descriptorPoolMap;
115 unordered_map<VkDescriptorSet, SET_NODE*> setMap;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700116 unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> descriptorSetLayoutMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700117 unordered_map<VkPipelineLayout, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
118 unordered_map<VkDeviceMemory, VkImage> memImageMap;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -0700119 unordered_map<VkFence, FENCE_NODE> fenceMap;
120 unordered_map<VkQueue, QUEUE_NODE> queueMap;
Michael Lentineb887b0a2015-12-29 14:12:11 -0600121 unordered_map<VkEvent, EVENT_NODE> eventMap;
122 unordered_map<QueryObject, bool> queryToStateMap;
Michael Lentine15a47882016-01-06 10:05:48 -0600123 unordered_map<VkSemaphore, uint32_t> semaphoreSignaledMap;
Mark Lobodzinski39298632015-11-18 08:38:27 -0700124 unordered_map<void*, GLOBAL_CB_NODE*> commandBufferMap;
125 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
126 unordered_map<VkImage, IMAGE_NODE*> imageLayoutMap;
127 unordered_map<VkRenderPass, RENDER_PASS_NODE*> renderPassMap;
Michael Lentine15a47882016-01-06 10:05:48 -0600128 unordered_map<VkShaderModule, shader_module*> shaderModuleMap;
Michael Lentineabc5e922015-10-12 11:30:14 -0500129 // Current render pass
Michael Lentine15a47882016-01-06 10:05:48 -0600130 VkRenderPassBeginInfo renderPassBeginInfo;
131 uint32_t currentSubpass;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700132 unordered_map<VkDevice, VkPhysicalDeviceProperties> physDevPropertyMap;
Cody Northrop55443ef2015-09-28 15:09:32 -0600133
134 layer_data() :
135 report_data(nullptr),
Tobin Ehlis0b632332015-10-07 09:38:40 -0600136 device_dispatch_table(nullptr),
137 instance_dispatch_table(nullptr),
138 device_extensions()
Cody Northrop55443ef2015-09-28 15:09:32 -0600139 {};
140};
Michael Lentine15a47882016-01-06 10:05:48 -0600141
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700142// Code imported from ShaderChecker
143static void
Chris Forbes21977d92016-01-26 13:41:39 +1300144build_def_index(shader_module *);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700145
Chris Forbesc7e2e202016-01-18 08:56:40 +1300146// A forward iterator over spirv instructions. Provides easy access to len, opcode, and content words
147// without the caller needing to care too much about the physical SPIRV module layout.
148struct spirv_inst_iter {
149 std::vector<uint32_t>::const_iterator zero;
150 std::vector<uint32_t>::const_iterator it;
151
152 uint32_t len() { return *it >> 16; }
153 uint32_t opcode() { return *it & 0x0ffffu; }
154 uint32_t const & word(unsigned n) { return it[n]; }
Mark Youngd652d132016-01-25 13:37:06 -0700155 uint32_t offset() { return (uint32_t)(it - zero); }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300156
157 spirv_inst_iter(std::vector<uint32_t>::const_iterator zero,
158 std::vector<uint32_t>::const_iterator it) : zero(zero), it(it) {}
159
160 bool operator== (spirv_inst_iter const & other) {
161 return it == other.it;
162 }
163
164 bool operator!= (spirv_inst_iter const & other) {
165 return it != other.it;
166 }
167
168 spirv_inst_iter operator++ (int) { /* x++ */
169 spirv_inst_iter ii = *this;
170 it += len();
171 return ii;
172 }
173
174 spirv_inst_iter operator++ () { /* ++x; */
175 it += len();
176 return *this;
177 }
178
179 /* The iterator and the value are the same thing. */
180 spirv_inst_iter & operator* () { return *this; }
181 spirv_inst_iter const & operator* () const { return *this; }
182};
183
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700184struct shader_module {
185 /* the spirv image itself */
186 vector<uint32_t> words;
187 /* a mapping of <id> to the first word of its def. this is useful because walking type
Chris Forbes21977d92016-01-26 13:41:39 +1300188 * trees, constant expressions, etc requires jumping all over the instruction stream.
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700189 */
Chris Forbes21977d92016-01-26 13:41:39 +1300190 unordered_map<unsigned, unsigned> def_index;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700191
192 shader_module(VkShaderModuleCreateInfo const *pCreateInfo) :
193 words((uint32_t *)pCreateInfo->pCode, (uint32_t *)pCreateInfo->pCode + pCreateInfo->codeSize / sizeof(uint32_t)),
Chris Forbes21977d92016-01-26 13:41:39 +1300194 def_index() {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700195
Chris Forbes21977d92016-01-26 13:41:39 +1300196 build_def_index(this);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700197 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300198
199 /* expose begin() / end() to enable range-based for */
200 spirv_inst_iter begin() const { return spirv_inst_iter(words.begin(), words.begin() + 5); } /* first insn */
201 spirv_inst_iter end() const { return spirv_inst_iter(words.begin(), words.end()); } /* just past last insn */
202 /* given an offset into the module, produce an iterator there. */
203 spirv_inst_iter at(unsigned offset) const { return spirv_inst_iter(words.begin(), words.begin() + offset); }
Chris Forbes1257f912016-01-18 12:07:01 +1300204
Chris Forbes21977d92016-01-26 13:41:39 +1300205 /* gets an iterator to the definition of an id */
206 spirv_inst_iter get_def(unsigned id) const {
207 auto it = def_index.find(id);
208 if (it == def_index.end()) {
Chris Forbes1257f912016-01-18 12:07:01 +1300209 return end();
210 }
211 return at(it->second);
212 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700213};
214
Tobin Ehlisb212dfc2015-10-07 15:40:22 -0600215// TODO : Do we need to guard access to layer_data_map w/ lock?
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -0700216static unordered_map<void*, layer_data*> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -0600217
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600218static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
219// TODO : This can be much smarter, using separate locks for separate global data
220static int globalLockInitialized = 0;
221static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600222#define MAX_TID 513
223static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
224static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600225
226template layer_data *get_my_data_ptr<layer_data>(
227 void *data_key,
228 std::unordered_map<void *, layer_data *> &data_map);
229
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600230// Map actual TID to an index value and return that index
231// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
232static uint32_t getTIDIndex() {
233 loader_platform_thread_id tid = loader_platform_get_thread_id();
234 for (uint32_t i = 0; i < g_maxTID; i++) {
235 if (tid == g_tidMapping[i])
236 return i;
237 }
238 // Don't yet have mapping, set it and return newly set index
239 uint32_t retVal = (uint32_t) g_maxTID;
240 g_tidMapping[g_maxTID++] = tid;
241 assert(g_maxTID < MAX_TID);
242 return retVal;
243}
Tobin Ehlis559c6382015-11-05 09:52:49 -0700244
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600245// Return a string representation of CMD_TYPE enum
246static string cmdTypeToString(CMD_TYPE cmd)
247{
248 switch (cmd)
249 {
250 case CMD_BINDPIPELINE:
251 return "CMD_BINDPIPELINE";
252 case CMD_BINDPIPELINEDELTA:
253 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600254 case CMD_SETVIEWPORTSTATE:
255 return "CMD_SETVIEWPORTSTATE";
256 case CMD_SETLINEWIDTHSTATE:
257 return "CMD_SETLINEWIDTHSTATE";
258 case CMD_SETDEPTHBIASSTATE:
259 return "CMD_SETDEPTHBIASSTATE";
260 case CMD_SETBLENDSTATE:
261 return "CMD_SETBLENDSTATE";
262 case CMD_SETDEPTHBOUNDSSTATE:
263 return "CMD_SETDEPTHBOUNDSSTATE";
264 case CMD_SETSTENCILREADMASKSTATE:
265 return "CMD_SETSTENCILREADMASKSTATE";
266 case CMD_SETSTENCILWRITEMASKSTATE:
267 return "CMD_SETSTENCILWRITEMASKSTATE";
268 case CMD_SETSTENCILREFERENCESTATE:
269 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600270 case CMD_BINDDESCRIPTORSETS:
271 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600272 case CMD_BINDINDEXBUFFER:
273 return "CMD_BINDINDEXBUFFER";
274 case CMD_BINDVERTEXBUFFER:
275 return "CMD_BINDVERTEXBUFFER";
276 case CMD_DRAW:
277 return "CMD_DRAW";
278 case CMD_DRAWINDEXED:
279 return "CMD_DRAWINDEXED";
280 case CMD_DRAWINDIRECT:
281 return "CMD_DRAWINDIRECT";
282 case CMD_DRAWINDEXEDINDIRECT:
283 return "CMD_DRAWINDEXEDINDIRECT";
284 case CMD_DISPATCH:
285 return "CMD_DISPATCH";
286 case CMD_DISPATCHINDIRECT:
287 return "CMD_DISPATCHINDIRECT";
288 case CMD_COPYBUFFER:
289 return "CMD_COPYBUFFER";
290 case CMD_COPYIMAGE:
291 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600292 case CMD_BLITIMAGE:
293 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600294 case CMD_COPYBUFFERTOIMAGE:
295 return "CMD_COPYBUFFERTOIMAGE";
296 case CMD_COPYIMAGETOBUFFER:
297 return "CMD_COPYIMAGETOBUFFER";
298 case CMD_CLONEIMAGEDATA:
299 return "CMD_CLONEIMAGEDATA";
300 case CMD_UPDATEBUFFER:
301 return "CMD_UPDATEBUFFER";
302 case CMD_FILLBUFFER:
303 return "CMD_FILLBUFFER";
304 case CMD_CLEARCOLORIMAGE:
305 return "CMD_CLEARCOLORIMAGE";
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -0600306 case CMD_CLEARATTACHMENTS:
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600307 return "CMD_CLEARCOLORATTACHMENT";
308 case CMD_CLEARDEPTHSTENCILIMAGE:
309 return "CMD_CLEARDEPTHSTENCILIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600310 case CMD_RESOLVEIMAGE:
311 return "CMD_RESOLVEIMAGE";
312 case CMD_SETEVENT:
313 return "CMD_SETEVENT";
314 case CMD_RESETEVENT:
315 return "CMD_RESETEVENT";
316 case CMD_WAITEVENTS:
317 return "CMD_WAITEVENTS";
318 case CMD_PIPELINEBARRIER:
319 return "CMD_PIPELINEBARRIER";
320 case CMD_BEGINQUERY:
321 return "CMD_BEGINQUERY";
322 case CMD_ENDQUERY:
323 return "CMD_ENDQUERY";
324 case CMD_RESETQUERYPOOL:
325 return "CMD_RESETQUERYPOOL";
Mark Lobodzinski5495d132015-09-30 16:19:16 -0600326 case CMD_COPYQUERYPOOLRESULTS:
327 return "CMD_COPYQUERYPOOLRESULTS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600328 case CMD_WRITETIMESTAMP:
329 return "CMD_WRITETIMESTAMP";
330 case CMD_INITATOMICCOUNTERS:
331 return "CMD_INITATOMICCOUNTERS";
332 case CMD_LOADATOMICCOUNTERS:
333 return "CMD_LOADATOMICCOUNTERS";
334 case CMD_SAVEATOMICCOUNTERS:
335 return "CMD_SAVEATOMICCOUNTERS";
336 case CMD_BEGINRENDERPASS:
337 return "CMD_BEGINRENDERPASS";
338 case CMD_ENDRENDERPASS:
339 return "CMD_ENDRENDERPASS";
340 case CMD_DBGMARKERBEGIN:
341 return "CMD_DBGMARKERBEGIN";
342 case CMD_DBGMARKEREND:
343 return "CMD_DBGMARKEREND";
344 default:
345 return "UNKNOWN";
346 }
347}
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700348
349// SPIRV utility functions
350static void
Chris Forbes21977d92016-01-26 13:41:39 +1300351build_def_index(shader_module *module)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700352{
Chris Forbesc7e2e202016-01-18 08:56:40 +1300353 for (auto insn : *module) {
354 switch (insn.opcode()) {
Chris Forbes92b9ab02016-01-26 13:49:27 +1300355 /* Types */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700356 case spv::OpTypeVoid:
357 case spv::OpTypeBool:
358 case spv::OpTypeInt:
359 case spv::OpTypeFloat:
360 case spv::OpTypeVector:
361 case spv::OpTypeMatrix:
362 case spv::OpTypeImage:
363 case spv::OpTypeSampler:
364 case spv::OpTypeSampledImage:
365 case spv::OpTypeArray:
366 case spv::OpTypeRuntimeArray:
367 case spv::OpTypeStruct:
368 case spv::OpTypeOpaque:
369 case spv::OpTypePointer:
370 case spv::OpTypeFunction:
371 case spv::OpTypeEvent:
372 case spv::OpTypeDeviceEvent:
373 case spv::OpTypeReserveId:
374 case spv::OpTypeQueue:
375 case spv::OpTypePipe:
Chris Forbes21977d92016-01-26 13:41:39 +1300376 module->def_index[insn.word(1)] = insn.offset();
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700377 break;
378
Chris Forbes92b9ab02016-01-26 13:49:27 +1300379 /* Fixed constants */
380 case spv::OpConstantTrue:
381 case spv::OpConstantFalse:
382 case spv::OpConstant:
383 case spv::OpConstantComposite:
384 case spv::OpConstantSampler:
385 case spv::OpConstantNull:
386 module->def_index[insn.word(2)] = insn.offset();
387 break;
388
389 /* Specialization constants */
390 case spv::OpSpecConstantTrue:
391 case spv::OpSpecConstantFalse:
392 case spv::OpSpecConstant:
393 case spv::OpSpecConstantComposite:
394 case spv::OpSpecConstantOp:
395 module->def_index[insn.word(2)] = insn.offset();
396 break;
397
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700398 default:
Chris Forbes92b9ab02016-01-26 13:49:27 +1300399 /* We don't care about any other defs for now. */
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700400 break;
401 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700402 }
403}
404
405bool
406shader_is_spirv(VkShaderModuleCreateInfo const *pCreateInfo)
407{
408 uint32_t *words = (uint32_t *)pCreateInfo->pCode;
409 size_t sizeInWords = pCreateInfo->codeSize / sizeof(uint32_t);
410
411 /* Just validate that the header makes sense. */
412 return sizeInWords >= 5 && words[0] == spv::MagicNumber && words[1] == spv::Version;
413}
414
415static char const *
416storage_class_name(unsigned sc)
417{
418 switch (sc) {
419 case spv::StorageClassInput: return "input";
420 case spv::StorageClassOutput: return "output";
421 case spv::StorageClassUniformConstant: return "const uniform";
422 case spv::StorageClassUniform: return "uniform";
423 case spv::StorageClassWorkgroup: return "workgroup local";
424 case spv::StorageClassCrossWorkgroup: return "workgroup global";
425 case spv::StorageClassPrivate: return "private global";
426 case spv::StorageClassFunction: return "function";
427 case spv::StorageClassGeneric: return "generic";
428 case spv::StorageClassAtomicCounter: return "atomic counter";
429 case spv::StorageClassImage: return "image";
430 default: return "unknown";
431 }
432}
433
Chris Forbes204207a2016-01-26 14:07:16 +1300434/* get the value of an integral constant */
435unsigned
436get_constant_value(shader_module const *src, unsigned id)
437{
438 auto value = src->get_def(id);
439 assert(value != src->end());
440
441 if (value.opcode() != spv::OpConstant) {
442 /* TODO: Either ensure that the specialization transform is already performed on a module we're
443 considering here, OR -- specialize on the fly now.
444 */
445 return 1;
446 }
447
448 return value.word(3);
449}
450
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700451/* returns ptr to null terminator */
452static char *
453describe_type(char *dst, shader_module const *src, unsigned type)
454{
Chris Forbes21977d92016-01-26 13:41:39 +1300455 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300456 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700457
Chris Forbes1257f912016-01-18 12:07:01 +1300458 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700459 case spv::OpTypeBool:
460 return dst + sprintf(dst, "bool");
461 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300462 return dst + sprintf(dst, "%cint%d", insn.word(3) ? 's' : 'u', insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700463 case spv::OpTypeFloat:
Chris Forbes1257f912016-01-18 12:07:01 +1300464 return dst + sprintf(dst, "float%d", insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700465 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300466 dst += sprintf(dst, "vec%d of ", insn.word(3));
467 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700468 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300469 dst += sprintf(dst, "mat%d of ", insn.word(3));
470 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700471 case spv::OpTypeArray:
Chris Forbes95c98052016-01-26 14:08:53 +1300472 dst += sprintf(dst, "arr[%d] of ", get_constant_value(src, insn.word(3)));
Chris Forbes1257f912016-01-18 12:07:01 +1300473 return describe_type(dst, src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700474 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300475 dst += sprintf(dst, "ptr to %s ", storage_class_name(insn.word(2)));
476 return describe_type(dst, src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700477 case spv::OpTypeStruct:
478 {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700479 dst += sprintf(dst, "struct of (");
Chris Forbes1257f912016-01-18 12:07:01 +1300480 for (unsigned i = 2; i < insn.len(); i++) {
481 dst = describe_type(dst, src, insn.word(i));
482 dst += sprintf(dst, i == insn.len()-1 ? ")" : ", ");
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700483 }
484 return dst;
485 }
486 case spv::OpTypeSampler:
487 return dst + sprintf(dst, "sampler");
488 default:
489 return dst + sprintf(dst, "oddtype");
490 }
491}
492
493static bool
494types_match(shader_module const *a, shader_module const *b, unsigned a_type, unsigned b_type, bool b_arrayed)
495{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700496 /* walk two type trees together, and complain about differences */
Chris Forbes21977d92016-01-26 13:41:39 +1300497 auto a_insn = a->get_def(a_type);
498 auto b_insn = b->get_def(b_type);
Chris Forbes1257f912016-01-18 12:07:01 +1300499 assert(a_insn != a->end());
500 assert(b_insn != b->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700501
Chris Forbes1257f912016-01-18 12:07:01 +1300502 if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700503 /* we probably just found the extra level of arrayness in b_type: compare the type inside it to a_type */
Chris Forbes1257f912016-01-18 12:07:01 +1300504 return types_match(a, b, a_type, b_insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700505 }
506
Chris Forbes1257f912016-01-18 12:07:01 +1300507 if (a_insn.opcode() != b_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700508 return false;
509 }
510
Chris Forbes1257f912016-01-18 12:07:01 +1300511 switch (a_insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700512 /* if b_arrayed and we hit a leaf type, then we can't match -- there's nowhere for the extra OpTypeArray to be! */
513 case spv::OpTypeBool:
514 return true && !b_arrayed;
515 case spv::OpTypeInt:
516 /* match on width, signedness */
Chris Forbes1257f912016-01-18 12:07:01 +1300517 return a_insn.word(2) == b_insn.word(2) && a_insn.word(3) == b_insn.word(3) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700518 case spv::OpTypeFloat:
519 /* match on width */
Chris Forbes1257f912016-01-18 12:07:01 +1300520 return a_insn.word(2) == b_insn.word(2) && !b_arrayed;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700521 case spv::OpTypeVector:
522 case spv::OpTypeMatrix:
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700523 /* match on element type, count. these all have the same layout. we don't get here if
524 * b_arrayed -- that is handled above. */
Chris Forbes95c98052016-01-26 14:08:53 +1300525 return !b_arrayed &&
526 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
527 a_insn.word(3) == b_insn.word(3);
528 case spv::OpTypeArray:
529 /* match on element type, count. these all have the same layout. we don't get here if
530 * b_arrayed. This differs from vector & matrix types in that the array size is the id of a constant instruction,
531 * not a literal within OpTypeArray */
532 return !b_arrayed &&
533 types_match(a, b, a_insn.word(2), b_insn.word(2), b_arrayed) &&
534 get_constant_value(a, a_insn.word(3)) == get_constant_value(b, b_insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700535 case spv::OpTypeStruct:
536 /* match on all element types */
537 {
538 if (b_arrayed) {
539 /* for the purposes of matching different levels of arrayness, structs are leaves. */
540 return false;
541 }
542
Chris Forbes1257f912016-01-18 12:07:01 +1300543 if (a_insn.len() != b_insn.len()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700544 return false; /* structs cannot match if member counts differ */
545 }
546
Chris Forbes1257f912016-01-18 12:07:01 +1300547 for (unsigned i = 2; i < a_insn.len(); i++) {
548 if (!types_match(a, b, a_insn.word(i), b_insn.word(i), b_arrayed)) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700549 return false;
550 }
551 }
552
553 return true;
554 }
555 case spv::OpTypePointer:
556 /* match on pointee type. storage class is expected to differ */
Chris Forbes1257f912016-01-18 12:07:01 +1300557 return types_match(a, b, a_insn.word(3), b_insn.word(3), b_arrayed);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700558
559 default:
560 /* remaining types are CLisms, or may not appear in the interfaces we
561 * are interested in. Just claim no match.
562 */
563 return false;
564
565 }
566}
567
568static int
569value_or_default(std::unordered_map<unsigned, unsigned> const &map, unsigned id, int def)
570{
571 auto it = map.find(id);
572 if (it == map.end())
573 return def;
574 else
575 return it->second;
576}
577
578
579static unsigned
580get_locations_consumed_by_type(shader_module const *src, unsigned type, bool strip_array_level)
581{
Chris Forbes21977d92016-01-26 13:41:39 +1300582 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300583 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700584
Chris Forbesc7e2e202016-01-18 08:56:40 +1300585 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700586 case spv::OpTypePointer:
587 /* see through the ptr -- this is only ever at the toplevel for graphics shaders;
588 * we're never actually passing pointers around. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300589 return get_locations_consumed_by_type(src, insn.word(3), strip_array_level);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700590 case spv::OpTypeArray:
591 if (strip_array_level) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300592 return get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700593 }
594 else {
Chris Forbes95c98052016-01-26 14:08:53 +1300595 return get_constant_value(src, insn.word(3)) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700596 }
597 case spv::OpTypeMatrix:
598 /* num locations is the dimension * element size */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300599 return insn.word(3) * get_locations_consumed_by_type(src, insn.word(2), false);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700600 default:
601 /* everything else is just 1. */
602 return 1;
603
604 /* TODO: extend to handle 64bit scalar types, whose vectors may need
605 * multiple locations. */
606 }
607}
608
609
610struct interface_var {
611 uint32_t id;
612 uint32_t type_id;
613 uint32_t offset;
614 /* TODO: collect the name, too? Isn't required to be present. */
615};
616
Chris Forbesa3e85f62016-01-15 14:53:11 +1300617
618static void
619collect_interface_block_members(layer_data *my_data, VkDevice dev,
620 shader_module const *src,
621 std::map<uint32_t, interface_var> &out,
622 std::map<uint32_t, interface_var> &builtins_out,
623 std::unordered_map<unsigned, unsigned> const &blocks,
624 bool is_array_of_verts,
625 uint32_t id,
626 uint32_t type_id)
627{
628 /* Walk down the type_id presented, trying to determine whether it's actually an interface block. */
Chris Forbes21977d92016-01-26 13:41:39 +1300629 auto type = src->get_def(type_id);
Chris Forbes1257f912016-01-18 12:07:01 +1300630
Chris Forbesa3e85f62016-01-15 14:53:11 +1300631 while (true) {
632
Chris Forbes1257f912016-01-18 12:07:01 +1300633 if (type.opcode() == spv::OpTypePointer) {
Chris Forbes21977d92016-01-26 13:41:39 +1300634 type = src->get_def(type.word(3));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300635 }
Chris Forbes1257f912016-01-18 12:07:01 +1300636 else if (type.opcode() == spv::OpTypeArray && is_array_of_verts) {
Chris Forbes21977d92016-01-26 13:41:39 +1300637 type = src->get_def(type.word(2));
Chris Forbesa3e85f62016-01-15 14:53:11 +1300638 is_array_of_verts = false;
639 }
Chris Forbes1257f912016-01-18 12:07:01 +1300640 else if (type.opcode() == spv::OpTypeStruct) {
641 if (blocks.find(type.word(1)) == blocks.end()) {
Chris Forbesa3e85f62016-01-15 14:53:11 +1300642 /* This isn't an interface block. */
643 return;
644 }
645 else {
646 /* We have found the correct type. Walk its members. */
647 break;
648 }
649 }
650 else {
651 /* not an interface block */
652 return;
653 }
654 }
655
Chris Forbes1257f912016-01-18 12:07:01 +1300656 /* Walk all the OpMemberDecorate for type's result id. */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300657 for (auto insn : *src) {
Chris Forbes1257f912016-01-18 12:07:01 +1300658 if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) {
Chris Forbesc7e2e202016-01-18 08:56:40 +1300659 unsigned member_index = insn.word(2);
Chris Forbes1257f912016-01-18 12:07:01 +1300660 unsigned member_type_id = type.word(2 + member_index);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300661
Chris Forbesc7e2e202016-01-18 08:56:40 +1300662 if (insn.word(3) == spv::DecorationLocation) {
663 unsigned location = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300664 unsigned num_locations = get_locations_consumed_by_type(src, member_type_id, false);
665 for (unsigned int offset = 0; offset < num_locations; offset++) {
666 interface_var v;
667 v.id = id;
668 /* TODO: member index in interface_var too? */
669 v.type_id = member_type_id;
670 v.offset = offset;
671 out[location + offset] = v;
672 }
673 }
Chris Forbesc7e2e202016-01-18 08:56:40 +1300674 else if (insn.word(3) == spv::DecorationBuiltIn) {
675 unsigned builtin = insn.word(4);
Chris Forbesa3e85f62016-01-15 14:53:11 +1300676 interface_var v;
677 v.id = id;
678 v.type_id = member_type_id;
679 v.offset = 0;
680 builtins_out[builtin] = v;
681 }
682 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300683 }
684}
685
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700686static void
687collect_interface_by_location(layer_data *my_data, VkDevice dev,
688 shader_module const *src, spv::StorageClass sinterface,
689 std::map<uint32_t, interface_var> &out,
690 std::map<uint32_t, interface_var> &builtins_out,
691 bool is_array_of_verts)
692{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700693 std::unordered_map<unsigned, unsigned> var_locations;
694 std::unordered_map<unsigned, unsigned> var_builtins;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300695 std::unordered_map<unsigned, unsigned> blocks;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700696
Chris Forbesc7e2e202016-01-18 08:56:40 +1300697 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700698
699 /* We consider two interface models: SSO rendezvous-by-location, and
700 * builtins. Complain about anything that fits neither model.
701 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300702 if (insn.opcode() == spv::OpDecorate) {
703 if (insn.word(2) == spv::DecorationLocation) {
704 var_locations[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700705 }
706
Chris Forbesc7e2e202016-01-18 08:56:40 +1300707 if (insn.word(2) == spv::DecorationBuiltIn) {
708 var_builtins[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700709 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300710
Chris Forbesc7e2e202016-01-18 08:56:40 +1300711 if (insn.word(2) == spv::DecorationBlock) {
712 blocks[insn.word(1)] = 1;
Chris Forbesa3e85f62016-01-15 14:53:11 +1300713 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700714 }
715
716 /* TODO: handle grouped decorations */
717 /* TODO: handle index=1 dual source outputs from FS -- two vars will
718 * have the same location, and we DONT want to clobber. */
719
Chris Forbesc7e2e202016-01-18 08:56:40 +1300720 else if (insn.opcode() == spv::OpVariable && insn.word(3) == sinterface) {
721 unsigned id = insn.word(2);
722 unsigned type = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700723
Chris Forbesc7e2e202016-01-18 08:56:40 +1300724 int location = value_or_default(var_locations, id, -1);
725 int builtin = value_or_default(var_builtins, id, -1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700726
Chris Forbesf5020cf2016-01-13 09:29:31 +1300727 /* All variables and interface block members in the Input or Output storage classes
728 * must be decorated with either a builtin or an explicit location.
729 *
730 * TODO: integrate the interface block support here. For now, don't complain --
731 * a valid SPIRV module will only hit this path for the interface block case, as the
732 * individual members of the type are decorated, rather than variable declarations.
733 */
734
735 if (location != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700736 /* A user-defined interface variable, with a location. Where a variable
737 * occupied multiple locations, emit one result for each. */
738 unsigned num_locations = get_locations_consumed_by_type(src, type,
739 is_array_of_verts);
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -0700740 for (unsigned int offset = 0; offset < num_locations; offset++) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700741 interface_var v;
742 v.id = id;
743 v.type_id = type;
744 v.offset = offset;
745 out[location + offset] = v;
746 }
747 }
Chris Forbesf5020cf2016-01-13 09:29:31 +1300748 else if (builtin != -1) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700749 /* A builtin interface variable */
750 /* Note that since builtin interface variables do not consume numbered
751 * locations, there is no larger-than-vec4 consideration as above
752 */
753 interface_var v;
754 v.id = id;
755 v.type_id = type;
756 v.offset = 0;
757 builtins_out[builtin] = v;
758 }
Chris Forbesa3e85f62016-01-15 14:53:11 +1300759 else {
760 /* An interface block instance */
761 collect_interface_block_members(my_data, dev, src, out, builtins_out,
762 blocks, is_array_of_verts, id, type);
763 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700764 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700765 }
766}
767
768static void
769collect_interface_by_descriptor_slot(layer_data *my_data, VkDevice dev,
770 shader_module const *src, spv::StorageClass sinterface,
771 std::map<std::pair<unsigned, unsigned>, interface_var> &out)
772{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700773
774 std::unordered_map<unsigned, unsigned> var_sets;
775 std::unordered_map<unsigned, unsigned> var_bindings;
776
Chris Forbesc7e2e202016-01-18 08:56:40 +1300777 for (auto insn : *src) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700778 /* All variables in the Uniform or UniformConstant storage classes are required to be decorated with both
779 * DecorationDescriptorSet and DecorationBinding.
780 */
Chris Forbesc7e2e202016-01-18 08:56:40 +1300781 if (insn.opcode() == spv::OpDecorate) {
782 if (insn.word(2) == spv::DecorationDescriptorSet) {
783 var_sets[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700784 }
785
Chris Forbesc7e2e202016-01-18 08:56:40 +1300786 if (insn.word(2) == spv::DecorationBinding) {
787 var_bindings[insn.word(1)] = insn.word(3);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700788 }
789 }
790
Chris Forbesc7e2e202016-01-18 08:56:40 +1300791 else if (insn.opcode() == spv::OpVariable &&
792 (insn.word(3) == spv::StorageClassUniform ||
793 insn.word(3) == spv::StorageClassUniformConstant)) {
794 unsigned set = value_or_default(var_sets, insn.word(2), 0);
795 unsigned binding = value_or_default(var_bindings, insn.word(2), 0);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700796
797 auto existing_it = out.find(std::make_pair(set, binding));
798 if (existing_it != out.end()) {
799 /* conflict within spv image */
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700800 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 -0700801 SHADER_CHECKER_INCONSISTENT_SPIRV, "SC",
802 "var %d (type %d) in %s interface in descriptor slot (%u,%u) conflicts with existing definition",
Chris Forbesc7e2e202016-01-18 08:56:40 +1300803 insn.word(2), insn.word(1), storage_class_name(sinterface),
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700804 existing_it->first.first, existing_it->first.second);
805 }
806
807 interface_var v;
Chris Forbesc7e2e202016-01-18 08:56:40 +1300808 v.id = insn.word(2);
809 v.type_id = insn.word(1);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700810 out[std::make_pair(set, binding)] = v;
811 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700812 }
813}
814
815static bool
816validate_interface_between_stages(layer_data *my_data, VkDevice dev,
817 shader_module const *producer, char const *producer_name,
818 shader_module const *consumer, char const *consumer_name,
819 bool consumer_arrayed_input)
820{
821 std::map<uint32_t, interface_var> outputs;
822 std::map<uint32_t, interface_var> inputs;
823
824 std::map<uint32_t, interface_var> builtin_outputs;
825 std::map<uint32_t, interface_var> builtin_inputs;
826
827 bool pass = true;
828
829 collect_interface_by_location(my_data, dev, producer, spv::StorageClassOutput, outputs, builtin_outputs, false);
830 collect_interface_by_location(my_data, dev, consumer, spv::StorageClassInput, inputs, builtin_inputs,
831 consumer_arrayed_input);
832
833 auto a_it = outputs.begin();
834 auto b_it = inputs.begin();
835
836 /* maps sorted by key (location); walk them together to find mismatches */
837 while ((outputs.size() > 0 && a_it != outputs.end()) || ( inputs.size() && b_it != inputs.end())) {
838 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
839 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
840 auto a_first = a_at_end ? 0 : a_it->first;
841 auto b_first = b_at_end ? 0 : b_it->first;
842
843 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700844 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 -0700845 "%s writes to output location %d which is not consumed by %s", producer_name, a_first, consumer_name)) {
846 pass = false;
847 }
848 a_it++;
849 }
850 else if (a_at_end || a_first > b_first) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700851 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 -0700852 "%s consumes input location %d which is not written by %s", consumer_name, b_first, producer_name)) {
853 pass = false;
854 }
855 b_it++;
856 }
857 else {
858 if (types_match(producer, consumer, a_it->second.type_id, b_it->second.type_id, consumer_arrayed_input)) {
859 /* OK! */
860 }
861 else {
862 char producer_type[1024];
863 char consumer_type[1024];
864 describe_type(producer_type, producer, a_it->second.type_id);
865 describe_type(consumer_type, consumer, b_it->second.type_id);
866
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700867 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 -0700868 "Type mismatch on location %d: '%s' vs '%s'", a_it->first, producer_type, consumer_type)) {
869 pass = false;
870 }
871 }
872 a_it++;
873 b_it++;
874 }
875 }
876
877 return pass;
878}
879
880enum FORMAT_TYPE {
881 FORMAT_TYPE_UNDEFINED,
882 FORMAT_TYPE_FLOAT, /* UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader */
883 FORMAT_TYPE_SINT,
884 FORMAT_TYPE_UINT,
885};
886
887static unsigned
888get_format_type(VkFormat fmt) {
889 switch (fmt) {
890 case VK_FORMAT_UNDEFINED:
891 return FORMAT_TYPE_UNDEFINED;
892 case VK_FORMAT_R8_SINT:
893 case VK_FORMAT_R8G8_SINT:
894 case VK_FORMAT_R8G8B8_SINT:
895 case VK_FORMAT_R8G8B8A8_SINT:
896 case VK_FORMAT_R16_SINT:
897 case VK_FORMAT_R16G16_SINT:
898 case VK_FORMAT_R16G16B16_SINT:
899 case VK_FORMAT_R16G16B16A16_SINT:
900 case VK_FORMAT_R32_SINT:
901 case VK_FORMAT_R32G32_SINT:
902 case VK_FORMAT_R32G32B32_SINT:
903 case VK_FORMAT_R32G32B32A32_SINT:
904 case VK_FORMAT_B8G8R8_SINT:
905 case VK_FORMAT_B8G8R8A8_SINT:
906 case VK_FORMAT_A2B10G10R10_SINT_PACK32:
907 case VK_FORMAT_A2R10G10B10_SINT_PACK32:
908 return FORMAT_TYPE_SINT;
909 case VK_FORMAT_R8_UINT:
910 case VK_FORMAT_R8G8_UINT:
911 case VK_FORMAT_R8G8B8_UINT:
912 case VK_FORMAT_R8G8B8A8_UINT:
913 case VK_FORMAT_R16_UINT:
914 case VK_FORMAT_R16G16_UINT:
915 case VK_FORMAT_R16G16B16_UINT:
916 case VK_FORMAT_R16G16B16A16_UINT:
917 case VK_FORMAT_R32_UINT:
918 case VK_FORMAT_R32G32_UINT:
919 case VK_FORMAT_R32G32B32_UINT:
920 case VK_FORMAT_R32G32B32A32_UINT:
921 case VK_FORMAT_B8G8R8_UINT:
922 case VK_FORMAT_B8G8R8A8_UINT:
923 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
924 case VK_FORMAT_A2R10G10B10_UINT_PACK32:
925 return FORMAT_TYPE_UINT;
926 default:
927 return FORMAT_TYPE_FLOAT;
928 }
929}
930
931/* characterizes a SPIR-V type appearing in an interface to a FF stage,
932 * for comparison to a VkFormat's characterization above. */
933static unsigned
934get_fundamental_type(shader_module const *src, unsigned type)
935{
Chris Forbes21977d92016-01-26 13:41:39 +1300936 auto insn = src->get_def(type);
Chris Forbes1257f912016-01-18 12:07:01 +1300937 assert(insn != src->end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700938
Chris Forbes1257f912016-01-18 12:07:01 +1300939 switch (insn.opcode()) {
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700940 case spv::OpTypeInt:
Chris Forbes1257f912016-01-18 12:07:01 +1300941 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700942 case spv::OpTypeFloat:
943 return FORMAT_TYPE_FLOAT;
944 case spv::OpTypeVector:
Chris Forbes1257f912016-01-18 12:07:01 +1300945 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700946 case spv::OpTypeMatrix:
Chris Forbes1257f912016-01-18 12:07:01 +1300947 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700948 case spv::OpTypeArray:
Chris Forbes1257f912016-01-18 12:07:01 +1300949 return get_fundamental_type(src, insn.word(2));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700950 case spv::OpTypePointer:
Chris Forbes1257f912016-01-18 12:07:01 +1300951 return get_fundamental_type(src, insn.word(3));
Tobin Ehlis7e2ad752015-12-01 09:48:58 -0700952 default:
953 return FORMAT_TYPE_UNDEFINED;
954 }
955}
956
957static bool
958validate_vi_consistency(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi)
959{
960 /* walk the binding descriptions, which describe the step rate and stride of each vertex buffer.
961 * each binding should be specified only once.
962 */
963 std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
964 bool pass = true;
965
966 for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) {
967 auto desc = &vi->pVertexBindingDescriptions[i];
968 auto & binding = bindings[desc->binding];
969 if (binding) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -0700970 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 -0700971 "Duplicate vertex input binding descriptions for binding %d", desc->binding)) {
972 pass = false;
973 }
974 }
975 else {
976 binding = desc;
977 }
978 }
979
980 return pass;
981}
982
983static bool
984validate_vi_against_vs_inputs(layer_data *my_data, VkDevice dev, VkPipelineVertexInputStateCreateInfo const *vi, shader_module const *vs)
985{
986 std::map<uint32_t, interface_var> inputs;
987 /* we collect builtin inputs, but they will never appear in the VI state --
988 * the vs builtin inputs are generated in the pipeline, not sourced from buffers (VertexID, etc)
989 */
990 std::map<uint32_t, interface_var> builtin_inputs;
991 bool pass = true;
992
993 collect_interface_by_location(my_data, dev, vs, spv::StorageClassInput, inputs, builtin_inputs, false);
994
995 /* Build index by location */
996 std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs;
997 if (vi) {
998 for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++)
999 attribs[vi->pVertexAttributeDescriptions[i].location] = &vi->pVertexAttributeDescriptions[i];
1000 }
1001
1002 auto it_a = attribs.begin();
1003 auto it_b = inputs.begin();
1004
1005 while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) {
1006 bool a_at_end = attribs.size() == 0 || it_a == attribs.end();
1007 bool b_at_end = inputs.size() == 0 || it_b == inputs.end();
1008 auto a_first = a_at_end ? 0 : it_a->first;
1009 auto b_first = b_at_end ? 0 : it_b->first;
Chris Forbes7d83cd52016-01-15 11:32:03 +13001010 if (!a_at_end && (b_at_end || a_first < b_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001011 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 -07001012 "Vertex attribute at location %d not consumed by VS", a_first)) {
1013 pass = false;
1014 }
1015 it_a++;
1016 }
Chris Forbes7d83cd52016-01-15 11:32:03 +13001017 else if (!b_at_end && (a_at_end || b_first < a_first)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001018 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 -07001019 "VS consumes input at location %d but not provided", b_first)) {
1020 pass = false;
1021 }
1022 it_b++;
1023 }
1024 else {
1025 unsigned attrib_type = get_format_type(it_a->second->format);
1026 unsigned input_type = get_fundamental_type(vs, it_b->second.type_id);
1027
1028 /* type checking */
1029 if (attrib_type != FORMAT_TYPE_UNDEFINED && input_type != FORMAT_TYPE_UNDEFINED && attrib_type != input_type) {
1030 char vs_type[1024];
1031 describe_type(vs_type, vs, it_b->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001032 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 -07001033 "Attribute type of `%s` at location %d does not match VS input type of `%s`",
1034 string_VkFormat(it_a->second->format), a_first, vs_type)) {
1035 pass = false;
1036 }
1037 }
1038
1039 /* OK! */
1040 it_a++;
1041 it_b++;
1042 }
1043 }
1044
1045 return pass;
1046}
1047
1048static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001049validate_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 -07001050{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001051 const std::vector<VkFormat> &color_formats = rp->subpassColorFormats[subpass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001052 std::map<uint32_t, interface_var> outputs;
1053 std::map<uint32_t, interface_var> builtin_outputs;
1054 bool pass = true;
1055
1056 /* TODO: dual source blend index (spv::DecIndex, zero if not provided) */
1057
1058 collect_interface_by_location(my_data, dev, fs, spv::StorageClassOutput, outputs, builtin_outputs, false);
1059
1060 auto it = outputs.begin();
1061 uint32_t attachment = 0;
1062
1063 /* Walk attachment list and outputs together -- this is a little overpowered since attachments
1064 * are currently dense, but the parallel with matching between shader stages is nice.
1065 */
1066
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001067 while ((outputs.size() > 0 && it != outputs.end()) || attachment < color_formats.size()) {
1068 if (attachment == color_formats.size() || ( it != outputs.end() && it->first < attachment)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001069 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 -07001070 "FS writes to output location %d with no matching attachment", it->first)) {
1071 pass = false;
1072 }
1073 it++;
1074 }
1075 else if (it == outputs.end() || it->first > attachment) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001076 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 -07001077 "Attachment %d not written by FS", attachment)) {
1078 pass = false;
1079 }
1080 attachment++;
1081 }
1082 else {
1083 unsigned output_type = get_fundamental_type(fs, it->second.type_id);
1084 unsigned att_type = get_format_type(color_formats[attachment]);
1085
1086 /* type checking */
1087 if (att_type != FORMAT_TYPE_UNDEFINED && output_type != FORMAT_TYPE_UNDEFINED && att_type != output_type) {
1088 char fs_type[1024];
1089 describe_type(fs_type, fs, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001090 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 -07001091 "Attachment %d of type `%s` does not match FS output type of `%s`",
1092 attachment, string_VkFormat(color_formats[attachment]), fs_type)) {
1093 pass = false;
1094 }
1095 }
1096
1097 /* OK! */
1098 it++;
1099 attachment++;
1100 }
1101 }
1102
1103 return pass;
1104}
1105
1106
1107struct shader_stage_attributes {
1108 char const * const name;
1109 bool arrayed_input;
1110};
1111
1112
1113static shader_stage_attributes
1114shader_stage_attribs[] = {
1115 { "vertex shader", false },
1116 { "tessellation control shader", true },
1117 { "tessellation evaluation shader", false },
1118 { "geometry shader", true },
1119 { "fragment shader", false },
1120};
1121
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001122// For given pipelineLayout verify that the setLayout at slot.first
1123// has the requested binding at slot.second
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001124static bool
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001125has_descriptor_binding(layer_data* my_data,
1126 vector<VkDescriptorSetLayout>* pipelineLayout,
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001127 std::pair<unsigned, unsigned> slot)
1128{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001129 if (!pipelineLayout)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001130 return false;
1131
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001132 if (slot.first >= pipelineLayout->size())
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001133 return false;
1134
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001135 auto set = my_data->descriptorSetLayoutMap[(*pipelineLayout)[slot.first]]->bindings;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001136
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001137 return (set.find(slot.second) != set.end());
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001138}
1139
1140static uint32_t get_shader_stage_id(VkShaderStageFlagBits stage)
1141{
1142 uint32_t bit_pos = u_ffs(stage);
1143 return bit_pos-1;
1144}
1145
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001146// Block of code at start here for managing/tracking Pipeline state that this layer cares about
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001147
1148static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
1149
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001150// 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 -06001151// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
1152// to that same cmd buffer by separate thread are not changing state from underneath us
1153// Track the last cmd buffer touched by this thread
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001154
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001155// prototype
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001156static GLOBAL_CB_NODE* getCBNode(layer_data*, const VkCommandBuffer);
Tobin Ehlis559c6382015-11-05 09:52:49 -07001157
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001158static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001159{
1160 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
1161 if (pCB->drawCount[i])
1162 return VK_TRUE;
1163 }
1164 return VK_FALSE;
1165}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001166
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001167// Check object status for selected flag state
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001168static 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 -06001169{
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001170 // If non-zero enable mask is present, check it against status but if enable_mask
1171 // is 0 then no enable required so we should always just check status
1172 if ((!enable_mask) || (enable_mask & pNode->status)) {
1173 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001174 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001175 return log_msg(my_data->report_data, msg_flags, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, error_code, "DS",
Mark Youngee3f3a22016-01-25 12:18:32 -07001176 "CB object %#" PRIxLEAST64 ": %s", (uint64_t)(pNode->commandBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001177 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001178 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001179 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001180}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001181
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001182// Retrieve pipeline node ptr for given pipeline object
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001183static PIPELINE_NODE* getPipeline(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001184{
1185 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001186 if (my_data->pipelineMap.find(pipeline) == my_data->pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001187 loader_platform_thread_unlock_mutex(&globalLock);
1188 return NULL;
1189 }
1190 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08001191 return my_data->pipelineMap[pipeline];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001192}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001193
Tobin Ehlisd332f282015-10-02 11:00:56 -06001194// Return VK_TRUE if for a given PSO, the given state enum is dynamic, else return VK_FALSE
1195static VkBool32 isDynamic(const PIPELINE_NODE* pPipeline, const VkDynamicState state)
1196{
1197 if (pPipeline && pPipeline->graphicsPipelineCI.pDynamicState) {
1198 for (uint32_t i=0; i<pPipeline->graphicsPipelineCI.pDynamicState->dynamicStateCount; i++) {
1199 if (state == pPipeline->graphicsPipelineCI.pDynamicState->pDynamicStates[i])
1200 return VK_TRUE;
1201 }
1202 }
1203 return VK_FALSE;
1204}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001205
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001206// Validate state stored as flags at time of draw call
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001207static VkBool32 validate_draw_state_flags(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001208 VkBool32 result;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001209 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");
1210 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");
1211 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");
1212 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");
1213 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");
1214 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");
1215 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");
1216 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");
1217 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 -06001218 if (indexedDraw)
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001219 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 -06001220 return result;
1221}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001222
Tobin Ehlis651d9b02015-12-16 05:01:22 -07001223// Verify attachment reference compatibility according to spec
1224// If one array is larger, treat missing elements of shorter array as VK_ATTACHMENT_UNUSED & other array much match this
1225// If both AttachmentReference arrays have requested index, check their corresponding AttachementDescriptions
1226// to make sure that format and samples counts match.
1227// If not, they are not compatible.
1228static bool attachment_references_compatible(const uint32_t index, const VkAttachmentReference* pPrimary, const uint32_t primaryCount, const VkAttachmentDescription* pPrimaryAttachments,
1229 const VkAttachmentReference* pSecondary, const uint32_t secondaryCount, const VkAttachmentDescription* pSecondaryAttachments)
1230{
1231 if (index >= primaryCount) { // Check secondary as if primary is VK_ATTACHMENT_UNUSED
1232 if (VK_ATTACHMENT_UNUSED != pSecondary[index].attachment)
1233 return false;
1234 } else if (index >= secondaryCount) { // Check primary as if secondary is VK_ATTACHMENT_UNUSED
1235 if (VK_ATTACHMENT_UNUSED != pPrimary[index].attachment)
1236 return false;
1237 } else { // format and sample count must match
1238 if ((pPrimaryAttachments[pPrimary[index].attachment].format == pSecondaryAttachments[pSecondary[index].attachment].format) &&
1239 (pPrimaryAttachments[pPrimary[index].attachment].samples == pSecondaryAttachments[pSecondary[index].attachment].samples))
1240 return true;
1241 }
1242 // Format and sample counts didn't match
1243 return false;
1244}
1245
1246// For give primary and secondary RenderPass objects, verify that they're compatible
1247static bool verify_renderpass_compatibility(layer_data* my_data, const VkRenderPass primaryRP, const VkRenderPass secondaryRP, string& errorMsg)
1248{
1249 stringstream errorStr;
1250 if (my_data->renderPassMap.find(primaryRP) == my_data->renderPassMap.end()) {
1251 errorStr << "invalid VkRenderPass (" << primaryRP << ")";
1252 errorMsg = errorStr.str();
1253 return false;
1254 } else if (my_data->renderPassMap.find(secondaryRP) == my_data->renderPassMap.end()) {
1255 errorStr << "invalid VkRenderPass (" << secondaryRP << ")";
1256 errorMsg = errorStr.str();
1257 return false;
1258 }
1259 // Trivial pass case is exact same RP
1260 if (primaryRP == secondaryRP)
1261 return true;
1262 const VkRenderPassCreateInfo* primaryRPCI = my_data->renderPassMap[primaryRP]->pCreateInfo;
1263 const VkRenderPassCreateInfo* secondaryRPCI = my_data->renderPassMap[secondaryRP]->pCreateInfo;
1264 if (primaryRPCI->subpassCount != secondaryRPCI->subpassCount) {
1265 errorStr << "RenderPass for primary cmdBuffer has " << primaryRPCI->subpassCount << " subpasses but renderPass for secondary cmdBuffer has " << secondaryRPCI->subpassCount << " subpasses.";
1266 errorMsg = errorStr.str();
1267 return false;
1268 }
1269 uint32_t spIndex = 0;
1270 for (spIndex = 0; spIndex < primaryRPCI->subpassCount; ++spIndex) {
1271 // For each subpass, verify that corresponding color, input, resolve & depth/stencil attachment references are compatible
1272 uint32_t primaryColorCount = primaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1273 uint32_t secondaryColorCount = secondaryRPCI->pSubpasses[spIndex].colorAttachmentCount;
1274 uint32_t colorMax = std::max(primaryColorCount, secondaryColorCount);
1275 for (uint32_t cIdx = 0; cIdx < colorMax; ++cIdx) {
1276 if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pColorAttachments, primaryColorCount, primaryRPCI->pAttachments,
1277 secondaryRPCI->pSubpasses[spIndex].pColorAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1278 errorStr << "color attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1279 errorMsg = errorStr.str();
1280 return false;
1281 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pResolveAttachments, primaryColorCount, primaryRPCI->pAttachments,
1282 secondaryRPCI->pSubpasses[spIndex].pResolveAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1283 errorStr << "resolve attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1284 errorMsg = errorStr.str();
1285 return false;
1286 } else if (!attachment_references_compatible(cIdx, primaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, primaryColorCount, primaryRPCI->pAttachments,
1287 secondaryRPCI->pSubpasses[spIndex].pDepthStencilAttachment, secondaryColorCount, secondaryRPCI->pAttachments)) {
1288 errorStr << "depth/stencil attachments at index " << cIdx << " of subpass index " << spIndex << " are not compatible.";
1289 errorMsg = errorStr.str();
1290 return false;
1291 }
1292 }
1293 uint32_t primaryInputCount = primaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1294 uint32_t secondaryInputCount = secondaryRPCI->pSubpasses[spIndex].inputAttachmentCount;
1295 uint32_t inputMax = std::max(primaryInputCount, secondaryInputCount);
1296 for (uint32_t i = 0; i < inputMax; ++i) {
1297 if (!attachment_references_compatible(i, primaryRPCI->pSubpasses[spIndex].pInputAttachments, primaryColorCount, primaryRPCI->pAttachments,
1298 secondaryRPCI->pSubpasses[spIndex].pInputAttachments, secondaryColorCount, secondaryRPCI->pAttachments)) {
1299 errorStr << "input attachments at index " << i << " of subpass index " << spIndex << " are not compatible.";
1300 errorMsg = errorStr.str();
1301 return false;
1302 }
1303 }
1304 }
1305 return true;
1306}
1307
Tobin Ehlis559c6382015-11-05 09:52:49 -07001308// For give SET_NODE, verify that its Set is compatible w/ the setLayout corresponding to pipelineLayout[layoutIndex]
1309static bool verify_set_layout_compatibility(layer_data* my_data, const SET_NODE* pSet, const VkPipelineLayout layout, const uint32_t layoutIndex, string& errorMsg)
1310{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001311 stringstream errorStr;
Tobin Ehlis559c6382015-11-05 09:52:49 -07001312 if (my_data->pipelineLayoutMap.find(layout) == my_data->pipelineLayoutMap.end()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001313 errorStr << "invalid VkPipelineLayout (" << layout << ")";
1314 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001315 return false;
1316 }
1317 PIPELINE_LAYOUT_NODE pl = my_data->pipelineLayoutMap[layout];
1318 if (layoutIndex >= pl.descriptorSetLayouts.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001319 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;
1320 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001321 return false;
1322 }
1323 // Get the specific setLayout from PipelineLayout that overlaps this set
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001324 LAYOUT_NODE* pLayoutNode = my_data->descriptorSetLayoutMap[pl.descriptorSetLayouts[layoutIndex]];
Tobin Ehlis559c6382015-11-05 09:52:49 -07001325 if (pLayoutNode->layout == pSet->pLayout->layout) { // trivial pass case
1326 return true;
1327 }
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001328 size_t descriptorCount = pLayoutNode->descriptorTypes.size();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001329 if (descriptorCount != pSet->pLayout->descriptorTypes.size()) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001330 errorStr << "setLayout " << layoutIndex << " from pipelineLayout " << layout << " has " << descriptorCount << " descriptors, but corresponding set being bound has " << pSet->pLayout->descriptorTypes.size() << " descriptors.";
1331 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001332 return false; // trivial fail case
1333 }
1334 // Now need to check set against corresponding pipelineLayout to verify compatibility
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07001335 for (size_t i=0; i<descriptorCount; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07001336 // Need to verify that layouts are identically defined
1337 // TODO : Is below sufficient? Making sure that types & stageFlags match per descriptor
1338 // do we also need to check immutable samplers?
1339 if (pLayoutNode->descriptorTypes[i] != pSet->pLayout->descriptorTypes[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001340 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]) << "'";
1341 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001342 return false;
1343 }
1344 if (pLayoutNode->stageFlags[i] != pSet->pLayout->stageFlags[i]) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001345 errorStr << "stageFlags " << i << " for descriptorSet being bound is " << pSet->pLayout->stageFlags[i] << "' but corresponding descriptor from pipelineLayout has stageFlags " << pLayoutNode->stageFlags[i];
1346 errorMsg = errorStr.str();
Tobin Ehlis559c6382015-11-05 09:52:49 -07001347 return false;
1348 }
1349 }
1350 return true;
1351}
1352
Tobin Ehlis88452832015-12-03 09:40:56 -07001353// Validate that the shaders used by the given pipeline
1354// As a side effect this function also records the sets that are actually used by the pipeline
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07001355static VkBool32
Tobin Ehlis88452832015-12-03 09:40:56 -07001356validate_pipeline_shaders(layer_data *my_data, VkDevice dev, PIPELINE_NODE* pPipeline)
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001357{
Tobin Ehlis88452832015-12-03 09:40:56 -07001358 VkGraphicsPipelineCreateInfo const *pCreateInfo = &pPipeline->graphicsPipelineCI;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001359 /* We seem to allow pipeline stages to be specified out of order, so collect and identify them
1360 * before trying to do anything more: */
1361 int vertex_stage = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1362 int geometry_stage = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1363 int fragment_stage = get_shader_stage_id(VK_SHADER_STAGE_FRAGMENT_BIT);
1364
1365 shader_module **shaders = new shader_module*[fragment_stage + 1]; /* exclude CS */
1366 memset(shaders, 0, sizeof(shader_module *) * (fragment_stage +1));
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001367 RENDER_PASS_NODE const *rp = 0;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001368 VkPipelineVertexInputStateCreateInfo const *vi = 0;
Mark Youngb20a6a82016-01-07 15:41:43 -07001369 VkBool32 pass = VK_TRUE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001370
1371 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1372 VkPipelineShaderStageCreateInfo const *pStage = &pCreateInfo->pStages[i];
1373 if (pStage->sType == VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO) {
1374
1375 if ((pStage->stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT | VK_SHADER_STAGE_FRAGMENT_BIT
1376 | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)) == 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001377 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 -07001378 "Unknown shader stage %d", pStage->stage)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001379 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001380 }
1381 }
1382 else {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001383 shader_module *module = my_data->shaderModuleMap[pStage->module];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001384 shaders[get_shader_stage_id(pStage->stage)] = module;
1385
1386 /* validate descriptor set layout against what the spirv module actually uses */
1387 std::map<std::pair<unsigned, unsigned>, interface_var> descriptor_uses;
1388 collect_interface_by_descriptor_slot(my_data, dev, module, spv::StorageClassUniform,
1389 descriptor_uses);
1390
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001391 auto layouts = pCreateInfo->layout != VK_NULL_HANDLE ?
1392 &(my_data->pipelineLayoutMap[pCreateInfo->layout].descriptorSetLayouts) : nullptr;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001393
1394 for (auto it = descriptor_uses.begin(); it != descriptor_uses.end(); it++) {
Tobin Ehlis88452832015-12-03 09:40:56 -07001395 // As a side-effect of this function, capture which sets are used by the pipeline
1396 pPipeline->active_sets.insert(it->first.first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001397
1398 /* find the matching binding */
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001399 auto found = has_descriptor_binding(my_data, layouts, it->first);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001400
1401 if (!found) {
1402 char type_name[1024];
1403 describe_type(type_name, module, it->second.type_id);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001404 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 -07001405 SHADER_CHECKER_MISSING_DESCRIPTOR, "SC",
1406 "Shader uses descriptor slot %u.%u (used as type `%s`) but not declared in pipeline layout",
1407 it->first.first, it->first.second, type_name)) {
Mark Youngb20a6a82016-01-07 15:41:43 -07001408 pass = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001409 }
1410 }
1411 }
1412 }
1413 }
1414 }
1415
1416 if (pCreateInfo->renderPass != VK_NULL_HANDLE)
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001417 rp = my_data->renderPassMap[pCreateInfo->renderPass];
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001418
1419 vi = pCreateInfo->pVertexInputState;
1420
1421 if (vi) {
1422 pass = validate_vi_consistency(my_data, dev, vi) && pass;
1423 }
1424
1425 if (shaders[vertex_stage]) {
1426 pass = validate_vi_against_vs_inputs(my_data, dev, vi, shaders[vertex_stage]) && pass;
1427 }
1428
1429 /* TODO: enforce rules about present combinations of shaders */
1430 int producer = get_shader_stage_id(VK_SHADER_STAGE_VERTEX_BIT);
1431 int consumer = get_shader_stage_id(VK_SHADER_STAGE_GEOMETRY_BIT);
1432
1433 while (!shaders[producer] && producer != fragment_stage) {
1434 producer++;
1435 consumer++;
1436 }
1437
1438 for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) {
1439 assert(shaders[producer]);
1440 if (shaders[consumer]) {
1441 pass = validate_interface_between_stages(my_data, dev,
1442 shaders[producer], shader_stage_attribs[producer].name,
1443 shaders[consumer], shader_stage_attribs[consumer].name,
1444 shader_stage_attribs[consumer].arrayed_input) && pass;
1445
1446 producer = consumer;
1447 }
1448 }
1449
1450 if (shaders[fragment_stage] && rp) {
1451 pass = validate_fs_outputs_against_render_pass(my_data, dev, shaders[fragment_stage], rp, pCreateInfo->subpass) && pass;
1452 }
1453
Chris Forbes47f4f6f2015-12-17 17:10:19 +13001454 delete [] shaders;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07001455
1456 return pass;
1457}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001458
Tobin Ehlisf6585052015-12-17 11:48:42 -07001459// Return Set node ptr for specified set or else NULL
1460static SET_NODE* getSetNode(layer_data* my_data, const VkDescriptorSet set)
1461{
1462 loader_platform_thread_lock_mutex(&globalLock);
1463 if (my_data->setMap.find(set) == my_data->setMap.end()) {
1464 loader_platform_thread_unlock_mutex(&globalLock);
1465 return NULL;
1466 }
1467 loader_platform_thread_unlock_mutex(&globalLock);
1468 return my_data->setMap[set];
1469}
Tobin Ehlisd2393772016-01-29 11:50:47 -07001470// For the given command buffer, verify that for each set set in activeSetNodes
1471// that any dynamic descriptor in that set has a valid dynamic offset bound.
1472// To be valid, the dynamic offset combined with the offet and range from its
1473// descriptor update must not overflow the size of its buffer being updated
1474static VkBool32 validate_dynamic_offsets(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const vector<SET_NODE*> activeSetNodes)
Tobin Ehlisf6585052015-12-17 11:48:42 -07001475{
1476 VkBool32 result = VK_FALSE;
Tobin Ehlisf6585052015-12-17 11:48:42 -07001477
1478 VkWriteDescriptorSet* pWDS = NULL;
1479 uint32_t dynOffsetIndex = 0;
1480 VkDeviceSize bufferSize = 0;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001481 for (auto set_node : activeSetNodes) {
1482 for (uint32_t i=0; i < set_node->descriptorCount; ++i) {
1483 switch (set_node->ppDescriptors[i]->sType) {
1484 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1485 pWDS = (VkWriteDescriptorSet*)set_node->ppDescriptors[i];
1486 if ((pWDS->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1487 (pWDS->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1488 for (uint32_t j=0; j<pWDS->descriptorCount; ++j) {
1489 bufferSize = my_data->bufferMap[pWDS->pBufferInfo[j].buffer].create_info->size;
1490 if ((pCB->dynamicOffsets[dynOffsetIndex] + pWDS->pBufferInfo[j].offset + pWDS->pBufferInfo[j].range) > bufferSize) {
1491 result |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)set_node->set, __LINE__, DRAWSTATE_DYNAMIC_OFFSET_OVERFLOW, "DS",
1492 "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 ".",
1493 (uint64_t)set_node->set, i, pCB->dynamicOffsets[dynOffsetIndex], pWDS->pBufferInfo[j].offset, pWDS->pBufferInfo[j].range, (uint64_t)pWDS->pBufferInfo[j].buffer, bufferSize);
1494 }
1495 dynOffsetIndex++;
1496 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)
Tobin Ehlisf6585052015-12-17 11:48:42 -07001497 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001498 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07001499 break;
1500 default: // Currently only shadowing Write update nodes so shouldn't get here
1501 assert(0);
1502 continue;
1503 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07001504 }
1505 }
1506 return result;
1507}
1508
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001509// Validate overall state at the time of a draw call
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001510static VkBool32 validate_draw_state(layer_data* my_data, GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001511 // First check flag states
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06001512 VkBool32 result = validate_draw_state_flags(my_data, pCB, indexedDraw);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001513 PIPELINE_NODE* pPipe = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001514 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -06001515 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
1516 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
1517 // We should have that check separately and then gate this check based on that check
Mark Lobodzinski74635932015-12-18 15:35:38 -07001518 if (pPipe) {
Tobin Ehlisd2393772016-01-29 11:50:47 -07001519 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski74635932015-12-18 15:35:38 -07001520 if (pCB->lastBoundPipelineLayout) {
1521 string errorString;
Tobin Ehlisd2393772016-01-29 11:50:47 -07001522 // Need a vector (vs. std::set) of active Sets for dynamicOffset validation in case same set bound w/ different offsets
1523 vector<SET_NODE*> activeSetNodes;
Mark Lobodzinski74635932015-12-18 15:35:38 -07001524 for (auto setIndex : pPipe->active_sets) {
1525 // If valid set is not bound throw an error
1526 if ((pCB->boundDescriptorSets.size() <= setIndex) || (!pCB->boundDescriptorSets[setIndex])) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001527 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 -07001528 "VkPipeline %#" PRIxLEAST64 " uses set #%u but that set is not bound.", (uint64_t)pPipe->pipeline, setIndex);
1529 } else if (!verify_set_layout_compatibility(my_data, my_data->setMap[pCB->boundDescriptorSets[setIndex]], pPipe->graphicsPipelineCI.layout, setIndex, errorString)) {
1530 // Set is bound but not compatible w/ overlapping pipelineLayout from PSO
1531 VkDescriptorSet setHandle = my_data->setMap[pCB->boundDescriptorSets[setIndex]]->set;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001532 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 -07001533 "VkDescriptorSet (%#" PRIxLEAST64 ") bound as set #%u is not compatible with overlapping VkPipelineLayout %#" PRIxLEAST64 " due to: %s",
1534 (uint64_t)setHandle, setIndex, (uint64_t)pPipe->graphicsPipelineCI.layout, errorString.c_str());
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001535 } else { // Valid set is bound and layout compatible, validate that it's updated and verify any dynamic offsets
1536 // Pull the set node
Tobin Ehlisd2393772016-01-29 11:50:47 -07001537 SET_NODE* pSet = my_data->setMap[pCB->boundDescriptorSets[setIndex]];
1538 // Save vector of all active sets to verify dynamicOffsets below
1539 activeSetNodes.push_back(pSet);
Tobin Ehlis43c39c02016-01-11 13:18:40 -07001540 // Make sure set has been updated
1541 if (!pSet->pUpdateStructs) {
1542 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",
1543 "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);
1544 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001545 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001546 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07001547 // For each dynamic descriptor, make sure dynamic offset doesn't overstep buffer
1548 if (!pCB->dynamicOffsets.empty())
1549 result |= validate_dynamic_offsets(my_data, pCB, activeSetNodes);
Tobin Ehlis88452832015-12-03 09:40:56 -07001550 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001551 // Verify Vtx binding
1552 if (pPipe->vtxBindingCount > 0) {
1553 VkPipelineVertexInputStateCreateInfo *vtxInCI = &pPipe->vertexInputCI;
1554 for (uint32_t i = 0; i < vtxInCI->vertexBindingDescriptionCount; i++) {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001555 if ((pCB->currentDrawData.buffers.size() < (i+1)) || (pCB->currentDrawData.buffers[i] == VK_NULL_HANDLE)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001556 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 -07001557 "The Pipeline State Object (%#" PRIxLEAST64 ") expects that this Command Buffer's vertex binding Index %d should be set via vkCmdBindVertexBuffers.",
1558 (uint64_t)pCB->lastBoundPipeline, i);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001559
Mark Lobodzinski74635932015-12-18 15:35:38 -07001560 }
1561 }
1562 } else {
Michael Lentine700b0aa2015-10-30 17:57:32 -07001563 if (!pCB->currentDrawData.buffers.empty()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001564 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 -07001565 "DS", "Vertex buffers are bound to command buffer (%#" PRIxLEAST64 ") but no vertex buffers are attached to this Pipeline State Object (%#" PRIxLEAST64 ").",
1566 (uint64_t)pCB->commandBuffer, (uint64_t)pCB->lastBoundPipeline);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06001567 }
1568 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001569 // If Viewport or scissors are dynamic, verify that dynamic count matches PSO count
1570 VkBool32 dynViewport = isDynamic(pPipe, VK_DYNAMIC_STATE_VIEWPORT);
1571 VkBool32 dynScissor = isDynamic(pPipe, VK_DYNAMIC_STATE_SCISSOR);
1572 if (dynViewport) {
1573 if (pCB->viewports.size() != pPipe->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001574 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 -07001575 "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);
1576 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001577 }
Mark Lobodzinski74635932015-12-18 15:35:38 -07001578 if (dynScissor) {
1579 if (pCB->scissors.size() != pPipe->graphicsPipelineCI.pViewportState->scissorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001580 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 -07001581 "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);
1582 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001583 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07001584 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001585 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -06001586 return result;
1587}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001588
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001589// Verify that create state for a pipeline is valid
Tobin Ehlis88452832015-12-03 09:40:56 -07001590static VkBool32 verifyPipelineCreateState(layer_data* my_data, const VkDevice device, PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001591{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001592 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski2fd2d032015-12-16 14:25:22 -07001593
Tobin Ehlis88452832015-12-03 09:40:56 -07001594 if (!validate_pipeline_shaders(my_data, device, pPipeline)) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001595 skipCall = VK_TRUE;
1596 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001597 // VS is required
1598 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_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",
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001600 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001601 }
1602 // Either both or neither TC/TE shaders should be defined
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001603 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) !=
1604 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) == 0) ) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001605 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 -06001606 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001607 }
1608 // Compute shaders should be specified independent of Gfx shaders
1609 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001610 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1611 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001612 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001613 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 -06001614 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001615 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001616 // VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines.
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001617 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001618 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) &&
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001619 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH_LIST)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001620 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001621 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST must be set as IA topology for tessellation pipelines");
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001622 }
Chia-I Wu515eb8f2015-10-31 00:31:16 +08001623 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) {
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001624 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001625 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 +08001626 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -06001627 }
1628 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001629 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 +08001630 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH_LIST primitive topology used with patchControlPoints value %u."
Tobin Ehlis912df022015-09-17 08:46:18 -06001631 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
1632 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001633 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001634 // Viewport state must be included and viewport and scissor counts should always match
Tobin Ehlise68360f2015-10-01 11:15:13 -06001635 // NOTE : Even if these are flagged as dynamic, counts need to be set correctly for shader compiler
Tobin Ehlisd332f282015-10-02 11:00:56 -06001636 if (!pPipeline->graphicsPipelineCI.pViewportState) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001637 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 -06001638 "Gfx Pipeline pViewportState is null. Even if viewport and scissors are dynamic PSO must include viewportCount and scissorCount in pViewportState.");
1639 } else if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount != pPipeline->graphicsPipelineCI.pViewportState->viewportCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001640 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 -06001641 "Gfx Pipeline viewport count (%u) must match scissor count (%u).", pPipeline->vpStateCI.viewportCount, pPipeline->vpStateCI.scissorCount);
Tobin Ehlisd332f282015-10-02 11:00:56 -06001642 } else {
1643 // If viewport or scissor are not dynamic, then verify that data is appropriate for count
1644 VkBool32 dynViewport = isDynamic(pPipeline, VK_DYNAMIC_STATE_VIEWPORT);
1645 VkBool32 dynScissor = isDynamic(pPipeline, VK_DYNAMIC_STATE_SCISSOR);
1646 if (!dynViewport) {
1647 if (pPipeline->graphicsPipelineCI.pViewportState->viewportCount && !pPipeline->graphicsPipelineCI.pViewportState->pViewports) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001648 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 -07001649 "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 -06001650 }
1651 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06001652 if (!dynScissor) {
1653 if (pPipeline->graphicsPipelineCI.pViewportState->scissorCount && !pPipeline->graphicsPipelineCI.pViewportState->pScissors) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001654 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 -07001655 "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 -06001656 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06001657 }
1658 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001659 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001660}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001661
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001662// Init the pipeline mapping info based on pipeline create info LL tree
1663// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis88452832015-12-03 09:40:56 -07001664// TODO : this should really just be in the constructor for PIPELINE_NODE
Mark Lobodzinski475a2182015-11-10 15:25:01 -07001665static PIPELINE_NODE* initGraphicsPipeline(layer_data* dev_data, const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001666{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001667 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001668
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001669 if (pBasePipeline) {
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001670 *pPipeline = *pBasePipeline;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001671 }
Mark Lobodzinskic44baa52015-12-11 11:56:07 -07001672
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001673 // First init create info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001674 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001675
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001676 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001677 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06001678 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001679
1680 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
1681 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
1682
Chia-I Wu28e06912015-10-31 00:31:16 +08001683 switch (pPSSCI->stage) {
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001684 case VK_SHADER_STAGE_VERTEX_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001685 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1686 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001687 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001688 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001689 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001690 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001691 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001692 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001693 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Courtney Goeltzenleuchter96835892015-10-15 17:35:38 -06001694 pPipeline->active_shaders |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001695 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001696 case VK_SHADER_STAGE_GEOMETRY_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001697 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1698 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001699 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001700 case VK_SHADER_STAGE_FRAGMENT_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001701 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
1702 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001703 break;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06001704 case VK_SHADER_STAGE_COMPUTE_BIT:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001705 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
1706 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001707 break;
1708 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001709 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001710 break;
1711 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001712 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001713 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
1714 if (pCreateInfo->stageCount != 0) {
1715 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
1716 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
1717 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
1718 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001719 if (pCreateInfo->pVertexInputState != NULL) {
1720 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
1721 // Copy embedded ptrs
1722 pVICI = pCreateInfo->pVertexInputState;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001723 pPipeline->vtxBindingCount = pVICI->vertexBindingDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001724 if (pPipeline->vtxBindingCount) {
1725 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
1726 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
1727 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
1728 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08001729 pPipeline->vtxAttributeCount = pVICI->vertexAttributeDescriptionCount;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001730 if (pPipeline->vtxAttributeCount) {
1731 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
1732 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
1733 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
1734 }
1735 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
1736 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001737 if (pCreateInfo->pInputAssemblyState != NULL) {
1738 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
1739 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001740 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001741 if (pCreateInfo->pTessellationState != NULL) {
1742 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
1743 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001744 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001745 if (pCreateInfo->pViewportState != NULL) {
1746 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
1747 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001748 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001749 if (pCreateInfo->pRasterizationState != NULL) {
1750 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo));
1751 pPipeline->graphicsPipelineCI.pRasterizationState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001752 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001753 if (pCreateInfo->pMultisampleState != NULL) {
1754 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
1755 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001756 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001757 if (pCreateInfo->pDepthStencilState != NULL) {
1758 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
1759 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
1760 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001761 if (pCreateInfo->pColorBlendState != NULL) {
1762 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001763 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001764 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001765 pPipeline->attachmentCount = pCBCI->attachmentCount;
1766 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001767 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
1768 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001769 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
1770 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -06001771 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001772 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001773 if (pCreateInfo->pDynamicState != NULL) {
1774 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
1775 if (pPipeline->dynStateCI.dynamicStateCount) {
1776 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
1777 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
1778 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
1779 }
1780 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001781 }
Tobin Ehlis88452832015-12-03 09:40:56 -07001782 pPipeline->active_sets.clear();
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001783 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001784}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001785
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001786// Free the Pipeline nodes
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001787static void deletePipelines(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001788{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001789 if (my_data->pipelineMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06001790 return;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001791 for (auto ii=my_data->pipelineMap.begin(); ii!=my_data->pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -06001792 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
1793 delete[] (*ii).second->graphicsPipelineCI.pStages;
1794 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -06001795 if ((*ii).second->pVertexBindingDescriptions) {
1796 delete[] (*ii).second->pVertexBindingDescriptions;
1797 }
1798 if ((*ii).second->pVertexAttributeDescriptions) {
1799 delete[] (*ii).second->pVertexAttributeDescriptions;
1800 }
1801 if ((*ii).second->pAttachments) {
1802 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001803 }
Tobin Ehlis963a4042015-09-29 08:18:34 -06001804 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
1805 delete[] (*ii).second->dynStateCI.pDynamicStates;
1806 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001807 delete (*ii).second;
1808 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001809 my_data->pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001810}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001811
Tobin Ehliseba312c2015-04-01 08:40:34 -06001812// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Chia-I Wu5c17c962015-10-31 00:31:16 +08001813static VkSampleCountFlagBits getNumSamples(layer_data* my_data, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001814{
Chia-I Wue2fc5522015-10-26 20:04:44 +08001815 PIPELINE_NODE* pPipe = my_data->pipelineMap[pipeline];
Tobin Ehlis577188e2015-07-13 14:51:15 -06001816 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001817 return pPipe->msStateCI.rasterizationSamples;
Tobin Ehlis577188e2015-07-13 14:51:15 -06001818 }
Chia-I Wu5c17c962015-10-31 00:31:16 +08001819 return VK_SAMPLE_COUNT_1_BIT;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001820}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001821
Tobin Ehliseba312c2015-04-01 08:40:34 -06001822// Validate state related to the PSO
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001823static VkBool32 validatePipelineState(layer_data* my_data, const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -06001824{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001825 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06001826 // Verify that any MSAA request in PSO matches sample# in bound FB
Chia-I Wu5c17c962015-10-31 00:31:16 +08001827 VkSampleCountFlagBits psoNumSamples = getNumSamples(my_data, pipeline);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001828 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001829 const VkRenderPassCreateInfo* pRPCI = my_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Chia-I Wu08accc62015-07-07 11:50:03 +08001830 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
Chia-I Wu5c17c962015-10-31 00:31:16 +08001831 VkSampleCountFlagBits subpassNumSamples = (VkSampleCountFlagBits) 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08001832 uint32_t i;
1833
Chia-I Wud50a7d72015-10-26 20:48:51 +08001834 for (i = 0; i < pSD->colorAttachmentCount; i++) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001835 VkSampleCountFlagBits samples;
Chia-I Wu08accc62015-07-07 11:50:03 +08001836
Cody Northropa505dda2015-08-04 11:16:41 -06001837 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +08001838 continue;
1839
Cody Northropa505dda2015-08-04 11:16:41 -06001840 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu5c17c962015-10-31 00:31:16 +08001841 if (subpassNumSamples == (VkSampleCountFlagBits) 0) {
Chia-I Wu08accc62015-07-07 11:50:03 +08001842 subpassNumSamples = samples;
1843 } else if (subpassNumSamples != samples) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001844 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001845 break;
1846 }
1847 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08001848 if (pSD->pDepthStencilAttachment && pSD->pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
Chia-I Wu5c17c962015-10-31 00:31:16 +08001849 const VkSampleCountFlagBits samples = pRPCI->pAttachments[pSD->pDepthStencilAttachment->attachment].samples;
1850 if (subpassNumSamples == (VkSampleCountFlagBits) 0)
Chia-I Wu08accc62015-07-07 11:50:03 +08001851 subpassNumSamples = samples;
1852 else if (subpassNumSamples != samples)
Chia-I Wu5c17c962015-10-31 00:31:16 +08001853 subpassNumSamples = (VkSampleCountFlagBits) -1;
Chia-I Wu08accc62015-07-07 11:50:03 +08001854 }
1855
1856 if (psoNumSamples != subpassNumSamples) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001857 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 -06001858 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!",
Chia-I Wue2fc5522015-10-26 20:04:44 +08001859 (uint64_t) pipeline, psoNumSamples, (uint64_t) pCB->activeRenderPass, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -06001860 }
1861 } else {
1862 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
1863 // Verify and flag error as appropriate
1864 }
1865 // TODO : Add more checks here
1866 } else {
1867 // TODO : Validate non-gfx pipeline updates
1868 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001869 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001870}
1871
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001872// Block of code at start here specifically for managing/tracking DSs
1873
Tobin Ehlis793ad302015-04-03 12:01:11 -06001874// Return Pool node ptr for specified pool or else NULL
Mark Lobodzinski39298632015-11-18 08:38:27 -07001875static DESCRIPTOR_POOL_NODE* getPoolNode(layer_data* my_data, const VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001876{
1877 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001878 if (my_data->descriptorPoolMap.find(pool) == my_data->descriptorPoolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001879 loader_platform_thread_unlock_mutex(&globalLock);
1880 return NULL;
1881 }
1882 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07001883 return my_data->descriptorPoolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001884}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001885
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06001886static LAYOUT_NODE* getLayoutNode(layer_data* my_data, const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001887 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001888 if (my_data->descriptorSetLayoutMap.find(layout) == my_data->descriptorSetLayoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001889 loader_platform_thread_unlock_mutex(&globalLock);
1890 return NULL;
1891 }
1892 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07001893 return my_data->descriptorSetLayoutMap[layout];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001894}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001895
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001896// 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 -06001897static VkBool32 validUpdateStruct(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001898{
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001899 switch (pUpdateStruct->sType)
1900 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001901 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1902 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001903 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001904 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001905 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 -06001906 "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 -06001907 }
1908}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001909
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001910// Set count for given update struct in the last parameter
Courtney Goeltzenleuchter085f8dd2015-12-16 16:08:44 -07001911// 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 -06001912static uint32_t getUpdateCount(layer_data* my_data, const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001913{
1914 switch (pUpdateStruct->sType)
1915 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001916 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Chia-I Wud50a7d72015-10-26 20:48:51 +08001917 return ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorCount;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001918 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -06001919 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wud50a7d72015-10-26 20:48:51 +08001920 return ((VkCopyDescriptorSet*)pUpdateStruct)->descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001921 }
Courtney Goeltzenleuchter7f47bca2015-12-16 16:08:08 -07001922
1923 return 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001924}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001925
Tobin Ehlis793ad302015-04-03 12:01:11 -06001926// For given Layout Node and binding, return index where that binding begins
1927static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1928{
1929 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001930 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001931 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001932 break;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001933 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001934 }
1935 return offsetIndex;
1936}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001937
Tobin Ehlis793ad302015-04-03 12:01:11 -06001938// For given layout node and binding, return last index that is updated
1939static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
1940{
1941 uint32_t offsetIndex = 0;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001942 for (uint32_t i = 0; i < pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07001943 offsetIndex += pLayout->createInfo.pBindings[i].descriptorCount;
1944 if (pLayout->createInfo.pBindings[i].binding == binding)
Chia-I Wud46e6ae2015-10-31 00:31:16 +08001945 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001946 }
1947 return offsetIndex-1;
1948}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001949
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001950// For given layout and update, return the first overall index of the layout that is updated
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001951static 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 -06001952{
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001953 return getBindingStartIndex(pLayout, binding)+arrayIndex;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001954}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001955
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001956// For given layout and update, return the last overall index of the layout that is updated
1957static 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 -06001958{
Tobin Ehlis8a62e632015-10-27 15:43:38 -06001959 uint32_t count = getUpdateCount(my_data, device, pUpdateStruct);
Tobin Ehlisbaca3ab2015-10-27 12:54:50 -06001960 return getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001961}
Tobin Ehlis559c6382015-11-05 09:52:49 -07001962
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001963// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001964static 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 -06001965{
1966 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001967 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001968 VkDescriptorType actualType;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001969 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001970 switch (pUpdateStruct->sType)
1971 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001972 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1973 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001974 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001975 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
1976 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001977 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001978 break;
1979 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001980 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 -06001981 "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 -06001982 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001983 if (VK_FALSE == skipCall) {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06001984 // Set first stageFlags as reference and verify that all other updates match it
1985 VkShaderStageFlags refStageFlags = pLayout->stageFlags[startIndex];
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001986 for (i = startIndex; i <= endIndex; i++) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06001987 if (pLayout->descriptorTypes[i] != actualType) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001988 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 -06001989 "Write descriptor update has descriptor type %s that does not match overlapping binding descriptor type of %s!",
1990 string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
1991 }
1992 if (pLayout->stageFlags[i] != refStageFlags) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07001993 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 -06001994 "Write descriptor update has stageFlags %x that do not match overlapping binding descriptor stageFlags of %x!",
1995 refStageFlags, pLayout->stageFlags[i]);
Tobin Ehlis483cc352015-09-30 08:30:20 -06001996 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001997 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001998 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001999 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002000}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002001
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002002// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002003// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002004// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002005static VkBool32 shadowUpdateNode(layer_data* my_data, const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002006{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002007 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002008 VkWriteDescriptorSet* pWDS = NULL;
2009 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002010 size_t array_size = 0;
2011 size_t base_array_size = 0;
2012 size_t total_array_size = 0;
2013 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002014 switch (pUpdate->sType)
2015 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002016 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2017 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002018 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002019 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002020
2021 switch (pWDS->descriptorType) {
2022 case VK_DESCRIPTOR_TYPE_SAMPLER:
2023 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2024 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2025 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2026 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002027 VkDescriptorImageInfo *info = new VkDescriptorImageInfo[pWDS->descriptorCount];
2028 memcpy(info, pWDS->pImageInfo, pWDS->descriptorCount * sizeof(VkDescriptorImageInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002029 pWDS->pImageInfo = info;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002030 }
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002031 break;
2032 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2033 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2034 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002035 VkBufferView *info = new VkBufferView[pWDS->descriptorCount];
2036 memcpy(info, pWDS->pTexelBufferView, pWDS->descriptorCount * sizeof(VkBufferView));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002037 pWDS->pTexelBufferView = info;
2038 }
2039 break;
2040 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2041 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2042 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2043 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2044 {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002045 VkDescriptorBufferInfo *info = new VkDescriptorBufferInfo[pWDS->descriptorCount];
2046 memcpy(info, pWDS->pBufferInfo, pWDS->descriptorCount * sizeof(VkDescriptorBufferInfo));
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002047 pWDS->pBufferInfo = info;
2048 }
2049 break;
2050 default:
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07002051 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06002052 break;
2053 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002054 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002055 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
2056 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002057 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002058 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002059 break;
2060 default:
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002061 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 -06002062 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
2063 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002064 }
2065 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002066 (*pNewNode)->pNext = NULL;
2067 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002068}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002069
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002070// Verify that given sampler is valid
2071static VkBool32 validateSampler(const layer_data* my_data, const VkSampler* pSampler, const VkBool32 immutable)
2072{
2073 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002074 auto sampIt = my_data->sampleMap.find(*pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002075 if (sampIt == my_data->sampleMap.end()) {
2076 if (!immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002077 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 +08002078 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002079 } else { // immutable
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002080 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, (uint64_t) *pSampler, __LINE__, DRAWSTATE_SAMPLER_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002081 "vkUpdateDescriptorSets: Attempt to update descriptor whose binding has an invalid immutable sampler %#" PRIxLEAST64, (uint64_t) *pSampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002082 }
2083 } else {
2084 // TODO : Any further checks we want to do on the sampler?
2085 }
2086 return skipCall;
2087}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002088
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002089// Verify that given imageView is valid
2090static VkBool32 validateImageView(const layer_data* my_data, const VkImageView* pImageView, const VkImageLayout imageLayout)
2091{
2092 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002093 auto ivIt = my_data->imageViewMap.find(*pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002094 if (ivIt == my_data->imageViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002095 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002096 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid imageView %#" PRIxLEAST64, (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002097 } else {
2098 // Validate that imageLayout is compatible with aspectMask and image format
2099 VkImageAspectFlags aspectMask = ivIt->second->subresourceRange.aspectMask;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002100 VkImage image = ivIt->second->image;
Michael Lentine7b236262015-10-23 12:41:44 -07002101 // TODO : Check here in case we have a bad image
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07002102 auto imgIt = my_data->imageLayoutMap.find(image);
2103 if (imgIt == my_data->imageLayoutMap.end()) {
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_EXT, (uint64_t) image, __LINE__, DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS",
Michael Lentine7b236262015-10-23 12:41:44 -07002105 "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 -06002106 } else {
2107 VkFormat format = (*imgIt).second->format;
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07002108 VkBool32 ds = vk_format_is_depth_or_stencil(format);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002109 switch (imageLayout) {
2110 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
2111 // Only Color bit must be set
2112 if ((aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002113 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 -06002114 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 +08002115 " that does not have VK_IMAGE_ASPECT_COLOR_BIT set.", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002116 }
2117 // format must NOT be DS
2118 if (ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002119 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 -06002120 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 +08002121 " 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 -06002122 }
2123 break;
2124 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
2125 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
2126 // Depth or stencil bit must be set, but both must NOT be set
2127 if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
2128 if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
2129 // both must NOT be set
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002130 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 -06002131 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002132 " that has both STENCIL and DEPTH aspects set", (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002133 }
2134 } else if (!(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
2135 // Neither were set
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_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002137 DRAWSTATE_INVALID_IMAGE_ASPECT, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002138 " that does not have STENCIL or DEPTH aspect set.", string_VkImageLayout(imageLayout), (uint64_t) *pImageView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002139 }
2140 // format must be DS
2141 if (!ds) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002142 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, (uint64_t) *pImageView, __LINE__,
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002143 DRAWSTATE_IMAGEVIEW_DESCRIPTOR_ERROR, "DS", "vkUpdateDescriptorSets: Updating descriptor with layout %s and imageView %#" PRIxLEAST64 ""
Chia-I Wue2fc5522015-10-26 20:04:44 +08002144 " 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 -06002145 }
2146 break;
2147 default:
2148 // anything to check for other layouts?
2149 break;
2150 }
2151 }
2152 }
2153 return skipCall;
2154}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002155
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002156// Verify that given bufferView is valid
2157static VkBool32 validateBufferView(const layer_data* my_data, const VkBufferView* pBufferView)
2158{
2159 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002160 auto sampIt = my_data->bufferViewMap.find(*pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002161 if (sampIt == my_data->bufferViewMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002162 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 +08002163 "vkUpdateDescriptorSets: Attempt to update descriptor with invalid bufferView %#" PRIxLEAST64, (uint64_t) *pBufferView);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002164 } else {
2165 // TODO : Any further checks we want to do on the bufferView?
2166 }
2167 return skipCall;
2168}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002169
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002170// Verify that given bufferInfo is valid
2171static VkBool32 validateBufferInfo(const layer_data* my_data, const VkDescriptorBufferInfo* pBufferInfo)
2172{
2173 VkBool32 skipCall = VK_FALSE;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002174 auto sampIt = my_data->bufferMap.find(pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002175 if (sampIt == my_data->bufferMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002176 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 +08002177 "vkUpdateDescriptorSets: Attempt to update descriptor where bufferInfo has invalid buffer %#" PRIxLEAST64, (uint64_t) pBufferInfo->buffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002178 } else {
2179 // TODO : Any further checks we want to do on the bufferView?
2180 }
2181 return skipCall;
2182}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002183
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002184static VkBool32 validateUpdateContents(const layer_data* my_data, const VkWriteDescriptorSet *pWDS, const VkDescriptorSetLayoutBinding* pLayoutBinding)
2185{
2186 VkBool32 skipCall = VK_FALSE;
2187 // First verify that for the given Descriptor type, the correct DescriptorInfo data is supplied
2188 VkBufferView* pBufferView = NULL;
2189 const VkSampler* pSampler = NULL;
2190 VkImageView* pImageView = NULL;
2191 VkImageLayout* pImageLayout = NULL;
2192 VkDescriptorBufferInfo* pBufferInfo = NULL;
2193 VkBool32 immutable = VK_FALSE;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002194 uint32_t i = 0;
2195 // For given update type, verify that update contents are correct
2196 switch (pWDS->descriptorType) {
2197 case VK_DESCRIPTOR_TYPE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002198 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002199 skipCall |= validateSampler(my_data, &(pWDS->pImageInfo[i].sampler), immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002200 }
2201 break;
2202 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002203 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002204 if (NULL == pLayoutBinding->pImmutableSamplers) {
2205 pSampler = &(pWDS->pImageInfo[i].sampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002206 if (immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002207 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 -06002208 "vkUpdateDescriptorSets: Update #%u is not an immutable sampler %#" PRIxLEAST64 ", but previous update(s) from this "
2209 "VkWriteDescriptorSet struct used an immutable sampler. All updates from a single struct must either "
Chia-I Wue2fc5522015-10-26 20:04:44 +08002210 "use immutable or non-immutable samplers.", i, (uint64_t) *pSampler);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002211 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002212 } else {
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002213 if (i>0 && !immutable) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002214 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 -06002215 "vkUpdateDescriptorSets: Update #%u is an immutable sampler, but previous update(s) from this "
2216 "VkWriteDescriptorSet struct used a non-immutable sampler. All updates from a single struct must either "
2217 "use immutable or non-immutable samplers.", i);
2218 }
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002219 immutable = VK_TRUE;
2220 pSampler = &(pLayoutBinding->pImmutableSamplers[i]);
2221 }
2222 skipCall |= validateSampler(my_data, pSampler, immutable);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002223 }
2224 // Intentionally fall through here to also validate image stuff
2225 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2226 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2227 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002228 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002229 skipCall |= validateImageView(my_data, &(pWDS->pImageInfo[i].imageView), pWDS->pImageInfo[i].imageLayout);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002230 }
2231 break;
2232 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2233 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002234 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002235 skipCall |= validateBufferView(my_data, &(pWDS->pTexelBufferView[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002236 }
2237 break;
2238 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2239 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2240 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2241 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Chia-I Wud50a7d72015-10-26 20:48:51 +08002242 for (i=0; i<pWDS->descriptorCount; ++i) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002243 skipCall |= validateBufferInfo(my_data, &(pWDS->pBufferInfo[i]));
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002244 }
2245 break;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002246 }
2247 return skipCall;
2248}
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002249// Validate that given set is valid and that it's not being used by an in-flight CmdBuffer
2250// func_str is the name of the calling function
2251// Return VK_FALSE if no errors occur
2252// Return VK_TRUE if validation error occurs and callback returns VK_TRUE (to skip upcoming API call down the chain)
2253VkBool32 validateIdleDescriptorSet(const layer_data* my_data, VkDescriptorSet set, std::string func_str) {
2254 VkBool32 skip_call = VK_FALSE;
2255 auto set_node = my_data->setMap.find(set);
2256 if (set_node == my_data->setMap.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002257 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
2258 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that has not been allocated.", func_str.c_str(), (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002259 } else {
2260 if (set_node->second->in_use.load()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07002261 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
2262 "Cannot call %s() on descriptor set %" PRIxLEAST64 " that is in use by a command buffer.", func_str.c_str(), (uint64_t)(set));
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002263 }
2264 }
2265 return skip_call;
2266}
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002267static void invalidateBoundCmdBuffers(layer_data* dev_data, const SET_NODE* pSet)
2268{
2269 // Flag any CBs this set is bound to as INVALID
2270 for (auto cb : pSet->boundCmdBuffers) {
2271 auto cb_node = dev_data->commandBufferMap.find(cb);
2272 if (cb_node != dev_data->commandBufferMap.end()) {
2273 cb_node->second->state = CB_INVALID;
2274 }
2275 }
2276}
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002277// update DS mappings based on write and copy update arrays
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002278static 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 -06002279{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002280 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002281
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002282 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002283 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002284 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002285 // Validate Write updates
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002286 uint32_t i = 0;
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002287 for (i=0; i < descriptorWriteCount; i++) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002288 VkDescriptorSet ds = pWDS[i].dstSet;
Chia-I Wue2fc5522015-10-26 20:04:44 +08002289 SET_NODE* pSet = my_data->setMap[ds];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002290 // Set being updated cannot be in-flight
2291 if ((skipCall = validateIdleDescriptorSet(my_data, ds, "VkUpdateDescriptorSets")) == VK_TRUE)
2292 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002293 // If set is bound to any cmdBuffers, mark them invalid
2294 invalidateBoundCmdBuffers(my_data, pSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002295 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*) &pWDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06002296 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002297 // First verify valid update struct
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002298 if ((skipCall = validUpdateStruct(my_data, device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002299 break;
2300 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002301 uint32_t binding = 0, endIndex = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002302 binding = pWDS[i].dstBinding;
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002303 // Make sure that layout being updated has the binding being updated
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002304 if (pLayout->bindings.find(binding) == pLayout->bindings.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002305 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",
2306 "Descriptor Set %" PRIu64 " does not have binding to match update binding %u for update type %s!", (uint64_t)(ds), binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06002307 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002308 // Next verify that update falls within size of given binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002309 endIndex = getUpdateEndIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002310 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002311 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002312 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Young93ecb1d2016-01-13 13:47:16 -07002313 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 -06002314 "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 -06002315 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002316 uint32_t startIndex;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002317 startIndex = getUpdateStartIndex(my_data, device, pLayout, binding, pWDS[i].dstArrayElement, pUpdate);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06002318 // Layout bindings match w/ update, now verify that update type & stageFlags are the same for entire update
2319 if ((skipCall = validateUpdateConsistency(my_data, device, pLayout, pUpdate, startIndex, endIndex)) == VK_FALSE) {
2320 // The update is within bounds and consistent, but need to make sure contents make sense as well
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002321 if ((skipCall = validateUpdateContents(my_data, &pWDS[i], &pLayout->createInfo.pBindings[binding])) == VK_FALSE) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002322 // Update is good. Save the update info
2323 // Create new update struct for this set's shadow copy
2324 GENERIC_HEADER* pNewNode = NULL;
2325 skipCall |= shadowUpdateNode(my_data, device, pUpdate, &pNewNode);
2326 if (NULL == pNewNode) {
Mark Young93ecb1d2016-01-13 13:47:16 -07002327 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 -06002328 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
2329 } else {
2330 // Insert shadow node into LL of updates for this set
2331 pNewNode->pNext = pSet->pUpdateStructs;
2332 pSet->pUpdateStructs = pNewNode;
2333 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002334 for (uint32_t j = startIndex; j <= endIndex; j++) {
2335 assert(j<pSet->descriptorCount);
2336 pSet->ppDescriptors[j] = pNewNode;
2337 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002338 }
2339 }
2340 }
2341 }
2342 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002343 }
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002344 // Now validate copy updates
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08002345 for (i=0; i < descriptorCopyCount; ++i) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002346 SET_NODE *pSrcSet = NULL, *pDstSet = NULL;
2347 LAYOUT_NODE *pSrcLayout = NULL, *pDstLayout = NULL;
2348 uint32_t srcStartIndex = 0, srcEndIndex = 0, dstStartIndex = 0, dstEndIndex = 0;
2349 // For each copy make sure that update falls within given layout and that types match
Chia-I Wue2fc5522015-10-26 20:04:44 +08002350 pSrcSet = my_data->setMap[pCDS[i].srcSet];
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002351 pDstSet = my_data->setMap[pCDS[i].dstSet];
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07002352 // Set being updated cannot be in-flight
2353 if ((skipCall = validateIdleDescriptorSet(my_data, pDstSet->set, "VkUpdateDescriptorSets")) == VK_TRUE)
2354 return skipCall;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002355 invalidateBoundCmdBuffers(my_data, pDstSet);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002356 pSrcLayout = pSrcSet->pLayout;
2357 pDstLayout = pDstSet->pLayout;
2358 // Validate that src binding is valid for src set layout
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002359 if (pSrcLayout->bindings.find(pCDS[i].srcBinding) == pSrcLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002360 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 -06002361 "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 +08002362 i, pCDS[i].srcBinding, (uint64_t) pSrcLayout->layout, pSrcLayout->createInfo.bindingCount-1);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08002363 } else if (pDstLayout->bindings.find(pCDS[i].dstBinding) == pDstLayout->bindings.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002364 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 +08002365 "Copy descriptor update %u has dstBinding %u which is out of bounds for underlying SetLayout %#" PRIxLEAST64 " which only has bindings 0-%u.",
2366 i, pCDS[i].dstBinding, (uint64_t) pDstLayout->layout, pDstLayout->createInfo.bindingCount-1);
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002367 } else {
2368 // Proceed with validation. Bindings are ok, but make sure update is within bounds of given layout
2369 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 +08002370 dstEndIndex = getUpdateEndIndex(my_data, device, pDstLayout, pCDS[i].dstBinding, pCDS[i].dstArrayElement, (const GENERIC_HEADER*)&(pCDS[i]));
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002371 if (getBindingEndIndex(pSrcLayout, pCDS[i].srcBinding) < srcEndIndex) {
2372 pLayoutCI = &pSrcLayout->createInfo;
2373 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002374 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 -06002375 "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 +08002376 } else if (getBindingEndIndex(pDstLayout, pCDS[i].dstBinding) < dstEndIndex) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002377 pLayoutCI = &pDstLayout->createInfo;
2378 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002379 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 +08002380 "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 -06002381 } else {
2382 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 +08002383 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 +08002384 for (uint32_t j=0; j<pCDS[i].descriptorCount; ++j) {
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002385 // For copy just make sure that the types match and then perform the update
2386 if (pSrcLayout->descriptorTypes[srcStartIndex+j] != pDstLayout->descriptorTypes[dstStartIndex+j]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002387 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 -06002388 "Copy descriptor update index %u, update count #%u, has src update descriptor type %s that does not match overlapping dest descriptor type of %s!",
2389 i, j+1, string_VkDescriptorType(pSrcLayout->descriptorTypes[srcStartIndex+j]), string_VkDescriptorType(pDstLayout->descriptorTypes[dstStartIndex+j]));
2390 } else {
2391 // point dst descriptor at corresponding src descriptor
Tobin Ehlisf6585052015-12-17 11:48:42 -07002392 // TODO : This may be a hole. I believe copy should be its own copy,
2393 // otherwise a subsequent write update to src will incorrectly affect the copy
Tobin Ehlis8a62e632015-10-27 15:43:38 -06002394 pDstSet->ppDescriptors[j+dstStartIndex] = pSrcSet->ppDescriptors[j+srcStartIndex];
2395 }
2396 }
2397 }
2398 }
2399 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002400 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002401 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002402}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002403
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002404// Verify that given pool has descriptors that are being requested for allocation
Mark Lobodzinski39298632015-11-18 08:38:27 -07002405static 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 -06002406{
2407 VkBool32 skipCall = VK_FALSE;
2408 uint32_t i = 0, j = 0;
2409 for (i=0; i<count; ++i) {
2410 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pSetLayouts[i]);
2411 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002412 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 +08002413 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pSetLayouts[i]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002414 } else {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002415 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002416 for (j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002417 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
2418 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002419 if (poolSizeCount > pPoolNode->availableDescriptorTypeCount[typeIndex]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002420 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 -06002421 "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 -07002422 poolSizeCount, string_VkDescriptorType(pLayout->createInfo.pBindings[j].descriptorType), (uint64_t) pPoolNode->pool, pPoolNode->availableDescriptorTypeCount[typeIndex]);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002423 } else { // Decrement available descriptors of this type
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002424 pPoolNode->availableDescriptorTypeCount[typeIndex] -= poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002425 }
2426 }
2427 }
2428 }
2429 return skipCall;
2430}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002431
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002432// Free the shadowed update node for this Set
2433// NOTE : Calls to this function should be wrapped in mutex
2434static void freeShadowUpdateTree(SET_NODE* pSet)
2435{
2436 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
2437 pSet->pUpdateStructs = NULL;
2438 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
2439 // Clear the descriptor mappings as they will now be invalid
2440 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
2441 while(pShadowUpdate) {
2442 pFreeUpdate = pShadowUpdate;
2443 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
2444 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002445 VkWriteDescriptorSet * pWDS = NULL;
2446 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002447 void** ppToFree = NULL;
2448 switch (pFreeUpdate->sType)
2449 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002450 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
2451 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
Tony Barbourb1947942015-11-02 11:46:29 -07002452 switch (pWDS->descriptorType) {
2453 case VK_DESCRIPTOR_TYPE_SAMPLER:
2454 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
2455 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2456 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
2457 {
2458 delete[] pWDS->pImageInfo;
2459 }
2460 break;
2461 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2462 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
2463 {
2464 delete[] pWDS->pTexelBufferView;
2465 }
2466 break;
2467 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2468 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2469 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2470 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
2471 {
2472 delete[] pWDS->pBufferInfo;
2473 }
2474 break;
2475 default:
2476 break;
Courtney Goeltzenleuchteraa132e72015-10-22 15:31:56 -06002477 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002478 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002479 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002480 break;
2481 default:
2482 assert(0);
2483 break;
2484 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002485 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002486 }
2487}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002488
Tobin Ehlis793ad302015-04-03 12:01:11 -06002489// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002491static void deletePools(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002492{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002493 if (my_data->descriptorPoolMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002494 return;
Mark Lobodzinski39298632015-11-18 08:38:27 -07002495 for (auto ii=my_data->descriptorPoolMap.begin(); ii!=my_data->descriptorPoolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002496 SET_NODE* pSet = (*ii).second->pSets;
2497 SET_NODE* pFreeSet = pSet;
2498 while (pSet) {
2499 pFreeSet = pSet;
2500 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002501 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002502 // Free Update shadow struct tree
2503 freeShadowUpdateTree(pFreeSet);
2504 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12002505 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002506 }
2507 delete pFreeSet;
2508 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002509 delete (*ii).second;
2510 }
Mark Lobodzinski39298632015-11-18 08:38:27 -07002511 my_data->descriptorPoolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002512}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002513
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002514// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002515// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002516static void deleteLayouts(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002517{
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002518 if (my_data->descriptorSetLayoutMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -06002519 return;
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002520 for (auto ii=my_data->descriptorSetLayoutMap.begin(); ii!=my_data->descriptorSetLayoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002521 LAYOUT_NODE* pLayout = (*ii).second;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002522 if (pLayout->createInfo.pBindings) {
Chia-I Wud50a7d72015-10-26 20:48:51 +08002523 for (uint32_t i=0; i<pLayout->createInfo.bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002524 if (pLayout->createInfo.pBindings[i].pImmutableSamplers)
2525 delete[] pLayout->createInfo.pBindings[i].pImmutableSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002526 }
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07002527 delete[] pLayout->createInfo.pBindings;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002528 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002529 delete pLayout;
2530 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07002531 my_data->descriptorSetLayoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002532}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002533
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002534// Currently clearing a set is removing all previous updates to that set
2535// TODO : Validate if this is correct clearing behavior
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002536static void clearDescriptorSet(layer_data* my_data, VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002537{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002538 SET_NODE* pSet = getSetNode(my_data, set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002539 if (!pSet) {
2540 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06002541 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002542 loader_platform_thread_lock_mutex(&globalLock);
2543 freeShadowUpdateTree(pSet);
2544 loader_platform_thread_unlock_mutex(&globalLock);
2545 }
2546}
2547
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002548static void clearDescriptorPool(layer_data* my_data, const VkDevice device, const VkDescriptorPool pool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002549{
Mark Lobodzinski39298632015-11-18 08:38:27 -07002550 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002551 if (!pPool) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002552 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 +08002553 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", (uint64_t) pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002554 } else {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002555 // TODO: validate flags
Tobin Ehlis793ad302015-04-03 12:01:11 -06002556 // For every set off of this pool, clear it
2557 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002558 while (pSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002559 clearDescriptorSet(my_data, pSet->set);
Mark Lobodzinskidcce0792016-01-04 09:40:19 -07002560 pSet = pSet->pNext;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002561 }
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06002562 // Reset available count to max count for this pool
2563 for (uint32_t i=0; i<pPool->availableDescriptorTypeCount.size(); ++i) {
2564 pPool->availableDescriptorTypeCount[i] = pPool->maxDescriptorTypeCount[i];
2565 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002566 }
2567}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002568
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002569// For given CB object, fetch associated CB Node from map
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002570static GLOBAL_CB_NODE* getCBNode(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002571{
2572 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002573 if (my_data->commandBufferMap.count(cb) == 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002574 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002575 // TODO : How to pass cb as srcObj here?
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002576 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
Mark Youngee3f3a22016-01-25 12:18:32 -07002577 "Attempt to use CommandBuffer %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002578 return NULL;
2579 }
2580 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002581 return my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002582}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002583
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002584// Free all CB Nodes
2585// NOTE : Calls to this function should be wrapped in mutex
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002586static void deleteCommandBuffers(layer_data* my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002587{
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002588 if (my_data->commandBufferMap.size() <= 0) {
David Pinedod8f83d82015-04-27 16:36:17 -06002589 return;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07002590 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002591 for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002592 delete (*ii).second;
2593 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002594 my_data->commandBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002595}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002596
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002597static 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 -06002598{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002599 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 -07002600 (uint64_t)cb, __LINE__, DRAWSTATE_NO_BEGIN_COMMAND_BUFFER, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002601 "You must call vkBeginCommandBuffer() before this call to %s", caller_name);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002602}
Michael Lentine3dea6512015-10-28 15:55:18 -07002603
Mark Youngb20a6a82016-01-07 15:41:43 -07002604VkBool32 validateCmdsInCmdBuffer(const layer_data* dev_data, const GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd_type) {
2605 if (!pCB->activeRenderPass) return VK_FALSE;
2606 VkBool32 skip_call = VK_FALSE;
Michael Lentine2e068b22015-12-29 16:05:27 -06002607 if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS && cmd_type != CMD_EXECUTECOMMANDS) {
2608 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2609 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "Commands cannot be called in a subpass using secondary command buffers.");
2610 } else if (pCB->activeSubpassContents == VK_SUBPASS_CONTENTS_INLINE && cmd_type == CMD_EXECUTECOMMANDS) {
2611 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
2612 DRAWSTATE_INVALID_COMMAND_BUFFER, "DS", "vkCmdExecuteCommands() cannot be called in a subpass using inline commands.");
2613 }
Michael Lentine3dea6512015-10-28 15:55:18 -07002614 return skip_call;
2615}
2616
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002617// Add specified CMD to the CmdBuffer in given pCB, flagging errors if CB is not
2618// in the recording state or if there's an issue with the Cmd ordering
2619static 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 -06002620{
Tobin Ehlis61b36f32015-12-16 08:19:42 -07002621 VkBool32 skipCall = VK_FALSE;
2622 if (pCB->state != CB_RECORDING) {
2623 skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name);
2624 skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002625 CMD_NODE cmdNode = {};
2626 // init cmd node and append to end of cmd LL
2627 cmdNode.cmdNumber = ++pCB->numCmds;
2628 cmdNode.type = cmd;
2629 pCB->cmds.push_back(cmdNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002630 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002631 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002632}
Tobin Ehlisef694652016-01-19 12:03:34 -07002633// Reset the command buffer state
2634// Maintain the createInfo and set state to CB_NEW, but clear all other state
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002635static void resetCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002636{
Tobin Ehlis74714d22016-01-25 15:24:34 -08002637 GLOBAL_CB_NODE* pCB = my_data->commandBufferMap[cb];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002638 if (pCB) {
Tobin Ehlis9a874302016-01-20 10:25:29 -07002639 pCB->cmds.clear();
Tobin Ehlisef694652016-01-19 12:03:34 -07002640 // Reset CB state (note that createInfo is not cleared)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002641 pCB->commandBuffer = cb;
Michael Lentineabc5e922015-10-12 11:30:14 -05002642 memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07002643 memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05002644 pCB->fence = 0;
2645 pCB->numCmds = 0;
2646 memset(pCB->drawCount, 0, NUM_DRAW_TYPES * sizeof(uint64_t));
2647 pCB->state = CB_NEW;
2648 pCB->submitCount = 0;
2649 pCB->status = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002650 pCB->lastBoundPipeline = 0;
2651 pCB->viewports.clear();
2652 pCB->scissors.clear();
2653 pCB->lineWidth = 0;
2654 pCB->depthBiasConstantFactor = 0;
2655 pCB->depthBiasClamp = 0;
2656 pCB->depthBiasSlopeFactor = 0;
2657 memset(pCB->blendConstants, 0, 4 * sizeof(float));
2658 pCB->minDepthBounds = 0;
2659 pCB->maxDepthBounds = 0;
2660 memset(&pCB->front, 0, sizeof(stencil_data));
2661 memset(&pCB->back, 0, sizeof(stencil_data));
2662 pCB->lastBoundDescriptorSet = 0;
2663 pCB->lastBoundPipelineLayout = 0;
2664 pCB->activeRenderPass = 0;
2665 pCB->activeSubpass = 0;
Tobin Ehlise6e574b2016-01-24 23:25:31 -07002666 // Before clearing uniqueBoundSets, remove this CB off of its boundCBs
2667 for (auto set : pCB->uniqueBoundSets) {
2668 auto set_node = my_data->setMap.find(set);
2669 if (set_node != my_data->setMap.end()) {
2670 set_node->second->boundCmdBuffers.erase(pCB->commandBuffer);
2671 }
2672 }
2673 pCB->uniqueBoundSets.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002674 pCB->framebuffer = 0;
Michael Lentineabc5e922015-10-12 11:30:14 -05002675 pCB->boundDescriptorSets.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07002676 pCB->drawData.clear();
2677 pCB->currentDrawData.buffers.clear();
Michael Lentineabc5e922015-10-12 11:30:14 -05002678 pCB->imageLayoutMap.clear();
Michael Lentineb887b0a2015-12-29 14:12:11 -06002679 pCB->waitedEvents.clear();
2680 pCB->waitedEventsBeforeQueryReset.clear();
2681 pCB->queryToStateMap.clear();
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07002682 pCB->secondaryCommandBuffers.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002683 }
2684}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002685
Tobin Ehlis963a4042015-09-29 08:18:34 -06002686// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002687static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
2688{
2689 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002690 if (0 != pPipe->pAttachments[i].colorWriteMask) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002691 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
2692 }
2693 }
2694 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06002695 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
2696 }
Cody Northrop82485a82015-08-18 15:21:16 -06002697 if (pPipe->dsStateCI.stencilTestEnable) {
2698 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002699 }
Tobin Ehlisd332f282015-10-02 11:00:56 -06002700 // Account for any dynamic state not set via this PSO
2701 if (!pPipe->dynStateCI.dynamicStateCount) { // All state is static
2702 pCB->status = CBSTATUS_ALL;
2703 } else {
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002704 // First consider all state on
2705 // Then unset any state that's noted as dynamic in PSO
2706 // Finally OR that into CB statemask
2707 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002708 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
2709 switch (pPipe->dynStateCI.pDynamicStates[i]) {
2710 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002711 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002712 break;
2713 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002714 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002715 break;
2716 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002717 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002718 break;
2719 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002720 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002721 break;
2722 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002723 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002724 break;
2725 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002726 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002727 break;
2728 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002729 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002730 break;
2731 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002732 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002733 break;
2734 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002735 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002736 break;
2737 default:
2738 // TODO : Flag error here
2739 break;
2740 }
2741 }
Tobin Ehlis5e5a1e92015-10-01 09:24:40 -06002742 pCB->status |= psoDynStateMask;
Tobin Ehlis963a4042015-09-29 08:18:34 -06002743 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002744}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002745
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002746// Print the last bound Gfx Pipeline
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002747static VkBool32 printPipeline(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002748{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002749 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002750 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002751 if (pCB) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002752 PIPELINE_NODE *pPipeTrav = getPipeline(my_data, pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002753 if (!pPipeTrav) {
2754 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06002755 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002756 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Michael Lentine010f4692015-11-03 16:19:46 -08002757 "%s", vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002758 }
2759 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002760 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002761}
Tobin Ehlis559c6382015-11-05 09:52:49 -07002762
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002763// Print details of DS config to stdout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002764static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002765{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002766 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002767 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 -06002768 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06002769 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002770 SET_NODE* pSet = getSetNode(my_data, pCB->lastBoundDescriptorSet);
Mark Lobodzinski39298632015-11-18 08:38:27 -07002771 DESCRIPTOR_POOL_NODE* pPool = getPoolNode(my_data, pSet->pool);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002772 // Print out pool details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002773 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002774 "Details for pool %#" PRIxLEAST64 ".", (uint64_t) pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002775 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002776 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002777 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002778 // Print out set details
2779 char prefix[10];
2780 uint32_t index = 0;
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002781 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 +08002782 "Details for descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002783 LAYOUT_NODE* pLayout = pSet->pLayout;
2784 // Print layout details
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002785 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07002786 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (uint64_t)(pLayout->layout), (uint64_t)(pSet->set));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002787 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002788 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002789 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 -06002790 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06002791 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002792 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
2793 if (pUpdate) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002794 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 +08002795 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", (uint64_t) pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002796 sprintf(prefix, " [UC] ");
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002797 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 -08002798 "%s", dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002799 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06002800 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002801 if (0 != pSet->descriptorCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002802 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 +08002803 "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 -06002804 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002805 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 +08002806 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", (uint64_t) pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06002807 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002808 }
2809 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002810 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002811}
2812
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002813static void printCB(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002814{
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002815 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002816 if (pCB && pCB->cmds.size() > 0) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002817 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 -06002818 "Cmds in CB %p", (void*)cb);
Tobin Ehlis9a874302016-01-20 10:25:29 -07002819 vector<CMD_NODE> cmds = pCB->cmds;
2820 for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002821 // TODO : Need to pass cb as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07002822 log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS",
Tobin Ehlis9a874302016-01-20 10:25:29 -07002823 " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002824 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002825 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002826 // Nothing to print
2827 }
2828}
2829
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002830static VkBool32 synchAndPrintDSConfig(layer_data* my_data, const VkCommandBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002831{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002832 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002833 if (!(my_data->report_data->active_flags & VK_DEBUG_REPORT_INFO_BIT_EXT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002834 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06002835 }
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002836 skipCall |= printDSConfig(my_data, cb);
2837 skipCall |= printPipeline(my_data, cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002838 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002839}
2840
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002841// Flags validation error if the associated call is made inside a render pass. The apiName
2842// routine should ONLY be called outside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002843static VkBool32 insideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002844{
2845 VkBool32 inside = VK_FALSE;
2846 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002847 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 -07002848 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002849 "%s: It is invalid to issue this call inside an active render pass (%#" PRIxLEAST64 ")",
Chia-I Wue2fc5522015-10-26 20:04:44 +08002850 apiName, (uint64_t) pCB->activeRenderPass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002851 }
2852 return inside;
2853}
2854
2855// Flags validation error if the associated call is made outside a render pass. The apiName
2856// routine should ONLY be called inside a render pass.
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06002857static VkBool32 outsideRenderPass(const layer_data* my_data, GLOBAL_CB_NODE *pCB, const char *apiName)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002858{
2859 VkBool32 outside = VK_FALSE;
Mark Lobodzinski74635932015-12-18 15:35:38 -07002860 if (((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
2861 (!pCB->activeRenderPass)) ||
2862 ((pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) &&
2863 (!pCB->activeRenderPass) &&
2864 !(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002865 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 -07002866 (uint64_t)pCB->commandBuffer, __LINE__, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Mark Lobodzinski5495d132015-09-30 16:19:16 -06002867 "%s: This call must be issued inside an active render pass.", apiName);
2868 }
2869 return outside;
2870}
2871
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -07002872static void init_draw_state(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002873{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002874 uint32_t report_flags = 0;
2875 uint32_t debug_action = 0;
2876 FILE *log_output = NULL;
2877 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002878 VkDebugReportCallbackEXT callback;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002879 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002880 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
2881 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002882
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002883 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002884 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002885 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06002886 log_output = getLayerLogOutput(option_str, "DrawState");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002887 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002888 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002889 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002890 dbgInfo.pfnCallback = log_callback;
2891 dbgInfo.pUserData = log_output;
2892 dbgInfo.flags = report_flags;
2893 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002894 my_data->logging_callback.push_back(callback);
2895 }
2896
2897 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002898 VkDebugReportCallbackCreateInfoEXT dbgInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002899 memset(&dbgInfo, 0, sizeof(dbgInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002900 dbgInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002901 dbgInfo.pfnCallback = win32_debug_output_msg;
2902 dbgInfo.pUserData = log_output;
2903 dbgInfo.flags = report_flags;
2904 layer_create_msg_callback(my_data->report_data, &dbgInfo, pAllocator, &callback);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002905 my_data->logging_callback.push_back(callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002906 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002907
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002908 if (!globalLockInitialized)
2909 {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002910 loader_platform_thread_create_mutex(&globalLock);
2911 globalLockInitialized = 1;
2912 }
2913}
2914
Chia-I Wu9ab61502015-11-06 06:42:02 +08002915VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002916{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002917 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002918
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002919 assert(chain_info->u.pLayerInfo);
2920 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
2921 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
2922 if (fpCreateInstance == NULL) {
2923 return VK_ERROR_INITIALIZATION_FAILED;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002924 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07002925
2926 // Advance the link info for the next element on the chain
2927 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
2928
2929 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
2930 if (result != VK_SUCCESS)
2931 return result;
2932
2933 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
2934 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
2935 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
2936
2937 my_data->report_data = debug_report_create_instance(
2938 my_data->instance_dispatch_table,
2939 *pInstance,
2940 pCreateInfo->enabledExtensionCount,
2941 pCreateInfo->ppEnabledExtensionNames);
2942
2943 init_draw_state(my_data, pAllocator);
2944
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002945 return result;
2946}
2947
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002948/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +08002949VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002950{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07002951 // TODOSC : Shouldn't need any customization here
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002952 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002953 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
2954 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002955 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002956
2957 // Clean up logging callback, if any
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002958 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07002959 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07002960 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter62d945a2015-10-05 15:58:38 -06002961 my_data->logging_callback.pop_back();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002962 }
2963
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06002964 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis0b632332015-10-07 09:38:40 -06002965 delete my_data->instance_dispatch_table;
2966 layer_data_map.erase(key);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06002967 // TODO : Potential race here with separate threads creating/destroying instance
Tobin Ehlis0b632332015-10-07 09:38:40 -06002968 if (layer_data_map.empty()) {
Mike Stroyanfcb4ba62015-08-18 15:56:18 -06002969 // Release mutex when destroying last instance.
2970 loader_platform_thread_delete_mutex(&globalLock);
2971 globalLockInitialized = 0;
2972 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002973}
2974
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002975static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
2976{
Tony Barbour3b4732f2015-07-13 13:37:24 -06002977 uint32_t i;
Tobin Ehlis0b632332015-10-07 09:38:40 -06002978 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
2979 dev_data->device_extensions.debug_marker_enabled = false;
Michael Lentineabc5e922015-10-12 11:30:14 -05002980 dev_data->device_extensions.wsi_enabled = false;
2981
2982
2983 VkLayerDispatchTable *pDisp = dev_data->device_dispatch_table;
2984 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
2985
Michael Lentineabc5e922015-10-12 11:30:14 -05002986 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
2987 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
2988 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
2989 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07002990 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002991
Jon Ashburnf19916e2016-01-11 13:12:43 -07002992 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -07002993 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Michael Lentineabc5e922015-10-12 11:30:14 -05002994 dev_data->device_extensions.wsi_enabled = true;
2995 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06002996 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06002997 /* Found a matching extension name, mark it enabled and init dispatch table*/
Tobin Ehlis0b632332015-10-07 09:38:40 -06002998 dev_data->device_extensions.debug_marker_enabled = true;
Jon Ashburn1d4b1282015-12-10 19:12:21 -07002999 initDebugMarkerTable(device);
3000
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003001 }
Jon Ashburne68a9ff2015-05-25 14:11:37 -06003002 }
3003}
3004
Chia-I Wu9ab61502015-11-06 06:42:02 +08003005VK_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 -06003006{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003007 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -07003008
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003009 assert(chain_info->u.pLayerInfo);
3010 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
3011 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
3012 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
3013 if (fpCreateDevice == NULL) {
3014 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003015 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07003016
3017 // Advance the link info for the next element on the chain
3018 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
3019
3020 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
3021 if (result != VK_SUCCESS) {
3022 return result;
3023 }
3024
3025 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
3026 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
3027
3028 // Setup device dispatch table
3029 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
3030 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
3031
3032 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
3033 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
3034 // Get physical device limits for this device
3035 my_instance_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_instance_data->physDevPropertyMap[*pDevice]));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003036 return result;
3037}
Tobin Ehlis559c6382015-11-05 09:52:49 -07003038
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003039// prototype
3040static void deleteRenderPasses(layer_data*);
Chia-I Wu9ab61502015-11-06 06:42:02 +08003041VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003042{
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003043 // TODOSC : Shouldn't need any customization here
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06003044 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003045 layer_data* dev_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003046 // Free all the memory
3047 loader_platform_thread_lock_mutex(&globalLock);
3048 deletePipelines(dev_data);
3049 deleteRenderPasses(dev_data);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003050 deleteCommandBuffers(dev_data);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003051 deletePools(dev_data);
3052 deleteLayouts(dev_data);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003053 dev_data->imageViewMap.clear();
3054 dev_data->imageMap.clear();
3055 dev_data->bufferViewMap.clear();
3056 dev_data->bufferMap.clear();
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003057 loader_platform_thread_unlock_mutex(&globalLock);
3058
Chia-I Wuf7458c52015-10-26 21:10:41 +08003059 dev_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06003060 tableDebugMarkerMap.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003061 delete dev_data->device_dispatch_table;
3062 layer_data_map.erase(key);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003063}
3064
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003065static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003066 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07003067 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -07003068 VK_EXT_DEBUG_REPORT_SPEC_VERSION
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003069 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003070};
3071
Chia-I Wu9ab61502015-11-06 06:42:02 +08003072VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003073 const char *pLayerName,
3074 uint32_t *pCount,
3075 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003076{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003077 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003078}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003079
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003080static const VkLayerProperties ds_global_layers[] = {
3081 {
Michael Lentine03107b42015-12-11 10:49:51 -08003082 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003083 VK_API_VERSION,
3084 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003085 "Validation layer: draw_state",
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -07003086 }
3087};
3088
Chia-I Wu9ab61502015-11-06 06:42:02 +08003089VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003090 uint32_t *pCount,
3091 VkLayerProperties* pProperties)
3092{
3093 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
3094 ds_global_layers,
3095 pCount, pProperties);
3096}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003097
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003098static const VkExtensionProperties ds_device_extensions[] = {
3099 {
3100 DEBUG_MARKER_EXTENSION_NAME,
3101 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003102 }
3103};
3104
3105static const VkLayerProperties ds_device_layers[] = {
3106 {
Michael Lentine1f8d4412016-01-19 14:19:38 -06003107 "VK_LAYER_LUNARG_draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003108 VK_API_VERSION,
3109 VK_MAKE_VERSION(0, 1, 0),
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07003110 "Validation layer: draw_state",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003111 }
3112};
3113
Chia-I Wu9ab61502015-11-06 06:42:02 +08003114VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003115 VkPhysicalDevice physicalDevice,
3116 const char* pLayerName,
3117 uint32_t* pCount,
3118 VkExtensionProperties* pProperties)
3119{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003120 // DrawState does not have any physical device extensions
Jon Ashburn751c4842015-11-02 17:37:20 -07003121 if (pLayerName == NULL) {
3122 dispatch_key key = get_dispatch_key(physicalDevice);
3123 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003124 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(
Jon Ashburn751c4842015-11-02 17:37:20 -07003125 physicalDevice,
3126 NULL,
3127 pCount,
3128 pProperties);
3129 } else {
3130 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions),
3131 ds_device_extensions,
3132 pCount, pProperties);
3133 }
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003134}
3135
Chia-I Wu9ab61502015-11-06 06:42:02 +08003136VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003137 VkPhysicalDevice physicalDevice,
3138 uint32_t* pCount,
3139 VkLayerProperties* pProperties)
3140{
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003141 /* DrawState physical device layers are the same as global */
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003142 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
3143 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06003144}
3145
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07003146VkBool32 ValidateCmdBufImageLayouts(VkCommandBuffer cmdBuffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003147 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05003148 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
3149 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
3150 for (auto cb_image_data : pCB->imageLayoutMap) {
3151 auto image_data = dev_data->imageLayoutMap.find(cb_image_data.first);
3152 if (image_data == dev_data->imageLayoutMap.end()) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003153 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_INVALID_IMAGE_LAYOUT, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07003154 "Cannot submit cmd buffer using deleted image %" PRIu64 ".", (uint64_t)(cb_image_data.first));
Michael Lentineabc5e922015-10-12 11:30:14 -05003155 } else {
3156 if (dev_data->imageLayoutMap[cb_image_data.first]->layout != cb_image_data.second.initialLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07003157 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 -05003158 "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);
3159 }
3160 dev_data->imageLayoutMap[cb_image_data.first]->layout = cb_image_data.second.layout;
3161 }
3162 }
3163 return skip_call;
3164}
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003165// Track which resources are in-flight by atomically incrementing their "in_use" count
Mark Young7a69c302016-01-07 09:48:47 -07003166VkBool32 validateAndIncrementResources(layer_data* my_data, GLOBAL_CB_NODE* pCB) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003167 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003168 for (auto drawDataElement : pCB->drawData) {
3169 for (auto buffer : drawDataElement.buffers) {
3170 auto buffer_data = my_data->bufferMap.find(buffer);
3171 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003172 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_INVALID_BUFFER, "DS",
3173 "Cannot submit cmd buffer using deleted buffer %" PRIu64 ".", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003174 } else {
3175 buffer_data->second.in_use.fetch_add(1);
3176 }
3177 }
3178 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003179 for (auto set : pCB->uniqueBoundSets) {
3180 auto setNode = my_data->setMap.find(set);
3181 if (setNode == my_data->setMap.end()) {
3182 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, (uint64_t)(set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
3183 "Cannot submit cmd buffer using deleted descriptor set %" PRIu64 ".", (uint64_t)(set));
3184 } else {
3185 setNode->second->in_use.fetch_add(1);
3186 }
3187 }
Michael Lentine2e068b22015-12-29 16:05:27 -06003188 return skip_call;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003189}
3190
3191void decrementResources(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3192 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
3193 for (auto drawDataElement : pCB->drawData) {
3194 for (auto buffer : drawDataElement.buffers) {
3195 auto buffer_data = my_data->bufferMap.find(buffer);
3196 if (buffer_data != my_data->bufferMap.end()) {
3197 buffer_data->second.in_use.fetch_sub(1);
3198 }
3199 }
3200 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003201 for (auto set : pCB->uniqueBoundSets) {
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003202 auto setNode = my_data->setMap.find(set);
3203 if (setNode != my_data->setMap.end()) {
3204 setNode->second->in_use.fetch_sub(1);
3205 }
3206 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003207 for (auto queryStatePair : pCB->queryToStateMap) {
3208 my_data->queryToStateMap[queryStatePair.first] = queryStatePair.second;
3209 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003210}
3211
3212void decrementResources(layer_data* my_data, uint32_t fenceCount, const VkFence* pFences) {
3213 for (uint32_t i = 0; i < fenceCount; ++i) {
3214 auto fence_data = my_data->fenceMap.find(pFences[i]);
3215 if (fence_data == my_data->fenceMap.end() || !fence_data->second.needsSignaled) return;
3216 fence_data->second.needsSignaled = false;
3217 if (fence_data->second.priorFence != VK_NULL_HANDLE) {
3218 decrementResources(my_data, 1, &fence_data->second.priorFence);
3219 }
3220 for (auto cmdBuffer : fence_data->second.cmdBuffers) {
3221 decrementResources(my_data, cmdBuffer);
3222 }
3223 }
3224}
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003225
Michael Lentine700b0aa2015-10-30 17:57:32 -07003226void decrementResources(layer_data* my_data, VkQueue queue) {
3227 auto queue_data = my_data->queueMap.find(queue);
3228 if (queue_data != my_data->queueMap.end()) {
3229 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3230 decrementResources(my_data, cmdBuffer);
3231 }
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07003232 queue_data->second.untrackedCmdBuffers.clear();
Michael Lentine700b0aa2015-10-30 17:57:32 -07003233 decrementResources(my_data, 1, &queue_data->second.priorFence);
3234 }
3235}
3236
3237void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence) {
3238 auto queue_data = my_data->queueMap.find(queue);
3239 if (fence != VK_NULL_HANDLE) {
3240 VkFence priorFence = VK_NULL_HANDLE;
3241 if (queue_data != my_data->queueMap.end()) {
3242 priorFence = queue_data->second.priorFence;
3243 queue_data->second.priorFence = fence;
3244 for (auto cmdBuffer : queue_data->second.untrackedCmdBuffers) {
3245 my_data->fenceMap[fence].cmdBuffers.push_back(cmdBuffer);
3246 }
3247 queue_data->second.untrackedCmdBuffers.clear();
3248 }
3249 my_data->fenceMap[fence].cmdBuffers.clear();
3250 my_data->fenceMap[fence].priorFence = priorFence;
3251 my_data->fenceMap[fence].needsSignaled = true;
Tobin Ehlis74714d22016-01-25 15:24:34 -08003252 my_data->fenceMap[fence].queue = queue;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003253 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003254 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3255 my_data->fenceMap[fence].cmdBuffers.push_back(secondaryCmdBuffer);
3256 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003257 my_data->fenceMap[fence].cmdBuffers.push_back(pCmdBuffers[i]);
3258 }
3259 } else {
3260 if (queue_data != my_data->queueMap.end()) {
3261 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003262 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
3263 queue_data->second.untrackedCmdBuffers.push_back(secondaryCmdBuffer);
3264 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003265 queue_data->second.untrackedCmdBuffers.push_back(pCmdBuffers[i]);
3266 }
3267 }
3268 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003269 if (queue_data != my_data->queueMap.end()) {
3270 for (uint32_t i = 0; i < cmdBufferCount; ++i) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003271 // Add cmdBuffers to both the global set and queue set
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003272 for (auto secondaryCmdBuffer : my_data->commandBufferMap[pCmdBuffers[i]]->secondaryCommandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003273 my_data->globalInFlightCmdBuffers.insert(secondaryCmdBuffer);
3274 queue_data->second.inFlightCmdBuffers.insert(secondaryCmdBuffer);
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07003275 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003276 my_data->globalInFlightCmdBuffers.insert(pCmdBuffers[i]);
3277 queue_data->second.inFlightCmdBuffers.insert(pCmdBuffers[i]);
3278 }
3279 }
3280}
3281
3282static VkBool32 validateCommandBufferState(layer_data* dev_data, GLOBAL_CB_NODE* pCB)
3283{
3284 // Track in-use for resources off of primary and any secondary CBs
3285 VkBool32 skipCall = validateAndIncrementResources(dev_data, pCB);
3286 if (!pCB->secondaryCommandBuffers.empty()) {
3287 for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
3288 skipCall |= validateAndIncrementResources(dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
3289 }
3290 }
3291 if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
3292 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",
3293 "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
3294 (uint64_t)(pCB->commandBuffer), pCB->submitCount);
3295 }
3296 // Validate that cmd buffers have been updated
3297 if (CB_RECORDED != pCB->state) {
3298 if (CB_INVALID == pCB->state) {
3299 // Inform app of reason CB invalid
3300 if (!pCB->destroyedSets.empty()) {
3301 std::stringstream set_string;
3302 for (auto set : pCB->destroyedSets) {
3303 set_string << " " << set;
3304 }
3305 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
3306 "You are submitting command buffer %#" PRIxLEAST64 " that is invalid because it had the following bound descriptor set(s) destroyed: %s", (uint64_t)(pCB->commandBuffer), set_string.str().c_str());
3307 }
3308 if (!pCB->updatedSets.empty()) {
3309 std::stringstream set_string;
3310 for (auto set : pCB->updatedSets) {
3311 set_string << " " << set;
3312 }
3313 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER, "DS",
3314 "You are submitting command buffer %#" PRIxLEAST64 " that is invalid because it had the following bound descriptor set(s) updated: %s", (uint64_t)(pCB->commandBuffer), set_string.str().c_str());
3315 }
3316 } else { // Flag error for using CB w/o vkEndCommandBuffer() called
3317 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_NO_END_COMMAND_BUFFER, "DS",
3318 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
3319 loader_platform_thread_unlock_mutex(&globalLock);
3320 return VK_ERROR_VALIDATION_FAILED_EXT;
3321 }
3322 }
3323 // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing on device
3324 if (!(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
3325 if (dev_data->globalInFlightCmdBuffers.find(pCB->commandBuffer) != dev_data->globalInFlightCmdBuffers.end()) {
3326 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
3327 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", (uint64_t)(pCB->commandBuffer));
Michael Lentineb887b0a2015-12-29 14:12:11 -06003328 }
3329 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003330}
3331
Chia-I Wu9ab61502015-11-06 06:42:02 +08003332VK_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 -06003333{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003334 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003335 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis0b632332015-10-07 09:38:40 -06003336 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003337 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003338 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Michael Lentine15a47882016-01-06 10:05:48 -06003339 for (uint32_t i=0; i < submit->waitSemaphoreCount; ++i) {
3340 if (dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]]) {
3341 dev_data->semaphoreSignaledMap[submit->pWaitSemaphores[i]] = 0;
3342 } else {
3343 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",
3344 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07003345 (uint64_t)(queue), (uint64_t)(submit->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06003346 }
3347 }
3348 for (uint32_t i=0; i < submit->signalSemaphoreCount; ++i) {
3349 dev_data->semaphoreSignaledMap[submit->pSignalSemaphores[i]] = 1;
3350 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08003351 for (uint32_t i=0; i < submit->commandBufferCount; i++) {
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07003352
3353#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
3354 skipCall |= ValidateCmdBufImageLayouts(submit->pCommandBuffers[i]);
3355#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
3356
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06003357 pCB = getCBNode(dev_data, submit->pCommandBuffers[i]);
3358 loader_platform_thread_lock_mutex(&globalLock);
3359 pCB->submitCount++; // increment submit count
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003360 skipCall |= validateCommandBufferState(dev_data, pCB);
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06003361 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06003362 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003363 trackCommandBuffers(dev_data, queue, submit->commandBufferCount, submit->pCommandBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003364 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003365 if (VK_FALSE == skipCall)
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08003366 return dev_data->device_dispatch_table->QueueSubmit(queue, submitCount, pSubmits, fence);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003367 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003368}
3369
Mark Youngb20a6a82016-01-07 15:41:43 -07003370VkBool32 cleanInFlightCmdBuffer(layer_data* my_data, VkCommandBuffer cmdBuffer) {
3371 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003372 GLOBAL_CB_NODE* pCB = getCBNode(my_data, cmdBuffer);
Mark Lobodzinskia9e7c042016-01-25 14:27:49 -07003373 if (pCB) {
3374 for (auto queryEventsPair : pCB->waitedEventsBeforeQueryReset) {
3375 for (auto event : queryEventsPair.second) {
3376 if (my_data->eventMap[event].needsSignaled) {
3377 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",
3378 "Cannot get query results on queryPool %" PRIu64 " with index %d which was guarded by unsignaled event %" PRIu64 ".",
3379 (uint64_t)(queryEventsPair.first.pool), queryEventsPair.first.index, (uint64_t)(event));
3380 }
Michael Lentineb887b0a2015-12-29 14:12:11 -06003381 }
3382 }
3383 }
3384 return skip_call;
3385}
Tobin Ehlis74714d22016-01-25 15:24:34 -08003386// Remove given cmd_buffer from the global inFlight set.
3387// Also, if given queue is valid, then remove the cmd_buffer from that queues
3388// inFlightCmdBuffer set. Finally, check all other queues and if given cmd_buffer
3389// is still in flight on another queue, add it back into the global set.
3390static inline void removeInFlightCmdBuffer(layer_data* dev_data, VkCommandBuffer cmd_buffer, VkQueue queue)
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003391{
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003392 // Pull it off of global list initially, but if we find it in any other queue list, add it back in
Tobin Ehlis74714d22016-01-25 15:24:34 -08003393 dev_data->globalInFlightCmdBuffers.erase(cmd_buffer);
3394 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
3395 dev_data->queueMap[queue].inFlightCmdBuffers.erase(cmd_buffer);
3396 for (auto q : dev_data->queues) {
3397 if ((q != queue) && (dev_data->queueMap[q].inFlightCmdBuffers.find(cmd_buffer) != dev_data->queueMap[q].inFlightCmdBuffers.end())) {
3398 dev_data->globalInFlightCmdBuffers.insert(cmd_buffer);
3399 break;
3400 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003401 }
3402 }
3403}
Michael Lentineb887b0a2015-12-29 14:12:11 -06003404
Michael Lentine700b0aa2015-10-30 17:57:32 -07003405VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
3406{
3407 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3408 VkResult result = dev_data->device_dispatch_table->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Youngb20a6a82016-01-07 15:41:43 -07003409 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis74714d22016-01-25 15:24:34 -08003410 if (result == VK_SUCCESS) {
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003411 // When we know that all fences are complete we can clean/remove their CBs
Tobin Ehlis74714d22016-01-25 15:24:34 -08003412 if (waitAll || fenceCount == 1) {
3413 for (uint32_t i = 0; i < fenceCount; ++i) {
3414 VkQueue fence_queue = dev_data->fenceMap[pFences[i]].queue;
3415 for (auto cmdBuffer : dev_data->fenceMap[pFences[i]].cmdBuffers) {
3416 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
3417 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
3418 }
3419 }
3420 decrementResources(dev_data, fenceCount, pFences);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003421 }
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003422 // NOTE : Alternate case not handled here is when some fences have completed. In
3423 // this case for app to guarantee which fences completed it will have to call
3424 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
Michael Lentine700b0aa2015-10-30 17:57:32 -07003425 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003426 if (VK_FALSE != skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003427 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003428 return result;
3429}
3430
3431
3432VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(VkDevice device, VkFence fence)
3433{
3434 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3435 VkResult result = dev_data->device_dispatch_table->GetFenceStatus(device, fence);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003436 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003437 if (result == VK_SUCCESS) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003438 auto fence_queue = dev_data->fenceMap[fence].queue;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003439 for (auto cmdBuffer : dev_data->fenceMap[fence].cmdBuffers) {
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003440 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003441 removeInFlightCmdBuffer(dev_data, cmdBuffer, fence_queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003442 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003443 decrementResources(dev_data, 1, &fence);
3444 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003445 if (VK_FALSE != skip_call)
3446 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003447 return result;
3448}
3449
3450VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
3451{
3452 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3453 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003454 dev_data->queues.push_back(*pQueue);
Michael Lentine700b0aa2015-10-30 17:57:32 -07003455 dev_data->queueMap[*pQueue].device = device;
3456}
3457
3458VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(VkQueue queue)
3459{
3460 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
3461 decrementResources(dev_data, queue);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003462 VkBool32 skip_call = VK_FALSE;
3463 // Iterate over local set since we erase set members as we go in for loop
3464 auto local_cb_set = dev_data->queueMap[queue].inFlightCmdBuffers;
3465 for (auto cmdBuffer : local_cb_set) {
3466 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003467 removeInFlightCmdBuffer(dev_data, cmdBuffer, queue);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003468 }
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003469 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3470 if (VK_FALSE != skip_call)
3471 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003472 return dev_data->device_dispatch_table->QueueWaitIdle(queue);
3473}
3474
3475VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
3476{
Tobin Ehlis74714d22016-01-25 15:24:34 -08003477 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003478 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisae82e7f2016-01-20 16:23:37 -07003479 for (auto queue : dev_data->queues) {
3480 decrementResources(dev_data, queue);
Tobin Ehlis74714d22016-01-25 15:24:34 -08003481 if (dev_data->queueMap.find(queue) != dev_data->queueMap.end()) {
3482 // Clear all of the queue inFlightCmdBuffers (global set cleared below)
3483 dev_data->queueMap[queue].inFlightCmdBuffers.clear();
3484 }
Michael Lentine700b0aa2015-10-30 17:57:32 -07003485 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003486 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
3487 skip_call |= cleanInFlightCmdBuffer(dev_data, cmdBuffer);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003488 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003489 dev_data->globalInFlightCmdBuffers.clear();
3490 if (VK_FALSE != skip_call)
3491 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003492 return dev_data->device_dispatch_table->DeviceWaitIdle(device);
3493}
3494
Chia-I Wu9ab61502015-11-06 06:42:02 +08003495VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003496{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003497 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 -06003498 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003499}
3500
Chia-I Wu9ab61502015-11-06 06:42:02 +08003501VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003502{
Michael Lentine15a47882016-01-06 10:05:48 -06003503 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3504 dev_data->device_dispatch_table->DestroySemaphore(device, semaphore, pAllocator);
3505 dev_data->semaphoreSignaledMap.erase(semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003506 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003507}
3508
Chia-I Wu9ab61502015-11-06 06:42:02 +08003509VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003510{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003511 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 -06003512 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003513}
3514
Chia-I Wu9ab61502015-11-06 06:42:02 +08003515VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003516{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003517 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 -06003518 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003519}
3520
Mark Lobodzinskice738852016-01-07 10:04:02 -07003521VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount,
Michael Lentineb887b0a2015-12-29 14:12:11 -06003522 size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) {
3523 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3524 unordered_map<QueryObject, vector<VkCommandBuffer>> queriesInFlight;
3525 GLOBAL_CB_NODE* pCB = nullptr;
Tobin Ehlis74714d22016-01-25 15:24:34 -08003526 for (auto cmdBuffer : dev_data->globalInFlightCmdBuffers) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06003527 pCB = getCBNode(dev_data, cmdBuffer);
3528 for (auto queryStatePair : pCB->queryToStateMap) {
3529 queriesInFlight[queryStatePair.first].push_back(cmdBuffer);
3530 }
3531 }
Mark Youngb20a6a82016-01-07 15:41:43 -07003532 VkBool32 skip_call = VK_FALSE;
Michael Lentineb887b0a2015-12-29 14:12:11 -06003533 for (uint32_t i = 0; i < queryCount; ++i) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003534 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06003535 auto queryElement = queriesInFlight.find(query);
3536 auto queryToStateElement = dev_data->queryToStateMap.find(query);
3537 if (queryToStateElement != dev_data->queryToStateMap.end()) {
3538 }
3539 // Available and in flight
3540 if(queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && queryToStateElement->second) {
3541 for (auto cmdBuffer : queryElement->second) {
3542 pCB = getCBNode(dev_data, cmdBuffer);
3543 auto queryEventElement = pCB->waitedEventsBeforeQueryReset.find(query);
3544 if (queryEventElement == pCB->waitedEventsBeforeQueryReset.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003545 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, 0, __LINE__,
3546 DRAWSTATE_INVALID_QUERY, "DS", "Cannot get query results on queryPool %" PRIu64 " with index %d which is in flight.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003547 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003548 } else {
3549 for (auto event : queryEventElement->second) {
3550 dev_data->eventMap[event].needsSignaled = true;
3551 }
3552 }
3553 }
3554 // Unavailable and in flight
3555 } else if (queryElement != queriesInFlight.end() && queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
3556 // TODO : Can there be the same query in use by multiple command buffers in flight?
3557 bool make_available = false;
3558 for (auto cmdBuffer : queryElement->second) {
3559 pCB = getCBNode(dev_data, cmdBuffer);
3560 make_available |= pCB->queryToStateMap[query];
3561 }
3562 if (!(((flags & VK_QUERY_RESULT_PARTIAL_BIT) || (flags & VK_QUERY_RESULT_WAIT_BIT)) && make_available)) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003563 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 -06003564 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003565 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003566 }
3567 // Unavailable
3568 } else if (queryToStateElement != dev_data->queryToStateMap.end() && !queryToStateElement->second) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003569 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 -06003570 "Cannot get query results on queryPool %" PRIu64 " with index %d which is unavailable.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003571 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003572 // Unitialized
3573 } else if (queryToStateElement == dev_data->queryToStateMap.end()) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07003574 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 -06003575 "Cannot get query results on queryPool %" PRIu64 " with index %d which is uninitialized.",
Mark Young93ecb1d2016-01-13 13:47:16 -07003576 (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003577 }
3578 }
3579 if (skip_call)
Mark Lobodzinskice738852016-01-07 10:04:02 -07003580 return VK_ERROR_VALIDATION_FAILED_EXT;
3581 return dev_data->device_dispatch_table->GetQueryPoolResults(device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags);
Michael Lentineb887b0a2015-12-29 14:12:11 -06003582}
3583
Mark Young7a69c302016-01-07 09:48:47 -07003584VkBool32 validateIdleBuffer(const layer_data* my_data, VkBuffer buffer) {
Mark Youngb20a6a82016-01-07 15:41:43 -07003585 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003586 auto buffer_data = my_data->bufferMap.find(buffer);
3587 if (buffer_data == my_data->bufferMap.end()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003588 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_DOUBLE_DESTROY, "DS",
3589 "Cannot free buffer %" PRIxLEAST64 " that has not been allocated.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003590 } else {
3591 if (buffer_data->second.in_use.load()) {
Mark Young93ecb1d2016-01-13 13:47:16 -07003592 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, (uint64_t)(buffer), __LINE__, DRAWSTATE_OBJECT_INUSE, "DS",
3593 "Cannot free buffer %" PRIxLEAST64 " that is in use by a command buffer.", (uint64_t)(buffer));
Michael Lentine700b0aa2015-10-30 17:57:32 -07003594 }
3595 }
3596 return skip_call;
3597}
3598
Chia-I Wu9ab61502015-11-06 06:42:02 +08003599VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003600{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003601 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07003602 VkBool32 skip_call = VK_FALSE;
Michael Lentine700b0aa2015-10-30 17:57:32 -07003603 if (!validateIdleBuffer(dev_data, buffer)) {
3604 dev_data->device_dispatch_table->DestroyBuffer(device, buffer, pAllocator);
3605 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08003606 dev_data->bufferMap.erase(buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003607}
3608
Chia-I Wu9ab61502015-11-06 06:42:02 +08003609VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003610{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003611 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003612 dev_data->device_dispatch_table->DestroyBufferView(device, bufferView, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003613 dev_data->bufferViewMap.erase(bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003614}
3615
Chia-I Wu9ab61502015-11-06 06:42:02 +08003616VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003617{
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003618 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003619 dev_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003620 dev_data->imageMap.erase(image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003621}
3622
Chia-I Wu9ab61502015-11-06 06:42:02 +08003623VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003624{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003625 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 -06003626 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003627}
3628
Chia-I Wu9ab61502015-11-06 06:42:02 +08003629VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003630{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003631 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 -06003632 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003633}
3634
Chia-I Wu9ab61502015-11-06 06:42:02 +08003635VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003636{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003637 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 -06003638 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003639}
3640
Chia-I Wu9ab61502015-11-06 06:42:02 +08003641VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003642{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003643 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 -06003644 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003645}
3646
Chia-I Wu9ab61502015-11-06 06:42:02 +08003647VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003648{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003649 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 -06003650 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003651}
3652
Chia-I Wu9ab61502015-11-06 06:42:02 +08003653VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003654{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003655 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 -06003656 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003657}
3658
Chia-I Wu9ab61502015-11-06 06:42:02 +08003659VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003660{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003661 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 -06003662 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003663}
3664
Chia-I Wu9ab61502015-11-06 06:42:02 +08003665VK_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 -06003666{
Mark Lobodzinski39298632015-11-18 08:38:27 -07003667 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3668
Courtney Goeltzenleuchter51239472015-12-16 16:06:06 -07003669 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003670 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003671 // Delete CB information structure, and remove from commandBufferMap
3672 auto cb = dev_data->commandBufferMap.find(pCommandBuffers[i]);
3673 if (cb != dev_data->commandBufferMap.end()) {
Tobin Ehlise6e574b2016-01-24 23:25:31 -07003674 // reset prior to delete for data clean-up
3675 resetCB(dev_data, (*cb).second->commandBuffer);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003676 delete (*cb).second;
3677 dev_data->commandBufferMap.erase(cb);
3678 }
3679
3680 // Remove commandBuffer reference from commandPoolMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003681 dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003682 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003683 }
3684
3685 dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
3686}
3687
3688VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
3689{
3690 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3691
3692 VkResult result = dev_data->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
3693
3694 if (VK_SUCCESS == result) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003695 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003696 dev_data->commandPoolMap[*pCommandPool].createFlags = pCreateInfo->flags;
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003697 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003698 }
3699 return result;
3700}
Michael Lentinee063fe42016-01-27 17:52:20 -06003701
Mark Youngbaa677f2016-01-28 09:36:15 -07003702VkBool32 validateCommandBuffersNotInUse(const layer_data* dev_data, VkCommandPool commandPool) {
3703 VkBool32 skipCall = VK_FALSE;
Michael Lentinee063fe42016-01-27 17:52:20 -06003704 loader_platform_thread_lock_mutex(&globalLock);
3705 auto pool_data = dev_data->commandPoolMap.find(commandPool);
3706 if (pool_data != dev_data->commandPoolMap.end()) {
3707 for (auto cmdBuffer : pool_data->second.commandBuffers) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003708 if (dev_data->globalInFlightCmdBuffers.count(cmdBuffer)) {
Mark Lobodzinskia724e142016-01-29 10:13:51 -07003709 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, (uint64_t)(commandPool),
Tobin Ehlis74714d22016-01-25 15:24:34 -08003710 __LINE__, DRAWSTATE_OBJECT_INUSE, "DS", "Cannot reset command pool %" PRIx64 " when allocated command buffer %" PRIx64 " is in use.",
3711 (uint64_t)(commandPool), (uint64_t)(cmdBuffer));
Michael Lentinee063fe42016-01-27 17:52:20 -06003712 }
3713 }
3714 }
3715 loader_platform_thread_unlock_mutex(&globalLock);
Mark Youngbaa677f2016-01-28 09:36:15 -07003716 return skipCall;
Michael Lentinee063fe42016-01-27 17:52:20 -06003717}
3718
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07003719// Destroy commandPool along with all of the commandBuffers allocated from that pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07003720VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
3721{
3722 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003723 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07003724
3725 // Must remove cmdpool from cmdpoolmap, after removing all cmdbuffers in its list from the commandPoolMap
3726 if (dev_data->commandPoolMap.find(commandPool) != dev_data->commandPoolMap.end()) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003727 for (auto poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.begin(); poolCb != dev_data->commandPoolMap[commandPool].commandBuffers.end();) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07003728 auto del_cb = dev_data->commandBufferMap.find(*poolCb);
3729 delete (*del_cb).second; // delete CB info structure
3730 dev_data->commandBufferMap.erase(del_cb); // Remove this command buffer from cbMap
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003731 poolCb = dev_data->commandPoolMap[commandPool].commandBuffers.erase(poolCb); // Remove CB reference from commandPoolMap's list
Mark Lobodzinski39298632015-11-18 08:38:27 -07003732 }
3733 }
3734 dev_data->commandPoolMap.erase(commandPool);
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07003735
3736 loader_platform_thread_unlock_mutex(&globalLock);
Michael Lentinee063fe42016-01-27 17:52:20 -06003737
Mark Youngbaa677f2016-01-28 09:36:15 -07003738 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentinee063fe42016-01-27 17:52:20 -06003739 return;
3740
Mark Lobodzinski39298632015-11-18 08:38:27 -07003741 dev_data->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003742}
3743
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003744VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
3745 VkDevice device,
3746 VkCommandPool commandPool,
3747 VkCommandPoolResetFlags flags)
3748{
3749 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003750 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003751
Mark Youngbaa677f2016-01-28 09:36:15 -07003752 if (VK_TRUE == validateCommandBuffersNotInUse(dev_data, commandPool))
Michael Lentined2a7d632016-01-27 17:02:39 -06003753 return VK_ERROR_VALIDATION_FAILED_EXT;
3754
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003755 result = dev_data->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
3756 // Reset all of the CBs allocated from this pool
3757 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08003758 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003759 auto it = dev_data->commandPoolMap[commandPool].commandBuffers.begin();
3760 while (it != dev_data->commandPoolMap[commandPool].commandBuffers.end()) {
3761 resetCB(dev_data, (*it));
3762 ++it;
3763 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08003764 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07003765 }
3766 return result;
3767}
3768
Chia-I Wu9ab61502015-11-06 06:42:02 +08003769VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003770{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003771 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 -06003772 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003773}
3774
Chia-I Wu9ab61502015-11-06 06:42:02 +08003775VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003776{
Chia-I Wuf7458c52015-10-26 21:10:41 +08003777 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 -06003778 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003779}
3780
Chia-I Wu9ab61502015-11-06 06:42:02 +08003781VK_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 -06003782{
3783 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003784 VkResult result = dev_data->device_dispatch_table->CreateBuffer(device, pCreateInfo, pAllocator, pBuffer);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003785 if (VK_SUCCESS == result) {
3786 loader_platform_thread_lock_mutex(&globalLock);
3787 // 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 -07003788 dev_data->bufferMap[*pBuffer].create_info = unique_ptr<VkBufferCreateInfo>(new VkBufferCreateInfo(*pCreateInfo));
3789 dev_data->bufferMap[*pBuffer].in_use.store(0);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003790 loader_platform_thread_unlock_mutex(&globalLock);
3791 }
3792 return result;
3793}
3794
Chia-I Wu9ab61502015-11-06 06:42:02 +08003795VK_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 -06003796{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003797 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003798 VkResult result = dev_data->device_dispatch_table->CreateBufferView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003799 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003800 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003801 dev_data->bufferViewMap[*pView] = unique_ptr<VkBufferViewCreateInfo>(new VkBufferViewCreateInfo(*pCreateInfo));
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003802 loader_platform_thread_unlock_mutex(&globalLock);
3803 }
3804 return result;
3805}
3806
Chia-I Wu9ab61502015-11-06 06:42:02 +08003807VK_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 -06003808{
3809 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003810 VkResult result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003811 if (VK_SUCCESS == result) {
Michael Lentineabc5e922015-10-12 11:30:14 -05003812 IMAGE_NODE* image_node = new IMAGE_NODE;
3813 image_node->layout = pCreateInfo->initialLayout;
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07003814 image_node->format = pCreateInfo->format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003815 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003816 dev_data->imageMap[*pImage] = unique_ptr<VkImageCreateInfo>(new VkImageCreateInfo(*pCreateInfo));
Michael Lentineabc5e922015-10-12 11:30:14 -05003817 dev_data->imageLayoutMap[*pImage] = image_node;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003818 loader_platform_thread_unlock_mutex(&globalLock);
3819 }
3820 return result;
3821}
3822
Chia-I Wu9ab61502015-11-06 06:42:02 +08003823VK_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 -06003824{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003825 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003826 VkResult result = dev_data->device_dispatch_table->CreateImageView(device, pCreateInfo, pAllocator, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003827 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003828 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003829 dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003830 loader_platform_thread_unlock_mutex(&globalLock);
3831 }
3832 return result;
3833}
3834
Jon Ashburnc669cc62015-07-09 15:02:25 -06003835//TODO handle pipeline caches
Chia-I Wu9ab61502015-11-06 06:42:02 +08003836VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003837 VkDevice device,
3838 const VkPipelineCacheCreateInfo* pCreateInfo,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003839 const VkAllocationCallbacks* pAllocator,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003840 VkPipelineCache* pPipelineCache)
3841{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003842 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003843 VkResult result = dev_data->device_dispatch_table->CreatePipelineCache(device, pCreateInfo, pAllocator, pPipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003844 return result;
3845}
3846
Chia-I Wu9ab61502015-11-06 06:42:02 +08003847VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003848 VkDevice device,
Chia-I Wuf7458c52015-10-26 21:10:41 +08003849 VkPipelineCache pipelineCache,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003850 const VkAllocationCallbacks* pAllocator)
Jon Ashburnc669cc62015-07-09 15:02:25 -06003851{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003852 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003853 dev_data->device_dispatch_table->DestroyPipelineCache(device, pipelineCache, pAllocator);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003854}
3855
Chia-I Wu9ab61502015-11-06 06:42:02 +08003856VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003857 VkDevice device,
3858 VkPipelineCache pipelineCache,
Chia-I Wub16facd2015-10-26 19:17:06 +08003859 size_t* pDataSize,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003860 void* pData)
3861{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003862 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wub16facd2015-10-26 19:17:06 +08003863 VkResult result = dev_data->device_dispatch_table->GetPipelineCacheData(device, pipelineCache, pDataSize, pData);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003864 return result;
3865}
3866
Chia-I Wu9ab61502015-11-06 06:42:02 +08003867VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
Jon Ashburnc669cc62015-07-09 15:02:25 -06003868 VkDevice device,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003869 VkPipelineCache dstCache,
Jon Ashburnc669cc62015-07-09 15:02:25 -06003870 uint32_t srcCacheCount,
3871 const VkPipelineCache* pSrcCaches)
3872{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003873 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003874 VkResult result = dev_data->device_dispatch_table->MergePipelineCaches(device, dstCache, srcCacheCount, pSrcCaches);
Jon Ashburnc669cc62015-07-09 15:02:25 -06003875 return result;
3876}
3877
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003878VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
3879 VkDevice device,
3880 VkPipelineCache pipelineCache,
3881 uint32_t count,
3882 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3883 const VkAllocationCallbacks *pAllocator,
3884 VkPipeline *pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003885{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06003886 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06003887 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003888 // The order of operations here is a little convoluted but gets the job done
3889 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
3890 // 2. Create state is then validated (which uses flags setup during shadowing)
3891 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06003892 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06003893 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3894 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis0b632332015-10-07 09:38:40 -06003895 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003896
Tobin Ehlis11efc302015-09-16 10:33:53 -06003897 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003898 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003899
Tobin Ehlis11efc302015-09-16 10:33:53 -06003900 for (i=0; i<count; i++) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003901 pPipeNode[i] = initGraphicsPipeline(dev_data, &pCreateInfos[i], NULL);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06003902 skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003903 }
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003904
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003905 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07003906
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07003907 if (VK_FALSE == skipCall) {
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003908 result = dev_data->device_dispatch_table->CreateGraphicsPipelines(device,
3909 pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003910 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06003911 for (i=0; i<count; i++) {
3912 pPipeNode[i]->pipeline = pPipelines[i];
Chia-I Wue2fc5522015-10-26 20:04:44 +08003913 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
Tobin Ehlis11efc302015-09-16 10:33:53 -06003914 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003915 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06003916 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06003917 for (i=0; i<count; i++) {
3918 if (pPipeNode[i]) {
3919 // If we allocated a pipeNode, need to clean it up here
3920 delete[] pPipeNode[i]->pVertexBindingDescriptions;
3921 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
3922 delete[] pPipeNode[i]->pAttachments;
3923 delete pPipeNode[i];
3924 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003925 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003926 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06003927 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06003928 return result;
3929}
3930
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003931VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
3932 VkDevice device,
3933 VkPipelineCache pipelineCache,
3934 uint32_t count,
3935 const VkComputePipelineCreateInfo *pCreateInfos,
3936 const VkAllocationCallbacks *pAllocator,
3937 VkPipeline *pPipelines)
3938{
3939 VkResult result = VK_SUCCESS;
3940 VkBool32 skipCall = VK_FALSE;
3941
3942 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
3943 vector<PIPELINE_NODE*> pPipeNode(count);
3944 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
3945
3946 uint32_t i=0;
3947 loader_platform_thread_lock_mutex(&globalLock);
3948 for (i=0; i<count; i++) {
3949 // TODO: Verify compute stage bits
3950
3951 // Create and initialize internal tracking data structure
3952 pPipeNode[i] = new PIPELINE_NODE;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003953 memcpy(&pPipeNode[i]->computePipelineCI, (const void*)&pCreateInfos[i], sizeof(VkComputePipelineCreateInfo));
3954
3955 // TODO: Add Compute Pipeline Verification
3956 // skipCall |= verifyPipelineCreateState(dev_data, device, pPipeNode[i]);
3957 }
3958 loader_platform_thread_unlock_mutex(&globalLock);
3959
3960 if (VK_FALSE == skipCall) {
3961 result = dev_data->device_dispatch_table->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
3962 loader_platform_thread_lock_mutex(&globalLock);
3963 for (i=0; i<count; i++) {
3964 pPipeNode[i]->pipeline = pPipelines[i];
3965 dev_data->pipelineMap[pPipeNode[i]->pipeline] = pPipeNode[i];
3966 }
3967 loader_platform_thread_unlock_mutex(&globalLock);
3968 } else {
3969 for (i=0; i<count; i++) {
3970 if (pPipeNode[i]) {
3971 // Clean up any locally allocated data structures
3972 delete pPipeNode[i];
3973 }
3974 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07003975 return VK_ERROR_VALIDATION_FAILED_EXT;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07003976 }
3977 return result;
3978}
3979
Chia-I Wu9ab61502015-11-06 06:42:02 +08003980VK_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 -06003981{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003982 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003983 VkResult result = dev_data->device_dispatch_table->CreateSampler(device, pCreateInfo, pAllocator, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003984 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003985 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wue2fc5522015-10-26 20:04:44 +08003986 dev_data->sampleMap[*pSampler] = unique_ptr<SAMPLER_NODE>(new SAMPLER_NODE(pSampler, pCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003987 loader_platform_thread_unlock_mutex(&globalLock);
3988 }
3989 return result;
3990}
3991
Chia-I Wu9ab61502015-11-06 06:42:02 +08003992VK_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 -06003993{
Tobin Ehlis0b632332015-10-07 09:38:40 -06003994 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003995 VkResult result = dev_data->device_dispatch_table->CreateDescriptorSetLayout(device, pCreateInfo, pAllocator, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003996 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07003997 // TODOSC : Capture layout bindings set
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003998 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
3999 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004000 if (log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, (uint64_t) *pSetLayout, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004001 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004002 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004003 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004004 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004005 pNewNode->createInfo.pBindings = new VkDescriptorSetLayoutBinding[pCreateInfo->bindingCount];
4006 memcpy((void*)pNewNode->createInfo.pBindings, pCreateInfo->pBindings, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->bindingCount);
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004007 // g++ does not like reserve with size 0
4008 if (pCreateInfo->bindingCount)
4009 pNewNode->bindings.reserve(pCreateInfo->bindingCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004010 uint32_t totalCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004011 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004012 if (!pNewNode->bindings.insert(pCreateInfo->pBindings[i].binding).second) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004013 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 +08004014 "duplicated binding number in VkDescriptorSetLayoutBinding"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004015 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wud46e6ae2015-10-31 00:31:16 +08004016 }
4017
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004018 totalCount += pCreateInfo->pBindings[i].descriptorCount;
4019 if (pCreateInfo->pBindings[i].pImmutableSamplers) {
4020 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBindings[i].pImmutableSamplers;
4021 *ppIS = new VkSampler[pCreateInfo->pBindings[i].descriptorCount];
4022 memcpy(*ppIS, pCreateInfo->pBindings[i].pImmutableSamplers, pCreateInfo->pBindings[i].descriptorCount*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06004023 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004024 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004025 pNewNode->layout = *pSetLayout;
4026 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004027 if (totalCount > 0) {
Cody Northrop43751cc2015-10-26 14:07:35 -06004028 pNewNode->descriptorTypes.resize(totalCount);
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004029 pNewNode->stageFlags.resize(totalCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004030 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06004031 uint32_t j = 0;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004032 VkDescriptorType dType;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004033 for (uint32_t i=0; i<pCreateInfo->bindingCount; i++) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004034 dType = pCreateInfo->pBindings[i].descriptorType;
4035 for (j = 0; j < pCreateInfo->pBindings[i].descriptorCount; j++) {
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004036 pNewNode->descriptorTypes[offset + j] = dType;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004037 pNewNode->stageFlags[offset + j] = pCreateInfo->pBindings[i].stageFlags;
Tobin Ehlisda2f0d02015-11-04 12:28:28 -07004038 if ((dType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
4039 (dType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
4040 pNewNode->dynamicDescriptorCount++;
4041 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004042 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004043 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004044 }
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004045 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
4046 } else { // no descriptors
4047 pNewNode->endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004048 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004049 // Put new node at Head of global Layer list
4050 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07004051 dev_data->descriptorSetLayoutMap[*pSetLayout] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004052 loader_platform_thread_unlock_mutex(&globalLock);
4053 }
4054 return result;
4055}
4056
Chia-I Wu9ab61502015-11-06 06:42:02 +08004057VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004058{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004059 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004060 VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004061 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07004062 // TODOSC : Merge capture of the setLayouts per pipeline
Tobin Ehlis559c6382015-11-05 09:52:49 -07004063 PIPELINE_LAYOUT_NODE& plNode = dev_data->pipelineLayoutMap[*pPipelineLayout];
Chia-I Wud50a7d72015-10-26 20:48:51 +08004064 plNode.descriptorSetLayouts.resize(pCreateInfo->setLayoutCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06004065 uint32_t i = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004066 for (i=0; i<pCreateInfo->setLayoutCount; ++i) {
Tobin Ehlis644ff042015-10-20 10:11:55 -06004067 plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
4068 }
Cody Northrop43751cc2015-10-26 14:07:35 -06004069 plNode.pushConstantRanges.resize(pCreateInfo->pushConstantRangeCount);
Tobin Ehlis644ff042015-10-20 10:11:55 -06004070 for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
4071 plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
4072 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004073 }
4074 return result;
4075}
4076
Chia-I Wu9ab61502015-11-06 06:42:02 +08004077VK_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 -06004078{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004079 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004080 VkResult result = dev_data->device_dispatch_table->CreateDescriptorPool(device, pCreateInfo, pAllocator, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004081 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004082 // Insert this pool into Global Pool LL at head
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004083 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 +08004084 "Created Descriptor Pool %#" PRIxLEAST64, (uint64_t) *pDescriptorPool))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004085 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004086 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004087 DESCRIPTOR_POOL_NODE* pNewNode = new DESCRIPTOR_POOL_NODE(*pDescriptorPool, pCreateInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004088 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004089 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 -07004090 "Out of memory while attempting to allocate DESCRIPTOR_POOL_NODE in vkCreateDescriptorPool()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004091 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004092 } else {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004093 dev_data->descriptorPoolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004094 }
4095 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004096 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06004097 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004098 }
4099 return result;
4100}
4101
Chia-I Wu9ab61502015-11-06 06:42:02 +08004102VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004103{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004104 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004105 VkResult result = dev_data->device_dispatch_table->ResetDescriptorPool(device, descriptorPool, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004106 if (VK_SUCCESS == result) {
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004107 clearDescriptorPool(dev_data, device, descriptorPool, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004108 }
4109 return result;
4110}
4111
Chia-I Wu9ab61502015-11-06 06:42:02 +08004112VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004113{
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004114 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004115 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004116 // Verify that requested descriptorSets are available in pool
Mark Lobodzinski39298632015-11-18 08:38:27 -07004117 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004118 if (!pPoolNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004119 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 +08004120 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", (uint64_t) pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004121 } else { // Make sure pool has all the available descriptors before calling down chain
Jon Ashburnf19916e2016-01-11 13:12:43 -07004122 skipCall |= validate_descriptor_availability_in_pool(dev_data, pPoolNode, pAllocateInfo->descriptorSetCount, pAllocateInfo->pSetLayouts);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004123 }
4124 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004125 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004126 VkResult result = dev_data->device_dispatch_table->AllocateDescriptorSets(device, pAllocateInfo, pDescriptorSets);
Cody Northrop1e4f8022015-08-03 12:47:29 -06004127 if (VK_SUCCESS == result) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004128 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, pAllocateInfo->descriptorPool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004129 if (pPoolNode) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004130 if (pAllocateInfo->descriptorSetCount == 0) {
4131 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 +08004132 "AllocateDescriptorSets called with 0 count");
Cody Northrop1e4f8022015-08-03 12:47:29 -06004133 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004134 for (uint32_t i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004135 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 +08004136 "Created Descriptor Set %#" PRIxLEAST64, (uint64_t) pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004137 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004138 SET_NODE* pNewNode = new SET_NODE;
4139 if (NULL == pNewNode) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004140 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 +08004141 "Out of memory while attempting to allocate SET_NODE in vkAllocateDescriptorSets()"))
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004142 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisce132d82015-06-19 15:07:05 -06004143 } else {
Tobin Ehlis8b5b28c2015-10-19 12:09:13 -06004144 // TODO : Pool should store a total count of each type of Descriptor available
4145 // When descriptors are allocated, decrement the count and validate here
4146 // that the count doesn't go below 0. One reset/free need to bump count back up.
Tobin Ehlis793ad302015-04-03 12:01:11 -06004147 // Insert set at head of Set LL for this pool
4148 pNewNode->pNext = pPoolNode->pSets;
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004149 pNewNode->in_use.store(0);
Tobin Ehlis793ad302015-04-03 12:01:11 -06004150 pPoolNode->pSets = pNewNode;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004151 LAYOUT_NODE* pLayout = getLayoutNode(dev_data, pAllocateInfo->pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004152 if (NULL == pLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004153 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 +08004154 "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 -07004155 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004156 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06004157 pNewNode->pLayout = pLayout;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004158 pNewNode->pool = pAllocateInfo->descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004159 pNewNode->set = pDescriptorSets[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004160 pNewNode->descriptorCount = pLayout->endIndex + 1;
4161 if (pNewNode->descriptorCount) {
4162 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
4163 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
4164 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
4165 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08004166 dev_data->setMap[pDescriptorSets[i]] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004167 }
4168 }
4169 }
4170 }
4171 return result;
4172}
4173
Chia-I Wu9ab61502015-11-06 06:42:02 +08004174VK_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 -06004175{
Tobin Ehlise735c692015-10-08 13:13:50 -06004176 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004177 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis9c4f38d2016-01-14 12:47:19 -07004178 // Make sure that no sets being destroyed are in-flight
4179 for (uint32_t i=0; i<count; ++i)
4180 skipCall |= validateIdleDescriptorSet(dev_data, pDescriptorSets[i], "vkFreeDesriptorSets");
Mark Lobodzinski39298632015-11-18 08:38:27 -07004181 DESCRIPTOR_POOL_NODE *pPoolNode = getPoolNode(dev_data, descriptorPool);
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004182 if (pPoolNode && !(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT & pPoolNode->createInfo.flags)) {
4183 // Can't Free from a NON_FREE pool
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004184 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 -06004185 "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 -06004186 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004187 if (VK_FALSE != skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004188 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis0b632332015-10-07 09:38:40 -06004189 VkResult result = dev_data->device_dispatch_table->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004190 if (VK_SUCCESS == result) {
4191 // For each freed descriptor add it back into the pool as available
4192 for (uint32_t i=0; i<count; ++i) {
Chia-I Wue2fc5522015-10-26 20:04:44 +08004193 SET_NODE* pSet = dev_data->setMap[pDescriptorSets[i]]; // getSetNode() without locking
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004194 invalidateBoundCmdBuffers(dev_data, pSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004195 LAYOUT_NODE* pLayout = pSet->pLayout;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004196 uint32_t typeIndex = 0, poolSizeCount = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004197 for (uint32_t j=0; j<pLayout->createInfo.bindingCount; ++j) {
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07004198 typeIndex = static_cast<uint32_t>(pLayout->createInfo.pBindings[j].descriptorType);
4199 poolSizeCount = pLayout->createInfo.pBindings[j].descriptorCount;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004200 pPoolNode->availableDescriptorTypeCount[typeIndex] += poolSizeCount;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004201 }
4202 }
4203 }
4204 // TODO : Any other clean-up or book-keeping to do here?
Tony Barbour34ec6922015-07-10 10:50:45 -06004205 return result;
4206}
4207
Chia-I Wu9ab61502015-11-06 06:42:02 +08004208VK_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 -06004209{
Tobin Ehlisa1f9b642015-10-27 12:25:35 -06004210 // 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 -06004211 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu40cf0ae2015-10-26 17:20:32 +08004212 if (!dsUpdate(dev_data, device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies)) {
4213 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004214 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004215}
4216
Chia-I Wu9ab61502015-11-06 06:42:02 +08004217VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004218{
Tobin Ehlis0b632332015-10-07 09:38:40 -06004219 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004220 VkResult result = dev_data->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004221 if (VK_SUCCESS == result) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004222 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
Mark Lobodzinski39298632015-11-18 08:38:27 -07004223 // Validate command pool
4224 if (dev_data->commandPoolMap.find(pCreateInfo->commandPool) != dev_data->commandPoolMap.end()) {
Mark Lobodzinskib8df78c2015-11-20 14:33:48 -07004225 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004226 // Add command buffer to its commandPool map
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004227 dev_data->commandPoolMap[pCreateInfo->commandPool].commandBuffers.push_back(pCommandBuffer[i]);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004228 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
4229 // Add command buffer to map
4230 dev_data->commandBufferMap[pCommandBuffer[i]] = pCB;
4231 resetCB(dev_data, pCommandBuffer[i]);
4232 pCB->commandBuffer = pCommandBuffer[i];
4233 pCB->createInfo = *pCreateInfo;
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004234 pCB->device = device;
Tobin Ehlis74714d22016-01-25 15:24:34 -08004235 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski39298632015-11-18 08:38:27 -07004236 }
4237 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004238 }
4239 return result;
4240}
4241
Chia-I Wu9ab61502015-11-06 06:42:02 +08004242VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004243{
Mark Youngb20a6a82016-01-07 15:41:43 -07004244 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004245 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004246 // Validate command buffer level
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004247 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004248 if (pCB) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004249 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
4250 // Secondary Command Buffer
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004251 // TODO : Add check here from spec "If commandBuffer is a secondary command buffer and either the
4252 // occlusionQueryEnable member of pBeginInfo is VK_FALSE, or the precise occlusion queries feature
4253 // is not enabled, the queryFlags member of pBeginInfo must not contain VK_QUERY_CONTROL_PRECISE_BIT"
Jon Ashburnf19916e2016-01-11 13:12:43 -07004254 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004255 if (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07004256 if (!pInfo->renderPass) { // renderpass should NOT be null for an Secondary CB
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004257 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 -07004258 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) must specify a valid renderpass parameter.", (void*)commandBuffer);
4259 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07004260 if (!pInfo->framebuffer) { // framebuffer may be null for an Secondary CB, but this affects perf
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004261 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 -07004262 "vkBeginCommandBuffer(): Secondary Command Buffers (%p) may perform better if a valid framebuffer parameter is specified.", (void*)commandBuffer);
4263 } else {
4264 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07004265 VkRenderPass fbRP = dev_data->frameBufferMap[pInfo->framebuffer]->renderPass;
4266 if (!verify_renderpass_compatibility(dev_data, fbRP, pInfo->renderPass, errorString)) {
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004267 // renderPass that framebuffer was created with must be compatible with local renderPass
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004268 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 -07004269 "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 -07004270 (void*)commandBuffer, (uint64_t)pInfo->renderPass, (uint64_t)pInfo->framebuffer, (uint64_t)fbRP, errorString.c_str());
Tobin Ehlis651d9b02015-12-16 05:01:22 -07004271 }
4272 }
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004273 }
4274 }
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004275 if (CB_RECORDING == pCB->state) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004276 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 -07004277 "vkBeginCommandBuffer(): Cannot call Begin on CB (%#" PRIxLEAST64 ") in the RECORDING state. Must first call vkEndCommandBuffer().", (uint64_t)commandBuffer);
4278 } else if (CB_RECORDED == pCB->state) {
4279 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4280 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004281 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 -07004282 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004283 "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.",
4284 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4285 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004286 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004287 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004288 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004289 }
Tobin Ehlisef694652016-01-19 12:03:34 -07004290 // Set updated state here in case implicit reset occurs above
Tobin Ehlis74714d22016-01-25 15:24:34 -08004291 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisef694652016-01-19 12:03:34 -07004292 pCB->state = CB_RECORDING;
4293 pCB->beginInfo = *pBeginInfo;
Tobin Ehliscd5bfd82016-01-19 13:12:52 -07004294 if (pCB->beginInfo.pInheritanceInfo) {
4295 pCB->inheritanceInfo = *(pCB->beginInfo.pInheritanceInfo);
4296 pCB->beginInfo.pInheritanceInfo = &pCB->inheritanceInfo;
4297 }
Tobin Ehlis74714d22016-01-25 15:24:34 -08004298 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004299 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004300 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 +08004301 "In vkBeginCommandBuffer() and unable to find CommandBuffer Node for CB %p!", (void*)commandBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06004302 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004303 if (VK_FALSE != skipCall) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004304 return VK_ERROR_VALIDATION_FAILED_EXT;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06004305 }
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004306 VkResult result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004307 return result;
4308}
4309
Chia-I Wu9ab61502015-11-06 06:42:02 +08004310VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004311{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004312 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06004313 VkResult result = VK_SUCCESS;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004314 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4315 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004316 if (pCB) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004317 if (pCB->state != CB_RECORDING) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004318 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004319 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004320 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004321 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004322 result = dev_data->device_dispatch_table->EndCommandBuffer(commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004323 if (VK_SUCCESS == result) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004324 pCB->state = CB_RECORDED;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004325 // Reset CB status flags
4326 pCB->status = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004327 printCB(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004328 }
4329 } else {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004330 result = VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004331 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004332 return result;
4333}
4334
Chia-I Wu9ab61502015-11-06 06:42:02 +08004335VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004336{
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004337 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004338 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004339 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
4340 VkCommandPool cmdPool = pCB->createInfo.commandPool;
4341 if (!(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT & dev_data->commandPoolMap[cmdPool].createFlags)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004342 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 -07004343 __LINE__, DRAWSTATE_INVALID_COMMAND_BUFFER_RESET, "DS",
Tobin Ehlisac0ef842015-12-14 13:46:38 -07004344 "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.",
4345 (uint64_t) commandBuffer, (uint64_t) cmdPool);
4346 }
Mark Youngb20a6a82016-01-07 15:41:43 -07004347 if (skipCall != VK_FALSE)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07004348 return VK_ERROR_VALIDATION_FAILED_EXT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004349 VkResult result = dev_data->device_dispatch_table->ResetCommandBuffer(commandBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06004350 if (VK_SUCCESS == result) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08004351 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004352 resetCB(dev_data, commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08004353 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004354 }
4355 return result;
4356}
4357
Chia-I Wu9ab61502015-11-06 06:42:02 +08004358VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004359{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004360 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004361 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4362 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004363 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004364 skipCall |= addCmd(dev_data, pCB, CMD_BINDPIPELINE, "vkCmdBindPipeline()");
4365 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
4366 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 -07004367 __LINE__, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004368 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")",
4369 (uint64_t) pipeline, (uint64_t) pCB->activeRenderPass);
4370 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4371 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindPipeline");
4372 }
4373
4374 PIPELINE_NODE* pPN = getPipeline(dev_data, pipeline);
4375 if (pPN) {
4376 pCB->lastBoundPipeline = pipeline;
4377 loader_platform_thread_lock_mutex(&globalLock);
4378 set_cb_pso_status(pCB, pPN);
4379 loader_platform_thread_unlock_mutex(&globalLock);
4380 skipCall |= validatePipelineState(dev_data, pCB, pipelineBindPoint, pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06004381 } else {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004382 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 -07004383 (uint64_t) pipeline, __LINE__, DRAWSTATE_INVALID_PIPELINE, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07004384 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (uint64_t)(pipeline));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004385 }
4386 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004387 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004388 dev_data->device_dispatch_table->CmdBindPipeline(commandBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004389}
4390
Chia-I Wu9ab61502015-11-06 06:42:02 +08004391VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004392 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004393 uint32_t firstViewport,
4394 uint32_t viewportCount,
4395 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004396{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004397 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004398 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4399 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004400 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004401 skipCall |= addCmd(dev_data, pCB, CMD_SETVIEWPORTSTATE, "vkCmdSetViewport()");
4402 loader_platform_thread_lock_mutex(&globalLock);
4403 pCB->status |= CBSTATUS_VIEWPORT_SET;
4404 pCB->viewports.resize(viewportCount);
4405 memcpy(pCB->viewports.data(), pViewports, viewportCount * sizeof(VkViewport));
4406 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06004407 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004408 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004409 dev_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004410}
4411
Chia-I Wu9ab61502015-11-06 06:42:02 +08004412VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004413 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004414 uint32_t firstScissor,
4415 uint32_t scissorCount,
4416 const VkRect2D* pScissors)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004417{
4418 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004419 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4420 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004421 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004422 skipCall |= addCmd(dev_data, pCB, CMD_SETSCISSORSTATE, "vkCmdSetScissor()");
4423 loader_platform_thread_lock_mutex(&globalLock);
4424 pCB->status |= CBSTATUS_SCISSOR_SET;
4425 pCB->scissors.resize(scissorCount);
4426 memcpy(pCB->scissors.data(), pScissors, scissorCount * sizeof(VkRect2D));
4427 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06004428 }
4429 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004430 dev_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004431}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004432
Chia-I Wu9ab61502015-11-06 06:42:02 +08004433VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004434{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004435 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004436 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4437 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004438 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004439 skipCall |= addCmd(dev_data, pCB, CMD_SETLINEWIDTHSTATE, "vkCmdSetLineWidth()");
4440 /* TODO: Do we still need this lock? */
4441 loader_platform_thread_lock_mutex(&globalLock);
4442 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
4443 pCB->lineWidth = lineWidth;
4444 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop12365112015-08-17 11:10:49 -06004445 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004446 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004447 dev_data->device_dispatch_table->CmdSetLineWidth(commandBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06004448}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004449
Chia-I Wu9ab61502015-11-06 06:42:02 +08004450VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004451 VkCommandBuffer commandBuffer,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004452 float depthBiasConstantFactor,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004453 float depthBiasClamp,
Chia-I Wud8c946a2015-10-26 19:08:09 +08004454 float depthBiasSlopeFactor)
Cody Northrop12365112015-08-17 11:10:49 -06004455{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004456 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004457 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4458 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop12365112015-08-17 11:10:49 -06004459 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004460 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBIASSTATE, "vkCmdSetDepthBias()");
4461 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
4462 pCB->depthBiasConstantFactor = depthBiasConstantFactor;
4463 pCB->depthBiasClamp = depthBiasClamp;
4464 pCB->depthBiasSlopeFactor = depthBiasSlopeFactor;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004465 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004466 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004467 dev_data->device_dispatch_table->CmdSetDepthBias(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004468}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004469
Chia-I Wu9ab61502015-11-06 06:42:02 +08004470VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004471{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004472 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004473 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4474 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004475 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004476 skipCall |= addCmd(dev_data, pCB, CMD_SETBLENDSTATE, "vkCmdSetBlendConstants()");
4477 pCB->status |= CBSTATUS_BLEND_SET;
4478 memcpy(pCB->blendConstants, blendConstants, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004479 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004480 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004481 dev_data->device_dispatch_table->CmdSetBlendConstants(commandBuffer, blendConstants);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004482}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004483
Chia-I Wu9ab61502015-11-06 06:42:02 +08004484VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004485 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004486 float minDepthBounds,
4487 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004488{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004489 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004490 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4491 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004492 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004493 skipCall |= addCmd(dev_data, pCB, CMD_SETDEPTHBOUNDSSTATE, "vkCmdSetDepthBounds()");
4494 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
4495 pCB->minDepthBounds = minDepthBounds;
4496 pCB->maxDepthBounds = maxDepthBounds;
Cody Northrop82485a82015-08-18 15:21:16 -06004497 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004498 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004499 dev_data->device_dispatch_table->CmdSetDepthBounds(commandBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06004500}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004501
Chia-I Wu9ab61502015-11-06 06:42:02 +08004502VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004503 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004504 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004505 uint32_t compareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06004506{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004507 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004508 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4509 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Cody Northrop82485a82015-08-18 15:21:16 -06004510 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004511 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREADMASKSTATE, "vkCmdSetStencilCompareMask()");
4512 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4513 pCB->front.compareMask = compareMask;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004514 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004515 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4516 pCB->back.compareMask = compareMask;
4517 }
4518 /* TODO: Do we need to track front and back separately? */
4519 /* TODO: We aren't capturing the faceMask, do we need to? */
4520 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004521 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004522 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004523 dev_data->device_dispatch_table->CmdSetStencilCompareMask(commandBuffer, faceMask, compareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06004524}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004525
Chia-I Wu9ab61502015-11-06 06:42:02 +08004526VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004527 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004528 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004529 uint32_t writeMask)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004530{
4531 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004532 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4533 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004534 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004535 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILWRITEMASKSTATE, "vkCmdSetStencilWriteMask()");
4536 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4537 pCB->front.writeMask = writeMask;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004538 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004539 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4540 pCB->back.writeMask = writeMask;
4541 }
4542 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004543 }
4544 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004545 dev_data->device_dispatch_table->CmdSetStencilWriteMask(commandBuffer, faceMask, writeMask);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004546}
4547
Chia-I Wu9ab61502015-11-06 06:42:02 +08004548VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004549 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004550 VkStencilFaceFlags faceMask,
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004551 uint32_t reference)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004552{
4553 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004554 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4555 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004556 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004557 skipCall |= addCmd(dev_data, pCB, CMD_SETSTENCILREFERENCESTATE, "vkCmdSetStencilReference()");
4558 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
4559 pCB->front.reference = reference;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004560 }
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004561 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
4562 pCB->back.reference = reference;
4563 }
4564 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004565 }
4566 if (VK_FALSE == skipCall)
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004567 dev_data->device_dispatch_table->CmdSetStencilReference(commandBuffer, faceMask, reference);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06004568}
4569
Chia-I Wu9ab61502015-11-06 06:42:02 +08004570VK_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 -06004571{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004572 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004573 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4574 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004575 if (pCB) {
Tobin Ehlisf6585052015-12-17 11:48:42 -07004576 if (pCB->state == CB_RECORDING) {
4577 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004578 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 -07004579 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", (uint64_t) pCB->activeRenderPass);
4580 } else if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
4581 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdBindDescriptorSets");
Mark Lobodzinski74635932015-12-18 15:35:38 -07004582 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004583 if (VK_FALSE == skipCall) {
4584 // Track total count of dynamic descriptor types to make sure we have an offset for each one
4585 uint32_t totalDynamicDescriptors = 0;
4586 string errorString = "";
4587 uint32_t lastSetIndex = firstSet+setCount-1;
4588 if (lastSetIndex >= pCB->boundDescriptorSets.size())
Tobin Ehlis559c6382015-11-05 09:52:49 -07004589 pCB->boundDescriptorSets.resize(lastSetIndex+1);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004590 VkDescriptorSet oldFinalBoundSet = pCB->boundDescriptorSets[lastSetIndex];
4591 for (uint32_t i=0; i<setCount; i++) {
4592 SET_NODE* pSet = getSetNode(dev_data, pDescriptorSets[i]);
4593 if (pSet) {
4594 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise6e574b2016-01-24 23:25:31 -07004595 pCB->uniqueBoundSets.insert(pDescriptorSets[i]);
4596 pSet->boundCmdBuffers.insert(commandBuffer);
Tobin Ehlisf6585052015-12-17 11:48:42 -07004597 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
4598 pCB->lastBoundPipelineLayout = layout;
4599 pCB->boundDescriptorSets[i+firstSet] = pDescriptorSets[i];
4600 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004601 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 -07004602 "DS %#" PRIxLEAST64 " bound on pipeline %s", (uint64_t) pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis43c39c02016-01-11 13:18:40 -07004603 if (!pSet->pUpdateStructs && (pSet->descriptorCount != 0)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004604 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 -07004605 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", (uint64_t) pDescriptorSets[i]);
4606 }
4607 // Verify that set being bound is compatible with overlapping setLayout of pipelineLayout
4608 if (!verify_set_layout_compatibility(dev_data, pSet, layout, i+firstSet, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004609 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 -07004610 "descriptorSet #%u being bound is not compatible with overlapping layout in pipelineLayout due to: %s", i, errorString.c_str());
4611 }
4612 if (pSet->pLayout->dynamicDescriptorCount) {
4613 // First make sure we won't overstep bounds of pDynamicOffsets array
4614 if ((totalDynamicDescriptors + pSet->pLayout->dynamicDescriptorCount) > dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004615 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 -07004616 "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.",
4617 i, (uint64_t) pDescriptorSets[i], pSet->pLayout->dynamicDescriptorCount, (dynamicOffsetCount - totalDynamicDescriptors));
Mark Lobodzinski941aea92016-01-13 10:23:15 -07004618 } else { // Validate and store dynamic offsets with the set
4619 // Validate Dynamic Offset Minimums
4620 uint32_t cur_dyn_offset = totalDynamicDescriptors;
4621 for (uint32_t d = 0; d < pSet->descriptorCount; d++) {
4622 if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
4623 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment) != 0) {
4624 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4625 __LINE__, DRAWSTATE_INVALID_UNIFORM_BUFFER_OFFSET, "DS",
4626 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
4627 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minUniformBufferOffsetAlignment);
4628 }
4629 cur_dyn_offset++;
4630 } else if (pSet->pLayout->descriptorTypes[i] == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
4631 if (vk_safe_modulo(pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment) != 0) {
4632 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
4633 __LINE__, DRAWSTATE_INVALID_STORAGE_BUFFER_OFFSET, "DS",
4634 "vkCmdBindDescriptorSets(): pDynamicOffsets[%d] is %d but must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
4635 cur_dyn_offset, pDynamicOffsets[cur_dyn_offset], dev_data->physDevPropertyMap[pCB->device].limits.minStorageBufferOffsetAlignment);
4636 }
4637 cur_dyn_offset++;
4638 }
4639 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07004640 // Keep running total of dynamic descriptor count to verify at the end
Tobin Ehlisf6585052015-12-17 11:48:42 -07004641 totalDynamicDescriptors += pSet->pLayout->dynamicDescriptorCount;
4642 }
4643 }
4644 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004645 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 -07004646 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", (uint64_t) pDescriptorSets[i]);
4647 }
4648 }
4649 skipCall |= addCmd(dev_data, pCB, CMD_BINDDESCRIPTORSETS, "vkCmdBindDescrsiptorSets()");
4650 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4651 if (firstSet > 0) { // Check set #s below the first bound set
4652 for (uint32_t i=0; i<firstSet; ++i) {
4653 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 -07004654 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 -07004655 "DescriptorSetDS %#" PRIxLEAST64 " previously bound as set #%u was disturbed by newly bound pipelineLayout (%#" PRIxLEAST64 ")", (uint64_t) pCB->boundDescriptorSets[i], i, (uint64_t) layout);
4656 pCB->boundDescriptorSets[i] = VK_NULL_HANDLE;
4657 }
4658 }
4659 }
4660 // Check if newly last bound set invalidates any remaining bound sets
4661 if ((pCB->boundDescriptorSets.size()-1) > (lastSetIndex)) {
4662 if (oldFinalBoundSet && !verify_set_layout_compatibility(dev_data, dev_data->setMap[oldFinalBoundSet], layout, lastSetIndex, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004663 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 -07004664 "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);
4665 pCB->boundDescriptorSets.resize(lastSetIndex+1);
4666 }
4667 }
4668 // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound
4669 if (totalDynamicDescriptors != dynamicOffsetCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004670 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 -07004671 "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 -07004672 }
Tobin Ehlisd2393772016-01-29 11:50:47 -07004673 if (dynamicOffsetCount) {
4674 // Save dynamicOffsets bound to this CB
4675 pCB->dynamicOffsets.assign(pDynamicOffsets, pDynamicOffsets + dynamicOffsetCount);
4676 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004677 }
Tobin Ehlisf6585052015-12-17 11:48:42 -07004678 } else {
4679 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004680 }
4681 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004682 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004683 dev_data->device_dispatch_table->CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004684}
4685
Chia-I Wu9ab61502015-11-06 06:42:02 +08004686VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004687{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004688 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004689 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4690 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004691 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004692 skipCall |= addCmd(dev_data, pCB, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
4693 VkDeviceSize offset_align = 0;
4694 switch (indexType) {
4695 case VK_INDEX_TYPE_UINT16:
4696 offset_align = 2;
4697 break;
4698 case VK_INDEX_TYPE_UINT32:
4699 offset_align = 4;
4700 break;
4701 default:
4702 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
4703 break;
4704 }
4705 if (!offset_align || (offset % offset_align)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004706 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 -07004707 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis9c536442015-06-19 13:00:59 -06004708 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06004709 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004710 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004711 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004712 dev_data->device_dispatch_table->CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004713}
4714
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004715void updateResourceTracking(GLOBAL_CB_NODE* pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers) {
4716 uint32_t end = firstBinding + bindingCount;
Michael Lentine700b0aa2015-10-30 17:57:32 -07004717 if (pCB->currentDrawData.buffers.size() < end) {
4718 pCB->currentDrawData.buffers.resize(end);
4719 }
4720 for (uint32_t i = 0; i < bindingCount; ++i) {
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004721 pCB->currentDrawData.buffers[i + firstBinding] = pBuffers[i];
Michael Lentine700b0aa2015-10-30 17:57:32 -07004722 }
4723}
4724
4725void updateResourceTrackingOnDraw(GLOBAL_CB_NODE* pCB) {
4726 pCB->drawData.push_back(pCB->currentDrawData);
4727}
4728
Chia-I Wu9ab61502015-11-06 06:42:02 +08004729VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004730 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004731 uint32_t firstBinding,
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06004732 uint32_t bindingCount,
Mark Lobodzinskidfcd9b62015-12-14 15:14:10 -07004733 const VkBuffer *pBuffers,
4734 const VkDeviceSize *pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004735{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004736 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004737 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4738 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004739 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004740 addCmd(dev_data, pCB, CMD_BINDVERTEXBUFFER, "vkCmdBindVertexBuffer()");
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07004741 updateResourceTracking(pCB, firstBinding, bindingCount, pBuffers);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004742 } else {
Mark Youngad779052016-01-06 14:26:04 -07004743 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdBindVertexBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004744 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004745 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07004746 dev_data->device_dispatch_table->CmdBindVertexBuffers(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004747}
4748
Chia-I Wu9ab61502015-11-06 06:42:02 +08004749VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004750{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004751 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004752 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4753 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004754 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004755 skipCall |= addCmd(dev_data, pCB, CMD_DRAW, "vkCmdDraw()");
4756 pCB->drawCount[DRAW]++;
4757 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4758 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004759 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 -07004760 "vkCmdDraw() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW]++);
4761 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004762 if (VK_FALSE == skipCall) {
4763 updateResourceTrackingOnDraw(pCB);
4764 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004765 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDraw");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004766 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004767 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004768 dev_data->device_dispatch_table->CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004769}
4770
Chia-I Wu9ab61502015-11-06 06:42:02 +08004771VK_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 -06004772{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004773 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4774 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004775 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004776 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004777 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXED, "vkCmdDrawIndexed()");
4778 pCB->drawCount[DRAW_INDEXED]++;
4779 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4780 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004781 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 -07004782 "vkCmdDrawIndexed() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED]++);
4783 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004784 if (VK_FALSE == skipCall) {
4785 updateResourceTrackingOnDraw(pCB);
4786 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004787 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexed");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004788 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004789 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004790 dev_data->device_dispatch_table->CmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004791}
4792
Chia-I Wu9ab61502015-11-06 06:42:02 +08004793VK_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 -06004794{
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004795 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4796 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004797 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004798 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004799 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDIRECT, "vkCmdDrawIndirect()");
4800 pCB->drawCount[DRAW_INDIRECT]++;
4801 skipCall |= validate_draw_state(dev_data, pCB, VK_FALSE);
4802 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004803 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 -07004804 "vkCmdDrawIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
4805 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004806 if (VK_FALSE == skipCall) {
4807 updateResourceTrackingOnDraw(pCB);
4808 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004809 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004810 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004811 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004812 dev_data->device_dispatch_table->CmdDrawIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004813}
4814
Chia-I Wu9ab61502015-11-06 06:42:02 +08004815VK_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 -06004816{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004817 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004818 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4819 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004820 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004821 skipCall |= addCmd(dev_data, pCB, CMD_DRAWINDEXEDINDIRECT, "vkCmdDrawIndexedIndirect()");
4822 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
4823 skipCall |= validate_draw_state(dev_data, pCB, VK_TRUE);
4824 // TODO : Need to pass commandBuffer as srcObj here
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004825 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 -07004826 "vkCmdDrawIndexedIndirect() call #%" PRIu64 ", reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
4827 skipCall |= synchAndPrintDSConfig(dev_data, commandBuffer);
Michael Lentine700b0aa2015-10-30 17:57:32 -07004828 if (VK_FALSE == skipCall) {
4829 updateResourceTrackingOnDraw(pCB);
4830 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004831 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdDrawIndexedIndirect");
Jon Ashburn3950e1b2015-05-20 09:00:28 -06004832 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004833 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004834 dev_data->device_dispatch_table->CmdDrawIndexedIndirect(commandBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004835}
4836
Chia-I Wu9ab61502015-11-06 06:42:02 +08004837VK_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 -06004838{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004839 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004840 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4841 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004842 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004843 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCH, "vkCmdDispatch()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004844 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatch");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004845 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004846 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004847 dev_data->device_dispatch_table->CmdDispatch(commandBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004848}
4849
Chia-I Wu9ab61502015-11-06 06:42:02 +08004850VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004851{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004852 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004853 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4854 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004855 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004856 skipCall |= addCmd(dev_data, pCB, CMD_DISPATCHINDIRECT, "vkCmdDispatchIndirect()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004857 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdDispatchIndirect");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004858 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004859 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004860 dev_data->device_dispatch_table->CmdDispatchIndirect(commandBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004861}
4862
Chia-I Wu9ab61502015-11-06 06:42:02 +08004863VK_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 -06004864{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004865 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004866 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4867 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004868 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004869 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFER, "vkCmdCopyBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004870 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004871 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004872 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004873 dev_data->device_dispatch_table->CmdCopyBuffer(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004874}
4875
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004876VkBool32 VerifySourceImageLayout(VkCommandBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004877 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004878
4879#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4880 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4881 return skip_call;
4882#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4883
Michael Lentineabc5e922015-10-12 11:30:14 -05004884 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4885 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4886 auto src_image_element = pCB->imageLayoutMap.find(srcImage);
4887 if (src_image_element == pCB->imageLayoutMap.end()) {
4888 pCB->imageLayoutMap[srcImage].initialLayout = srcImageLayout;
4889 pCB->imageLayoutMap[srcImage].layout = srcImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004890 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004891 }
4892 if (src_image_element->second.layout != srcImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004893 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 -05004894 "Cannot copy from an image whose source layout is %d and doesn't match the current layout %d.", srcImageLayout, src_image_element->second.layout);
4895 }
4896 if (srcImageLayout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
4897 if (srcImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004898 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004899 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 -05004900 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Michael Lentineabc5e922015-10-12 11:30:14 -05004901 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004902 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 -05004903 "Layout for input image is %d but can only be TRANSFER_SRC_OPTIMAL or GENERAL.", srcImageLayout);
Michael Lentineabc5e922015-10-12 11:30:14 -05004904 }
4905 }
4906 return skip_call;
4907}
4908
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07004909VkBool32 VerifyDestImageLayout(VkCommandBuffer cmdBuffer, VkImage destImage, VkImageLayout destImageLayout) {
Mark Youngb20a6a82016-01-07 15:41:43 -07004910 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07004911
4912#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
4913 // TODO: Fix -- initialLayout may have been set in a previous command buffer
4914 return skip_call;
4915#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
4916
Michael Lentineabc5e922015-10-12 11:30:14 -05004917 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
4918 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
4919 auto dest_image_element = pCB->imageLayoutMap.find(destImage);
4920 if (dest_image_element == pCB->imageLayoutMap.end()) {
4921 pCB->imageLayoutMap[destImage].initialLayout = destImageLayout;
4922 pCB->imageLayoutMap[destImage].layout = destImageLayout;
Mark Youngb20a6a82016-01-07 15:41:43 -07004923 return VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05004924 }
4925 if (dest_image_element->second.layout != destImageLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004926 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 -05004927 "Cannot copy from an image whose dest layout is %d and doesn't match the current layout %d.", destImageLayout, dest_image_element->second.layout);
4928 }
4929 if (destImageLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
4930 if (destImageLayout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07004931 // LAYOUT_GENERAL is allowed, but may not be performance optimal, flag as perf warning.
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004932 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 -05004933 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
4934 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07004935 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 -05004936 "Layout for output image is %d but can only be TRANSFER_DST_OPTIMAL or GENERAL.", destImageLayout);
4937 }
4938 }
4939 return skip_call;
4940}
4941
Chia-I Wu9ab61502015-11-06 06:42:02 +08004942VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004943 VkImage srcImage,
4944 VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004945 VkImage dstImage,
4946 VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004947 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004948{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004949 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004950 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4951 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004952 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004953 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGE, "vkCmdCopyImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004954 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004955 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
4956 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004957 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004958 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004959 dev_data->device_dispatch_table->CmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004960}
4961
Chia-I Wu9ab61502015-11-06 06:42:02 +08004962VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004963 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004964 VkImage dstImage, VkImageLayout dstImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05004965 uint32_t regionCount, const VkImageBlit* pRegions,
Chia-I Wub99df442015-10-26 16:49:32 +08004966 VkFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004967{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004968 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004969 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4970 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004971 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004972 skipCall |= addCmd(dev_data, pCB, CMD_BLITIMAGE, "vkCmdBlitImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004973 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBlitImage");
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004974 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004975 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004976 dev_data->device_dispatch_table->CmdBlitImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06004977}
4978
Chia-I Wu9ab61502015-11-06 06:42:02 +08004979VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004980 VkBuffer srcBuffer,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004981 VkImage dstImage, VkImageLayout dstImageLayout,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004982 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004983{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004984 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004985 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
4986 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004987 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07004988 skipCall |= addCmd(dev_data, pCB, CMD_COPYBUFFERTOIMAGE, "vkCmdCopyBufferToImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06004989 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyBufferToImage");
Michael Lentineabc5e922015-10-12 11:30:14 -05004990 skipCall |= VerifyDestImageLayout(commandBuffer, dstImage, dstImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004991 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06004992 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004993 dev_data->device_dispatch_table->CmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06004994}
4995
Chia-I Wu9ab61502015-11-06 06:42:02 +08004996VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004997 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004998 VkBuffer dstBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06004999 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005000{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005001 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005002 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5003 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005004 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005005 skipCall |= addCmd(dev_data, pCB, CMD_COPYIMAGETOBUFFER, "vkCmdCopyImageToBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005006 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyImageToBuffer");
Michael Lentineabc5e922015-10-12 11:30:14 -05005007 skipCall |= VerifySourceImageLayout(commandBuffer, srcImage, srcImageLayout);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005008 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005009 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005010 dev_data->device_dispatch_table->CmdCopyImageToBuffer(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005011}
5012
Chia-I Wu9ab61502015-11-06 06:42:02 +08005013VK_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 -06005014{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005015 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005016 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5017 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005018 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005019 skipCall |= addCmd(dev_data, pCB, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005020 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyUpdateBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005021 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005022 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005023 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005024}
5025
Chia-I Wu9ab61502015-11-06 06:42:02 +08005026VK_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 -06005027{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005028 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005029 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5030 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005031 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005032 skipCall |= addCmd(dev_data, pCB, CMD_FILLBUFFER, "vkCmdFillBuffer()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005033 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyFillBuffer");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005034 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005035 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005036 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005037}
5038
Chia-I Wu9ab61502015-11-06 06:42:02 +08005039VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005040 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005041 uint32_t attachmentCount,
5042 const VkClearAttachment* pAttachments,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005043 uint32_t rectCount,
Courtney Goeltzenleuchter4ca43f62015-10-15 18:22:08 -06005044 const VkClearRect* pRects)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005045{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005046 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005047 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5048 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005049 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005050 skipCall |= addCmd(dev_data, pCB, CMD_CLEARATTACHMENTS, "vkCmdClearAttachments()");
5051 // Warn if this is issued prior to Draw Cmd and clearing the entire attachment
5052 if (!hasDrawCmd(pCB) &&
5053 (pCB->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
5054 (pCB->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
5055 // TODO : commandBuffer should be srcObj
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005056 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 -07005057 "vkCmdClearAttachments() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Mark Youngee3f3a22016-01-25 12:18:32 -07005058 " It is recommended you use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.", (uint64_t)(commandBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005059 }
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005060 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdClearAttachments");
5061 }
5062
5063 // Validate that attachment is in reference list of active subpass
5064 if (pCB->activeRenderPass) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005065 const VkRenderPassCreateInfo *pRPCI = dev_data->renderPassMap[pCB->activeRenderPass]->pCreateInfo;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005066 const VkSubpassDescription *pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
5067
5068 for (uint32_t attachment_idx = 0; attachment_idx < attachmentCount; attachment_idx++) {
5069 const VkClearAttachment *attachment = &pAttachments[attachment_idx];
5070 if (attachment->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
5071 VkBool32 found = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005072 for (uint32_t i = 0; i < pSD->colorAttachmentCount; i++) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005073 if (attachment->colorAttachment == pSD->pColorAttachments[i].attachment) {
5074 found = VK_TRUE;
5075 break;
5076 }
5077 }
5078 if (VK_FALSE == found) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005079 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 -07005080 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005081 "vkCmdClearAttachments() attachment index %d not found in attachment reference array of active subpass %d",
5082 attachment->colorAttachment, pCB->activeSubpass);
5083 }
5084 } else if (attachment->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005085 if (!pSD->pDepthStencilAttachment || // Says no DS will be used in active subpass
Mark Lobodzinski2fd355a2015-11-18 08:58:31 -07005086 (pSD->pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED)) { // Says no DS will be used in active subpass
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005087
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005088 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 -07005089 (uint64_t)commandBuffer, __LINE__, DRAWSTATE_MISSING_ATTACHMENT_REFERENCE, "DS",
Mark Lobodzinskid6e7bff2015-11-17 15:11:24 -07005090 "vkCmdClearAttachments() attachment index %d does not match depthStencilAttachment.attachment (%d) found in active subpass %d",
5091 attachment->colorAttachment,
5092 (pSD->pDepthStencilAttachment) ? pSD->pDepthStencilAttachment->attachment : VK_ATTACHMENT_UNUSED,
5093 pCB->activeSubpass);
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06005094 }
5095 }
5096 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005097 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005098 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005099 dev_data->device_dispatch_table->CmdClearAttachments(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06005100}
5101
Chia-I Wu9ab61502015-11-06 06:42:02 +08005102VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005103 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06005104 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12005105 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06005106 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005107{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005108 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005109 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5110 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005111 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005112 skipCall |= addCmd(dev_data, pCB, CMD_CLEARCOLORIMAGE, "vkCmdClearColorImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005113 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearColorImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005114 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005115 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005116 dev_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005117}
5118
Chia-I Wu9ab61502015-11-06 06:42:02 +08005119VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005120 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06005121 VkImage image, VkImageLayout imageLayout,
5122 const VkClearDepthStencilValue *pDepthStencil,
5123 uint32_t rangeCount,
5124 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005125{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005126 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005127 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5128 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005129 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005130 skipCall |= addCmd(dev_data, pCB, CMD_CLEARDEPTHSTENCILIMAGE, "vkCmdClearDepthStencilImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005131 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdClearDepthStencilImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005132 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005133 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005134 dev_data->device_dispatch_table->CmdClearDepthStencilImage(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005135}
5136
Chia-I Wu9ab61502015-11-06 06:42:02 +08005137VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005138 VkImage srcImage, VkImageLayout srcImageLayout,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005139 VkImage dstImage, VkImageLayout dstImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06005140 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005141{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005142 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005143 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5144 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005145 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005146 skipCall |= addCmd(dev_data, pCB, CMD_RESOLVEIMAGE, "vkCmdResolveImage()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005147 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResolveImage");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005148 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005149 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005150 dev_data->device_dispatch_table->CmdResolveImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005151}
5152
Chia-I Wu9ab61502015-11-06 06:42:02 +08005153VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005154{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005155 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005156 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5157 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005158 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005159 skipCall |= addCmd(dev_data, pCB, CMD_SETEVENT, "vkCmdSetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005160 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdSetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005161 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005162 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005163 dev_data->device_dispatch_table->CmdSetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005164}
5165
Chia-I Wu9ab61502015-11-06 06:42:02 +08005166VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005167{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005168 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005169 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5170 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005171 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005172 skipCall |= addCmd(dev_data, pCB, CMD_RESETEVENT, "vkCmdResetEvent()");
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005173 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdResetEvent");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005174 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005175 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005176 dev_data->device_dispatch_table->CmdResetEvent(commandBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005177}
5178
Jon Ashburnf19916e2016-01-11 13:12:43 -07005179VkBool32 TransitionImageLayouts(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkImageMemoryBarrier* pImgMemBarriers) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005180 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5181 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Mark Youngb20a6a82016-01-07 15:41:43 -07005182 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005183
5184#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5185 // TODO: Fix -- pay attention to image subresource ranges -- not all subresources transition at the same time
5186 return skip;
5187#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5188
Michael Lentineabc5e922015-10-12 11:30:14 -05005189 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005190 auto mem_barrier = &pImgMemBarriers[i];
Michael Lentineabc5e922015-10-12 11:30:14 -05005191 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005192 auto image_data = pCB->imageLayoutMap.find(mem_barrier->image);
Michael Lentineabc5e922015-10-12 11:30:14 -05005193 if (image_data == pCB->imageLayoutMap.end()) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005194 pCB->imageLayoutMap[mem_barrier->image].initialLayout = mem_barrier->oldLayout;
5195 pCB->imageLayoutMap[mem_barrier->image].layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005196 } else {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005197 if (image_data->second.layout != mem_barrier->oldLayout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005198 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 -07005199 "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 -05005200 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005201 image_data->second.layout = mem_barrier->newLayout;
Michael Lentineabc5e922015-10-12 11:30:14 -05005202 }
5203 }
5204 }
5205 return skip;
5206}
5207
Mark Lobodzinskia3a86112016-01-05 17:17:55 -07005208// Print readable FlagBits in FlagMask
5209std::string string_VkAccessFlags(VkAccessFlags accessMask)
5210{
5211 std::string result;
5212 std::string separator;
5213
5214 if (accessMask == 0) {
5215 result = "[None]";
5216 } else {
5217 result = "[";
5218 for (auto i = 0; i < 32; i++) {
5219 if (accessMask & (1 << i)) {
5220 result = result + separator + string_VkAccessFlagBits((VkAccessFlagBits)(1 << i));
5221 separator = " | ";
5222 }
5223 }
5224 result = result + "]";
5225 }
5226 return result;
5227}
5228
Michael Lentine97eb7462015-11-20 09:48:52 -08005229// AccessFlags MUST have 'required_bit' set, and may have one or more of 'optional_bits' set.
5230// If required_bit is zero, accessMask must have at least one of 'optional_bits' set
Mark Lobodzinskifd740fc2016-01-06 12:56:29 -07005231// TODO: Add tracking to ensure that at least one barrier has been set for these layout transitions
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005232VkBool32 ValidateMaskBits(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout,
5233 VkAccessFlags required_bit, VkAccessFlags optional_bits, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005234 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005235
Michael Lentine97eb7462015-11-20 09:48:52 -08005236 if ((accessMask & required_bit) || (!required_bit && (accessMask & optional_bits))) {
5237 if (accessMask & !(required_bit | optional_bits)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005238 // TODO: Verify against Valid Use
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005239 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 -07005240 "Additional bits in %s accessMask %d %s are specified when layout is %s.",
5241 type, accessMask, string_VkAccessFlags(accessMask).c_str(), string_VkImageLayout(layout));
Michael Lentineecc32b72015-10-16 18:08:09 -05005242 }
5243 } else {
Michael Lentine97eb7462015-11-20 09:48:52 -08005244 if (!required_bit) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005245 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 -07005246 "%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 -07005247 type, accessMask, string_VkAccessFlags(accessMask).c_str(), optional_bits,
5248 string_VkAccessFlags(optional_bits).c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005249 } else {
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005250 std::string opt_bits;
5251 if (optional_bits != 0) {
Michael Lentine6bd4f122016-01-19 14:00:53 -06005252 std::stringstream ss;
5253 ss << optional_bits;
5254 opt_bits = "and may have optional bits " + ss.str() + ' ' + string_VkAccessFlags(optional_bits);
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005255 }
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005256 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 -07005257 "%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 -07005258 type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5259 required_bit, string_VkAccessFlags(required_bit).c_str(),
Mark Lobodzinskif2cc2a52016-01-05 13:35:29 -07005260 opt_bits.c_str(), string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005261 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005262 }
5263 return skip_call;
5264}
5265
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005266VkBool32 ValidateMaskBitsFromLayouts(const layer_data* my_data, VkCommandBuffer cmdBuffer, const VkAccessFlags& accessMask, const VkImageLayout& layout, const char* type) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005267 VkBool32 skip_call = VK_FALSE;
Michael Lentine97eb7462015-11-20 09:48:52 -08005268 switch (layout) {
5269 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005270 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 -08005271 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005272 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005273 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005274 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 -08005275 break;
Michael Lentineecc32b72015-10-16 18:08:09 -05005276 }
Michael Lentine97eb7462015-11-20 09:48:52 -08005277 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005278 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005279 break;
5280 }
5281 case VK_IMAGE_LAYOUT_PREINITIALIZED: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005282 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_HOST_WRITE_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005283 break;
5284 }
5285 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005286 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 -08005287 break;
5288 }
5289 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005290 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 -08005291 break;
5292 }
5293 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: {
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005294 skip_call |= ValidateMaskBits(my_data, cmdBuffer, accessMask, layout, VK_ACCESS_TRANSFER_READ_BIT, 0, type);
Michael Lentine97eb7462015-11-20 09:48:52 -08005295 break;
5296 }
5297 case VK_IMAGE_LAYOUT_UNDEFINED: {
5298 if (accessMask != 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005299 // TODO: Verify against Valid Use section spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005300 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_BARRIER, "DS",
Mark Lobodzinski882655d2016-01-05 11:32:53 -07005301 "Additional bits in %s accessMask %d %s are specified when layout is %s.", type, accessMask, string_VkAccessFlags(accessMask).c_str(),
5302 string_VkImageLayout(layout));
Michael Lentine97eb7462015-11-20 09:48:52 -08005303 }
5304 break;
5305 }
5306 case VK_IMAGE_LAYOUT_GENERAL:
5307 default: {
5308 break;
5309 }
Michael Lentineecc32b72015-10-16 18:08:09 -05005310 }
5311 return skip_call;
5312}
5313
Jon Ashburnf19916e2016-01-11 13:12:43 -07005314VkBool32 ValidateBarriers(VkCommandBuffer cmdBuffer, uint32_t memBarrierCount, const VkMemoryBarrier* pMemBarriers, uint32_t imageMemBarrierCount, const VkImageMemoryBarrier *pImageMemBarriers)
5315{
Mark Youngb20a6a82016-01-07 15:41:43 -07005316 VkBool32 skip_call = VK_FALSE;
Michael Lentine48930b82015-10-15 17:07:00 -05005317 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5318 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5319 if (pCB->activeRenderPass && memBarrierCount) {
5320 for (uint32_t i = 0; i < memBarrierCount; ++i) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005321 auto mem_barrier = &pMemBarriers[i];
Michael Lentine48930b82015-10-15 17:07:00 -05005322 if (mem_barrier && mem_barrier->sType != VK_STRUCTURE_TYPE_MEMORY_BARRIER) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005323 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 -05005324 "Image or Buffers Barriers cannot be used during a render pass.");
5325 }
5326 }
5327 if (!dev_data->renderPassMap[pCB->activeRenderPass]->hasSelfDependency[pCB->activeSubpass]) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005328 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 -05005329 "Barriers cannot be set during subpass %d with no self dependency specified.", pCB->activeSubpass);
5330 }
5331 }
Mark Lobodzinski73a37ec2015-11-20 09:27:27 -07005332
Jon Ashburnf19916e2016-01-11 13:12:43 -07005333 for (uint32_t i = 0; i < imageMemBarrierCount; ++i) {
5334 auto mem_barrier = &pImageMemBarriers[i];
Michael Lentineecc32b72015-10-16 18:08:09 -05005335 if (mem_barrier && mem_barrier->sType == VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005336 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->srcAccessMask, mem_barrier->oldLayout, "Source");
5337 skip_call |= ValidateMaskBitsFromLayouts(dev_data, cmdBuffer, mem_barrier->dstAccessMask, mem_barrier->newLayout, "Dest");
Michael Lentineecc32b72015-10-16 18:08:09 -05005338 }
5339 }
Mark Lobodzinski3cba24a2015-12-03 15:42:32 -07005340
Michael Lentine48930b82015-10-15 17:07:00 -05005341 return skip_call;
5342}
5343
Jon Ashburnf19916e2016-01-11 13:12:43 -07005344VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
5345 VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
5346 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
5347 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5348 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5349 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005350{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005351 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005352 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5353 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005354 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005355 for (uint32_t i = 0; i < eventCount; ++i) {
5356 pCB->waitedEvents.push_back(pEvents[i]);
5357 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005358 if (pCB->state == CB_RECORDING) {
5359 skipCall |= addCmd(dev_data, pCB, CMD_WAITEVENTS, "vkCmdWaitEvents()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005360 } else {
5361 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWaitEvents()");
5362 }
Jon Ashburnf19916e2016-01-11 13:12:43 -07005363 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5364 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005365 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005366 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005367 dev_data->device_dispatch_table->CmdWaitEvents(commandBuffer, eventCount, pEvents, sourceStageMask, dstStageMask,
5368 memoryBarrierCount, pMemoryBarriers,
5369 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5370 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005371}
5372
Jon Ashburnf19916e2016-01-11 13:12:43 -07005373VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
5374 VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
5375 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
5376 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
5377 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
5378 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005379{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005380 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005381 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5382 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005383 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005384 skipCall |= addCmd(dev_data, pCB, CMD_PIPELINEBARRIER, "vkCmdPipelineBarrier()");
Jon Ashburnf19916e2016-01-11 13:12:43 -07005385 skipCall |= TransitionImageLayouts(commandBuffer, imageMemoryBarrierCount, pImageMemoryBarriers);
5386 skipCall |= ValidateBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005387 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005388 if (VK_FALSE == skipCall)
Jon Ashburnf19916e2016-01-11 13:12:43 -07005389 dev_data->device_dispatch_table->CmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags,
5390 memoryBarrierCount, pMemoryBarriers,
5391 bufferMemoryBarrierCount, pBufferMemoryBarriers,
5392 imageMemoryBarrierCount, pImageMemoryBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005393}
5394
Chia-I Wu9ab61502015-11-06 06:42:02 +08005395VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005396{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005397 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005398 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5399 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005400 if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005401 skipCall |= addCmd(dev_data, pCB, CMD_BEGINQUERY, "vkCmdBeginQuery()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005402 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005403 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005404 dev_data->device_dispatch_table->CmdBeginQuery(commandBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005405}
5406
Chia-I Wu9ab61502015-11-06 06:42:02 +08005407VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005408{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005409 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005410 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5411 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005412 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005413 QueryObject query = {queryPool, slot};
5414 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005415 if (pCB->state == CB_RECORDING) {
5416 skipCall |= addCmd(dev_data, pCB, CMD_ENDQUERY, "VkCmdEndQuery()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005417 } else {
5418 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdEndQuery()");
5419 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005420 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005421 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005422 dev_data->device_dispatch_table->CmdEndQuery(commandBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005423}
5424
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005425VK_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 -06005426{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005427 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005428 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5429 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005430 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005431 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005432 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005433 pCB->waitedEventsBeforeQueryReset[query] = pCB->waitedEvents;
5434 pCB->queryToStateMap[query] = 0;
5435 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005436 if (pCB->state == CB_RECORDING) {
5437 skipCall |= addCmd(dev_data, pCB, CMD_RESETQUERYPOOL, "VkCmdResetQueryPool()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005438 } else {
5439 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdResetQueryPool()");
5440 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005441 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdQueryPool");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005442 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005443 if (VK_FALSE == skipCall)
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005444 dev_data->device_dispatch_table->CmdResetQueryPool(commandBuffer, queryPool, firstQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005445}
5446
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005447VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery,
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005448 uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset,
Chia-I Wuccc93a72015-10-26 18:36:20 +08005449 VkDeviceSize stride, VkQueryResultFlags flags)
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005450{
5451 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005452 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5453 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005454 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005455 for (uint32_t i = 0; i < queryCount; i++) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005456 QueryObject query = {queryPool, firstQuery + i};
Michael Lentineb887b0a2015-12-29 14:12:11 -06005457 if(!pCB->queryToStateMap[query]) {
Mark Lobodzinskice738852016-01-07 10:04:02 -07005458 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_QUERY, "DS",
Mark Young93ecb1d2016-01-13 13:47:16 -07005459 "Requesting a copy from query to buffer with invalid query: queryPool %" PRIu64 ", index %d", (uint64_t)(queryPool), firstQuery + i);
Michael Lentineb887b0a2015-12-29 14:12:11 -06005460 }
5461 }
Mark Lobodzinskice738852016-01-07 10:04:02 -07005462 if (pCB->state == CB_RECORDING) {
5463 skipCall |= addCmd(dev_data, pCB, CMD_COPYQUERYPOOLRESULTS, "vkCmdCopyQueryPoolResults()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005464 } else {
5465 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdCopyQueryPoolResults()");
5466 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005467 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdCopyQueryPoolResults");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005468 }
5469 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005470 dev_data->device_dispatch_table->CmdCopyQueryPoolResults(commandBuffer, queryPool,
Jon Ashburn19d3bf12015-12-30 14:06:55 -07005471 firstQuery, queryCount, dstBuffer, dstOffset, stride, flags);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005472}
5473
Chia-I Wu9ab61502015-11-06 06:42:02 +08005474VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005475{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005476 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005477 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5478 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005479 if (pCB) {
Michael Lentineb887b0a2015-12-29 14:12:11 -06005480 QueryObject query = {queryPool, slot};
5481 pCB->queryToStateMap[query] = 1;
Mark Lobodzinskice738852016-01-07 10:04:02 -07005482 if (pCB->state == CB_RECORDING) {
5483 skipCall |= addCmd(dev_data, pCB, CMD_WRITETIMESTAMP, "vkCmdWriteTimestamp()");
Michael Lentineb887b0a2015-12-29 14:12:11 -06005484 } else {
5485 skipCall |= report_error_no_cb_begin(dev_data, commandBuffer, "vkCmdWriteTimestamp()");
5486 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005487 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005488 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005489 dev_data->device_dispatch_table->CmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005490}
5491
Chia-I Wu9ab61502015-11-06 06:42:02 +08005492VK_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 -06005493{
Tobin Ehlis0b632332015-10-07 09:38:40 -06005494 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +08005495 VkResult result = dev_data->device_dispatch_table->CreateFramebuffer(device, pCreateInfo, pAllocator, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005496 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06005497 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005498 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005499 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06005500 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
5501 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005502 }
Chia-I Wue2fc5522015-10-26 20:04:44 +08005503 dev_data->frameBufferMap[*pFramebuffer] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06005504 }
5505 return result;
5506}
5507
Michael Lentineb6986752015-10-06 14:56:18 -07005508// Store the DAG.
5509struct DAGNode {
5510 uint32_t pass;
5511 std::vector<uint32_t> prev;
5512 std::vector<uint32_t> next;
5513};
5514
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005515VkBool32 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 -07005516 // If we have already checked this node we have not found a dependency path so return false.
5517 if (processed_nodes.count(index))
Mark Youngb20a6a82016-01-07 15:41:43 -07005518 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005519 processed_nodes.insert(index);
5520 const DAGNode& node = subpass_to_node[index];
5521 // Look for a dependency path. If one exists return true else recurse on the previous nodes.
5522 if (std::find(node.prev.begin(), node.prev.end(), dependent) == node.prev.end()) {
5523 for (auto elem : node.prev) {
5524 if (FindDependency(elem, dependent, subpass_to_node, processed_nodes))
Mark Youngb20a6a82016-01-07 15:41:43 -07005525 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005526 }
5527 } else {
Mark Youngb20a6a82016-01-07 15:41:43 -07005528 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005529 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005530 return VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005531}
5532
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005533VkBool32 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 -07005534 VkBool32 result = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005535 // Loop through all subpasses that share the same attachment and make sure a dependency exists
5536 for (uint32_t k = 0; k < dependent_subpasses.size(); ++k) {
5537 if (subpass == dependent_subpasses[k])
5538 continue;
5539 const DAGNode& node = subpass_to_node[subpass];
5540 // Check for a specified dependency between the two nodes. If one exists we are done.
5541 auto prev_elem = std::find(node.prev.begin(), node.prev.end(), dependent_subpasses[k]);
5542 auto next_elem = std::find(node.next.begin(), node.next.end(), dependent_subpasses[k]);
5543 if (prev_elem == node.prev.end() && next_elem == node.next.end()) {
5544 // If no dependency exits an implicit dependency still might. If so, warn and if not throw an error.
5545 std::unordered_set<uint32_t> processed_nodes;
5546 if (FindDependency(subpass, dependent_subpasses[k], subpass_to_node, processed_nodes) ||
5547 FindDependency(dependent_subpasses[k], subpass, subpass_to_node, processed_nodes)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005548 // TODO: Verify against Valid Use section of spec
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005549 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 -07005550 "A dependency between subpasses %d and %d must exist but only an implicit one is specified.",
5551 subpass, dependent_subpasses[k]);
5552 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005553 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 -07005554 "A dependency between subpasses %d and %d must exist but one is not specified.",
5555 subpass, dependent_subpasses[k]);
Mark Youngb20a6a82016-01-07 15:41:43 -07005556 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005557 }
5558 }
5559 }
5560 return result;
5561}
5562
Jon Ashburnf19916e2016-01-11 13:12:43 -07005563VkBool32 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 -07005564 const DAGNode& node = subpass_to_node[index];
5565 // If this node writes to the attachment return true as next nodes need to preserve the attachment.
5566 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005567 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005568 if (attachment == subpass.pColorAttachments[j].attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005569 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005570 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005571 if (subpass.pDepthStencilAttachment &&
5572 subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5573 if (attachment == subpass.pDepthStencilAttachment->attachment)
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005574 return VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005575 }
Courtney Goeltzenleuchter6ed5dc22015-11-03 15:41:43 -07005576 VkBool32 result = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005577 // Loop through previous nodes and see if any of them write to the attachment.
5578 for (auto elem : node.prev) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005579 result |= CheckPreserved(my_data, device, pCreateInfo, elem, attachment, subpass_to_node, depth + 1, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005580 }
5581 // If the attachment was written to by a previous node than this node needs to preserve it.
5582 if (result && depth > 0) {
5583 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[index];
Mark Youngb20a6a82016-01-07 15:41:43 -07005584 VkBool32 has_preserved = VK_FALSE;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005585 for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
Jon Ashburnf19916e2016-01-11 13:12:43 -07005586 if (subpass.pPreserveAttachments[j] == attachment) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005587 has_preserved = VK_TRUE;
Michael Lentineb6986752015-10-06 14:56:18 -07005588 break;
5589 }
5590 }
Mark Youngb20a6a82016-01-07 15:41:43 -07005591 if (has_preserved == VK_FALSE) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005592 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 -07005593 "Attachment %d is used by a later subpass and must be preserved in subpass %d.", attachment, index);
5594 }
5595 }
5596 return result;
5597}
5598
Michael Lentineb4979492015-12-22 11:36:14 -06005599VkBool32 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 -07005600 VkBool32 skip_call = VK_FALSE;
Michael Lentineb6986752015-10-06 14:56:18 -07005601 std::vector<std::vector<uint32_t>> output_attachment_to_subpass(pCreateInfo->attachmentCount);
5602 std::vector<std::vector<uint32_t>> input_attachment_to_subpass(pCreateInfo->attachmentCount);
Michael Lentineb6986752015-10-06 14:56:18 -07005603 // Find for each attachment the subpasses that use them.
5604 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5605 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005606 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005607 input_attachment_to_subpass[subpass.pInputAttachments[j].attachment].push_back(i);
5608 }
Chia-I Wud50a7d72015-10-26 20:48:51 +08005609 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005610 output_attachment_to_subpass[subpass.pColorAttachments[j].attachment].push_back(i);
5611 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005612 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5613 output_attachment_to_subpass[subpass.pDepthStencilAttachment->attachment].push_back(i);
Michael Lentineb6986752015-10-06 14:56:18 -07005614 }
5615 }
5616 // If there is a dependency needed make sure one exists
5617 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5618 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5619 // If the attachment is an input then all subpasses that output must have a dependency relationship
Chia-I Wud50a7d72015-10-26 20:48:51 +08005620 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005621 const uint32_t& attachment = subpass.pInputAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005622 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005623 }
5624 // 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 +08005625 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
Michael Lentineb6986752015-10-06 14:56:18 -07005626 const uint32_t& attachment = subpass.pColorAttachments[j].attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005627 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5628 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005629 }
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005630 if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
5631 const uint32_t& attachment = subpass.pDepthStencilAttachment->attachment;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005632 CheckDependencyExists(my_data, device, i, output_attachment_to_subpass[attachment], subpass_to_node, skip_call);
5633 CheckDependencyExists(my_data, device, i, input_attachment_to_subpass[attachment], subpass_to_node, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005634 }
5635 }
5636 // Loop through implicit dependencies, if this pass reads make sure the attachment is preserved for all passes after it was written.
5637 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5638 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005639 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005640 CheckPreserved(my_data, device, pCreateInfo, i, subpass.pInputAttachments[j].attachment, subpass_to_node, 0, skip_call);
Michael Lentineb6986752015-10-06 14:56:18 -07005641 }
5642 }
5643 return skip_call;
5644}
5645
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005646VkBool32 ValidateLayouts(const layer_data* my_data, VkDevice device, const VkRenderPassCreateInfo* pCreateInfo) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005647 VkBool32 skip = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07005648
5649#ifdef DISABLE_IMAGE_LAYOUT_VALIDATION
5650 return skip;
5651#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
5652
Michael Lentineabc5e922015-10-12 11:30:14 -05005653 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5654 const VkSubpassDescription& subpass = pCreateInfo->pSubpasses[i];
5655 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5656 if (subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL &&
5657 subpass.pInputAttachments[j].layout != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
5658 if (subpass.pInputAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005659 // 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 -07005660 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 -05005661 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
5662 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005663 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 -05005664 "Layout for input attachment is %d but can only be READ_ONLY_OPTIMAL or GENERAL.", subpass.pInputAttachments[j].attachment);
5665 }
5666 }
5667 }
5668 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5669 if (subpass.pColorAttachments[j].layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
5670 if (subpass.pColorAttachments[j].layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005671 // 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 -07005672 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 -05005673 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
5674 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005675 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 -05005676 "Layout for color attachment is %d but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pColorAttachments[j].attachment);
5677 }
5678 }
5679 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005680 if ((subpass.pDepthStencilAttachment != NULL) &&
5681 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005682 if (subpass.pDepthStencilAttachment->layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
5683 if (subpass.pDepthStencilAttachment->layout == VK_IMAGE_LAYOUT_GENERAL) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005684 // 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 -07005685 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 -05005686 "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL.");
5687 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005688 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 -05005689 "Layout for depth attachment is %d but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL.", subpass.pDepthStencilAttachment->attachment);
5690 }
5691 }
5692 }
5693 }
5694 return skip;
5695}
5696
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005697VkBool32 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 -07005698 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005699 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
5700 DAGNode& subpass_node = subpass_to_node[i];
5701 subpass_node.pass = i;
5702 }
5703 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
5704 const VkSubpassDependency& dependency = pCreateInfo->pDependencies[i];
Michael Lentine6bd4f122016-01-19 14:00:53 -06005705 if (dependency.srcSubpass > dependency.dstSubpass && dependency.srcSubpass != VK_SUBPASS_EXTERNAL && dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005706 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 -05005707 "Depedency graph must be specified such that an earlier pass cannot depend on a later pass.");
Michael Lentine6bd4f122016-01-19 14:00:53 -06005708 } else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL && dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
5709 skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, DRAWSTATE_INVALID_RENDERPASS, "DS",
5710 "The src and dest subpasses cannot both be external.");
Michael Lentine48930b82015-10-15 17:07:00 -05005711 } else if (dependency.srcSubpass == dependency.dstSubpass) {
5712 has_self_dependency[dependency.srcSubpass] = true;
Michael Lentineabc5e922015-10-12 11:30:14 -05005713 }
Michael Lentine6bd4f122016-01-19 14:00:53 -06005714 if (dependency.dstSubpass != VK_SUBPASS_EXTERNAL) {
5715 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
5716 }
5717 if (dependency.srcSubpass != VK_SUBPASS_EXTERNAL) {
5718 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
5719 }
Michael Lentineabc5e922015-10-12 11:30:14 -05005720 }
5721 return skip_call;
5722}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005723// TODOSC : Add intercept of vkCreateShaderModule
Michael Lentineabc5e922015-10-12 11:30:14 -05005724
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005725VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
5726 VkDevice device,
5727 const VkShaderModuleCreateInfo *pCreateInfo,
5728 const VkAllocationCallbacks* pAllocator,
5729 VkShaderModule *pShaderModule)
5730{
5731 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07005732 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005733 if (!shader_is_spirv(pCreateInfo)) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07005734 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 -07005735 /* dev */ 0, __LINE__, SHADER_CHECKER_NON_SPIRV_SHADER, "SC",
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005736 "Shader is not SPIR-V");
5737 }
5738
Mark Youngb20a6a82016-01-07 15:41:43 -07005739 if (VK_FALSE != skip_call)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005740 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005741
5742 VkResult res = my_data->device_dispatch_table->CreateShaderModule(device, pCreateInfo, pAllocator, pShaderModule);
5743
5744 if (res == VK_SUCCESS) {
5745 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005746 my_data->shaderModuleMap[*pShaderModule] = new shader_module(pCreateInfo);
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005747 loader_platform_thread_unlock_mutex(&globalLock);
5748 }
5749 return res;
5750}
5751
Chia-I Wu9ab61502015-11-06 06:42:02 +08005752VK_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 -06005753{
Mark Youngb20a6a82016-01-07 15:41:43 -07005754 VkBool32 skip_call = VK_FALSE;
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005755 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05005756 // Create DAG
Michael Lentine48930b82015-10-15 17:07:00 -05005757 std::vector<bool> has_self_dependency(pCreateInfo->subpassCount);
Michael Lentineabc5e922015-10-12 11:30:14 -05005758 std::vector<DAGNode> subpass_to_node(pCreateInfo->subpassCount);
Michael Lentine48930b82015-10-15 17:07:00 -05005759 skip_call |= CreatePassDAG(dev_data, device, pCreateInfo, subpass_to_node, has_self_dependency);
Michael Lentineabc5e922015-10-12 11:30:14 -05005760 // Validate using DAG
5761 skip_call |= ValidateDependencies(dev_data, device, pCreateInfo, subpass_to_node);
5762 skip_call |= ValidateLayouts(dev_data, device, pCreateInfo);
Mark Youngb20a6a82016-01-07 15:41:43 -07005763 if (VK_FALSE != skip_call) {
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07005764 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineb6986752015-10-06 14:56:18 -07005765 }
Chia-I Wuf7458c52015-10-26 21:10:41 +08005766 VkResult result = dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06005767 if (VK_SUCCESS == result) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07005768 // TODOSC : Merge in tracking of renderpass from ShaderChecker
Tobin Ehliseba312c2015-04-01 08:40:34 -06005769 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06005770 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08005771 if (pCreateInfo->pAttachments) {
5772 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
5773 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005774 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005775 if (pCreateInfo->pSubpasses) {
5776 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
5777 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
5778
5779 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
5780 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
Chia-I Wud50a7d72015-10-26 20:48:51 +08005781 const uint32_t attachmentCount = subpass->inputAttachmentCount +
5782 subpass->colorAttachmentCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005783 ((subpass->pDepthStencilAttachment) ? 1 : 0) + subpass->preserveAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005784 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
5785
Cody Northropa505dda2015-08-04 11:16:41 -06005786 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005787 sizeof(attachments[0]) * subpass->inputAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005788 subpass->pInputAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005789 attachments += subpass->inputAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005790
Cody Northropa505dda2015-08-04 11:16:41 -06005791 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005792 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005793 subpass->pColorAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005794 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005795
Cody Northropa505dda2015-08-04 11:16:41 -06005796 if (subpass->pResolveAttachments) {
5797 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005798 sizeof(attachments[0]) * subpass->colorAttachmentCount);
Cody Northropa505dda2015-08-04 11:16:41 -06005799 subpass->pResolveAttachments = attachments;
Chia-I Wud50a7d72015-10-26 20:48:51 +08005800 attachments += subpass->colorAttachmentCount;
Chia-I Wu08accc62015-07-07 11:50:03 +08005801 }
5802
Chia-I Wu1efb7e52015-10-26 17:32:47 +08005803 if (subpass->pDepthStencilAttachment) {
5804 memcpy(attachments, subpass->pDepthStencilAttachment,
5805 sizeof(attachments[0]) * 1);
5806 subpass->pDepthStencilAttachment = attachments;
5807 attachments += 1;
5808 }
5809
Cody Northropa505dda2015-08-04 11:16:41 -06005810 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wud50a7d72015-10-26 20:48:51 +08005811 sizeof(attachments[0]) * subpass->preserveAttachmentCount);
Jon Ashburnf19916e2016-01-11 13:12:43 -07005812 subpass->pPreserveAttachments = &attachments->attachment;
Chia-I Wu08accc62015-07-07 11:50:03 +08005813 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06005814 }
Chia-I Wu08accc62015-07-07 11:50:03 +08005815 if (pCreateInfo->pDependencies) {
5816 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
5817 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06005818 }
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005819 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005820 dev_data->renderPassMap[*pRenderPass] = new RENDER_PASS_NODE(localRPCI);
Michael Lentine48930b82015-10-15 17:07:00 -05005821 dev_data->renderPassMap[*pRenderPass]->hasSelfDependency = has_self_dependency;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07005822 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06005823 }
5824 return result;
5825}
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005826// Free the renderpass shadow
5827static void deleteRenderPasses(layer_data* my_data)
5828{
5829 if (my_data->renderPassMap.size() <= 0)
5830 return;
5831 for (auto ii=my_data->renderPassMap.begin(); ii!=my_data->renderPassMap.end(); ++ii) {
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005832 const VkRenderPassCreateInfo* pRenderPassInfo = (*ii).second->pCreateInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005833 if (pRenderPassInfo->pAttachments) {
5834 delete[] pRenderPassInfo->pAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005835 }
Michael Lentine48930b82015-10-15 17:07:00 -05005836 if (pRenderPassInfo->pSubpasses) {
5837 for (uint32_t i=0; i<pRenderPassInfo->subpassCount; ++i) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005838 // Attachements are all allocated in a block, so just need to
5839 // find the first non-null one to delete
Michael Lentine48930b82015-10-15 17:07:00 -05005840 if (pRenderPassInfo->pSubpasses[i].pInputAttachments) {
5841 delete[] pRenderPassInfo->pSubpasses[i].pInputAttachments;
5842 } else if (pRenderPassInfo->pSubpasses[i].pColorAttachments) {
5843 delete[] pRenderPassInfo->pSubpasses[i].pColorAttachments;
5844 } else if (pRenderPassInfo->pSubpasses[i].pResolveAttachments) {
5845 delete[] pRenderPassInfo->pSubpasses[i].pResolveAttachments;
5846 } else if (pRenderPassInfo->pSubpasses[i].pPreserveAttachments) {
5847 delete[] pRenderPassInfo->pSubpasses[i].pPreserveAttachments;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005848 }
5849 }
Michael Lentine48930b82015-10-15 17:07:00 -05005850 delete[] pRenderPassInfo->pSubpasses;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005851 }
Michael Lentine48930b82015-10-15 17:07:00 -05005852 if (pRenderPassInfo->pDependencies) {
5853 delete[] pRenderPassInfo->pDependencies;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005854 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005855 delete pRenderPassInfo;
Michael Lentine48930b82015-10-15 17:07:00 -05005856 delete (*ii).second;
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06005857 }
5858 my_data->renderPassMap.clear();
5859}
Michael Lentineabc5e922015-10-12 11:30:14 -05005860
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005861VkBool32 VerifyFramebufferAndRenderPassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005862 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05005863 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5864 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005865 const VkRenderPassCreateInfo* pRenderPassInfo = dev_data->renderPassMap[pRenderPassBegin->renderPass]->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005866 const VkFramebufferCreateInfo* pFramebufferInfo = dev_data->frameBufferMap[pRenderPassBegin->framebuffer];
5867 if (pRenderPassInfo->attachmentCount != pFramebufferInfo->attachmentCount) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005868 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 -05005869 "You cannot start a render pass using a framebuffer with a different number of attachments.");
5870 }
5871 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5872 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5873 const VkImage& image = dev_data->imageViewMap[image_view]->image;
5874 auto image_data = pCB->imageLayoutMap.find(image);
5875 if (image_data == pCB->imageLayoutMap.end()) {
5876 pCB->imageLayoutMap[image].initialLayout = pRenderPassInfo->pAttachments[i].initialLayout;
5877 pCB->imageLayoutMap[image].layout = pRenderPassInfo->pAttachments[i].initialLayout;
5878 } else if (pRenderPassInfo->pAttachments[i].initialLayout != image_data->second.layout) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005879 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 -05005880 "You cannot start a render pass using attachment %i where the intial layout differs from the starting layout.", i);
5881 }
5882 }
5883 return skip_call;
5884}
5885
5886void TransitionSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const int subpass_index) {
5887 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5888 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5889 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5890 if (render_pass_data == dev_data->renderPassMap.end()) {
5891 return;
5892 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005893 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005894 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5895 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5896 return;
5897 }
5898 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5899 const VkSubpassDescription& subpass = pRenderPassInfo->pSubpasses[subpass_index];
5900 for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
5901 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pInputAttachments[j].attachment];
5902 auto image_view_data = dev_data->imageViewMap.find(image_view);
5903 if (image_view_data != dev_data->imageViewMap.end()) {
5904 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5905 if (image_layout != pCB->imageLayoutMap.end()) {
5906 image_layout->second.layout = subpass.pInputAttachments[j].layout;
5907 }
5908 }
5909 }
5910 for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
5911 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pColorAttachments[j].attachment];
5912 auto image_view_data = dev_data->imageViewMap.find(image_view);
5913 if (image_view_data != dev_data->imageViewMap.end()) {
5914 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5915 if (image_layout != pCB->imageLayoutMap.end()) {
5916 image_layout->second.layout = subpass.pColorAttachments[j].layout;
5917 }
5918 }
5919 }
Michael Lentine3dea6512015-10-28 15:55:18 -07005920 if ((subpass.pDepthStencilAttachment != NULL) &&
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005921 (subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED)) {
Michael Lentineabc5e922015-10-12 11:30:14 -05005922 const VkImageView& image_view = pFramebufferInfo->pAttachments[subpass.pDepthStencilAttachment->attachment];
5923 auto image_view_data = dev_data->imageViewMap.find(image_view);
5924 if (image_view_data != dev_data->imageViewMap.end()) {
5925 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5926 if (image_layout != pCB->imageLayoutMap.end()) {
5927 image_layout->second.layout = subpass.pDepthStencilAttachment->layout;
5928 }
5929 }
5930 }
5931}
5932
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07005933VkBool32 validatePrimaryCommandBuffer(const layer_data* my_data, const GLOBAL_CB_NODE* pCB, const std::string& cmd_name) {
Mark Youngb20a6a82016-01-07 15:41:43 -07005934 VkBool32 skip_call = VK_FALSE;
Michael Lentine3dea6512015-10-28 15:55:18 -07005935 if (pCB->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005936 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 -07005937 "Cannot execute command %s on a secondary command buffer.", cmd_name.c_str());
5938 }
5939 return skip_call;
5940}
5941
Michael Lentineabc5e922015-10-12 11:30:14 -05005942void TransitionFinalSubpassLayouts(VkCommandBuffer cmdBuffer, const VkRenderPassBeginInfo* pRenderPassBegin) {
5943 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
5944 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, cmdBuffer);
5945 auto render_pass_data = dev_data->renderPassMap.find(pRenderPassBegin->renderPass);
5946 if (render_pass_data == dev_data->renderPassMap.end()) {
5947 return;
5948 }
Tobin Ehlis3f5ddbb2015-12-02 13:53:34 -07005949 const VkRenderPassCreateInfo* pRenderPassInfo = render_pass_data->second->pCreateInfo;
Michael Lentineabc5e922015-10-12 11:30:14 -05005950 auto framebuffer_data = dev_data->frameBufferMap.find(pRenderPassBegin->framebuffer);
5951 if (framebuffer_data == dev_data->frameBufferMap.end()) {
5952 return;
5953 }
5954 const VkFramebufferCreateInfo* pFramebufferInfo = framebuffer_data->second;
5955 for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) {
5956 const VkImageView& image_view = pFramebufferInfo->pAttachments[i];
5957 auto image_view_data = dev_data->imageViewMap.find(image_view);
5958 if (image_view_data != dev_data->imageViewMap.end()) {
5959 auto image_layout = pCB->imageLayoutMap.find(image_view_data->second->image);
5960 if (image_layout != pCB->imageLayoutMap.end()) {
5961 image_layout->second.layout = pRenderPassInfo->pAttachments[i].finalLayout;
5962 }
5963 }
5964 }
5965}
5966
Chia-I Wu9ab61502015-11-06 06:42:02 +08005967VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005968{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005969 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005970 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
5971 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005972 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06005973 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005974 skipCall |= VerifyFramebufferAndRenderPassLayouts(commandBuffer, pRenderPassBegin);
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06005975 skipCall |= insideRenderPass(dev_data, pCB, "vkCmdBeginRenderPass");
Michael Lentine3dea6512015-10-28 15:55:18 -07005976 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdBeginRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07005977 skipCall |= addCmd(dev_data, pCB, CMD_BEGINRENDERPASS, "vkCmdBeginRenderPass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005978 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Michael Lentineabc5e922015-10-12 11:30:14 -05005979 // This is a shallow copy as that is all that is needed for now
5980 pCB->activeRenderPassBeginInfo = *pRenderPassBegin;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005981 pCB->activeSubpass = 0;
Michael Lentine2e068b22015-12-29 16:05:27 -06005982 pCB->activeSubpassContents = contents;
Mark Lobodzinski5495d132015-09-30 16:19:16 -06005983 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tobin Ehlis502480b2015-06-24 15:53:07 -06005984 } else {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07005985 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 -06005986 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06005987 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005988 }
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005989 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005990 dev_data->device_dispatch_table->CmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents);
Mark Lobodzinski0f30f9e2015-10-28 13:03:56 -06005991 // This is a shallow copy as that is all that is needed for now
5992 dev_data->renderPassBeginInfo = *pRenderPassBegin;
5993 dev_data->currentSubpass = 0;
5994 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06005995}
5996
Chia-I Wu9ab61502015-11-06 06:42:02 +08005997VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents)
Chia-I Wu08accc62015-07-07 11:50:03 +08005998{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06005999 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006000 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6001 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006002 TransitionSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo, ++dev_data->currentSubpass);
Chia-I Wu08accc62015-07-07 11:50:03 +08006003 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07006004 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdNextSubpass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006005 skipCall |= addCmd(dev_data, pCB, CMD_NEXTSUBPASS, "vkCmdNextSubpass()");
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006006 pCB->activeSubpass++;
Michael Lentine2e068b22015-12-29 16:05:27 -06006007 pCB->activeSubpassContents = contents;
Tony Barbourfc5bb6f2016-01-12 11:16:52 -07006008 TransitionSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo, pCB->activeSubpass);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006009 if (pCB->lastBoundPipeline) {
Tobin Ehlisb212dfc2015-10-07 15:40:22 -06006010 skipCall |= validatePipelineState(dev_data, pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08006011 }
Tobin Ehlis432ef5c2015-10-20 17:06:16 -06006012 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdNextSubpass");
Chia-I Wu08accc62015-07-07 11:50:03 +08006013 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006014 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006015 dev_data->device_dispatch_table->CmdNextSubpass(commandBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08006016}
6017
Chia-I Wu9ab61502015-11-06 06:42:02 +08006018VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006019{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006020 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006021 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6022 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Michael Lentineabc5e922015-10-12 11:30:14 -05006023 TransitionFinalSubpassLayouts(commandBuffer, &dev_data->renderPassBeginInfo);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006024 if (pCB) {
Michael Lentine3dea6512015-10-28 15:55:18 -07006025 skipCall |= outsideRenderPass(dev_data, pCB, "vkCmdEndRenderpass");
Michael Lentine3dea6512015-10-28 15:55:18 -07006026 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdEndRenderPass");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006027 skipCall |= addCmd(dev_data, pCB, CMD_ENDRENDERPASS, "vkCmdEndRenderPass()");
Michael Lentineabc5e922015-10-12 11:30:14 -05006028 TransitionFinalSubpassLayouts(commandBuffer, &pCB->activeRenderPassBeginInfo);
Mark Lobodzinski5495d132015-09-30 16:19:16 -06006029 pCB->activeRenderPass = 0;
6030 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006031 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006032 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006033 dev_data->device_dispatch_table->CmdEndRenderPass(commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006034}
6035
Chia-I Wu9ab61502015-11-06 06:42:02 +08006036VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount, const VkCommandBuffer* pCommandBuffers)
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006037{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006038 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006039 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6040 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08006041 if (pCB) {
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006042 GLOBAL_CB_NODE* pSubCB = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006043 for (uint32_t i=0; i<commandBuffersCount; i++) {
6044 pSubCB = getCBNode(dev_data, pCommandBuffers[i]);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006045 if (!pSubCB) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006046 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 +08006047 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCommandBuffers array.", (void*)pCommandBuffers[i], i);
6048 } else if (VK_COMMAND_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006049 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 +08006050 "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 -07006051 } else if (pCB->activeRenderPass) { // Secondary CB w/i RenderPass must have *CONTINUE_BIT set
6052 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006053 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 -07006054 "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);
6055 }
6056 string errorString = "";
Jon Ashburnf19916e2016-01-11 13:12:43 -07006057 if (!verify_renderpass_compatibility(dev_data, pCB->activeRenderPass, pSubCB->beginInfo.pInheritanceInfo->renderPass, errorString)) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006058 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 -07006059 "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 -07006060 (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 -07006061 }
6062 // If framebuffer for secondary CB is not NULL, then it must match FB from vkCmdBeginRenderPass()
6063 // 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 -07006064 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer) {
6065 if (pSubCB->beginInfo.pInheritanceInfo->framebuffer != pCB->activeRenderPassBeginInfo.framebuffer) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006066 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 -07006067 "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 -07006068 (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 -07006069 }
6070 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006071 }
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006072 // Secondary cmdBuffers are considered pending execution starting w/ being recorded
6073 if (!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
Tobin Ehlis74714d22016-01-25 15:24:34 -08006074 if (dev_data->globalInFlightCmdBuffers.find(pSubCB->commandBuffer) != dev_data->globalInFlightCmdBuffers.end()) {
Mark Youngee3f3a22016-01-25 12:18:32 -07006075 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
6076 "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006077 }
6078 if (pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
6079 // Warn that non-simultaneous secondary cmd buffer renders primary non-simultaneous
Mark Youngee3f3a22016-01-25 12:18:32 -07006080 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCommandBuffers[i]), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006081 "vkCmdExecuteCommands(): Secondary Command Buffer (%#" PRIxLEAST64 ") does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and will cause primary command buffer (%#" PRIxLEAST64 ") to be treated as if it does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set, even though it does.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006082 (uint64_t)(pCommandBuffers[i]), (uint64_t)(pCB->commandBuffer));
Tobin Ehlisf4aafc02016-01-15 13:34:44 -07006083 pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
6084 }
6085 }
6086 pCB->secondaryCommandBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis74714d22016-01-25 15:24:34 -08006087 dev_data->globalInFlightCmdBuffers.insert(pSubCB->commandBuffer);
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006088 }
Michael Lentine3dea6512015-10-28 15:55:18 -07006089 skipCall |= validatePrimaryCommandBuffer(dev_data, pCB, "vkCmdExecuteComands");
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006090 skipCall |= addCmd(dev_data, pCB, CMD_EXECUTECOMMANDS, "vkCmdExecuteComands()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006091 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006092 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006093 dev_data->device_dispatch_table->CmdExecuteCommands(commandBuffer, commandBuffersCount, pCommandBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006094}
6095
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006096VkBool32 ValidateMapImageLayouts(VkDevice device, VkDeviceMemory mem) {
Mark Youngb20a6a82016-01-07 15:41:43 -07006097 VkBool32 skip_call = VK_FALSE;
Michael Lentine7b236262015-10-23 12:41:44 -07006098 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6099 auto mem_data = dev_data->memImageMap.find(mem);
6100 if (mem_data != dev_data->memImageMap.end()) {
6101 auto image_data = dev_data->imageLayoutMap.find(mem_data->second);
6102 if (image_data != dev_data->imageLayoutMap.end()) {
6103 if (image_data->second->layout != VK_IMAGE_LAYOUT_PREINITIALIZED && image_data->second->layout != VK_IMAGE_LAYOUT_GENERAL) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006104 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 -07006105 "Cannot map an image with layout %d. Only GENERAL or PREINITIALIZED are supported.", image_data->second->layout);
6106 }
6107 }
6108 }
6109 return skip_call;
6110}
6111
Chia-I Wu9ab61502015-11-06 06:42:02 +08006112VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07006113 VkDevice device,
6114 VkDeviceMemory mem,
6115 VkDeviceSize offset,
6116 VkDeviceSize size,
6117 VkFlags flags,
6118 void **ppData)
6119{
6120 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006121
Courtney Goeltzenleuchtere6dd8082015-12-16 16:07:01 -07006122 VkBool32 skip_call = VK_FALSE;
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006123#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
6124 skip_call = ValidateMapImageLayouts(device, mem);
6125#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
6126
Michael Lentine7b236262015-10-23 12:41:44 -07006127 if (VK_FALSE == skip_call) {
6128 return dev_data->device_dispatch_table->MapMemory(device, mem, offset, size, flags, ppData);
6129 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006130 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7b236262015-10-23 12:41:44 -07006131}
6132
Chia-I Wu9ab61502015-11-06 06:42:02 +08006133VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
Michael Lentine7b236262015-10-23 12:41:44 -07006134 VkDevice device,
6135 VkImage image,
6136 VkDeviceMemory mem,
6137 VkDeviceSize memOffset)
6138{
6139 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6140 VkResult result = dev_data->device_dispatch_table->BindImageMemory(device, image, mem, memOffset);
6141 loader_platform_thread_lock_mutex(&globalLock);
6142 dev_data->memImageMap[mem] = image;
6143 loader_platform_thread_unlock_mutex(&globalLock);
6144 return result;
6145}
6146
Michael Lentineb887b0a2015-12-29 14:12:11 -06006147
6148VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(VkDevice device, VkEvent event) {
6149 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6150 dev_data->eventMap[event].needsSignaled = false;
6151 VkResult result = dev_data->device_dispatch_table->SetEvent(device, event);
6152 return result;
6153}
6154
Michael Lentine15a47882016-01-06 10:05:48 -06006155VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
6156 VkQueue queue,
6157 uint32_t bindInfoCount,
6158 const VkBindSparseInfo* pBindInfo,
6159 VkFence fence)
6160{
6161 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006162 VkBool32 skip_call = VK_FALSE;
Michael Lentine15a47882016-01-06 10:05:48 -06006163
6164 for (uint32_t bindIdx=0; bindIdx < bindInfoCount; ++bindIdx) {
6165 const VkBindSparseInfo& bindInfo = pBindInfo[bindIdx];
6166 for (uint32_t i=0; i < bindInfo.waitSemaphoreCount; ++i) {
6167 if (dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]]) {
6168 dev_data->semaphoreSignaledMap[bindInfo.pWaitSemaphores[i]] = 0;
6169 } else {
6170 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",
6171 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006172 (uint64_t)(queue), (uint64_t)(bindInfo.pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006173 }
6174 }
6175 for (uint32_t i=0; i < bindInfo.signalSemaphoreCount; ++i) {
6176 dev_data->semaphoreSignaledMap[bindInfo.pSignalSemaphores[i]] = 1;
6177 }
6178 }
6179
Mark Youngb20a6a82016-01-07 15:41:43 -07006180 if (VK_FALSE == skip_call)
Michael Lentine15a47882016-01-06 10:05:48 -06006181 return dev_data->device_dispatch_table->QueueBindSparse(queue, bindInfoCount, pBindInfo, fence);
Mark Youngb20a6a82016-01-07 15:41:43 -07006182 else
6183 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine15a47882016-01-06 10:05:48 -06006184}
6185
6186VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
6187 VkDevice device,
6188 const VkSemaphoreCreateInfo* pCreateInfo,
6189 const VkAllocationCallbacks* pAllocator,
6190 VkSemaphore* pSemaphore)
6191{
6192 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6193 VkResult result = dev_data->device_dispatch_table->CreateSemaphore(device, pCreateInfo, pAllocator, pSemaphore);
6194 if (result == VK_SUCCESS) {
6195 dev_data->semaphoreSignaledMap[*pSemaphore] = 0;
6196 }
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006197 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006198}
6199
Chia-I Wu9ab61502015-11-06 06:42:02 +08006200VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006201 VkDevice device,
6202 const VkSwapchainCreateInfoKHR *pCreateInfo,
Ian Elliott05846062015-11-20 14:13:17 -07006203 const VkAllocationCallbacks *pAllocator,
Michael Lentineabc5e922015-10-12 11:30:14 -05006204 VkSwapchainKHR *pSwapchain)
6205{
6206 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott05846062015-11-20 14:13:17 -07006207 VkResult result = dev_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
Michael Lentineabc5e922015-10-12 11:30:14 -05006208
6209 if (VK_SUCCESS == result) {
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006210 SWAPCHAIN_NODE *swapchain_data = new SWAPCHAIN_NODE(pCreateInfo);
Michael Lentineabc5e922015-10-12 11:30:14 -05006211 loader_platform_thread_lock_mutex(&globalLock);
6212 dev_data->device_extensions.swapchainMap[*pSwapchain] = swapchain_data;
6213 loader_platform_thread_unlock_mutex(&globalLock);
6214 }
6215
6216 return result;
6217}
6218
Ian Elliott05846062015-11-20 14:13:17 -07006219VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006220 VkDevice device,
Ian Elliott05846062015-11-20 14:13:17 -07006221 VkSwapchainKHR swapchain,
6222 const VkAllocationCallbacks *pAllocator)
Michael Lentineabc5e922015-10-12 11:30:14 -05006223{
6224 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Michael Lentineabc5e922015-10-12 11:30:14 -05006225
6226 loader_platform_thread_lock_mutex(&globalLock);
6227 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(swapchain);
6228 if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) {
6229 if (swapchain_data->second->images.size() > 0) {
6230 for (auto swapchain_image : swapchain_data->second->images) {
6231 auto image_item = dev_data->imageLayoutMap.find(swapchain_image);
6232 if (image_item != dev_data->imageLayoutMap.end())
6233 dev_data->imageLayoutMap.erase(image_item);
6234 }
6235 }
6236 delete swapchain_data->second;
6237 dev_data->device_extensions.swapchainMap.erase(swapchain);
6238 }
6239 loader_platform_thread_unlock_mutex(&globalLock);
Ian Elliott05846062015-11-20 14:13:17 -07006240 return dev_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator);
Michael Lentineabc5e922015-10-12 11:30:14 -05006241}
6242
Chia-I Wu9ab61502015-11-06 06:42:02 +08006243VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
Michael Lentineabc5e922015-10-12 11:30:14 -05006244 VkDevice device,
6245 VkSwapchainKHR swapchain,
6246 uint32_t* pCount,
6247 VkImage* pSwapchainImages)
6248{
6249 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6250 VkResult result = dev_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
6251
6252 if (result == VK_SUCCESS && pSwapchainImages != NULL) {
6253 // This should never happen and is checked by param checker.
6254 if (!pCount) return result;
6255 for (uint32_t i = 0; i < *pCount; ++i) {
6256 IMAGE_NODE* image_node = new IMAGE_NODE;
6257 image_node->layout = VK_IMAGE_LAYOUT_UNDEFINED;
6258 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis75cd1c52016-01-21 10:21:04 -07006259 auto swapchain_node = dev_data->device_extensions.swapchainMap[swapchain];
6260 image_node->format = swapchain_node->createInfo.imageFormat;
6261 swapchain_node->images.push_back(pSwapchainImages[i]);
Michael Lentineabc5e922015-10-12 11:30:14 -05006262 dev_data->imageLayoutMap[pSwapchainImages[i]] = image_node;
6263 loader_platform_thread_unlock_mutex(&globalLock);
6264 }
6265 }
6266 return result;
6267}
6268
Ian Elliott05846062015-11-20 14:13:17 -07006269VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Michael Lentineabc5e922015-10-12 11:30:14 -05006270{
6271 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(queue), layer_data_map);
Mark Youngb20a6a82016-01-07 15:41:43 -07006272 VkBool32 skip_call = VK_FALSE;
Michael Lentineabc5e922015-10-12 11:30:14 -05006273
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006274#ifndef DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006275 if (pPresentInfo) {
Michael Lentine15a47882016-01-06 10:05:48 -06006276 for (uint32_t i=0; i < pPresentInfo->waitSemaphoreCount; ++i) {
6277 if (dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]]) {
6278 dev_data->semaphoreSignaledMap[pPresentInfo->pWaitSemaphores[i]] = 0;
6279 } else {
6280 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",
6281 "Queue %#" PRIx64 " is waiting on semaphore %#" PRIx64 " that has no way to be signaled.",
Mark Youngee3f3a22016-01-25 12:18:32 -07006282 (uint64_t)(queue), (uint64_t)(pPresentInfo->pWaitSemaphores[i]));
Michael Lentine15a47882016-01-06 10:05:48 -06006283 }
6284 }
Michael Lentineabc5e922015-10-12 11:30:14 -05006285 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
Ian Elliott05846062015-11-20 14:13:17 -07006286 auto swapchain_data = dev_data->device_extensions.swapchainMap.find(pPresentInfo->pSwapchains[i]);
6287 if (swapchain_data != dev_data->device_extensions.swapchainMap.end() && pPresentInfo->pImageIndices[i] < swapchain_data->second->images.size()) {
6288 VkImage image = swapchain_data->second->images[pPresentInfo->pImageIndices[i]];
Michael Lentineabc5e922015-10-12 11:30:14 -05006289 auto image_data = dev_data->imageLayoutMap.find(image);
6290 if (image_data != dev_data->imageLayoutMap.end()) {
Ian Elliott05846062015-11-20 14:13:17 -07006291 if (image_data->second->layout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006292 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 -05006293 "Images passed to present must be in layout PRESENT_SOURCE_KHR but is in %d", image_data->second->layout);
6294 }
6295 }
6296 }
6297 }
6298 }
Mark Lobodzinski31e5f282015-11-30 16:48:53 -07006299#endif // DISABLE_IMAGE_LAYOUT_VALIDATION
Michael Lentineabc5e922015-10-12 11:30:14 -05006300
6301 if (VK_FALSE == skip_call)
6302 return dev_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07006303 return VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentineabc5e922015-10-12 11:30:14 -05006304}
6305
Michael Lentine15a47882016-01-06 10:05:48 -06006306VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
6307 VkDevice device,
6308 VkSwapchainKHR swapchain,
6309 uint64_t timeout,
6310 VkSemaphore semaphore,
6311 VkFence fence,
6312 uint32_t* pImageIndex)
6313{
6314 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
6315 VkResult result = dev_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
6316 dev_data->semaphoreSignaledMap[semaphore] = 1;
Tobin Ehlis51b78af2016-01-06 10:27:47 -07006317 return result;
Michael Lentine15a47882016-01-06 10:05:48 -06006318}
6319
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006320VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
6321 VkInstance instance,
6322 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
6323 const VkAllocationCallbacks* pAllocator,
6324 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006325{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006326 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006327 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006328 VkResult res = pTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006329 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006330 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06006331 }
6332 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006333}
6334
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006335VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006336 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006337 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006338 const VkAllocationCallbacks* pAllocator)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006339{
Tobin Ehlis0b632332015-10-07 09:38:40 -06006340 layer_data* my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006341 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006342 pTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -07006343 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006344}
6345
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006346VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006347 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006348 VkDebugReportFlagsEXT flags,
6349 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006350 uint64_t object,
6351 size_t location,
6352 int32_t msgCode,
6353 const char* pLayerPrefix,
6354 const char* pMsg)
6355{
6356 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006357 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -07006358}
6359
Chia-I Wu9ab61502015-11-06 06:42:02 +08006360VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerBegin(VkCommandBuffer commandBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006361{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006362 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006363 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6364 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006365 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006366 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 -06006367 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006368 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006369 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006370 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKERBEGIN, "vkCmdDbgMarkerBegin()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006371 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006372 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006373 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerBegin(commandBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006374}
6375
Chia-I Wu9ab61502015-11-06 06:42:02 +08006376VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdDbgMarkerEnd(VkCommandBuffer commandBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006377{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006378 VkBool32 skipCall = VK_FALSE;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006379 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
6380 GLOBAL_CB_NODE* pCB = getCBNode(dev_data, commandBuffer);
Tobin Ehlis0b632332015-10-07 09:38:40 -06006381 if (!dev_data->device_extensions.debug_marker_enabled) {
Mark Lobodzinskib01451b2016-01-04 13:18:10 -07006382 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 -06006383 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06006384 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06006385 } else if (pCB) {
Tobin Ehlis61b36f32015-12-16 08:19:42 -07006386 skipCall |= addCmd(dev_data, pCB, CMD_DBGMARKEREND, "vkCmdDbgMarkerEnd()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006387 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06006388 if (VK_FALSE == skipCall)
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006389 debug_marker_dispatch_table(commandBuffer)->CmdDbgMarkerEnd(commandBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06006390}
6391
Chia-I Wu9ab61502015-11-06 06:42:02 +08006392VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006393{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006394 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006395 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006396 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006397 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006398 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006399 return (PFN_vkVoidFunction) vkQueueSubmit;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006400 if (!strcmp(funcName, "vkWaitForFences"))
6401 return (PFN_vkVoidFunction) vkWaitForFences;
6402 if (!strcmp(funcName, "vkGetFenceStatus"))
6403 return (PFN_vkVoidFunction) vkGetFenceStatus;
Mark Lobodzinski8da0d1e2016-01-06 14:58:59 -07006404 if (!strcmp(funcName, "vkQueueWaitIdle"))
6405 return (PFN_vkVoidFunction) vkQueueWaitIdle;
6406 if (!strcmp(funcName, "vkDeviceWaitIdle"))
6407 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Michael Lentine700b0aa2015-10-30 17:57:32 -07006408 if (!strcmp(funcName, "vkGetDeviceQueue"))
6409 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006410 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006411 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006412 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006413 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006414 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006415 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006416 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006417 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006418 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006419 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006420 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006421 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006422 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006423 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006424 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006425 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006426 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006427 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006428 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006429 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006430 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006431 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006432 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006433 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006434 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006435 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006436 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006437 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006438 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006439 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006440 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006441 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006442 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006443 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06006444 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006445 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006446 if (!strcmp(funcName, "vkCreateBuffer"))
6447 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006448 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006449 return (PFN_vkVoidFunction) vkCreateBufferView;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06006450 if (!strcmp(funcName, "vkCreateImage"))
6451 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006452 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006453 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006454 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006455 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006456 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006457 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006458 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006459 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006460 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006461 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006462 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006463 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Mark Lobodzinski475a2182015-11-10 15:25:01 -07006464 if (!strcmp(funcName, "vkCreateComputePipelines"))
6465 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006466 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006467 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006468 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006469 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05006470 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006471 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006472 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006473 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006474 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006475 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006476 if (!strcmp(funcName, "vkAllocateDescriptorSets"))
6477 return (PFN_vkVoidFunction) vkAllocateDescriptorSets;
Tobin Ehlise735c692015-10-08 13:13:50 -06006478 if (!strcmp(funcName, "vkFreeDescriptorSets"))
6479 return (PFN_vkVoidFunction) vkFreeDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08006480 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006481 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006482 if (!strcmp(funcName, "vkCreateCommandPool"))
6483 return (PFN_vkVoidFunction) vkCreateCommandPool;
6484 if (!strcmp(funcName, "vkDestroyCommandPool"))
6485 return (PFN_vkVoidFunction) vkDestroyCommandPool;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006486 if (!strcmp(funcName, "vkResetCommandPool"))
6487 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006488 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
6489 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Mark Lobodzinski39298632015-11-18 08:38:27 -07006490 if (!strcmp(funcName, "vkFreeCommandBuffers"))
6491 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006492 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006493 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006494 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006495 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006496 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006497 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006498 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006499 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006500 if (!strcmp(funcName, "vkCmdSetViewport"))
6501 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06006502 if (!strcmp(funcName, "vkCmdSetScissor"))
6503 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06006504 if (!strcmp(funcName, "vkCmdSetLineWidth"))
6505 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
6506 if (!strcmp(funcName, "vkCmdSetDepthBias"))
6507 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
6508 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
6509 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
6510 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
6511 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
6512 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
6513 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
6514 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
6515 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
6516 if (!strcmp(funcName, "vkCmdSetStencilReference"))
6517 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006518 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006519 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06006520 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006521 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006522 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006523 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006524 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006525 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006526 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006527 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006528 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006529 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006530 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006531 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006532 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006533 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006534 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006535 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006536 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006537 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006538 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006539 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006540 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006541 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006542 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006543 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006544 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006545 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006546 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006547 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006548 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006549 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12006550 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006551 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06006552 if (!strcmp(funcName, "vkCmdClearAttachments"))
6553 return (PFN_vkVoidFunction) vkCmdClearAttachments;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006554 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006555 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006556 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006557 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006558 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006559 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006560 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006561 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006562 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006563 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006564 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006565 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006566 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006567 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006568 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006569 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006570 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006571 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006572 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006573 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006574 if (!strcmp(funcName, "vkCreateShaderModule"))
6575 return (PFN_vkVoidFunction) vkCreateShaderModule;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006576 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006577 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006578 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006579 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08006580 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006581 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06006582 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006583 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06006584 if (!strcmp(funcName, "vkCmdExecuteCommands"))
6585 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006586 if (!strcmp(funcName, "vkSetEvent"))
6587 return (PFN_vkVoidFunction) vkSetEvent;
Michael Lentine7b236262015-10-23 12:41:44 -07006588 if (!strcmp(funcName, "vkMapMemory"))
6589 return (PFN_vkVoidFunction) vkMapMemory;
Michael Lentineb887b0a2015-12-29 14:12:11 -06006590 if (!strcmp(funcName, "vkGetQueryPoolResults"))
6591 return (PFN_vkVoidFunction) vkGetQueryPoolResults;
Michael Lentine15a47882016-01-06 10:05:48 -06006592 if (!strcmp(funcName, "vkBindImageMemory"))
6593 return (PFN_vkVoidFunction) vkBindImageMemory;
6594 if (!strcmp(funcName, "vkQueueBindSparse"))
6595 return (PFN_vkVoidFunction) vkQueueBindSparse;
6596 if (!strcmp(funcName, "vkCreateSemaphore"))
6597 return (PFN_vkVoidFunction) vkCreateSemaphore;
Jon Ashburneab34492015-06-01 09:37:38 -06006598
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006599 if (dev == NULL)
6600 return NULL;
6601
6602 layer_data *dev_data;
6603 dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
6604
Michael Lentineabc5e922015-10-12 11:30:14 -05006605 if (dev_data->device_extensions.wsi_enabled)
6606 {
6607 if (!strcmp(funcName, "vkCreateSwapchainKHR"))
6608 return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
6609 if (!strcmp(funcName, "vkDestroySwapchainKHR"))
6610 return (PFN_vkVoidFunction) vkDestroySwapchainKHR;
6611 if (!strcmp(funcName, "vkGetSwapchainImagesKHR"))
6612 return (PFN_vkVoidFunction) vkGetSwapchainImagesKHR;
Michael Lentine15a47882016-01-06 10:05:48 -06006613 if (!strcmp(funcName, "vkAcquireNextImageKHR"))
6614 return (PFN_vkVoidFunction) vkAcquireNextImageKHR;
Michael Lentineabc5e922015-10-12 11:30:14 -05006615 if (!strcmp(funcName, "vkQueuePresentKHR"))
6616 return (PFN_vkVoidFunction) vkQueuePresentKHR;
6617 }
6618
Tobin Ehlis0b632332015-10-07 09:38:40 -06006619 VkLayerDispatchTable* pTable = dev_data->device_dispatch_table;
6620 if (dev_data->device_extensions.debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06006621 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06006622 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006623 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06006624 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006625 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Jon Ashburneab34492015-06-01 09:37:38 -06006626 }
6627 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06006628 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006629 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06006630 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006631 }
6632}
6633
Chia-I Wu9ab61502015-11-06 06:42:02 +08006634VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06006635{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006636 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006637 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006638 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
6639 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06006640 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006641 return (PFN_vkVoidFunction) vkCreateInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006642 if (!strcmp(funcName, "vkCreateDevice"))
6643 return (PFN_vkVoidFunction) vkCreateDevice;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06006644 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06006645 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06006646 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
6647 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
6648 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
6649 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
6650 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
6651 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
6652 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
6653 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006654
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006655 if (instance == NULL)
6656 return NULL;
6657
6658 PFN_vkVoidFunction fptr;
6659
6660 layer_data* my_data;
Tobin Ehlis7e2ad752015-12-01 09:48:58 -07006661 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06006662 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06006663 if (fptr)
6664 return fptr;
6665
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -07006666 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
6667 if (pTable->GetInstanceProcAddr == NULL)
6668 return NULL;
6669 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06006670}