blob: f6b6a6d2927e7900b356305e88995da2961b94aa [file] [log] [blame]
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060035#endif
Tony Barbour18f71552015-04-22 11:36:22 -060036#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060037#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060038#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060039#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060040#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060041#include "vk_layer_config.h"
Jon Ashburne68a9ff2015-05-25 14:11:37 -060042#include "vk_debug_marker_layer.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060043// The following is #included again to catch certain OS-specific functions
44// being used:
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060046#include "vk_layer_msg.h"
47#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060051#include "vk_layer_extension_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060052
Tobin Ehlisc16c3e92015-06-16 09:04:30 -060053typedef struct _layer_data {
54 debug_report_data *report_data;
55 // TODO: put instance data here
56 VkDbgMsgCallback logging_callback;
57} layer_data;
58
59static std::unordered_map<void *, layer_data *> layer_data_map;
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -060060static device_table_map draw_state_device_table_map;
61static instance_table_map draw_state_instance_table_map;
62
Mike Stroyan1ccea632015-09-11 13:29:21 -060063static unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
64static unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
65static unordered_map<uint64_t, VkImageViewCreateInfo> viewMap;
66static unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
Mike Stroyan1ccea632015-09-11 13:29:21 -060067static unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
68static unordered_map<uint64_t, POOL_NODE*> poolMap;
69static unordered_map<uint64_t, SET_NODE*> setMap;
70static unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlis793ad302015-04-03 12:01:11 -060071// Map for layout chains
Mike Stroyan1ccea632015-09-11 13:29:21 -060072static unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
73static unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
74static unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060075
Jon Ashburneab34492015-06-01 09:37:38 -060076struct devExts {
77 bool debug_marker_enabled;
78};
79
Jon Ashburneab34492015-06-01 09:37:38 -060080static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburn3950e1b2015-05-20 09:00:28 -060081
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060082static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060083
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060084// TODO : This can be much smarter, using separate locks for separate global data
85static int globalLockInitialized = 0;
86static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060087#define MAX_TID 513
88static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
89static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -060090
91template layer_data *get_my_data_ptr<layer_data>(
92 void *data_key,
93 std::unordered_map<void *, layer_data *> &data_map);
94
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -060095debug_report_data *mdd(void* object)
Tobin Ehlisa16e8922015-06-16 15:50:44 -060096{
97 dispatch_key key = get_dispatch_key(object);
98 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
99#if DISPATCH_MAP_DEBUG
100 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
101#endif
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600102 return my_data->report_data;
103}
104
105debug_report_data *mid(VkInstance object)
106{
107 dispatch_key key = get_dispatch_key(object);
Tobin Ehlisbfbac252015-09-01 11:46:36 -0600108 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600109#if DISPATCH_MAP_DEBUG
110 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
111#endif
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600112 return my_data->report_data;
113}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600114// Map actual TID to an index value and return that index
115// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
116static uint32_t getTIDIndex() {
117 loader_platform_thread_id tid = loader_platform_get_thread_id();
118 for (uint32_t i = 0; i < g_maxTID; i++) {
119 if (tid == g_tidMapping[i])
120 return i;
121 }
122 // Don't yet have mapping, set it and return newly set index
123 uint32_t retVal = (uint32_t) g_maxTID;
124 g_tidMapping[g_maxTID++] = tid;
125 assert(g_maxTID < MAX_TID);
126 return retVal;
127}
128// Return a string representation of CMD_TYPE enum
129static string cmdTypeToString(CMD_TYPE cmd)
130{
131 switch (cmd)
132 {
133 case CMD_BINDPIPELINE:
134 return "CMD_BINDPIPELINE";
135 case CMD_BINDPIPELINEDELTA:
136 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600137 case CMD_SETVIEWPORTSTATE:
138 return "CMD_SETVIEWPORTSTATE";
139 case CMD_SETLINEWIDTHSTATE:
140 return "CMD_SETLINEWIDTHSTATE";
141 case CMD_SETDEPTHBIASSTATE:
142 return "CMD_SETDEPTHBIASSTATE";
143 case CMD_SETBLENDSTATE:
144 return "CMD_SETBLENDSTATE";
145 case CMD_SETDEPTHBOUNDSSTATE:
146 return "CMD_SETDEPTHBOUNDSSTATE";
147 case CMD_SETSTENCILREADMASKSTATE:
148 return "CMD_SETSTENCILREADMASKSTATE";
149 case CMD_SETSTENCILWRITEMASKSTATE:
150 return "CMD_SETSTENCILWRITEMASKSTATE";
151 case CMD_SETSTENCILREFERENCESTATE:
152 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600153 case CMD_BINDDESCRIPTORSETS:
154 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600155 case CMD_BINDINDEXBUFFER:
156 return "CMD_BINDINDEXBUFFER";
157 case CMD_BINDVERTEXBUFFER:
158 return "CMD_BINDVERTEXBUFFER";
159 case CMD_DRAW:
160 return "CMD_DRAW";
161 case CMD_DRAWINDEXED:
162 return "CMD_DRAWINDEXED";
163 case CMD_DRAWINDIRECT:
164 return "CMD_DRAWINDIRECT";
165 case CMD_DRAWINDEXEDINDIRECT:
166 return "CMD_DRAWINDEXEDINDIRECT";
167 case CMD_DISPATCH:
168 return "CMD_DISPATCH";
169 case CMD_DISPATCHINDIRECT:
170 return "CMD_DISPATCHINDIRECT";
171 case CMD_COPYBUFFER:
172 return "CMD_COPYBUFFER";
173 case CMD_COPYIMAGE:
174 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600175 case CMD_BLITIMAGE:
176 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600177 case CMD_COPYBUFFERTOIMAGE:
178 return "CMD_COPYBUFFERTOIMAGE";
179 case CMD_COPYIMAGETOBUFFER:
180 return "CMD_COPYIMAGETOBUFFER";
181 case CMD_CLONEIMAGEDATA:
182 return "CMD_CLONEIMAGEDATA";
183 case CMD_UPDATEBUFFER:
184 return "CMD_UPDATEBUFFER";
185 case CMD_FILLBUFFER:
186 return "CMD_FILLBUFFER";
187 case CMD_CLEARCOLORIMAGE:
188 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600189 case CMD_CLEARCOLORATTACHMENT:
190 return "CMD_CLEARCOLORATTACHMENT";
191 case CMD_CLEARDEPTHSTENCILIMAGE:
192 return "CMD_CLEARDEPTHSTENCILIMAGE";
193 case CMD_CLEARDEPTHSTENCILATTACHMENT:
194 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600195 case CMD_RESOLVEIMAGE:
196 return "CMD_RESOLVEIMAGE";
197 case CMD_SETEVENT:
198 return "CMD_SETEVENT";
199 case CMD_RESETEVENT:
200 return "CMD_RESETEVENT";
201 case CMD_WAITEVENTS:
202 return "CMD_WAITEVENTS";
203 case CMD_PIPELINEBARRIER:
204 return "CMD_PIPELINEBARRIER";
205 case CMD_BEGINQUERY:
206 return "CMD_BEGINQUERY";
207 case CMD_ENDQUERY:
208 return "CMD_ENDQUERY";
209 case CMD_RESETQUERYPOOL:
210 return "CMD_RESETQUERYPOOL";
211 case CMD_WRITETIMESTAMP:
212 return "CMD_WRITETIMESTAMP";
213 case CMD_INITATOMICCOUNTERS:
214 return "CMD_INITATOMICCOUNTERS";
215 case CMD_LOADATOMICCOUNTERS:
216 return "CMD_LOADATOMICCOUNTERS";
217 case CMD_SAVEATOMICCOUNTERS:
218 return "CMD_SAVEATOMICCOUNTERS";
219 case CMD_BEGINRENDERPASS:
220 return "CMD_BEGINRENDERPASS";
221 case CMD_ENDRENDERPASS:
222 return "CMD_ENDRENDERPASS";
223 case CMD_DBGMARKERBEGIN:
224 return "CMD_DBGMARKERBEGIN";
225 case CMD_DBGMARKEREND:
226 return "CMD_DBGMARKEREND";
227 default:
228 return "UNKNOWN";
229 }
230}
231// Block of code at start here for managing/tracking Pipeline state that this layer cares about
232// Just track 2 shaders for now
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600233#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600234#define MAX_SLOTS 2048
235#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
236
237static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
238
239// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
240// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
241// to that same cmd buffer by separate thread are not changing state from underneath us
242// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600243static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600244// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600245static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
246static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600247// Track the last global DrawState of interest touched by any thread
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600248static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
249static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Dana Jansensc73ff982015-07-30 13:22:15 -0700250static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600251#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
252
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600253// Free all sampler nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600254static void deleteSamplers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600255{
David Pinedod8f83d82015-04-27 16:36:17 -0600256 if (sampleMap.size() <= 0)
257 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600258 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600259 delete (*ii).second;
260 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600261 sampleMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600262}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600263static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600264{
265 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600266 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600267 loader_platform_thread_unlock_mutex(&globalLock);
268 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600269 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600270 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600271 return &imageMap[view.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600272 }
273}
274// Free all image nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600275static void deleteImages()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600276{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600277 if (imageMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -0600278 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600279 imageMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600280}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600281static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600282{
283 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600284 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600285 loader_platform_thread_unlock_mutex(&globalLock);
286 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600287 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600288 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600289 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600290 }
291}
292// Free all buffer nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600293static void deleteBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600294{
David Pinedod8f83d82015-04-27 16:36:17 -0600295 if (bufferMap.size() <= 0)
296 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600297 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600298 delete (*ii).second;
299 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600300 bufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600301}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600302static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600303// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600304static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600305{
306 g_lastCmdBuffer[getTIDIndex()] = cb;
307 GLOBAL_CB_NODE* pCB = getCBNode(cb);
308 loader_platform_thread_lock_mutex(&globalLock);
309 g_lastGlobalCB = pCB;
310 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
311 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
312 if (g_pLastTouchedCB[i] == pCB) {
313 loader_platform_thread_unlock_mutex(&globalLock);
314 return;
315 }
316 }
317 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
318 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
319 loader_platform_thread_unlock_mutex(&globalLock);
320}
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600321static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600322{
323 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
324 if (pCB->drawCount[i])
325 return VK_TRUE;
326 }
327 return VK_FALSE;
328}
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600329// Check object status for selected flag state
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600330static VkBool32 validate_status(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 -0600331{
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600332 // If non-zero enable mask is present, check it against status but if enable_mask
333 // is 0 then no enable required so we should always just check status
334 if ((!enable_mask) || (enable_mask & pNode->status)) {
335 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600336 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600337 return log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -0600338 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->cmdBuffer), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600339 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600340 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600341 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600342}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600343// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600345{
346 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600347 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600348 loader_platform_thread_unlock_mutex(&globalLock);
349 return NULL;
350 }
351 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600352 return pipelineMap[pipeline.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600353}
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600354// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600355static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
356 VkBool32 result;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600357 result = validate_status(pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_SET, CBSTATUS_VIEWPORT_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
358 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_LINE_WIDTH_SET, CBSTATUS_LINE_WIDTH_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_LINE_WIDTH_NOT_BOUND, "Line width object not bound to this command buffer");
359 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_DEPTH_BIAS_SET, CBSTATUS_DEPTH_BIAS_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_BIAS_NOT_BOUND, "Depth bias object not bound to this command buffer");
360 result |= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_BLEND_SET, CBSTATUS_BLEND_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_BLEND_NOT_BOUND, "Blend object not bound to this command buffer");
361 result |= validate_status(pCB, CBSTATUS_DEPTH_WRITE_ENABLE, CBSTATUS_DEPTH_BOUNDS_SET, CBSTATUS_DEPTH_BOUNDS_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, "Depth bounds object not bound to this command buffer");
362 result |= validate_status(pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_READ_MASK_SET, CBSTATUS_STENCIL_READ_MASK_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Stencil read mask not set on this command buffer");
363 result |= validate_status(pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_WRITE_MASK_SET, CBSTATUS_STENCIL_WRITE_MASK_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Stencil write mask not set on this command buffer");
364 result |= validate_status(pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_REFERENCE_SET, CBSTATUS_STENCIL_REFERENCE_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Stencil reference not set on this command buffer");
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600365 if (indexedDraw)
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600366 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Index Draw attempted");
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600367 return result;
368}
369// Validate overall state at the time of a draw call
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600370static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600371 // First check flag states
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600372 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600373 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
374 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -0600375 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
376 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
377 // We should have that check separately and then gate this check based on that check
378 if (pPipe && (pCB->lastBoundPipelineLayout) && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600379 result = VK_FALSE;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600380 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Mark Lobodzinski735e4b32015-08-04 10:54:43 -0600381 "Pipeline layout from last vkCmdBindDescriptorSets() (%#" PRIxLEAST64 ") does not match PSO Pipeline layout (%#" PRIxLEAST64 ") ", pCB->lastBoundPipelineLayout.handle, pPipe->graphicsPipelineCI.layout.handle);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600382 }
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -0600383 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600384 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -0600385 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
386 }
Tobin Ehlisf7bf4502015-09-09 15:12:35 -0600387 // Verify Vtx binding
388 if (MAX_BINDING != pCB->lastVtxBinding) {
389 if (pCB->lastVtxBinding >= pPipe->vtxBindingCount) {
390 if (0 == pPipe->vtxBindingCount) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600391 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisf7bf4502015-09-09 15:12:35 -0600392 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -0600393 }
394 else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600395 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisf7bf4502015-09-09 15:12:35 -0600396 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipe->vtxBindingCount - 1));
Tobin Ehlisf7bf4502015-09-09 15:12:35 -0600397 }
398 }
399 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600400 return result;
401}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600402// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600404{
405 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600406 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600407 loader_platform_thread_unlock_mutex(&globalLock);
408 return NULL;
409 }
410 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600411 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600412}
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600413// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600414static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600415{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600416 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600417 // VS is required
418 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600419 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600420 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600421 }
422 // Either both or neither TC/TE shaders should be defined
423 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
424 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600425 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600426 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600427 }
428 // Compute shaders should be specified independent of Gfx shaders
429 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
430 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
431 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
432 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600433 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600434 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600435 }
436 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
437 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
438 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
439 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600440 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600441 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600442 }
Tobin Ehlis912df022015-09-17 08:46:18 -0600443 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) {
444 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) {
445 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600446 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
Tobin Ehlis912df022015-09-17 08:46:18 -0600447 }
448 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
449 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
450 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology used with patchControlPoints value %u."
451 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
452 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600453 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600454 return skipCall;
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600455}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600456// Init the pipeline mapping info based on pipeline create info LL tree
457// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600458static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600459{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600460 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
461 if (pBasePipeline) {
462 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlis9c536442015-06-19 13:00:59 -0600463 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600464 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
465 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600466 // First init create info
Tobin Ehliseba312c2015-04-01 08:40:34 -0600467 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600468 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600469
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600470 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600471 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -0600472 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600473
474 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
475 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
476
477 switch (pPSSCI->stage) {
478 case VK_SHADER_STAGE_VERTEX:
479 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
480 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600481 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600482 case VK_SHADER_STAGE_TESS_CONTROL:
483 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
484 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600485 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600486 case VK_SHADER_STAGE_TESS_EVALUATION:
487 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
488 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600489 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600490 case VK_SHADER_STAGE_GEOMETRY:
491 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
492 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600493 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600494 case VK_SHADER_STAGE_FRAGMENT:
495 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
496 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600497 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600498 case VK_SHADER_STAGE_COMPUTE:
499 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
500 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600501 break;
502 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600503 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600504 break;
505 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600506 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600507
508 if (pCreateInfo->pVertexInputState != NULL) {
509 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
510 // Copy embedded ptrs
511 pVICI = pCreateInfo->pVertexInputState;
512 pPipeline->vtxBindingCount = pVICI->bindingCount;
513 if (pPipeline->vtxBindingCount) {
514 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
515 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
516 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
517 }
518 pPipeline->vtxAttributeCount = pVICI->attributeCount;
519 if (pPipeline->vtxAttributeCount) {
520 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
521 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
522 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
523 }
524 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
525 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600526 if (pCreateInfo->pInputAssemblyState != NULL) {
527 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
528 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600529 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600530 if (pCreateInfo->pTessellationState != NULL) {
531 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
532 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600533 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600534 if (pCreateInfo->pViewportState != NULL) {
535 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
536 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600537 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600538 if (pCreateInfo->pRasterState != NULL) {
539 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
540 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600541 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600542 if (pCreateInfo->pMultisampleState != NULL) {
543 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
544 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600545 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600546 if (pCreateInfo->pColorBlendState != NULL) {
547 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600548 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600549 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600550 pPipeline->attachmentCount = pCBCI->attachmentCount;
551 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600552 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
553 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600554 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
555 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600556 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600557 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600558 if (pCreateInfo->pDepthStencilState != NULL) {
559 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600561 }
562
563 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
564 if (pCreateInfo->stageCount != 0) {
565 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
566 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
567 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
568 }
569
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600570 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600571}
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600572
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600573// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600574static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600575{
David Pinedod8f83d82015-04-27 16:36:17 -0600576 if (pipelineMap.size() <= 0)
577 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600578 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600579 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
580 delete[] (*ii).second->graphicsPipelineCI.pStages;
581 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600582 if ((*ii).second->pVertexBindingDescriptions) {
583 delete[] (*ii).second->pVertexBindingDescriptions;
584 }
585 if ((*ii).second->pVertexAttributeDescriptions) {
586 delete[] (*ii).second->pVertexAttributeDescriptions;
587 }
588 if ((*ii).second->pAttachments) {
589 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600590 }
591 delete (*ii).second;
592 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600593 pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600594}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600595// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600596static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600597{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600598 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlis577188e2015-07-13 14:51:15 -0600599 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
600 return pPipe->msStateCI.rasterSamples;
601 }
Tobin Ehliseba312c2015-04-01 08:40:34 -0600602 return 1;
603}
604// Validate state related to the PSO
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600605static VkBool32 validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600606{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600607 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600608 // Verify that any MSAA request in PSO matches sample# in bound FB
609 uint32_t psoNumSamples = getNumSamples(pipeline);
610 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600611 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wu08accc62015-07-07 11:50:03 +0800612 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
613 int subpassNumSamples = 0;
614 uint32_t i;
615
616 for (i = 0; i < pSD->colorCount; i++) {
617 uint32_t samples;
618
Cody Northropa505dda2015-08-04 11:16:41 -0600619 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +0800620 continue;
621
Cody Northropa505dda2015-08-04 11:16:41 -0600622 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu08accc62015-07-07 11:50:03 +0800623 if (subpassNumSamples == 0) {
624 subpassNumSamples = samples;
625 } else if (subpassNumSamples != samples) {
626 subpassNumSamples = -1;
627 break;
628 }
629 }
630 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
631 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
632 if (subpassNumSamples == 0)
633 subpassNumSamples = samples;
634 else if (subpassNumSamples != samples)
635 subpassNumSamples = -1;
636 }
637
638 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600639 return log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600640 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!", pipeline.handle, psoNumSamples, pCB->activeRenderPass.handle, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -0600641 }
642 } else {
643 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
644 // Verify and flag error as appropriate
645 }
646 // TODO : Add more checks here
647 } else {
648 // TODO : Validate non-gfx pipeline updates
649 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600650 return VK_FALSE;
Tobin Ehliseba312c2015-04-01 08:40:34 -0600651}
652
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600653// Block of code at start here specifically for managing/tracking DSs
654
Tobin Ehlis793ad302015-04-03 12:01:11 -0600655// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600656static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600657{
658 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600659 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600660 loader_platform_thread_unlock_mutex(&globalLock);
661 return NULL;
662 }
663 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600664 return poolMap[pool.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600665}
666// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600667static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600668{
669 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600670 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600671 loader_platform_thread_unlock_mutex(&globalLock);
672 return NULL;
673 }
674 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600675 return setMap[set.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600676}
677
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600678static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600679 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600680 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600681 loader_platform_thread_unlock_mutex(&globalLock);
682 return NULL;
683 }
684 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600685 return layoutMap[layout.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600686}
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600687// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600688static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600689{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600690 switch (pUpdateStruct->sType)
691 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800692 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
693 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600694 return VK_FALSE;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600695 default:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600696 return log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600697 "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 -0600698 }
699}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600700// For given update struct, return binding
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600701static VkBool32 getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* binding)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600702{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600703 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600704 switch (pUpdateStruct->sType)
705 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800706 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600707 *binding = ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
708 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800709 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600710 *binding = ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
711 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600712 default:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600713 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600714 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600715 *binding = 0xFFFFFFFF;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600716 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600717 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600718}
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600719// Set arrayIndex for given update struct in the last parameter
720// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
721static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* arrayIndex)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600722{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600723 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600724 switch (pUpdateStruct->sType)
725 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800726 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600727 *arrayIndex = ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
728 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800729 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600730 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600731 *arrayIndex = ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
732 break;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600733 default:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600734 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600735 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600736 *arrayIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600737 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600738 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600739}
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600740// Set count for given update struct in the last parameter
741// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
742static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* count)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600743{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600744 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600745 switch (pUpdateStruct->sType)
746 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800747 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600748 *count = ((VkWriteDescriptorSet*)pUpdateStruct)->count;
749 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800750 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600751 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600752 *count = ((VkCopyDescriptorSet*)pUpdateStruct)->count;
753 break;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600754 default:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600755 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600756 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600757 *count = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600758 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600759 return skipCall;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600760}
761// For given Layout Node and binding, return index where that binding begins
762static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
763{
764 uint32_t offsetIndex = 0;
765 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800766 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600767 }
768 return offsetIndex;
769}
770// For given layout node and binding, return last index that is updated
771static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
772{
773 uint32_t offsetIndex = 0;
774 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800775 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600776 }
777 return offsetIndex-1;
778}
779// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600780static VkBool32 getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* startIndex)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600781{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600782 uint32_t binding = 0, arrayIndex = 0;
783 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
784 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
785 if (VK_FALSE == skipCall)
786 *startIndex = getBindingStartIndex(pLayout, binding)+arrayIndex;
787 return skipCall;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600788}
789// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600790static VkBool32 getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* endIndex)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600791{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600792 uint32_t binding = 0, arrayIndex = 0, count = 0;
793 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
794 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
795 skipCall |= getUpdateCount(device, pUpdateStruct, &count);
796 if (VK_FALSE == skipCall)
797 *endIndex = getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
798 return skipCall;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600799}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600800// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600801static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600802{
803 // First get actual type of update
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600804 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600805 VkDescriptorType actualType;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600806 uint32_t i = 0, startIndex = 0, endIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600807 switch (pUpdateStruct->sType)
808 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800809 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
810 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600811 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800812 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
813 /* no need to validate */
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600814 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600815 break;
816 default:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600817 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600818 "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 -0600819 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600820 skipCall |= getUpdateStartIndex(device, pLayout, pUpdateStruct, &startIndex);
821 skipCall |= getUpdateEndIndex(device, pLayout, pUpdateStruct, &endIndex);
822 if (VK_FALSE == skipCall) {
823 for (i = startIndex; i <= endIndex; i++) {
824 if (pLayout->pTypes[i] != actualType)
825 return VK_TRUE;
826 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600827 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600828 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600829}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600830// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600831// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600832// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600833static VkBool32 shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600834{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600835 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800836 VkWriteDescriptorSet* pWDS = NULL;
837 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600838 size_t array_size = 0;
839 size_t base_array_size = 0;
840 size_t total_array_size = 0;
841 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600842 switch (pUpdate->sType)
843 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800844 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
845 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600846 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800847 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
848 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
849 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
850 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600851 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800852 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
853 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600854 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800855 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600856 break;
857 default:
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600858 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
859 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
860 return VK_TRUE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600861 }
862 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600863 (*pNewNode)->pNext = NULL;
864 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600865}
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800866// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600867static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600868{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800869 const VkWriteDescriptorSet *pWDS = NULL;
870 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600871 VkBool32 skipCall = VK_FALSE;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800872
873 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
874 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
875 else
876 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
877
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600878 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600879 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600880 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600881 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600882 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600883 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800884 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600885 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800886 g_lastBoundDescriptorSet = pSet->set;
887 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600888 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600889 // First verify valid update struct
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600890 if ((skipCall = validUpdateStruct(device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600891 break;
892 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600893 // Make sure that binding is within bounds
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600894 uint32_t binding = 0, endIndex = 0;
895 skipCall |= getUpdateBinding(device, pUpdate, &binding);
896 if (pLayout->createInfo.count < binding) {
897 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
898 "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -0600899 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600900 // Next verify that update falls within size of given binding
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600901 skipCall |= getUpdateBinding(device, pUpdate, &binding);
902 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
903 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tony Barbour3b4732f2015-07-13 13:37:24 -0600904 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlis793ad302015-04-03 12:01:11 -0600905 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600906 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600907 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
908 "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 -0600909 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600910 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600911 if ((skipCall = validateUpdateType(device, pLayout, pUpdate)) == VK_TRUE) {
912 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600913 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis9c536442015-06-19 13:00:59 -0600914 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600915 // Save the update info
916 // TODO : Info message that update successful
917 // Create new update struct for this set's shadow copy
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600918 GENERIC_HEADER* pNewNode = NULL;
919 skipCall |= shadowUpdateNode(device, pUpdate, &pNewNode);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600920 if (NULL == pNewNode) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600921 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600922 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis9c536442015-06-19 13:00:59 -0600923 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600924 // Insert shadow node into LL of updates for this set
925 pNewNode->pNext = pSet->pUpdateStructs;
926 pSet->pUpdateStructs = pNewNode;
927 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600928 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
929 uint32_t startIndex;
930 skipCall |= getUpdateStartIndex(device, pLayout, pUpdate, &startIndex);
931 for (uint32_t j = startIndex; j <= endIndex; j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600932 assert(j<pSet->descriptorCount);
933 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600934 }
935 }
936 }
937 }
938 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600939 }
940 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -0600941 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600942}
943// Free the shadowed update node for this Set
944// NOTE : Calls to this function should be wrapped in mutex
945static void freeShadowUpdateTree(SET_NODE* pSet)
946{
947 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
948 pSet->pUpdateStructs = NULL;
949 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
950 // Clear the descriptor mappings as they will now be invalid
951 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
952 while(pShadowUpdate) {
953 pFreeUpdate = pShadowUpdate;
954 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
955 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800956 VkWriteDescriptorSet * pWDS = NULL;
957 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600958 void** ppToFree = NULL;
959 switch (pFreeUpdate->sType)
960 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800961 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
962 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
963 if (pWDS->pDescriptors)
964 delete[] pWDS->pDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600965 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800966 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600967 break;
968 default:
969 assert(0);
970 break;
971 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600972 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600973 }
974}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600975// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600976// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600977static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600978{
David Pinedod8f83d82015-04-27 16:36:17 -0600979 if (poolMap.size() <= 0)
980 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600981 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600982 SET_NODE* pSet = (*ii).second->pSets;
983 SET_NODE* pFreeSet = pSet;
984 while (pSet) {
985 pFreeSet = pSet;
986 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600987 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600988 // Free Update shadow struct tree
989 freeShadowUpdateTree(pFreeSet);
990 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +1200991 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600992 }
993 delete pFreeSet;
994 }
995 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes02038792015-06-04 10:49:27 +1200996 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600997 }
998 delete (*ii).second;
999 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001000 poolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001001}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001002// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001003// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001004static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001005{
David Pinedod8f83d82015-04-27 16:36:17 -06001006 if (layoutMap.size() <= 0)
1007 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001008 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001009 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001010 if (pLayout->createInfo.pBinding) {
1011 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1012 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1013 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1014 }
1015 delete[] pLayout->createInfo.pBinding;
1016 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001017 if (pLayout->pTypes) {
Chris Forbes02038792015-06-04 10:49:27 +12001018 delete[] pLayout->pTypes;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001019 }
1020 delete pLayout;
1021 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001022 layoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001023}
1024// Currently clearing a set is removing all previous updates to that set
1025// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001026static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001027{
1028 SET_NODE* pSet = getSetNode(set);
1029 if (!pSet) {
1030 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06001031 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001032 loader_platform_thread_lock_mutex(&globalLock);
1033 freeShadowUpdateTree(pSet);
1034 loader_platform_thread_unlock_mutex(&globalLock);
1035 }
1036}
1037
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001038static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001039{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001040 POOL_NODE* pPool = getPoolNode(pool);
1041 if (!pPool) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001042 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1043 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001044 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001045 // For every set off of this pool, clear it
1046 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001047 while (pSet) {
1048 clearDescriptorSet(pSet->set);
1049 }
1050 }
1051}
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001052// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001053static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001054{
1055 loader_platform_thread_lock_mutex(&globalLock);
1056 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1057 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001058 // TODO : How to pass cb as srcObj here?
1059 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001060 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001061 return NULL;
1062 }
1063 loader_platform_thread_unlock_mutex(&globalLock);
1064 return cmdBufferMap[cb];
1065}
1066// Free all CB Nodes
1067// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001068static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001069{
David Pinedod8f83d82015-04-27 16:36:17 -06001070 if (cmdBufferMap.size() <= 0)
1071 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001072 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06001073 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1074 while (!cmd_node_list.empty()) {
1075 CMD_NODE* cmd_node = cmd_node_list.back();
1076 delete cmd_node;
1077 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001078 }
1079 delete (*ii).second;
1080 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001081 cmdBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001082}
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001083static VkBool32 report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
Tobin Ehlis9c536442015-06-19 13:00:59 -06001084{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001085 // TODO : How to pass cb as srcObj here?
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001086 return log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_BEGIN_CMD_BUFFER, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06001087 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1088}
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001089static VkBool32 addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001090{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001091 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001092 CMD_NODE* pCmd = new CMD_NODE;
1093 if (pCmd) {
1094 // init cmd node and append to end of cmd LL
1095 memset(pCmd, 0, sizeof(CMD_NODE));
1096 pCmd->cmdNumber = ++pCB->numCmds;
1097 pCmd->type = cmd;
1098 pCB->pCmds.push_back(pCmd);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001099 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001100 // TODO : How to pass cb as srcObj here?
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001101 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001102 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001103 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001104 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001105}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001106static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001107{
1108 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1109 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001110 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1111 while (!cmd_list.empty()) {
1112 delete cmd_list.back();
1113 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001114 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001115 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001116 // Reset CB state (need to save createInfo)
1117 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001118 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1119 pCB->cmdBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001120 pCB->createInfo = saveCBCI;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001121 pCB->lastVtxBinding = MAX_BINDING;
1122 }
1123}
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001124// Set PSO-related status bits for CB
1125static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1126{
1127 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1128 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1129 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1130 }
1131 }
1132 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06001133 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1134 }
1135
1136 if (pPipe->dsStateCI.stencilTestEnable) {
1137 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001138 }
1139}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001140// Print the last bound Gfx Pipeline
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001141static VkBool32 printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001142{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001143 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001144 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1145 if (pCB) {
1146 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1147 if (!pPipeTrav) {
1148 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06001149 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001150 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001151 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001152 }
1153 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001154 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001155}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001156// Print details of DS config to stdout
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001157static VkBool32 printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001158{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001159 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001160 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.
1161 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06001162 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001163 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001164 POOL_NODE* pPool = getPoolNode(pSet->pool);
1165 // Print out pool details
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001166 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001167 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001168 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001169 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001170 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001171 // Print out set details
1172 char prefix[10];
1173 uint32_t index = 0;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001174 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001175 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001176 LAYOUT_NODE* pLayout = pSet->pLayout;
1177 // Print layout details
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001178 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001179 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001180 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001181 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001182 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001183 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06001184 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001185 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1186 if (pUpdate) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001187 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001188 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001189 sprintf(prefix, " [UC] ");
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001190 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001191 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001192 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06001193 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001194 if (0 != pSet->descriptorCount) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001195 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001196 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", pSet->set.handle, pSet->descriptorCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001197 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001198 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001199 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001200 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001201 }
1202 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001203 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001204}
1205
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001206static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001207{
1208 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001209 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001210 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001211 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001212 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001213 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1214 // TODO : Need to pass cb as srcObj here
1215 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001216 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001217 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06001218 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001219 // Nothing to print
1220 }
1221}
1222
1223
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001224static VkBool32 synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001225{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001226 VkBool32 skipCall = VK_FALSE;
Mike Stroyanba35e352015-08-12 17:11:28 -06001227 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001228 return skipCall;
Mike Stroyanba35e352015-08-12 17:11:28 -06001229 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001230 skipCall |= printDSConfig(cb);
1231 skipCall |= printPipeline(cb);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001232 return skipCall;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001233}
1234
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001235static void init_draw_state(layer_data *my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001236{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001237 uint32_t report_flags = 0;
1238 uint32_t debug_action = 0;
1239 FILE *log_output = NULL;
1240 const char *option_str;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001241 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001242 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1243 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001244
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001245 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001246 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001247 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -06001248 log_output = getLayerLogOutput(option_str, "DrawState");
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001249 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001250 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001251
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001252 if (!globalLockInitialized)
1253 {
1254 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001255 // suggestion is to call this during vkCreateInstance(), and then we
1256 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001257 // that the layer have per-instance locks. We need to come back and
1258 // address this soon.
1259 loader_platform_thread_create_mutex(&globalLock);
1260 globalLockInitialized = 1;
1261 }
1262}
1263
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001264VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1265{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001266 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001267 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1268
1269 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001270 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1271 my_data->report_data = debug_report_create_instance(
1272 pTable,
1273 *pInstance,
1274 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001275 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001276
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001277 init_draw_state(my_data);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001278 }
1279 return result;
1280}
1281
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001282/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001283VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001284{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001285 dispatch_key key = get_dispatch_key(instance);
1286 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001287 pTable->DestroyInstance(instance);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001288
1289 // Clean up logging callback, if any
1290 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1291 if (my_data->logging_callback) {
1292 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1293 }
1294
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001295 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001296 layer_data_map.erase(pTable);
1297
1298 draw_state_instance_table_map.erase(key);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001299}
1300
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001301static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1302{
Tony Barbour3b4732f2015-07-13 13:37:24 -06001303 uint32_t i;
Jon Ashburn747f2b62015-06-18 15:02:58 -06001304 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburneab34492015-06-01 09:37:38 -06001305 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001306
1307 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001308 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06001309 /* Found a matching extension name, mark it enabled and init dispatch table*/
1310 initDebugMarkerTable(device);
1311 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001312 }
1313
1314 }
1315}
1316
Tony Barbourd1c35722015-04-16 15:59:00 -06001317VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001318{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06001319 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1320 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001321 if (result == VK_SUCCESS) {
1322 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1323 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1324 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1325 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001326 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001327 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001328 return result;
1329}
1330
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001331VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001332{
1333 // Free all the memory
1334 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001335 deletePipelines();
1336 deleteSamplers();
1337 deleteImages();
1338 deleteBuffers();
1339 deleteCmdBuffers();
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001340 deletePools();
1341 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001342 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001343
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001344 dispatch_key key = get_dispatch_key(device);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001345 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001346 pDisp->DestroyDevice(device);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001347 deviceExtMap.erase(pDisp);
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001348 draw_state_device_table_map.erase(key);
Jon Ashburneab34492015-06-01 09:37:38 -06001349 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001350}
1351
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001352static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001353 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001354 "DrawState",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001355 VK_API_VERSION,
1356 VK_MAKE_VERSION(0, 1, 0),
1357 "Validation layer: DrawState",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001358 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001359};
1360
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06001361VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001362 const char *pLayerName,
1363 uint32_t *pCount,
1364 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001365{
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001366 /* DrawState does not have any global extensions */
1367 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1368}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001369
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06001370VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001371 uint32_t *pCount,
1372 VkLayerProperties* pProperties)
1373{
1374 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1375 ds_global_layers,
1376 pCount, pProperties);
1377}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001378
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001379static const VkExtensionProperties ds_device_extensions[] = {
1380 {
1381 DEBUG_MARKER_EXTENSION_NAME,
1382 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001383 }
1384};
1385
1386static const VkLayerProperties ds_device_layers[] = {
1387 {
1388 "DrawState",
1389 VK_API_VERSION,
1390 VK_MAKE_VERSION(0, 1, 0),
1391 "Validation layer: DrawState",
1392 }
1393};
1394
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06001395VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001396 VkPhysicalDevice physicalDevice,
1397 const char* pLayerName,
1398 uint32_t* pCount,
1399 VkExtensionProperties* pProperties)
1400{
1401 /* Mem tracker does not have any physical device extensions */
1402 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1403 pCount, pProperties);
1404}
1405
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06001406VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001407 VkPhysicalDevice physicalDevice,
1408 uint32_t* pCount,
1409 VkLayerProperties* pProperties)
1410{
1411 /* Mem tracker's physical device layers are the same as global */
1412 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1413 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001414}
1415
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001416VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001417{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001418 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001419 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001420 for (uint32_t i=0; i < cmdBufferCount; i++) {
1421 // Validate that cmd buffers have been updated
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001422 pCB = getCBNode(pCmdBuffers[i]);
1423 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001424 pCB->submitCount++; // increment submit count
1425 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001426 skipCall |= log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CMD_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001427 "CB %#" PRIxLEAST64 " was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.", reinterpret_cast<uint64_t>(pCB->cmdBuffer), pCB->submitCount);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001428 }
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001429 if (CB_UPDATE_COMPLETE != pCB->state) {
1430 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001431 // TODO : How to pass cb as srcObj?
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001432 skipCall |= log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001433 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001434 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001435 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001436 }
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06001437 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001438 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001439 if (VK_FALSE == skipCall)
1440 return get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
1441 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001442}
1443
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001444VK_LAYER_EXPORT void VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001445{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001446 get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001447 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001448}
1449
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001450VK_LAYER_EXPORT void VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001451{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001452 get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001453 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001454}
1455
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001456VK_LAYER_EXPORT void VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001457{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001458 get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001459 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001460}
1461
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001462VK_LAYER_EXPORT void VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001463{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001464 get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001465 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001466}
1467
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001468VK_LAYER_EXPORT void VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001469{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001470 get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001471 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001472}
1473
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001474VK_LAYER_EXPORT void VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001475{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001476 get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001477 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001478}
1479
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001480VK_LAYER_EXPORT void VKAPI vkDestroyImage(VkDevice device, VkImage image)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001481{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001482 get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001483 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001484}
1485
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001486VK_LAYER_EXPORT void VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001487{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001488 get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001489 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001490}
1491
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001492VK_LAYER_EXPORT void VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001493{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001494 get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001495 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001496}
1497
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001498VK_LAYER_EXPORT void VKAPI vkDestroyShader(VkDevice device, VkShader shader)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001499{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001500 get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001501 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001502}
1503
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001504VK_LAYER_EXPORT void VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001505{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001506 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001507 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001508}
1509
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001510VK_LAYER_EXPORT void VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001511{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001512 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001513 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001514}
1515
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001516VK_LAYER_EXPORT void VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001517{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001518 get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001519 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001520}
1521
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001522VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001523{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001524 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001525 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001526}
1527
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001528VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001529{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001530 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001531 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001532}
1533
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001534VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001535{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001536 get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001537 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001538}
1539
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001540VK_LAYER_EXPORT void VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001541{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001542 get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001543 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001544}
1545
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001546VK_LAYER_EXPORT void VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001547{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001548 get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001549 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001550}
1551
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001552VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001553{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001554 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001555 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001556 loader_platform_thread_lock_mutex(&globalLock);
1557 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1558 pNewNode->buffer = *pView;
1559 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001560 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001561 loader_platform_thread_unlock_mutex(&globalLock);
1562 }
1563 return result;
1564}
1565
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001566VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001567{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001568 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001569 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001570 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001571 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001572 loader_platform_thread_unlock_mutex(&globalLock);
1573 }
1574 return result;
1575}
1576
Jon Ashburnc669cc62015-07-09 15:02:25 -06001577//TODO handle pipeline caches
1578VkResult VKAPI vkCreatePipelineCache(
1579 VkDevice device,
1580 const VkPipelineCacheCreateInfo* pCreateInfo,
1581 VkPipelineCache* pPipelineCache)
1582{
1583 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1584 return result;
1585}
1586
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001587void VKAPI vkDestroyPipelineCache(
Jon Ashburnc669cc62015-07-09 15:02:25 -06001588 VkDevice device,
1589 VkPipelineCache pipelineCache)
1590{
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001591 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001592}
1593
1594size_t VKAPI vkGetPipelineCacheSize(
1595 VkDevice device,
1596 VkPipelineCache pipelineCache)
1597{
1598 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1599 return size;
1600}
1601
1602VkResult VKAPI vkGetPipelineCacheData(
1603 VkDevice device,
1604 VkPipelineCache pipelineCache,
1605 void* pData)
1606{
1607 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1608 return result;
1609}
1610
1611VkResult VKAPI vkMergePipelineCaches(
1612 VkDevice device,
1613 VkPipelineCache destCache,
1614 uint32_t srcCacheCount,
1615 const VkPipelineCache* pSrcCaches)
1616{
1617 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1618 return result;
1619}
1620
1621VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001622{
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06001623 VkResult result = VK_SUCCESS;
Tobin Ehlis11efc302015-09-16 10:33:53 -06001624 //TODO What to do with pipelineCache?
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001625 // The order of operations here is a little convoluted but gets the job done
1626 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1627 // 2. Create state is then validated (which uses flags setup during shadowing)
1628 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlis11efc302015-09-16 10:33:53 -06001629 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis65399772015-09-17 16:33:58 -06001630 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
1631 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlis11efc302015-09-16 10:33:53 -06001632 uint32_t i=0;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001633 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06001634 for (i=0; i<count; i++) {
1635 pPipeNode[i] = initPipeline(&pCreateInfos[i], NULL);
1636 skipCall |= verifyPipelineCreateState(device, pPipeNode[i]);
1637 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001638 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001639 if (VK_FALSE == skipCall) {
Jon Ashburnc669cc62015-07-09 15:02:25 -06001640 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001641 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis11efc302015-09-16 10:33:53 -06001642 for (i=0; i<count; i++) {
1643 pPipeNode[i]->pipeline = pPipelines[i];
1644 pipelineMap[pPipeNode[i]->pipeline.handle] = pPipeNode[i];
1645 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001646 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001647 } else {
Tobin Ehlis11efc302015-09-16 10:33:53 -06001648 for (i=0; i<count; i++) {
1649 if (pPipeNode[i]) {
1650 // If we allocated a pipeNode, need to clean it up here
1651 delete[] pPipeNode[i]->pVertexBindingDescriptions;
1652 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
1653 delete[] pPipeNode[i]->pAttachments;
1654 delete pPipeNode[i];
1655 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001656 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001657 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001658 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001659 return result;
1660}
1661
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001662VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001663{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001664 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001665 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001666 loader_platform_thread_lock_mutex(&globalLock);
1667 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1668 pNewNode->sampler = *pSampler;
1669 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001670 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001671 loader_platform_thread_unlock_mutex(&globalLock);
1672 }
1673 return result;
1674}
1675
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001676VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001677{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001678 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001679 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001680 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1681 if (NULL == pNewNode) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001682 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1683 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
1684 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001685 }
1686 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001687 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1688 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1689 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001690 uint32_t totalCount = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001691 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001692 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001693 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001694 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001695 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1696 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001697 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001698 }
1699 if (totalCount > 0) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001700 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001701 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001702 uint32_t j = 0;
1703 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001704 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001705 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001706 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001707 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001708 }
1709 }
1710 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001711 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001712 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1713 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001714 // Put new node at Head of global Layer list
1715 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001716 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001717 loader_platform_thread_unlock_mutex(&globalLock);
1718 }
1719 return result;
1720}
1721
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001722VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001723{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001724 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001725 if (VK_SUCCESS == result) {
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001726 // TODO : Need to capture the pipeline layout
Tobin Ehlis793ad302015-04-03 12:01:11 -06001727 }
1728 return result;
1729}
1730
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001731VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001732{
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001733 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001734 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001735 // Insert this pool into Global Pool LL at head
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001736 if (log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1737 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle))
1738 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001739 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001740 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001741 if (NULL == pNewNode) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001742 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1743 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()"))
1744 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisce132d82015-06-19 15:07:05 -06001745 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001746 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001747 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1748 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001749 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001750 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1751 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001752 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1753 }
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06001754 pNewNode->poolUsage = pCreateInfo->poolUsage;
1755 pNewNode->maxSets = pCreateInfo->maxSets;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001756 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001757 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001758 }
1759 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001760 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001761 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001762 }
1763 return result;
1764}
1765
Mike Stroyanb050c682015-04-17 12:36:38 -06001766VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001767{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001768 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001769 if (VK_SUCCESS == result) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001770 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001771 }
1772 return result;
1773}
1774
Cody Northrop1e4f8022015-08-03 12:47:29 -06001775VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001776{
Cody Northrop1e4f8022015-08-03 12:47:29 -06001777 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1778 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001779 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1780 if (!pPoolNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001781 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1782 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001783 } else {
Cody Northrop1e4f8022015-08-03 12:47:29 -06001784 if (count == 0) {
1785 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1786 "AllocDescriptorSets called with 0 count");
1787 }
1788 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001789 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1790 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001791 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001792 SET_NODE* pNewNode = new SET_NODE;
1793 if (NULL == pNewNode) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001794 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1795 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()"))
1796 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisce132d82015-06-19 15:07:05 -06001797 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001798 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001799 // Insert set at head of Set LL for this pool
1800 pNewNode->pNext = pPoolNode->pSets;
1801 pPoolNode->pSets = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001802 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1803 if (NULL == pLayout) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001804 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1805 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle))
1806 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001807 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001808 pNewNode->pLayout = pLayout;
1809 pNewNode->pool = descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001810 pNewNode->set = pDescriptorSets[i];
1811 pNewNode->setUsage = setUsage;
1812 pNewNode->descriptorCount = pLayout->endIndex + 1;
1813 if (pNewNode->descriptorCount) {
1814 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1815 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1816 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1817 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001818 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001819 }
1820 }
1821 }
1822 }
1823 return result;
1824}
1825
Tony Barbour34ec6922015-07-10 10:50:45 -06001826VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1827{
1828 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1829 // TODO : Clean up any internal data structures using this obj.
1830 return result;
1831}
1832
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001833VK_LAYER_EXPORT void VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001834{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001835 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when both updates return VK_FALSE
1836 if (!dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1837 !dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Mark Lobodzinski2141f652015-09-07 13:59:43 -06001838 get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001839 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001840}
1841
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001842VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001843{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001844 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001845 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001846 loader_platform_thread_lock_mutex(&globalLock);
1847 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1848 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1849 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001850 pCB->createInfo = *pCreateInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001851 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001852 pCB->level = pCreateInfo->level;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001853 cmdBufferMap[*pCmdBuffer] = pCB;
1854 loader_platform_thread_unlock_mutex(&globalLock);
1855 updateCBTracking(*pCmdBuffer);
1856 }
1857 return result;
1858}
1859
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001860VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001861{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001862 VkBool32 skipCall = false;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001863 // Validate command buffer level
1864 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1865 if (pCB) {
1866 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
1867 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
1868 // These should be NULL for a Primary CB
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001869 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001870 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
1871 }
1872 } else {
1873 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
1874 // These should NOT be null for an Secondary CB
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001875 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001876 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
1877 }
1878 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001879 pCB->beginInfo = *pBeginInfo;
1880 } else {
1881 // TODO : Need to pass cmdBuffer as objType here
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001882 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001883 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001884 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001885 if (skipCall) {
1886 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter5fe086f2015-09-04 15:03:52 -06001887 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001888 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001889 if (VK_SUCCESS == result) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001890 if (CB_NEW != pCB->state)
1891 resetCB(cmdBuffer);
1892 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001893 updateCBTracking(cmdBuffer);
1894 }
1895 return result;
1896}
1897
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001898VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001899{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001900 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06001901 VkResult result = VK_SUCCESS;
Tobin Ehlis9c536442015-06-19 13:00:59 -06001902 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -06001903 /* TODO: preference is to always call API function after reporting any validation errors */
Tobin Ehlis9c536442015-06-19 13:00:59 -06001904 if (pCB) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001905 if (pCB->state != CB_UPDATE_ACTIVE) {
1906 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001907 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001908 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001909 if (VK_FALSE == skipCall) {
1910 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
1911 if (VK_SUCCESS == result) {
1912 updateCBTracking(cmdBuffer);
1913 pCB->state = CB_UPDATE_COMPLETE;
1914 // Reset CB status flags
1915 pCB->status = 0;
1916 printCB(cmdBuffer);
1917 }
1918 } else {
1919 result = VK_ERROR_VALIDATION_FAILED;
1920 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001921 return result;
1922}
1923
Cody Northrope62183e2015-07-09 18:08:05 -06001924VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001925{
Cody Northrope62183e2015-07-09 18:08:05 -06001926 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001927 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001928 resetCB(cmdBuffer);
1929 updateCBTracking(cmdBuffer);
1930 }
1931 return result;
1932}
1933
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001934VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001935{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001936 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001937 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1938 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06001939 if (pCB->state == CB_UPDATE_ACTIVE) {
1940 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001941 skipCall |= addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis6d58e6d2015-06-23 08:46:18 -06001942 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001943 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001944 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06001945 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001946 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001947 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001948 } else {
Tobin Ehlis502480b2015-06-24 15:53:07 -06001949 PIPELINE_NODE* pPN = getPipeline(pipeline);
1950 if (pPN) {
1951 pCB->lastBoundPipeline = pipeline;
1952 loader_platform_thread_lock_mutex(&globalLock);
1953 set_cb_pso_status(pCB, pPN);
1954 g_lastBoundPipeline = pPN;
1955 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001956 skipCall |= validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis502480b2015-06-24 15:53:07 -06001957 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001958 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001959 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06001960 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06001961 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06001962 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001963 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001964 }
1965 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001966 if (VK_FALSE == skipCall)
1967 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001968}
1969
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06001970VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
1971 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06001972 uint32_t viewportCount,
1973 const VkViewport* pViewports)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001974{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001975 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis9c536442015-06-19 13:00:59 -06001976 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1977 if (pCB) {
1978 if (pCB->state == CB_UPDATE_ACTIVE) {
1979 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06001980 skipCall |= addCmd(pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06001981 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001982 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06001983 "Incorrect call to vkCmdSetViewport() without an active RenderPass.");
Tobin Ehlis502480b2015-06-24 15:53:07 -06001984 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06001985 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06001986 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06001987 pCB->viewports.resize(viewportCount);
1988 memcpy(pCB->viewports.data(), pViewports, viewportCount);
Tobin Ehlis9c536442015-06-19 13:00:59 -06001989 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis9c536442015-06-19 13:00:59 -06001990 } else {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06001991 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetViewport()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06001992 }
1993 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06001994 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06001995 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
1996}
1997
1998VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
1999 VkCmdBuffer cmdBuffer,
2000 uint32_t scissorCount,
2001 const VkRect2D* pScissors)
2002{
2003 VkBool32 skipCall = VK_FALSE;
2004 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2005 if (pCB) {
2006 if (pCB->state == CB_UPDATE_ACTIVE) {
2007 updateCBTracking(cmdBuffer);
2008 skipCall |= addCmd(pCB, CMD_SETSCISSORSTATE);
2009 if (!pCB->activeRenderPass) {
2010 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2011 "Incorrect call to vkCmdSetScissor() without an active RenderPass.");
2012 }
2013 loader_platform_thread_lock_mutex(&globalLock);
2014 pCB->status |= CBSTATUS_SCISSOR_SET;
2015 pCB->scissors.resize(scissorCount);
2016 memcpy(pCB->scissors.data(), pScissors, scissorCount);
2017 loader_platform_thread_unlock_mutex(&globalLock);
2018 } else {
2019 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetScissor()");
2020 }
2021 }
2022 if (VK_FALSE == skipCall)
2023 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002024}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002025
2026VK_LAYER_EXPORT void VKAPI vkCmdSetLineWidth(VkCmdBuffer cmdBuffer, float lineWidth)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002027{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002028 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002029 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2030 if (pCB) {
2031 if (pCB->state == CB_UPDATE_ACTIVE) {
2032 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002033 skipCall |= addCmd(pCB, CMD_SETLINEWIDTHSTATE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002034 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002035 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002036 "Incorrect call to vkCmdSetLineWidth() without an active RenderPass.");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002037 }
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002038 /* TODO: Do we still need this lock? */
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002039 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002040 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
2041 pCB->lineWidth = lineWidth;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002042 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002043 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002044 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northrop12365112015-08-17 11:10:49 -06002045 }
2046 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002047 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002048 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetLineWidth(cmdBuffer, lineWidth);
Cody Northrop12365112015-08-17 11:10:49 -06002049}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002050
2051VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBias(
2052 VkCmdBuffer cmdBuffer,
2053 float depthBias,
2054 float depthBiasClamp,
2055 float slopeScaledDepthBias)
Cody Northrop12365112015-08-17 11:10:49 -06002056{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002057 VkBool32 skipCall = VK_FALSE;
Cody Northrop12365112015-08-17 11:10:49 -06002058 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2059 if (pCB) {
2060 if (pCB->state == CB_UPDATE_ACTIVE) {
2061 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002062 skipCall |= addCmd(pCB, CMD_SETDEPTHBIASSTATE);
Cody Northrop12365112015-08-17 11:10:49 -06002063 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002064 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002065 "Incorrect call to vkCmdSetDepthBias() without an active RenderPass.");
Cody Northrop12365112015-08-17 11:10:49 -06002066 }
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002067 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
2068 pCB->depthBias = depthBias;
2069 pCB->depthBiasClamp = depthBiasClamp;
2070 pCB->slopeScaledDepthBias = slopeScaledDepthBias;
Cody Northrop12365112015-08-17 11:10:49 -06002071 } else {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002072 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002073 }
2074 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002075 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002076 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBias(cmdBuffer, depthBias, depthBiasClamp, slopeScaledDepthBias);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002077}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002078
2079VK_LAYER_EXPORT void VKAPI vkCmdSetBlendConstants(VkCmdBuffer cmdBuffer, const float blendConst[4])
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002080{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002081 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002082 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2083 if (pCB) {
2084 if (pCB->state == CB_UPDATE_ACTIVE) {
2085 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002086 skipCall |= addCmd(pCB, CMD_SETBLENDSTATE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002087 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002088 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002089 "Incorrect call to vkSetBlendConstants() without an active RenderPass.");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002090 }
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002091 pCB->status |= CBSTATUS_BLEND_SET;
2092 memcpy(pCB->blendConst, blendConst, 4 * sizeof(float));
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002093 } else {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002094 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002095 }
2096 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002097 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002098 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetBlendConstants(cmdBuffer, blendConst);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002099}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002100
2101VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBounds(
2102 VkCmdBuffer cmdBuffer,
2103 float minDepthBounds,
2104 float maxDepthBounds)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002105{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002106 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002107 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2108 if (pCB) {
2109 if (pCB->state == CB_UPDATE_ACTIVE) {
2110 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002111 skipCall |= addCmd(pCB, CMD_SETDEPTHBOUNDSSTATE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002112 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002113 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002114 "Incorrect call to vkCmdSetDepthBounds() without an active RenderPass.");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002115 }
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002116 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
2117 pCB->minDepthBounds = minDepthBounds;
2118 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002119 } else {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002120 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBounds()");
Cody Northrop82485a82015-08-18 15:21:16 -06002121 }
2122 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002123 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002124 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBounds(cmdBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop82485a82015-08-18 15:21:16 -06002125}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002126
2127VK_LAYER_EXPORT void VKAPI vkCmdSetStencilCompareMask(
2128 VkCmdBuffer cmdBuffer,
2129 VkStencilFaceFlags faceMask,
2130 uint32_t stencilCompareMask)
Cody Northrop82485a82015-08-18 15:21:16 -06002131{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002132 VkBool32 skipCall = VK_FALSE;
Cody Northrop82485a82015-08-18 15:21:16 -06002133 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2134 if (pCB) {
2135 if (pCB->state == CB_UPDATE_ACTIVE) {
2136 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002137 skipCall |= addCmd(pCB, CMD_SETSTENCILREADMASKSTATE);
Cody Northrop82485a82015-08-18 15:21:16 -06002138 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002139 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002140 "Incorrect call to vkCmdSetStencilCompareMask() without an active RenderPass.");
Cody Northrop82485a82015-08-18 15:21:16 -06002141 }
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002142 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2143 pCB->front.stencilCompareMask = stencilCompareMask;
Cody Northrop82485a82015-08-18 15:21:16 -06002144 }
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002145 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2146 pCB->back.stencilCompareMask = stencilCompareMask;
2147 }
2148 /* TODO: Do we need to track front and back separately? */
2149 /* TODO: We aren't capturing the faceMask, do we need to? */
2150 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop82485a82015-08-18 15:21:16 -06002151 } else {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002152 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002153 }
2154 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002155 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002156 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilCompareMask(cmdBuffer, faceMask, stencilCompareMask);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002157}
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06002158
2159VK_LAYER_EXPORT void VKAPI vkCmdSetStencilWriteMask(
2160 VkCmdBuffer cmdBuffer,
2161 VkStencilFaceFlags faceMask,
2162 uint32_t stencilWriteMask)
2163{
2164 VkBool32 skipCall = VK_FALSE;
2165 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2166 if (pCB) {
2167 if (pCB->state == CB_UPDATE_ACTIVE) {
2168 updateCBTracking(cmdBuffer);
2169 skipCall |= addCmd(pCB, CMD_SETSTENCILWRITEMASKSTATE);
2170 if (!pCB->activeRenderPass) {
2171 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2172 "Incorrect call to vkCmdSetStencilWriteMask() without an active RenderPass.");
2173 }
2174 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2175 pCB->front.stencilWriteMask = stencilWriteMask;
2176 }
2177 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2178 pCB->back.stencilWriteMask = stencilWriteMask;
2179 }
2180 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
2181 } else {
2182 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilWriteMask()");
2183 }
2184 }
2185 if (VK_FALSE == skipCall)
2186 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilWriteMask(cmdBuffer, faceMask, stencilWriteMask);
2187}
2188
2189VK_LAYER_EXPORT void VKAPI vkCmdSetStencilReference(
2190 VkCmdBuffer cmdBuffer,
2191 VkStencilFaceFlags faceMask,
2192 uint32_t stencilReference)
2193{
2194 VkBool32 skipCall = VK_FALSE;
2195 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2196 if (pCB) {
2197 if (pCB->state == CB_UPDATE_ACTIVE) {
2198 updateCBTracking(cmdBuffer);
2199 skipCall |= addCmd(pCB, CMD_SETSTENCILREFERENCESTATE);
2200 if (!pCB->activeRenderPass) {
2201 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2202 "Incorrect call to vkCmdSetStencilReference() without an active RenderPass.");
2203 }
2204 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2205 pCB->front.stencilReference = stencilReference;
2206 }
2207 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2208 pCB->back.stencilReference = stencilReference;
2209 }
2210 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
2211 } else {
2212 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilReference()");
2213 }
2214 }
2215 if (VK_FALSE == skipCall)
2216 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilReference(cmdBuffer, faceMask, stencilReference);
2217}
2218
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06002219VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, 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 -06002220{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002221 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002222 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2223 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002224 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002225 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002226 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002227 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002228 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002229 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis502480b2015-06-24 15:53:07 -06002230 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06002231 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002232 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002233 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2234 if (pSet) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002235 loader_platform_thread_lock_mutex(&globalLock);
2236 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002237 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002238 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2239 g_lastBoundDescriptorSet = pDescriptorSets[i];
2240 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002241 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002242 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002243 if (!pSet->pUpdateStructs)
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002244 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002245 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", pDescriptorSets[i].handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002246 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002247 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002248 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002249 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002250 }
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002251 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002252 skipCall |= addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002253 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002254 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002255 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002256 }
2257 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002258 if (VK_FALSE == skipCall)
2259 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002260}
2261
Tony Barbourd1c35722015-04-16 15:59:00 -06002262VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002263{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002264 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002265 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2266 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002267 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002268 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002269 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis502480b2015-06-24 15:53:07 -06002270 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002271 }
2272 VkDeviceSize offset_align = 0;
2273 switch (indexType) {
2274 case VK_INDEX_TYPE_UINT16:
2275 offset_align = 2;
2276 break;
2277 case VK_INDEX_TYPE_UINT32:
2278 offset_align = 4;
2279 break;
2280 default:
2281 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
2282 break;
2283 }
2284 if (!offset_align || (offset % offset_align)) {
2285 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
2286 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlis502480b2015-06-24 15:53:07 -06002287 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002288 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002289 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002290 }
Tobin Ehlisc4c23182015-09-17 12:24:13 -06002291 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
2292 updateCBTracking(cmdBuffer);
2293 skipCall |= addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002294 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002295 if (VK_FALSE == skipCall)
2296 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002297}
2298
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002299VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2300 VkCmdBuffer cmdBuffer,
2301 uint32_t startBinding,
2302 uint32_t bindingCount,
2303 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002304 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002305{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002306 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002307 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2308 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002309 if (pCB->state == CB_UPDATE_ACTIVE) {
2310 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis502480b2015-06-24 15:53:07 -06002311 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002312 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis502480b2015-06-24 15:53:07 -06002313 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2314 } else {
2315 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06002316 updateCBTracking(cmdBuffer);
2317 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002318 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002319 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002320 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002321 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002322 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002323 if (VK_FALSE == skipCall)
2324 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002325}
2326
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002327VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002328{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002329 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002330 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2331 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002332 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002333 pCB->drawCount[DRAW]++;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002334 skipCall |= validate_draw_state(pCB, VK_FALSE);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06002335 /* TODO: Check that scissor and viewport counts are the same */
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002336 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002337 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002338 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002339 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2340 if (VK_FALSE == skipCall) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002341 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002342 skipCall |= addCmd(pCB, CMD_DRAW);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002343 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002344 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002345 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002346 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002347 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002348 if (VK_FALSE == skipCall)
2349 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002350}
2351
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002352VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002353{
2354 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002355 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002356 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002357 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002358 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002359 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002360 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002361 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002362 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002363 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2364 if (VK_FALSE == skipCall) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002365 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002366 skipCall |= addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002367 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002368 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002369 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002370 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002371 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002372 if (VK_FALSE == skipCall)
2373 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002374}
2375
Tony Barbourd1c35722015-04-16 15:59:00 -06002376VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002377{
2378 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002379 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002380 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002381 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002382 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002383 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002384 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002385 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002386 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002387 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2388 if (VK_FALSE == skipCall) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002389 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002390 skipCall |= addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002391 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002392 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002393 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002394 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002395 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002396 if (VK_FALSE == skipCall)
2397 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002398}
2399
Tony Barbourd1c35722015-04-16 15:59:00 -06002400VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002401{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002402 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002403 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2404 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002405 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002406 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002407 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002408 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002409 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002410 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002411 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2412 if (VK_FALSE == skipCall) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002413 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002414 skipCall |= addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002415 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002416 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002417 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002418 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002419 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002420 if (VK_FALSE == skipCall)
2421 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002422}
2423
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002424VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002425{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002426 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002427 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2428 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002429 if (pCB->state == CB_UPDATE_ACTIVE) {
2430 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002431 skipCall |= addCmd(pCB, CMD_DISPATCH);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002432 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002433 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002434 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002435 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002436 if (VK_FALSE == skipCall)
2437 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002438}
2439
Tony Barbourd1c35722015-04-16 15:59:00 -06002440VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002441{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002442 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002443 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2444 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002445 if (pCB->state == CB_UPDATE_ACTIVE) {
2446 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002447 skipCall |= addCmd(pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002448 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002449 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002450 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002451 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002452 if (VK_FALSE == skipCall)
2453 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002454}
2455
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002456VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002457{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002458 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002459 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2460 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002461 if (pCB->state == CB_UPDATE_ACTIVE) {
2462 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002463 skipCall |= addCmd(pCB, CMD_COPYBUFFER);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002464 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002465 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002466 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002467 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002468 if (VK_FALSE == skipCall)
2469 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002470}
2471
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002472VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2473 VkImage srcImage,
2474 VkImageLayout srcImageLayout,
2475 VkImage destImage,
2476 VkImageLayout destImageLayout,
2477 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002478{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002479 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002480 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2481 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002482 if (pCB->state == CB_UPDATE_ACTIVE) {
2483 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002484 skipCall |= addCmd(pCB, CMD_COPYIMAGE);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002485 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002486 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002487 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002488 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002489 if (VK_FALSE == skipCall)
2490 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002491}
2492
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002493VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2494 VkImage srcImage, VkImageLayout srcImageLayout,
2495 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002496 uint32_t regionCount, const VkImageBlit* pRegions,
2497 VkTexFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002498{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002499 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002500 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2501 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002502 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehliseac83792015-06-23 10:41:13 -06002503 if (pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002504 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002505 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002506 } else {
2507 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002508 skipCall |= addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002509 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002510 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002511 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002512 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002513 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002514 if (VK_FALSE == skipCall)
2515 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002516}
2517
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002518VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2519 VkBuffer srcBuffer,
2520 VkImage destImage, VkImageLayout destImageLayout,
2521 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002522{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002523 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002524 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2525 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002526 if (pCB->state == CB_UPDATE_ACTIVE) {
2527 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002528 skipCall |= addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002529 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002530 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002531 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002532 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002533 if (VK_FALSE == skipCall)
2534 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002535}
2536
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002537VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2538 VkImage srcImage, VkImageLayout srcImageLayout,
2539 VkBuffer destBuffer,
2540 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002541{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002542 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002543 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2544 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002545 if (pCB->state == CB_UPDATE_ACTIVE) {
2546 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002547 skipCall |= addCmd(pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002548 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002549 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002550 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002551 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002552 if (VK_FALSE == skipCall)
2553 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002554}
2555
Tony Barbourd1c35722015-04-16 15:59:00 -06002556VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002557{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002558 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002559 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2560 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002561 if (pCB->state == CB_UPDATE_ACTIVE) {
2562 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002563 skipCall |= addCmd(pCB, CMD_UPDATEBUFFER);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002564 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002565 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002566 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002567 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002568 if (VK_FALSE == skipCall)
2569 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002570}
2571
Tony Barbourd1c35722015-04-16 15:59:00 -06002572VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002573{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002574 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002575 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2576 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002577 if (pCB->state == CB_UPDATE_ACTIVE) {
2578 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002579 skipCall |= addCmd(pCB, CMD_FILLBUFFER);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002580 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002581 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002582 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002583 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002584 if (VK_FALSE == skipCall)
2585 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002586}
2587
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002588VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2589 VkCmdBuffer cmdBuffer,
2590 uint32_t colorAttachment,
2591 VkImageLayout imageLayout,
2592 const VkClearColorValue* pColor,
2593 uint32_t rectCount,
2594 const VkRect3D* pRects)
2595{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002596 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002597 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2598 if (pCB) {
2599 if (pCB->state == CB_UPDATE_ACTIVE) {
2600 // Warn if this is issued prior to Draw Cmd
2601 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002602 // TODO : cmdBuffer should be srcObj
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002603 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002604 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06002605 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002606 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002607 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002608 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002609 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2610 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2611 } else {
2612 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002613 skipCall |= addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
Tobin Ehlise2473152015-06-23 11:34:28 -06002614 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002615 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002616 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002617 }
2618 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002619 if (VK_FALSE == skipCall)
2620 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002621}
2622
2623VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2624 VkCmdBuffer cmdBuffer,
2625 VkImageAspectFlags imageAspectMask,
2626 VkImageLayout imageLayout,
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06002627 const VkClearDepthStencilValue* pDepthStencil,
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002628 uint32_t rectCount,
2629 const VkRect3D* pRects)
2630{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002631 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002632 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2633 if (pCB) {
2634 if (pCB->state == CB_UPDATE_ACTIVE) {
2635 // Warn if this is issued prior to Draw Cmd
2636 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002637 // TODO : cmdBuffer should be srcObj
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002638 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002639 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06002640 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002641 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002642 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002643 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002644 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2645 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2646 } else {
2647 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002648 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
Tobin Ehlise2473152015-06-23 11:34:28 -06002649 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002650 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002651 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002652 }
2653 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002654 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06002655 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, pDepthStencil, rectCount, pRects);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002656}
2657
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002658VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2659 VkCmdBuffer cmdBuffer,
2660 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12002661 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002662 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002663{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002664 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002665 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2666 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002667 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002668 if (pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002669 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002670 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2671 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2672 } else {
2673 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002674 skipCall |= addCmd(pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlise2473152015-06-23 11:34:28 -06002675 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002676 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002677 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002678 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002679 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002680 if (VK_FALSE == skipCall)
2681 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002682}
2683
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06002684VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(
2685 VkCmdBuffer cmdBuffer,
2686 VkImage image, VkImageLayout imageLayout,
2687 const VkClearDepthStencilValue *pDepthStencil,
2688 uint32_t rangeCount,
2689 const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002690{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002691 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002692 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2693 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002694 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002695 if (pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002696 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002697 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2698 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2699 } else {
2700 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002701 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlise2473152015-06-23 11:34:28 -06002702 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002703 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002704 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002705 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002706 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002707 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter45df9e12015-09-15 18:03:22 -06002708 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002709}
2710
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002711VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2712 VkImage srcImage, VkImageLayout srcImageLayout,
2713 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002714 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002715{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002716 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002717 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2718 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002719 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002720 if (pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002721 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002722 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlise2473152015-06-23 11:34:28 -06002723 } else {
2724 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002725 skipCall |= addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise2473152015-06-23 11:34:28 -06002726 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002727 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002728 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002729 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002730 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002731 if (VK_FALSE == skipCall)
2732 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002733}
2734
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002735VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002736{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002737 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002738 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2739 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002740 if (pCB->state == CB_UPDATE_ACTIVE) {
2741 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002742 skipCall |= addCmd(pCB, CMD_SETEVENT);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002743 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002744 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002745 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002746 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002747 if (VK_FALSE == skipCall)
2748 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002749}
2750
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002751VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002752{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002753 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002754 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2755 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002756 if (pCB->state == CB_UPDATE_ACTIVE) {
2757 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002758 skipCall |= addCmd(pCB, CMD_RESETEVENT);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002759 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002760 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002761 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002762 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002763 if (VK_FALSE == skipCall)
2764 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002765}
2766
Courtney Goeltzenleuchterdbd20322015-07-12 12:58:58 -06002767VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags destStageMask, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002768{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002769 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002770 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2771 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002772 if (pCB->state == CB_UPDATE_ACTIVE) {
2773 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002774 skipCall |= addCmd(pCB, CMD_WAITEVENTS);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002775 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002776 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002777 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002778 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002779 if (VK_FALSE == skipCall)
2780 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002781}
2782
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06002783VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags destStageMask, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002784{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002785 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002786 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2787 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002788 if (pCB->state == CB_UPDATE_ACTIVE) {
2789 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002790 skipCall |= addCmd(pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002791 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002792 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002793 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002794 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002795 if (VK_FALSE == skipCall)
2796 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002797}
2798
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002799VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002800{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002801 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002802 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2803 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002804 if (pCB->state == CB_UPDATE_ACTIVE) {
2805 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002806 skipCall |= addCmd(pCB, CMD_BEGINQUERY);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002807 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002808 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002809 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002810 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002811 if (VK_FALSE == skipCall)
2812 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002813}
2814
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002815VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002816{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002817 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002818 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2819 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002820 if (pCB->state == CB_UPDATE_ACTIVE) {
2821 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002822 skipCall |= addCmd(pCB, CMD_ENDQUERY);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002823 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002824 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002825 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002826 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002827 if (VK_FALSE == skipCall)
2828 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002829}
2830
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002831VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002832{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002833 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002834 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2835 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002836 if (pCB->state == CB_UPDATE_ACTIVE) {
2837 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002838 skipCall |= addCmd(pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002839 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002840 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002841 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002842 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002843 if (VK_FALSE == skipCall)
2844 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002845}
2846
Tony Barbourd1c35722015-04-16 15:59:00 -06002847VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002848{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002849 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002850 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2851 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002852 if (pCB->state == CB_UPDATE_ACTIVE) {
2853 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002854 skipCall |= addCmd(pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002855 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002856 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002857 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002858 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002859 if (VK_FALSE == skipCall)
2860 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002861}
2862
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002863VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002864{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002865 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002866 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002867 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002868 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002869 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06002870 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2871 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002872 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002873 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002874 }
2875 return result;
2876}
2877
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002878VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002879{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002880 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002881 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002882 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002883 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002884 if (pCreateInfo->pAttachments) {
2885 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2886 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002887 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002888 if (pCreateInfo->pSubpasses) {
2889 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2890 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2891
2892 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2893 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2894 const uint32_t attachmentCount = subpass->inputCount +
Cody Northropa505dda2015-08-04 11:16:41 -06002895 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu08accc62015-07-07 11:50:03 +08002896 subpass->preserveCount;
2897 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2898
Cody Northropa505dda2015-08-04 11:16:41 -06002899 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002900 sizeof(attachments[0]) * subpass->inputCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002901 subpass->pInputAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002902 attachments += subpass->inputCount;
2903
Cody Northropa505dda2015-08-04 11:16:41 -06002904 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002905 sizeof(attachments[0]) * subpass->colorCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002906 subpass->pColorAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002907 attachments += subpass->colorCount;
2908
Cody Northropa505dda2015-08-04 11:16:41 -06002909 if (subpass->pResolveAttachments) {
2910 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002911 sizeof(attachments[0]) * subpass->colorCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002912 subpass->pResolveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002913 attachments += subpass->colorCount;
2914 }
2915
Cody Northropa505dda2015-08-04 11:16:41 -06002916 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002917 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002918 subpass->pPreserveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002919 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06002920 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002921 if (pCreateInfo->pDependencies) {
2922 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2923 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002924 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002925 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002926 }
2927 return result;
2928}
2929
Chia-I Wu08accc62015-07-07 11:50:03 +08002930VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002931{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002932 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002933 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2934 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002935 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002936 if (pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002937 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002938 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002939 } else {
2940 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002941 skipCall |= addCmd(pCB, CMD_BEGINRENDERPASS);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002942 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08002943 pCB->activeSubpass = 0;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002944 pCB->framebuffer = pRenderPassBegin->framebuffer;
2945 if (pCB->lastBoundPipeline) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002946 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002947 }
Tobin Ehlis259730a2015-06-23 16:13:03 -06002948 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06002949 } else {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002950 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis259730a2015-06-23 16:13:03 -06002951 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06002952 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002953 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002954 if (VK_FALSE == skipCall)
2955 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002956}
2957
Chia-I Wu08accc62015-07-07 11:50:03 +08002958VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2959{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002960 VkBool32 skipCall = VK_FALSE;
Chia-I Wu08accc62015-07-07 11:50:03 +08002961 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2962 if (pCB) {
2963 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002964 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu08accc62015-07-07 11:50:03 +08002965 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2966 } else {
2967 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002968 skipCall |= addCmd(pCB, CMD_NEXTSUBPASS);
Chia-I Wu08accc62015-07-07 11:50:03 +08002969 pCB->activeSubpass++;
2970 if (pCB->lastBoundPipeline) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002971 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wu08accc62015-07-07 11:50:03 +08002972 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002973 }
2974 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002975 if (VK_FALSE == skipCall)
2976 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
Chia-I Wu08accc62015-07-07 11:50:03 +08002977}
2978
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002979VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002980{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002981 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002982 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2983 if (pCB) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002984 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002985 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002986 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis59a9c832015-06-23 16:13:03 -06002987 } else {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002988 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002989 skipCall |= addCmd(pCB, CMD_ENDRENDERPASS);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002990 pCB->activeRenderPass = 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08002991 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002992 }
2993 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06002994 if (VK_FALSE == skipCall)
2995 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002996}
2997
2998VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2999{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003000 VkBool32 skipCall = VK_FALSE;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08003001 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3002 if (pCB) {
3003 if (!pCB->activeRenderPass) {
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003004 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08003005 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
Tobin Ehlis259730a2015-06-23 16:13:03 -06003006 }
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003007 GLOBAL_CB_NODE* pSubCB = NULL;
3008 for (uint32_t i=0; i<cmdBuffersCount; i++) {
3009 pSubCB = getCBNode(pCmdBuffers[i]);
3010 if (!pSubCB) {
3011 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3012 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCmdBuffers array.", (void*)pCmdBuffers[i], i);
3013 } else if (VK_CMD_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
3014 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3015 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer %p in element %u of pCmdBuffers array. All cmd buffers in pCmdBuffers array must be secondary.", (void*)pCmdBuffers[i], i);
3016 }
3017 }
3018 updateCBTracking(cmdBuffer);
3019 skipCall |= addCmd(pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003020 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003021 if (VK_FALSE == skipCall)
3022 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003023}
3024
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003025VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3026 VkInstance instance,
3027 VkFlags msgFlags,
3028 const PFN_vkDbgMsgCallback pfnMsgCallback,
3029 void* pUserData,
3030 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003031{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003032 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06003033 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3034 if (VK_SUCCESS == res) {
3035 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3036 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3037 }
3038 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003039}
3040
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003041VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3042 VkInstance instance,
3043 VkDbgMsgCallback msgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003044{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003045 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06003046 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3047 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3048 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3049 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003050}
3051
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003052VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003053{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003054 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003055 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06003056 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3057 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003058 // TODO : cmdBuffer should be srcObj
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003059 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003060 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06003061 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003062 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003063 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003064 skipCall |= addCmd(pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003065 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003066 if (VK_FALSE == skipCall)
3067 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003068}
3069
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003070VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003071{
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003072 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003073 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06003074 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3075 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003076 // TODO : cmdBuffer should be srcObj
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003077 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003078 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06003079 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003080 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003081 updateCBTracking(cmdBuffer);
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003082 skipCall |= addCmd(pCB, CMD_DBGMARKEREND);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003083 }
Tobin Ehlis1cfb30a2015-09-09 11:31:10 -06003084 if (VK_FALSE == skipCall)
3085 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06003086}
3087
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003088//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3089//{
3090// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3091// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3092// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3093// "Attempt to use DbgSetObjectTag but extension disabled!");
3094// return VK_ERROR_UNAVAILABLE;
3095// }
3096// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3097//}
3098//
3099//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3100//{
3101// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3102// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3103// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3104// "Attempt to use DbgSetObjectName but extension disabled!");
3105// return VK_ERROR_UNAVAILABLE;
3106// }
3107// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3108//}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003109
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003110VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003111{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06003112 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003113 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003114
Jon Ashburn8fd08252015-05-28 16:25:02 -06003115 /* loader uses this to force layer initialization; device object is wrapped */
3116 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003117 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003118 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003119 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06003120 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003122 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003124 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003126 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003128 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003130 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003132 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003134 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003136 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003138 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003140 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003142 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003143 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003144 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003145 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003146 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003147 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003148 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003150 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003152 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003154 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003156 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003158 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003160 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003161 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003162 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003163 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003164 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003165 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003166 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003167 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003168 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003169 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003170 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003172 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003173 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003174 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003175 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003176 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003177 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003178 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003179 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003180 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003181 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003182 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003183 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003184 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003185 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05003186 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003187 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003188 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003189 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003190 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003191 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003192 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003193 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003194 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003195 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003196 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003197 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003198 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003199 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003200 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003201 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003202 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003204 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003206 if (!strcmp(funcName, "vkCmdSetViewport"))
3207 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -06003208 if (!strcmp(funcName, "vkCmdSetScissor"))
3209 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -06003210 if (!strcmp(funcName, "vkCmdSetLineWidth"))
3211 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
3212 if (!strcmp(funcName, "vkCmdSetDepthBias"))
3213 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
3214 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
3215 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
3216 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
3217 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
3218 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
3219 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
3220 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
3221 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
3222 if (!strcmp(funcName, "vkCmdSetStencilReference"))
3223 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003224 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06003226 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003228 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003230 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003232 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003234 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003236 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003238 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003240 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003242 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003243 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003244 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003245 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003246 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003247 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003248 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003249 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003250 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003251 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003252 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003253 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003254 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12003256 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003258 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003260 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003262 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003264 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003265 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003266 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003267 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003268 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003269 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003270 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003271 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003272 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003273 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003274 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003276 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003278 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003280 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003282 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003284 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08003286 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003287 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003288 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003289 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06003290 if (!strcmp(funcName, "vkCmdExecuteCommands"))
3291 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Jon Ashburneab34492015-06-01 09:37:38 -06003292
Jon Ashburn747f2b62015-06-18 15:02:58 -06003293 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3294 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06003295 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06003296 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003297 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003298 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003299 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003300// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3301// return (void*) vkDbgSetObjectTag;
3302// if (!strcmp(funcName, "vkDbgSetObjectName"))
3303// return (void*) vkDbgSetObjectName;
Jon Ashburneab34492015-06-01 09:37:38 -06003304 }
3305 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06003306 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003307 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003308 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003309 }
3310}
3311
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003312VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003313{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003314 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003315 if (instance == NULL)
3316 return NULL;
3317
Jon Ashburn8fd08252015-05-28 16:25:02 -06003318 /* loader uses this to force layer initialization; instance object is wrapped */
3319 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003320 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003321 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003322 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003323 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003324 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003325 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003326 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -06003327 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
3328 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
3329 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
3330 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
3331 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
3332 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
3333 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
3334 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003335
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003336 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3337 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003338 if (fptr)
3339 return fptr;
3340
Jon Ashburn8fd08252015-05-28 16:25:02 -06003341 {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003342 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn8fd08252015-05-28 16:25:02 -06003343 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003344 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003345 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003346 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003347}