blob: b3c79745da6c9bc6359976467a4a3771d30b8907 [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
30#include "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
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036#include "vk_struct_graphviz_helper.h"
Tony Barbour18f71552015-04-22 11:36:22 -060037#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060038#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060039#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060040#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060041#include "draw_state.h"
42#include "layers_config.h"
Jon Ashburne68a9ff2015-05-25 14:11:37 -060043#include "vk_debug_marker_layer.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060044// The following is #included again to catch certain OS-specific functions
45// being used:
46#include "loader_platform.h"
47#include "layers_msg.h"
Jon Ashburn9eed2892015-06-01 10:02:09 -060048#include "layers_table.h"
Jon Ashburneab34492015-06-01 09:37:38 -060049#include "layers_debug_marker_table.h"
Tobin Ehlisa16e8922015-06-16 15:50:44 -060050#include "layer_data.h"
Tobin Ehlisc16c3e92015-06-16 09:04:30 -060051#include "layer_logging.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
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060063unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
64unordered_map<VkImageView, IMAGE_NODE*> imageMap;
65unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
66unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
67unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
68unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
69unordered_map<VkDescriptorSet, SET_NODE*> setMap;
70unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlis793ad302015-04-03 12:01:11 -060071// Map for layout chains
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060072unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
73unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
74unordered_map<VkFramebuffer, 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
95debug_report_data *mdd(VkObject object)
96{
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
102 assert(my_data->report_data != NULL);
103 return my_data->report_data;
104}
105
106debug_report_data *mid(VkInstance object)
107{
108 dispatch_key key = get_dispatch_key(object);
109 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
110#if DISPATCH_MAP_DEBUG
111 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
112#endif
113 assert(my_data->report_data != NULL);
114 return my_data->report_data;
115}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600116// Map actual TID to an index value and return that index
117// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
118static uint32_t getTIDIndex() {
119 loader_platform_thread_id tid = loader_platform_get_thread_id();
120 for (uint32_t i = 0; i < g_maxTID; i++) {
121 if (tid == g_tidMapping[i])
122 return i;
123 }
124 // Don't yet have mapping, set it and return newly set index
125 uint32_t retVal = (uint32_t) g_maxTID;
126 g_tidMapping[g_maxTID++] = tid;
127 assert(g_maxTID < MAX_TID);
128 return retVal;
129}
130// Return a string representation of CMD_TYPE enum
131static string cmdTypeToString(CMD_TYPE cmd)
132{
133 switch (cmd)
134 {
135 case CMD_BINDPIPELINE:
136 return "CMD_BINDPIPELINE";
137 case CMD_BINDPIPELINEDELTA:
138 return "CMD_BINDPIPELINEDELTA";
139 case CMD_BINDDYNAMICSTATEOBJECT:
140 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600141 case CMD_BINDDESCRIPTORSETS:
142 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600143 case CMD_BINDINDEXBUFFER:
144 return "CMD_BINDINDEXBUFFER";
145 case CMD_BINDVERTEXBUFFER:
146 return "CMD_BINDVERTEXBUFFER";
147 case CMD_DRAW:
148 return "CMD_DRAW";
149 case CMD_DRAWINDEXED:
150 return "CMD_DRAWINDEXED";
151 case CMD_DRAWINDIRECT:
152 return "CMD_DRAWINDIRECT";
153 case CMD_DRAWINDEXEDINDIRECT:
154 return "CMD_DRAWINDEXEDINDIRECT";
155 case CMD_DISPATCH:
156 return "CMD_DISPATCH";
157 case CMD_DISPATCHINDIRECT:
158 return "CMD_DISPATCHINDIRECT";
159 case CMD_COPYBUFFER:
160 return "CMD_COPYBUFFER";
161 case CMD_COPYIMAGE:
162 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600163 case CMD_BLITIMAGE:
164 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600165 case CMD_COPYBUFFERTOIMAGE:
166 return "CMD_COPYBUFFERTOIMAGE";
167 case CMD_COPYIMAGETOBUFFER:
168 return "CMD_COPYIMAGETOBUFFER";
169 case CMD_CLONEIMAGEDATA:
170 return "CMD_CLONEIMAGEDATA";
171 case CMD_UPDATEBUFFER:
172 return "CMD_UPDATEBUFFER";
173 case CMD_FILLBUFFER:
174 return "CMD_FILLBUFFER";
175 case CMD_CLEARCOLORIMAGE:
176 return "CMD_CLEARCOLORIMAGE";
177 case CMD_CLEARCOLORIMAGERAW:
178 return "CMD_CLEARCOLORIMAGERAW";
179 case CMD_CLEARDEPTHSTENCIL:
180 return "CMD_CLEARDEPTHSTENCIL";
181 case CMD_RESOLVEIMAGE:
182 return "CMD_RESOLVEIMAGE";
183 case CMD_SETEVENT:
184 return "CMD_SETEVENT";
185 case CMD_RESETEVENT:
186 return "CMD_RESETEVENT";
187 case CMD_WAITEVENTS:
188 return "CMD_WAITEVENTS";
189 case CMD_PIPELINEBARRIER:
190 return "CMD_PIPELINEBARRIER";
191 case CMD_BEGINQUERY:
192 return "CMD_BEGINQUERY";
193 case CMD_ENDQUERY:
194 return "CMD_ENDQUERY";
195 case CMD_RESETQUERYPOOL:
196 return "CMD_RESETQUERYPOOL";
197 case CMD_WRITETIMESTAMP:
198 return "CMD_WRITETIMESTAMP";
199 case CMD_INITATOMICCOUNTERS:
200 return "CMD_INITATOMICCOUNTERS";
201 case CMD_LOADATOMICCOUNTERS:
202 return "CMD_LOADATOMICCOUNTERS";
203 case CMD_SAVEATOMICCOUNTERS:
204 return "CMD_SAVEATOMICCOUNTERS";
205 case CMD_BEGINRENDERPASS:
206 return "CMD_BEGINRENDERPASS";
207 case CMD_ENDRENDERPASS:
208 return "CMD_ENDRENDERPASS";
209 case CMD_DBGMARKERBEGIN:
210 return "CMD_DBGMARKERBEGIN";
211 case CMD_DBGMARKEREND:
212 return "CMD_DBGMARKEREND";
213 default:
214 return "UNKNOWN";
215 }
216}
217// Block of code at start here for managing/tracking Pipeline state that this layer cares about
218// Just track 2 shaders for now
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600219#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600220#define MAX_SLOTS 2048
221#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
222
223static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
224
225// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
226// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
227// to that same cmd buffer by separate thread are not changing state from underneath us
228// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600229static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600230// Track the last group of CBs touched for displaying to dot file
231static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
232static uint32_t g_lastTouchedCBIndex = 0;
233// Track the last global DrawState of interest touched by any thread
234static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
235static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600236static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600237static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600238#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
239
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600240//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600241
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600242static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600243{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600244 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600245 size_t scSize = 0;
246 size_t vpSize = 0;
247 loader_platform_thread_lock_mutex(&globalLock);
248 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
249 pStateNode->stateObj = state;
250 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600251 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600252 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
253 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
254 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
255 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
256 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
257 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600258 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
259 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
260 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600261 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600262 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600263 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600264 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600265 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600266 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600267 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600268 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600269 break;
270 default:
271 assert(0);
272 break;
273 }
274 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
275 dynamicStateMap[state] = pStateNode;
276 loader_platform_thread_unlock_mutex(&globalLock);
277}
278// Free all allocated nodes for Dynamic State objs
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600279static void deleteDynamicState()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600280{
David Pinedod8f83d82015-04-27 16:36:17 -0600281 if (dynamicStateMap.size() <= 0)
282 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600283 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600284 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600285 delete[] (*ii).second->create_info.vpci.pScissors;
286 delete[] (*ii).second->create_info.vpci.pViewports;
287 }
288 delete (*ii).second;
289 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600290 dynamicStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600291}
292// Free all sampler nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600293static void deleteSamplers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600294{
David Pinedod8f83d82015-04-27 16:36:17 -0600295 if (sampleMap.size() <= 0)
296 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600297 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600298 delete (*ii).second;
299 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600300 sampleMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600301}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600302static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600303{
304 loader_platform_thread_lock_mutex(&globalLock);
305 if (imageMap.find(view) == imageMap.end()) {
306 loader_platform_thread_unlock_mutex(&globalLock);
307 return NULL;
308 }
309 else {
310 loader_platform_thread_unlock_mutex(&globalLock);
311 return &imageMap[view]->createInfo;
312 }
313}
314// Free all image nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600315static void deleteImages()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600316{
David Pinedod8f83d82015-04-27 16:36:17 -0600317 if (imageMap.size() <= 0)
318 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600319 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600320 delete (*ii).second;
321 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600322 imageMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600323}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600324static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600325{
326 loader_platform_thread_lock_mutex(&globalLock);
327 if (bufferMap.find(view) == bufferMap.end()) {
328 loader_platform_thread_unlock_mutex(&globalLock);
329 return NULL;
330 }
331 else {
332 loader_platform_thread_unlock_mutex(&globalLock);
333 return &bufferMap[view]->createInfo;
334 }
335}
336// Free all buffer nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600337static void deleteBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600338{
David Pinedod8f83d82015-04-27 16:36:17 -0600339 if (bufferMap.size() <= 0)
340 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600341 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600342 delete (*ii).second;
343 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600344 bufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600345}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600346static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600347
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600348static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600349{
350 g_lastCmdBuffer[getTIDIndex()] = cb;
351 GLOBAL_CB_NODE* pCB = getCBNode(cb);
352 loader_platform_thread_lock_mutex(&globalLock);
353 g_lastGlobalCB = pCB;
354 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
355 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
356 if (g_pLastTouchedCB[i] == pCB) {
357 loader_platform_thread_unlock_mutex(&globalLock);
358 return;
359 }
360 }
361 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
362 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
363 loader_platform_thread_unlock_mutex(&globalLock);
364}
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600365// Check object status for selected flag state
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600366static bool32_t validate_status(VkCmdBuffer cb, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
367{
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600368 if (cmdBufferMap.find(cb) != cmdBufferMap.end()) {
369 GLOBAL_CB_NODE* pNode = cmdBufferMap[cb];
370 // If non-zero enable mask is present, check it against status but if enable_mask
371 // is 0 then no enable required so we should always just check status
372 if ((!enable_mask) || (enable_mask & pNode->status)) {
373 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600374 log_msg(mdd(cb), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, error_code, "DS",
375 "CB object 0x%" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(cb), fail_msg);
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600376 return VK_FALSE;
377 }
378 }
379 return VK_TRUE;
380 }
381 else {
382 // If we do not find it print an error
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600383 log_msg(mdd(cb), msg_flags, (VkObjectType) 0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
384 "Unable to obtain status for non-existent CB object 0x%" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600385 return VK_FALSE;
386 }
387}
388static bool32_t validate_draw_state_flags(VkCmdBuffer cb) {
389 bool32_t result1, result2, result3, result4;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600390 result1 = validate_status(cb, CBSTATUS_NONE, CBSTATUS_VIEWPORT_BOUND, CBSTATUS_VIEWPORT_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
391 result2 = validate_status(cb, CBSTATUS_NONE, CBSTATUS_RASTER_BOUND, CBSTATUS_RASTER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");
392 result3 = validate_status(cb, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_COLOR_BLEND_BOUND, CBSTATUS_COLOR_BLEND_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");
393 result4 = validate_status(cb, CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE, CBSTATUS_DEPTH_STENCIL_BOUND, CBSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600394 return ((result1 == VK_TRUE) && (result2 == VK_TRUE) && (result3 == VK_TRUE) && (result4 == VK_TRUE));
395}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600396// Print the last bound dynamic state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600398{
399 GLOBAL_CB_NODE* pCB = getCBNode(cb);
400 if (pCB) {
401 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600402 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600403 if (pCB->lastBoundDynamicState[i]) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600404 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS",
405 "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
406 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS",
407 dynamic_display(pCB->lastBoundDynamicState[i]->pCreateInfo, " ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600408 break;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600409 } else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600410 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
411 "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600412 }
413 }
414 loader_platform_thread_unlock_mutex(&globalLock);
415 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600416}
417// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600418static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600419{
420 loader_platform_thread_lock_mutex(&globalLock);
421 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
422 loader_platform_thread_unlock_mutex(&globalLock);
423 return NULL;
424 }
425 loader_platform_thread_unlock_mutex(&globalLock);
426 return pipelineMap[pipeline];
427}
428
429// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600430static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600431{
432 loader_platform_thread_lock_mutex(&globalLock);
433 if (sampleMap.find(sampler) == sampleMap.end()) {
434 loader_platform_thread_unlock_mutex(&globalLock);
435 return NULL;
436 }
437 loader_platform_thread_unlock_mutex(&globalLock);
438 return &sampleMap[sampler]->createInfo;
439}
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600440// Verify that create state for a pipeline is valid
441static bool32_t verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
442{
443 // VS is required
444 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
445 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
446 "Invalid Pipeline CreateInfo State: Vtx Shader required");
447 return VK_FALSE;
448 }
449 // Either both or neither TC/TE shaders should be defined
450 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
451 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
452 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
453 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
454 return VK_FALSE;
455 }
456 // Compute shaders should be specified independent of Gfx shaders
457 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
458 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
459 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
460 VK_SHADER_STAGE_FRAGMENT_BIT))) {
461 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
462 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
463 return VK_FALSE;
464 }
465 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
466 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
467 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
468 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
469 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
470 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
471 return VK_FALSE;
472 }
473 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
474 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
475 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
476 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
477 return VK_FALSE;
478 }
479 return VK_TRUE;
480}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600481// Init the pipeline mapping info based on pipeline create info LL tree
482// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600483static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600484{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600485 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
486 if (pBasePipeline) {
487 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
488 }
489 else {
490 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
491 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600492 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehliseba312c2015-04-01 08:40:34 -0600493 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600494 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600495 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600496 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600497 size_t bufferSize = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600498 VkPipelineVertexInputCreateInfo* pVICI = NULL;
499 VkPipelineCbStateCreateInfo* pCBCI = NULL;
500 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600501 while (pTrav) {
502 switch (pTrav->sType) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600503 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600504 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600505 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600506 case VK_SHADER_STAGE_VERTEX:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600507 pPrev->pNext = &pPipeline->vsCI;
508 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600509 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600510 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600511 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600512 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600513 pPrev->pNext = &pPipeline->tcsCI;
514 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600515 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600516 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600517 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600518 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600519 pPrev->pNext = &pPipeline->tesCI;
520 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600521 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600522 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600523 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600524 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600525 pPrev->pNext = &pPipeline->gsCI;
526 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600527 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600528 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600529 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600530 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600531 pPrev->pNext = &pPipeline->fsCI;
532 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600533 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600534 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600535 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600536 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600537 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehlisa85167d2015-06-18 11:02:59 -0600538 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600539 break;
540 default:
541 // TODO : Flag error
542 break;
543 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600544 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600545 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600546 pPrev->pNext = &pPipeline->vertexInputCI;
547 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600548 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600549 // Copy embedded ptrs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600550 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600551 pPipeline->vtxBindingCount = pVICI->bindingCount;
552 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600553 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
554 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
Tobin Ehlis3a10e622015-06-09 10:48:55 -0600555 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexBindingDescriptions, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600556 }
557 pPipeline->vtxAttributeCount = pVICI->attributeCount;
558 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600559 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
560 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
561 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600562 }
563 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600564 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600565 pPrev->pNext = &pPipeline->iaStateCI;
566 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600567 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600568 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600569 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600570 pPrev->pNext = &pPipeline->tessStateCI;
571 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600572 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600573 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600574 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600575 pPrev->pNext = &pPipeline->vpStateCI;
576 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600577 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600578 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600579 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600580 pPrev->pNext = &pPipeline->rsStateCI;
581 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600582 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600583 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600584 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600585 pPrev->pNext = &pPipeline->msStateCI;
586 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600587 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600588 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600589 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600590 pPrev->pNext = &pPipeline->cbStateCI;
591 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600592 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600593 // Copy embedded ptrs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600594 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600595 pPipeline->attachmentCount = pCBCI->attachmentCount;
596 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600597 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
598 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
599 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600600 }
601 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600602 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600603 pPrev->pNext = &pPipeline->dsStateCI;
604 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600605 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600606 break;
607 default:
608 assert(0);
609 break;
610 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600611 pTrav = (GENERIC_HEADER*)pTrav->pNext;
612 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600613 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600614}
615// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600616static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600617{
David Pinedod8f83d82015-04-27 16:36:17 -0600618 if (pipelineMap.size() <= 0)
619 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600620 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600621 if ((*ii).second->pVertexBindingDescriptions) {
622 delete[] (*ii).second->pVertexBindingDescriptions;
623 }
624 if ((*ii).second->pVertexAttributeDescriptions) {
625 delete[] (*ii).second->pVertexAttributeDescriptions;
626 }
627 if ((*ii).second->pAttachments) {
628 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600629 }
630 delete (*ii).second;
631 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600632 pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600633}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600634// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600635static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600636{
637 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600638 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600639 if (pPipe->msStateCI.multisampleEnable)
640 return pPipe->msStateCI.samples;
Tobin Ehliseba312c2015-04-01 08:40:34 -0600641 }
642 return 1;
643}
644// Validate state related to the PSO
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600645static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600646{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600647 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600648 // Verify that any MSAA request in PSO matches sample# in bound FB
649 uint32_t psoNumSamples = getNumSamples(pipeline);
650 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600651 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
652 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis7c3ec602015-05-21 09:06:56 -0600653 if ((psoNumSamples != pFBCI->sampleCount) || (psoNumSamples != pRPCI->sampleCount)) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600654 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
655 "Num samples mismatch! Binding PSO (%p) with %u samples while current RenderPass (%p) w/ %u samples uses FB (%p) with %u samples!", (void*)pipeline, psoNumSamples, (void*)pCB->activeRenderPass, pRPCI->sampleCount, (void*)pCB->framebuffer, pFBCI->sampleCount);
Tobin Ehliseba312c2015-04-01 08:40:34 -0600656 }
657 } else {
658 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
659 // Verify and flag error as appropriate
660 }
661 // TODO : Add more checks here
662 } else {
663 // TODO : Validate non-gfx pipeline updates
664 }
665}
666
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600667// Block of code at start here specifically for managing/tracking DSs
668
Tobin Ehlis793ad302015-04-03 12:01:11 -0600669// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600670static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600671{
672 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600673 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600674 loader_platform_thread_unlock_mutex(&globalLock);
675 return NULL;
676 }
677 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600678 return poolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600679}
680// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600681static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600682{
683 loader_platform_thread_lock_mutex(&globalLock);
684 if (setMap.find(set) == setMap.end()) {
685 loader_platform_thread_unlock_mutex(&globalLock);
686 return NULL;
687 }
688 loader_platform_thread_unlock_mutex(&globalLock);
689 return setMap[set];
690}
691
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600692static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600693 loader_platform_thread_lock_mutex(&globalLock);
694 if (layoutMap.find(layout) == layoutMap.end()) {
695 loader_platform_thread_unlock_mutex(&globalLock);
696 return NULL;
697 }
698 loader_platform_thread_unlock_mutex(&globalLock);
699 return layoutMap[layout];
700}
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600701// Return 1 if update struct is of valid type, 0 otherwise
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600702static bool32_t validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600703{
704 char str[1024];
705 switch (pUpdateStruct->sType)
706 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800707 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
708 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600709 return 1;
710 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600711 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600712 "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 -0600713 return 0;
714 }
715}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600716// For given update struct, return binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600717static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600718{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600719 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600720 switch (pUpdateStruct->sType)
721 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800722 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
723 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
724 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
725 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600726 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600727 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600728 "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 -0600729 return 0xFFFFFFFF;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600730 }
731}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600732// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600733static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600734{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600735 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600736 switch (pUpdateStruct->sType)
737 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800738 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
739 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
740 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600741 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800742 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600743 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600744 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600745 "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 -0600746 return 0;
747 }
748}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600749// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600750static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600751{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600752 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600753 switch (pUpdateStruct->sType)
754 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800755 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
756 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
757 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600758 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800759 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600760 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600761 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600762 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600763 return 0;
764 }
765}
766// For given Layout Node and binding, return index where that binding begins
767static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
768{
769 uint32_t offsetIndex = 0;
770 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800771 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600772 }
773 return offsetIndex;
774}
775// For given layout node and binding, return last index that is updated
776static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
777{
778 uint32_t offsetIndex = 0;
779 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800780 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600781 }
782 return offsetIndex-1;
783}
784// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600785static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600786{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600787 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
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 Ehlis75283bf2015-06-18 15:59:33 -0600790static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600791{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600792 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600793}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600794// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600795static bool32_t validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600796{
797 // First get actual type of update
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600798 VkDescriptorType actualType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600799 uint32_t i = 0;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600800 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600801 switch (pUpdateStruct->sType)
802 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800803 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
804 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600805 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800806 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
807 /* no need to validate */
808 return 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600809 break;
810 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600811 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600812 "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 -0600813 return 0;
814 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600815 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600816 if (pLayout->pTypes[i] != actualType)
817 return 0;
818 }
819 return 1;
820}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600821// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
822// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
823// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600824static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600825{
826 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800827 VkWriteDescriptorSet* pWDS = NULL;
828 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600829 size_t array_size = 0;
830 size_t base_array_size = 0;
831 size_t total_array_size = 0;
832 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600833 char str[1024];
834 switch (pUpdate->sType)
835 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800836 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
837 pWDS = new VkWriteDescriptorSet;
838 pNewNode = (GENERIC_HEADER*)pWDS;
839 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
840 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
841 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
842 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600843 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800844 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
845 pCDS = new VkCopyDescriptorSet;
846 pUpdate = (GENERIC_HEADER*)pCDS;
847 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600848 break;
849 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600850 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600851 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600852 return NULL;
853 }
854 // Make sure that pNext for the end of shadow copy is NULL
855 pNewNode->pNext = NULL;
856 return pNewNode;
857}
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800858// update DS mappings based on ppUpdateArray
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600859static bool32_t dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600860{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800861 const VkWriteDescriptorSet *pWDS = NULL;
862 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600863 bool32_t result = 1;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800864
865 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
866 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
867 else
868 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
869
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600870 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600871 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600872 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600873 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600874 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600875 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800876 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
877 SET_NODE* pSet = setMap[ds]; // getSetNode() without locking
878 g_lastBoundDescriptorSet = pSet->set;
879 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600880 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600881 // First verify valid update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600882 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600883 result = 0;
884 break;
885 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600886 // Make sure that binding is within bounds
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600887 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600888 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600889 "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, getUpdateBinding(device, pUpdate), string_VkStructureType(pUpdate->sType));
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600890 result = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600891 }
892 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600893 // Next verify that update falls within size of given binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600894 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600895 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlis793ad302015-04-03 12:01:11 -0600896 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600897 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600898 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600899 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), getUpdateBinding(device, pUpdate), DSstr.c_str());
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600900 result = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600901 }
902 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600903 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600904 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600905 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
906 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600907 result = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600908 }
909 else {
910 // Save the update info
911 // TODO : Info message that update successful
912 // Create new update struct for this set's shadow copy
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600913 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600914 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600915 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
916 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600917 result = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600918 }
919 else {
920 // Insert shadow node into LL of updates for this set
921 pNewNode->pNext = pSet->pUpdateStructs;
922 pSet->pUpdateStructs = pNewNode;
923 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600924 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600925 assert(j<pSet->descriptorCount);
926 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600927 }
928 }
929 }
930 }
931 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600932 }
933 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600934 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600935}
936// Free the shadowed update node for this Set
937// NOTE : Calls to this function should be wrapped in mutex
938static void freeShadowUpdateTree(SET_NODE* pSet)
939{
940 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
941 pSet->pUpdateStructs = NULL;
942 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
943 // Clear the descriptor mappings as they will now be invalid
944 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
945 while(pShadowUpdate) {
946 pFreeUpdate = pShadowUpdate;
947 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
948 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800949 VkWriteDescriptorSet * pWDS = NULL;
950 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600951 void** ppToFree = NULL;
952 switch (pFreeUpdate->sType)
953 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800954 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
955 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
956 if (pWDS->pDescriptors)
957 delete[] pWDS->pDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600958 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800959 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600960 break;
961 default:
962 assert(0);
963 break;
964 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600965 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600966 }
967}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600968// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600969// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600970static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600971{
David Pinedod8f83d82015-04-27 16:36:17 -0600972 if (poolMap.size() <= 0)
973 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600974 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600975 SET_NODE* pSet = (*ii).second->pSets;
976 SET_NODE* pFreeSet = pSet;
977 while (pSet) {
978 pFreeSet = pSet;
979 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600980 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600981 // Free Update shadow struct tree
982 freeShadowUpdateTree(pFreeSet);
983 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +1200984 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600985 }
986 delete pFreeSet;
987 }
988 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes02038792015-06-04 10:49:27 +1200989 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600990 }
991 delete (*ii).second;
992 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600993 poolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600994}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600995// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600996// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600997static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600998{
David Pinedod8f83d82015-04-27 16:36:17 -0600999 if (layoutMap.size() <= 0)
1000 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001001 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001002 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001003 if (pLayout->createInfo.pBinding) {
1004 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1005 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1006 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1007 }
1008 delete[] pLayout->createInfo.pBinding;
1009 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001010 if (pLayout->pTypes) {
Chris Forbes02038792015-06-04 10:49:27 +12001011 delete[] pLayout->pTypes;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001012 }
1013 delete pLayout;
1014 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001015 layoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001016}
1017// Currently clearing a set is removing all previous updates to that set
1018// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001019static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001020{
1021 SET_NODE* pSet = getSetNode(set);
1022 if (!pSet) {
1023 // TODO : Return error
1024 }
1025 else {
1026 loader_platform_thread_lock_mutex(&globalLock);
1027 freeShadowUpdateTree(pSet);
1028 loader_platform_thread_unlock_mutex(&globalLock);
1029 }
1030}
1031
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001032static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001033{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001034 POOL_NODE* pPool = getPoolNode(pool);
1035 if (!pPool) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001036 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool, 0, DRAWSTATE_INVALID_POOL, "DS",
1037 "Unable to find pool node for pool %p specified in vkResetDescriptorPool() call", (void*)pool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001038 }
1039 else
1040 {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001041 // For every set off of this pool, clear it
1042 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001043 while (pSet) {
1044 clearDescriptorSet(pSet->set);
1045 }
1046 }
1047}
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001048// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001049static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001050{
1051 loader_platform_thread_lock_mutex(&globalLock);
1052 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1053 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001054 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1055 "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001056 return NULL;
1057 }
1058 loader_platform_thread_unlock_mutex(&globalLock);
1059 return cmdBufferMap[cb];
1060}
1061// Free all CB Nodes
1062// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001063static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001064{
David Pinedod8f83d82015-04-27 16:36:17 -06001065 if (cmdBufferMap.size() <= 0)
1066 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001067 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06001068 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1069 while (!cmd_node_list.empty()) {
1070 CMD_NODE* cmd_node = cmd_node_list.back();
1071 delete cmd_node;
1072 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001073 }
1074 delete (*ii).second;
1075 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001076 cmdBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001077}
1078static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1079{
1080 CMD_NODE* pCmd = new CMD_NODE;
1081 if (pCmd) {
1082 // init cmd node and append to end of cmd LL
1083 memset(pCmd, 0, sizeof(CMD_NODE));
1084 pCmd->cmdNumber = ++pCB->numCmds;
1085 pCmd->type = cmd;
1086 pCB->pCmds.push_back(pCmd);
1087 }
1088 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001089 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1090 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001091 }
1092}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001093static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001094{
1095 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1096 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001097 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1098 while (!cmd_list.empty()) {
1099 delete cmd_list.back();
1100 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001101 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001102 pCB->pCmds.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001103 // Reset CB state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001104 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001105 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001106 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1107 pCB->cmdBuffer = cb;
1108 pCB->flags = saveFlags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001109 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001110 pCB->lastVtxBinding = MAX_BINDING;
1111 }
1112}
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001113// Set PSO-related status bits for CB
1114static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1115{
1116 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1117 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1118 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1119 }
1120 }
1121 if (pPipe->dsStateCI.depthWriteEnable) {
1122 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1123 }
1124}
1125// Set dyn-state related status bits for an object node
1126static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, VkStateBindPoint stateBindPoint) {
1127 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1128 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1129 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1130 pNode->status |= CBSTATUS_RASTER_BOUND;
1131 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1132 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1133 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1134 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1135 }
1136}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001137// Set the last bound dynamic state of given type
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001138static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001139{
1140 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1141 if (pCB) {
1142 updateCBTracking(cmdBuffer);
1143 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001144 set_cb_dyn_status(pCB, sType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001145 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1146 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001147 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
1148 "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001149 }
1150 else {
1151 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1152 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1153 }
1154 loader_platform_thread_unlock_mutex(&globalLock);
1155 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001156}
1157// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001158static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001159{
1160 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1161 if (pCB) {
1162 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1163 if (!pPipeTrav) {
1164 // nothing to print
1165 }
1166 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001167 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1168 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001169 }
1170 }
1171}
1172// Common Dot dumping code
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001173static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001174{
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001175#if 0
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001176 SET_NODE* pSet = getSetNode(ds);
1177 if (pSet) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001178 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001179 char tmp_str[4*1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001180 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1181 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001182 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001183 fprintf(pOutFile, "%s", pGVstr);
1184 free(pGVstr);
1185 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1186 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001187 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001188 uint32_t layout_index = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001189 ++layout_index;
1190 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001191 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001192 fprintf(pOutFile, "%s", pGVstr);
1193 free(pGVstr);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001194 if (pSet->pUpdateStructs) {
1195 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1196 fprintf(pOutFile, "%s", pGVstr);
1197 free(pGVstr);
1198 }
1199 if (pSet->ppDescriptors) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001200 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1201 uint32_t i = 0;
1202 for (i=0; i < pSet->descriptorCount; i++) {
1203 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001204 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_VkStructureType(pSet->ppDescriptors[i]->sType));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001205 }
1206 }
1207#define NUM_COLORS 7
1208 vector<string> edgeColors;
1209 edgeColors.push_back("0000ff");
1210 edgeColors.push_back("ff00ff");
1211 edgeColors.push_back("ffff00");
1212 edgeColors.push_back("00ff00");
1213 edgeColors.push_back("000000");
1214 edgeColors.push_back("00ffff");
1215 edgeColors.push_back("ff0000");
1216 uint32_t colorIdx = 0;
1217 fprintf(pOutFile, "</TABLE>>\n];\n");
1218 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001219 VkUpdateSamplers* pUS = NULL;
1220 VkUpdateSamplerTextures* pUST = NULL;
1221 VkUpdateImages* pUI = NULL;
1222 VkUpdateBuffers* pUB = NULL;
1223 VkUpdateAsCopy* pUAC = NULL;
1224 VkSamplerCreateInfo* pSCI = NULL;
1225 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001226 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001227 void** ppNextPtr = NULL;
1228 void* pSaveNext = NULL;
1229 for (i=0; i < pSet->descriptorCount; i++) {
1230 if (pSet->ppDescriptors[i]) {
1231 switch (pSet->ppDescriptors[i]->sType)
1232 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001233 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001234 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001235 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001236 if (pSCI) {
1237 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001238 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001239 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1240 }
1241 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001242 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001243 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterf39b3ec2015-04-09 11:43:10 -06001244 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001245 if (pSCI) {
1246 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001247 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001248 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1249 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001250 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001251 if (pIVCI) {
1252 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001253 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001254 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1255 }
1256 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001257 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001258 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001259 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001260 if (pIVCI) {
1261 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001262 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001263 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1264 }
1265 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001266 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001267 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001268 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001269 if (pBVCI) {
1270 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001271 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001272 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1273 }
1274 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001275 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001276 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001277 // TODO : Need to validate this code
1278 // Save off pNext and set to NULL while printing this struct, then restore it
1279 ppNextPtr = (void**)&pUAC->pNext;
1280 pSaveNext = *ppNextPtr;
1281 *ppNextPtr = NULL;
1282 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001283 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001284 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1285 // Restore next ptr
1286 *ppNextPtr = pSaveNext;
1287 break;
1288 default:
1289 break;
1290 }
1291 colorIdx = (colorIdx+1) % NUM_COLORS;
1292 }
1293 }
1294 }
1295 fprintf(pOutFile, "}\n");
1296 fprintf(pOutFile, "}\n");
1297 }
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001298#endif
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001299}
1300// Dump subgraph w/ DS info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001301static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001302{
1303 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1304 if (pCB && pCB->lastBoundDescriptorSet) {
1305 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1306 }
1307}
1308// Dump a GraphViz dot file showing the Cmd Buffers
1309static void cbDumpDotFile(string outFileName)
1310{
1311 // Print CB Chain for each CB
1312 FILE* pOutFile;
1313 pOutFile = fopen(outFileName.c_str(), "w");
1314 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1315 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1316 GLOBAL_CB_NODE* pCB = NULL;
1317 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1318 pCB = g_pLastTouchedCB[i];
David Pinedod8f83d82015-04-27 16:36:17 -06001319 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001320 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1321 uint32_t instNum = 0;
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001322 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1323 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001324 if (instNum) {
1325 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1326 }
1327 if (pCB == g_lastGlobalCB) {
1328 fprintf(pOutFile, "\"CB%pCMD%u\" [\nlabel=<<TABLE BGCOLOR=\"#00FF00\" BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD>CMD#</TD><TD>%u</TD></TR><TR><TD>CMD Type</TD><TD>%s</TD></TR></TABLE>>\n];\n", (void*)pCB->cmdBuffer, instNum, instNum, cmdTypeToString((*ii)->type).c_str());
1329 }
1330 else {
1331 fprintf(pOutFile, "\"CB%pCMD%u\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD>CMD#</TD><TD>%u</TD></TR><TR><TD>CMD Type</TD><TD>%s</TD></TR></TABLE>>\n];\n", (void*)pCB->cmdBuffer, instNum, instNum, cmdTypeToString((*ii)->type).c_str());
1332 }
1333 ++instNum;
1334 }
1335 fprintf(pOutFile, "}\n");
1336 }
1337 }
1338 fprintf(pOutFile, "}\n");
1339 fprintf(pOutFile, "}\n"); // close main graph "g"
1340 fclose(pOutFile);
1341}
1342// Dump a GraphViz dot file showing the pipeline for last bound global state
1343static void dumpGlobalDotFile(char *outFileName)
1344{
1345 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1346 if (pPipeTrav) {
1347 FILE* pOutFile;
1348 pOutFile = fopen(outFileName, "w");
1349 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1350 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1351 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001352 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001353 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001354 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001355 fprintf(pOutFile, "%s", pGVstr);
1356 free(pGVstr);
1357 }
1358 }
1359 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1360 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001361 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001362 fprintf(pOutFile, "%s", pGVstr);
1363 free(pGVstr);
1364 fprintf(pOutFile, "}\n");
1365 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1366 fprintf(pOutFile, "}\n"); // close main graph "g"
1367 fclose(pOutFile);
1368 }
1369}
1370// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001371static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001372{
1373 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1374 if (pCB) {
1375 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1376 if (pPipeTrav) {
1377 FILE* pOutFile;
1378 pOutFile = fopen(outFileName.c_str(), "w");
1379 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1380 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1381 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001382 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001383 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001384 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001385 fprintf(pOutFile, "%s", pGVstr);
1386 free(pGVstr);
1387 }
1388 }
1389 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1390 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001391 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001392 fprintf(pOutFile, "%s", pGVstr);
1393 free(pGVstr);
1394 fprintf(pOutFile, "}\n");
1395 dsDumpDot(cb, pOutFile);
1396 fprintf(pOutFile, "}\n"); // close main graph "g"
1397 fclose(pOutFile);
1398 }
1399 }
1400}
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001401// Verify bound Pipeline State Object
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001402static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001403{
1404 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1405 if (pCB && pCB->lastBoundPipeline) {
1406 // First verify that we have a Node for bound pipeline
1407 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1408 char str[1024];
1409 if (!pPipeTrav) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001410 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1411 "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001412 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001413 }
1414 else {
1415 // Verify Vtx binding
1416 if (MAX_BINDING != pCB->lastVtxBinding) {
1417 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1418 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001419 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1420 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001421 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001422 }
1423 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001424 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1425 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001426 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001427 }
1428 }
1429 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001430 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1431 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001432 }
1433 }
1434 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001435 return true;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001436 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001437 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001438}
1439// Print details of DS config to stdout
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001440static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001441{
1442 char tmp_str[1024];
1443 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.
1444 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06001445 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001446 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001447 POOL_NODE* pPool = getPoolNode(pSet->pool);
1448 // Print out pool details
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001449 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1450 "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001451 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001452 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1453 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001454 // Print out set details
1455 char prefix[10];
1456 uint32_t index = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001457 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1458 "Details for descriptor set %p.", (void*)pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001459 LAYOUT_NODE* pLayout = pSet->pLayout;
1460 // Print layout details
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001461 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1462 "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001463 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001464 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001465 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1466 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06001467 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001468 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1469 if (pUpdate) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001470 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1471 "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001472 sprintf(prefix, " [UC] ");
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001473 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1474 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001475 // TODO : If there is a "view" associated with this update, print CI for that view
1476 }
1477 else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001478 if (0 != pSet->descriptorCount) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001479 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1480 "No Update Chain for descriptor set %p which has %u descriptors (vkUpdateDescriptors has not been called)", (void*)pSet->set, pSet->descriptorCount);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001481 }
1482 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001483 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1484 "FYI: No descriptors in descriptor set %p.", (void*)pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001485 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001486 }
1487 }
1488}
1489
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001490static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001491{
1492 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001493 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001494 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1495 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001496 vector<CMD_NODE*> pCmds = pCB->pCmds;
1497 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001498 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, DRAWSTATE_NONE, "DS",
1499 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001500 }
1501 }
1502 else {
1503 // Nothing to print
1504 }
1505}
1506
1507
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001508static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001509{
1510 printDSConfig(cb);
1511 printPipeline(cb);
1512 printDynamicState(cb);
1513 static int autoDumpOnce = 0;
1514 if (autoDumpOnce) {
1515 autoDumpOnce = 0;
1516 dumpDotFile(cb, "pipeline_dump.dot");
1517 cbDumpDotFile("cb_dump.dot");
1518#if defined(_WIN32)
1519// FIXME: NEED WINDOWS EQUIVALENT
1520#else // WIN32
1521 // Convert dot to svg if dot available
1522 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbourf20f87b2015-04-22 09:02:32 -06001523 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1524 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001525 }
1526#endif // WIN32
1527 }
1528}
1529
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001530static void init_draw_state(layer_data *my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001531{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001532 uint32_t report_flags = 0;
1533 uint32_t debug_action = 0;
1534 FILE *log_output = NULL;
1535 const char *option_str;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001536 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001537 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1538 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001539
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001540 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001541 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001542 option_str = getLayerOption("DrawStateLogFilename");
1543 if (option_str)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001544 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001545 log_output = fopen(option_str, "w");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001546 }
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001547 if (log_output == NULL)
1548 log_output = stdout;
1549
1550 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 -06001551 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001552
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001553 if (!globalLockInitialized)
1554 {
1555 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001556 // suggestion is to call this during vkCreateInstance(), and then we
1557 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001558 // that the layer have per-instance locks. We need to come back and
1559 // address this soon.
1560 loader_platform_thread_create_mutex(&globalLock);
1561 globalLockInitialized = 1;
1562 }
1563}
1564
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001565VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1566{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001567 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001568 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1569
1570 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001571 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1572 my_data->report_data = debug_report_create_instance(
1573 pTable,
1574 *pInstance,
1575 pCreateInfo->extensionCount,
1576 pCreateInfo->pEnabledExtensions);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001577
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001578 init_draw_state(my_data);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001579 }
1580 return result;
1581}
1582
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001583/* hook DestroyInstance to remove tableInstanceMap entry */
1584VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1585{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001586 dispatch_key key = get_dispatch_key(instance);
1587 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1588 VkResult res = pTable->DestroyInstance(instance);
1589
1590 // Clean up logging callback, if any
1591 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1592 if (my_data->logging_callback) {
1593 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1594 }
1595
1596 layer_debug_report_destroy_instance(mid(instance));
1597 layer_data_map.erase(pTable);
1598
1599 draw_state_instance_table_map.erase(key);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001600 return res;
1601}
1602
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001603static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1604{
1605 uint32_t i, ext_idx;
Jon Ashburn747f2b62015-06-18 15:02:58 -06001606 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburneab34492015-06-01 09:37:38 -06001607 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001608
1609 for (i = 0; i < pCreateInfo->extensionCount; i++) {
1610 if (strcmp(pCreateInfo->pEnabledExtensions[i].name, DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06001611 /* Found a matching extension name, mark it enabled and init dispatch table*/
1612 initDebugMarkerTable(device);
1613 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001614 }
1615
1616 }
1617}
1618
Tony Barbourd1c35722015-04-16 15:59:00 -06001619VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001620{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001621 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(draw_state_instance_table_map, gpu);
1622 VkResult result = pInstanceTable->CreateDevice(gpu, pCreateInfo, pDevice);
1623 if (result == VK_SUCCESS) {
1624 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1625 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1626 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1627 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001628 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001629 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001630 return result;
1631}
1632
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001633VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001634{
1635 // Free all the memory
1636 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001637 deletePipelines();
1638 deleteSamplers();
1639 deleteImages();
1640 deleteBuffers();
1641 deleteCmdBuffers();
1642 deleteDynamicState();
1643 deletePools();
1644 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001645 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001646
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001647 dispatch_key key = get_dispatch_key(device);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001648 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1649 VkResult result = pDisp->DestroyDevice(device);
1650 deviceExtMap.erase(pDisp);
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001651 draw_state_device_table_map.erase(key);
Jon Ashburneab34492015-06-01 09:37:38 -06001652 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001653 return result;
1654}
1655
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001656struct extProps {
1657 uint32_t version;
1658 const char * const name;
1659};
Jon Ashburna050a8a2015-06-15 16:08:39 -06001660#define DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE 3
1661static const VkExtensionProperties dsDevExts[DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001662 {
1663 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1664 "DrawState",
1665 0x10,
1666 "Sample layer: DrawState",
Courtney Goeltzenleuchter491d59d2015-06-01 14:34:25 -06001667 },
1668 {
1669 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1670 "Validation",
1671 0x10,
1672 "Sample layer: DrawState",
Jon Ashburna050a8a2015-06-15 16:08:39 -06001673 },
1674 {
1675 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1676 DEBUG_MARKER_EXTENSION_NAME,
1677 0x10,
1678 "Sample layer: DrawState",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001679 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001680};
1681
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001682//TODO add DEBUG_MARKER to device extension list
Jon Ashburn2b850e52015-06-15 12:21:02 -06001683VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionInfo(
1684 VkPhysicalDevice physical_device,
1685 VkExtensionInfoType infoType,
1686 uint32_t extensionIndex,
1687 size_t *pDataSize,
1688 void *pData)
1689{
1690 uint32_t *count;
1691
1692 if (pDataSize == NULL) {
1693 return VK_ERROR_INVALID_POINTER;
1694 }
1695
1696 switch (infoType) {
1697 case VK_EXTENSION_INFO_TYPE_COUNT:
1698 *pDataSize = sizeof(uint32_t);
1699 if (pData == NULL) {
1700 return VK_SUCCESS;
1701 }
1702 count = (uint32_t *) pData;
Jon Ashburna050a8a2015-06-15 16:08:39 -06001703 *count = DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE;
Jon Ashburn2b850e52015-06-15 12:21:02 -06001704 break;
1705 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1706 *pDataSize = sizeof(VkExtensionProperties);
1707 if (pData == NULL) {
1708 return VK_SUCCESS;
1709 }
Jon Ashburna050a8a2015-06-15 16:08:39 -06001710 if (extensionIndex >= DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE) {
Jon Ashburn2b850e52015-06-15 12:21:02 -06001711 return VK_ERROR_INVALID_VALUE;
1712 }
Jon Ashburna050a8a2015-06-15 16:08:39 -06001713 memcpy((VkExtensionProperties *) pData, &dsDevExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn2b850e52015-06-15 12:21:02 -06001714 break;
1715 default:
1716 return VK_ERROR_INVALID_VALUE;
1717 }
1718
1719 return VK_SUCCESS;
1720}
1721
Jon Ashburna050a8a2015-06-15 16:08:39 -06001722#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 2
1723static const VkExtensionProperties dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1724 {
1725 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1726 "DrawState",
1727 0x10,
1728 "Sample layer: DrawState",
1729 },
1730 {
1731 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1732 "Validation",
1733 0x10,
1734 "Sample layer: DrawState",
1735 }
1736};
1737
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001738VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001739 VkExtensionInfoType infoType,
1740 uint32_t extensionIndex,
1741 size_t* pDataSize,
1742 void* pData)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001743{
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001744 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001745 uint32_t *count;
1746
1747 if (pDataSize == NULL)
1748 return VK_ERROR_INVALID_POINTER;
1749
1750 switch (infoType) {
1751 case VK_EXTENSION_INFO_TYPE_COUNT:
1752 *pDataSize = sizeof(uint32_t);
1753 if (pData == NULL)
1754 return VK_SUCCESS;
1755 count = (uint32_t *) pData;
1756 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1757 break;
1758 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1759 *pDataSize = sizeof(VkExtensionProperties);
1760 if (pData == NULL)
1761 return VK_SUCCESS;
1762 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1763 return VK_ERROR_INVALID_VALUE;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001764 memcpy((VkExtensionProperties *) pData, &dsExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001765 break;
1766 default:
1767 return VK_ERROR_INVALID_VALUE;
1768 };
1769
1770 return VK_SUCCESS;
1771}
1772
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001773VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001774{
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001775 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001776 for (uint32_t i=0; i < cmdBufferCount; i++) {
1777 // Validate that cmd buffers have been updated
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001778 pCB = getCBNode(pCmdBuffers[i]);
1779 loader_platform_thread_lock_mutex(&globalLock);
1780 if (CB_UPDATE_COMPLETE != pCB->state) {
1781 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001782 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, pCB->cmdBuffer, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1783 "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001784 loader_platform_thread_unlock_mutex(&globalLock);
1785 return VK_ERROR_UNKNOWN;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001786 }
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06001787 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001788 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001789
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001790 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001791 return result;
1792}
1793
Mike Stroyanb050c682015-04-17 12:36:38 -06001794VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001795{
1796 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001797 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyObject(device, objType, object);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001798 return result;
1799}
1800
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001801VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001802{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001803 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001804 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001805 loader_platform_thread_lock_mutex(&globalLock);
1806 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1807 pNewNode->buffer = *pView;
1808 pNewNode->createInfo = *pCreateInfo;
1809 bufferMap[*pView] = pNewNode;
1810 loader_platform_thread_unlock_mutex(&globalLock);
1811 }
1812 return result;
1813}
1814
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001815VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001816{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001817 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001818 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001819 loader_platform_thread_lock_mutex(&globalLock);
1820 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1821 pNewNode->image = *pView;
1822 pNewNode->createInfo = *pCreateInfo;
1823 imageMap[*pView] = pNewNode;
1824 loader_platform_thread_unlock_mutex(&globalLock);
1825 }
1826 return result;
1827}
1828
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001829VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001830{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001831 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
1832 // The order of operations here is a little convoluted but gets the job done
1833 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1834 // 2. Create state is then validated (which uses flags setup during shadowing)
1835 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1836 loader_platform_thread_lock_mutex(&globalLock);
1837 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfo, NULL);
1838 bool32_t valid = verifyPipelineCreateState(device, pPipeNode);
1839 loader_platform_thread_unlock_mutex(&globalLock);
1840 if (VK_TRUE == valid) {
1841 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
1842 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS",
1843 "Created Gfx Pipeline %p", (void*)*pPipeline);
1844 loader_platform_thread_lock_mutex(&globalLock);
1845 pPipeNode->pipeline = *pPipeline;
1846 pipelineMap[pPipeNode->pipeline] = pPipeNode;
1847 loader_platform_thread_unlock_mutex(&globalLock);
1848 }
1849 else {
1850 if (pPipeNode) {
1851 // If we allocated a pipeNode, need to clean it up here
1852 delete[] pPipeNode->pVertexBindingDescriptions;
1853 delete[] pPipeNode->pVertexAttributeDescriptions;
1854 delete[] pPipeNode->pAttachments;
1855 delete pPipeNode;
1856 }
1857 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001858 return result;
1859}
1860
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001861VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1862 VkDevice device,
1863 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1864 VkPipeline basePipeline,
1865 VkPipeline* pPipeline)
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001866{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001867 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
1868 loader_platform_thread_lock_mutex(&globalLock);
1869 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfo, NULL);
1870 bool32_t valid = verifyPipelineCreateState(device, pipelineMap[basePipeline]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001871 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001872 if (VK_TRUE == valid) {
1873 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
1874 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS",
1875 "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
1876 loader_platform_thread_lock_mutex(&globalLock);
1877 pPipeNode->pipeline = *pPipeline;
1878 pipelineMap[pPipeNode->pipeline] = pPipeNode;
1879 loader_platform_thread_unlock_mutex(&globalLock);
1880 }
1881 else { // Skipped pipeline creation due to bad CreateInfo data
1882 if (pPipeNode) {
1883 // If we allocated a pipeNode, need to clean it up here
1884 delete[] pPipeNode->pVertexBindingDescriptions;
1885 delete[] pPipeNode->pVertexAttributeDescriptions;
1886 delete[] pPipeNode->pAttachments;
1887 delete pPipeNode;
1888 }
1889 }
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001890 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001891}
1892
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001893VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001894{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001895 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001896 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001897 loader_platform_thread_lock_mutex(&globalLock);
1898 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1899 pNewNode->sampler = *pSampler;
1900 pNewNode->createInfo = *pCreateInfo;
1901 sampleMap[*pSampler] = pNewNode;
1902 loader_platform_thread_unlock_mutex(&globalLock);
1903 }
1904 return result;
1905}
1906
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001907VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001908{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001909 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001910 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001911 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1912 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001913 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1914 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001915 }
1916 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001917 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1918 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1919 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001920 uint32_t totalCount = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001921 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001922 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001923 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001924 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001925 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1926 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001927 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001928 }
1929 if (totalCount > 0) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001930 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001931 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001932 uint32_t j = 0;
1933 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001934 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001935 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001936 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001937 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001938 }
1939 }
1940 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001941 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001942 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1943 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001944 // Put new node at Head of global Layer list
1945 loader_platform_thread_lock_mutex(&globalLock);
1946 layoutMap[*pSetLayout] = pNewNode;
1947 loader_platform_thread_unlock_mutex(&globalLock);
1948 }
1949 return result;
1950}
1951
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001952VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001953{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001954 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001955 if (VK_SUCCESS == result) {
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001956 // TODO : Need to capture the pipeline layout
Tobin Ehlis793ad302015-04-03 12:01:11 -06001957 }
1958 return result;
1959}
1960
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001961VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001962{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001963 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001964 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001965 // Insert this pool into Global Pool LL at head
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001966 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1967 "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001968 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001969 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001970 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001971 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1972 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001973 }
1974 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001975 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001976 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1977 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001978 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001979 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1980 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001981 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1982 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001983 pNewNode->poolUsage = poolUsage;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001984 pNewNode->maxSets = maxSets;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001985 pNewNode->pool = *pDescriptorPool;
1986 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001987 }
1988 loader_platform_thread_unlock_mutex(&globalLock);
1989 }
1990 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001991 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001992 }
1993 return result;
1994}
1995
Mike Stroyanb050c682015-04-17 12:36:38 -06001996VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001997{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001998 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001999 if (VK_SUCCESS == result) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002000 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002001 }
2002 return result;
2003}
2004
Mike Stroyanb050c682015-04-17 12:36:38 -06002005VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002006{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002007 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002008 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002009 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
2010 if (!pPoolNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002011 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS",
2012 "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002013 }
2014 else {
2015 for (uint32_t i = 0; i < *pCount; i++) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002016 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
2017 "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002018 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002019 SET_NODE* pNewNode = new SET_NODE;
2020 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002021 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
2022 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002023 }
2024 else {
2025 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis793ad302015-04-03 12:01:11 -06002026 // Insert set at head of Set LL for this pool
2027 pNewNode->pNext = pPoolNode->pSets;
2028 pPoolNode->pSets = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002029 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
2030 if (NULL == pLayout) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002031 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
2032 "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002033 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06002034 pNewNode->pLayout = pLayout;
2035 pNewNode->pool = descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002036 pNewNode->set = pDescriptorSets[i];
2037 pNewNode->setUsage = setUsage;
2038 pNewNode->descriptorCount = pLayout->endIndex + 1;
2039 if (pNewNode->descriptorCount) {
2040 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
2041 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
2042 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
2043 }
2044 setMap[pDescriptorSets[i]] = pNewNode;
2045 }
2046 }
2047 }
2048 }
2049 return result;
2050}
2051
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002052VK_LAYER_EXPORT VkResult VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002053{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002054 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
2055 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002056 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002057 }
2058 return VK_ERROR_UNKNOWN;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002059}
2060
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06002061VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002062{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002063 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06002064 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002065 return result;
2066}
2067
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06002068VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002069{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002070 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06002071 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002072 return result;
2073}
2074
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06002075VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002076{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002077 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06002078 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002079 return result;
2080}
2081
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06002082VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002083{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002084 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06002085 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002086 return result;
2087}
2088
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002089VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002090{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002091 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002092 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002093 loader_platform_thread_lock_mutex(&globalLock);
2094 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2095 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2096 pCB->cmdBuffer = *pCmdBuffer;
2097 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07002098 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002099 pCB->lastVtxBinding = MAX_BINDING;
2100 cmdBufferMap[*pCmdBuffer] = pCB;
2101 loader_platform_thread_unlock_mutex(&globalLock);
2102 updateCBTracking(*pCmdBuffer);
2103 }
2104 return result;
2105}
2106
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002107VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002108{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002109 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002110 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002111 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2112 if (pCB) {
2113 if (CB_NEW != pCB->state)
2114 resetCB(cmdBuffer);
2115 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002116 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002117 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002118 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002119 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002120 }
2121 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002122 }
2123 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002124 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
2125 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002126 }
2127 updateCBTracking(cmdBuffer);
2128 }
2129 return result;
2130}
2131
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002132VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002133{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002134 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002135 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002136 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2137 if (pCB) {
2138 pCB->state = CB_UPDATE_COMPLETE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002139 // Reset CB status flags
2140 pCB->status = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002141 printCB(cmdBuffer);
2142 }
2143 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002144 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
2145 "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002146 }
2147 updateCBTracking(cmdBuffer);
2148 //cbDumpDotFile("cb_dump.dot");
2149 }
2150 return result;
2151}
2152
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002153VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002154{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002155 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002156 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002157 resetCB(cmdBuffer);
2158 updateCBTracking(cmdBuffer);
2159 }
2160 return result;
2161}
2162
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002163VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002164{
2165 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2166 if (pCB) {
2167 updateCBTracking(cmdBuffer);
2168 addCmd(pCB, CMD_BINDPIPELINE);
2169 PIPELINE_NODE* pPN = getPipeline(pipeline);
2170 if (pPN) {
2171 pCB->lastBoundPipeline = pipeline;
2172 loader_platform_thread_lock_mutex(&globalLock);
2173 g_lastBoundPipeline = pPN;
2174 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002175 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002176 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002177 }
2178 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002179 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2180 "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002181 }
2182 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002183}
2184
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002185VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002186{
2187 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002188 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002189}
2190
Cody Northropd4c1a502015-04-16 13:41:56 -06002191VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002192{
2193 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2194 if (pCB) {
2195 updateCBTracking(cmdBuffer);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002196 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002197 if (validateBoundPipeline(cmdBuffer)) {
2198 for (uint32_t i=0; i<setCount; i++) {
2199 if (getSetNode(pDescriptorSets[i])) {
2200 loader_platform_thread_lock_mutex(&globalLock);
2201 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2202 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2203 g_lastBoundDescriptorSet = pDescriptorSets[i];
2204 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002205 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
2206 "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002207 }
2208 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002209 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS",
2210 "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002211 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002212 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002213 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002214 }
2215 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002216}
2217
Tony Barbourd1c35722015-04-16 15:59:00 -06002218VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002219{
2220 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2221 if (pCB) {
2222 updateCBTracking(cmdBuffer);
2223 addCmd(pCB, CMD_BINDINDEXBUFFER);
2224 // TODO : Track idxBuffer binding
2225 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002226 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002227}
2228
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002229VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2230 VkCmdBuffer cmdBuffer,
2231 uint32_t startBinding,
2232 uint32_t bindingCount,
2233 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002234 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002235{
2236 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2237 if (pCB) {
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002238 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002239 updateCBTracking(cmdBuffer);
2240 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002241 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002242 if (validateBoundPipeline(cmdBuffer)) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002243 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002244 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002245 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002246}
2247
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002248VK_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 -06002249{
2250 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002251 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002252 if (pCB) {
2253 updateCBTracking(cmdBuffer);
2254 addCmd(pCB, CMD_DRAW);
2255 pCB->drawCount[DRAW]++;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002256 loader_platform_thread_lock_mutex(&globalLock);
2257 valid = validate_draw_state_flags(cmdBuffer);
2258 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002259 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2260 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002261 synchAndPrintDSConfig(cmdBuffer);
2262 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002263 if (valid) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002264 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002265 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002266}
2267
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002268VK_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 -06002269{
2270 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002271 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002272 if (pCB) {
2273 updateCBTracking(cmdBuffer);
2274 addCmd(pCB, CMD_DRAWINDEXED);
2275 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002276 loader_platform_thread_lock_mutex(&globalLock);
2277 valid = validate_draw_state_flags(cmdBuffer);
2278 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002279 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2280 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002281 synchAndPrintDSConfig(cmdBuffer);
2282 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002283 if (valid) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002284 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002285 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002286}
2287
Tony Barbourd1c35722015-04-16 15:59:00 -06002288VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002289{
2290 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002291 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002292 if (pCB) {
2293 updateCBTracking(cmdBuffer);
2294 addCmd(pCB, CMD_DRAWINDIRECT);
2295 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002296 loader_platform_thread_lock_mutex(&globalLock);
2297 valid = validate_draw_state_flags(cmdBuffer);
2298 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002299 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2300 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002301 synchAndPrintDSConfig(cmdBuffer);
2302 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002303 if (valid) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002304 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002305 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002306}
2307
Tony Barbourd1c35722015-04-16 15:59:00 -06002308VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002309{
2310 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002311 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002312 if (pCB) {
2313 updateCBTracking(cmdBuffer);
2314 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2315 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002316 loader_platform_thread_lock_mutex(&globalLock);
2317 valid = validate_draw_state_flags(cmdBuffer);
2318 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002319 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2320 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002321 synchAndPrintDSConfig(cmdBuffer);
2322 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002323 if (valid) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002324 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002325 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002326}
2327
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002328VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002329{
2330 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2331 if (pCB) {
2332 updateCBTracking(cmdBuffer);
2333 addCmd(pCB, CMD_DISPATCH);
2334 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002335 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002336}
2337
Tony Barbourd1c35722015-04-16 15:59:00 -06002338VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002339{
2340 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2341 if (pCB) {
2342 updateCBTracking(cmdBuffer);
2343 addCmd(pCB, CMD_DISPATCHINDIRECT);
2344 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002345 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002346}
2347
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002348VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002349{
2350 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2351 if (pCB) {
2352 updateCBTracking(cmdBuffer);
2353 addCmd(pCB, CMD_COPYBUFFER);
2354 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002355 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002356}
2357
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002358VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2359 VkImage srcImage,
2360 VkImageLayout srcImageLayout,
2361 VkImage destImage,
2362 VkImageLayout destImageLayout,
2363 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002364{
2365 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2366 if (pCB) {
2367 updateCBTracking(cmdBuffer);
2368 addCmd(pCB, CMD_COPYIMAGE);
2369 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002370 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002371}
2372
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002373VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2374 VkImage srcImage, VkImageLayout srcImageLayout,
2375 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002376 uint32_t regionCount, const VkImageBlit* pRegions,
2377 VkTexFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002378{
2379 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2380 if (pCB) {
2381 updateCBTracking(cmdBuffer);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002382 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002383 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002384 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 -06002385}
2386
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002387VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2388 VkBuffer srcBuffer,
2389 VkImage destImage, VkImageLayout destImageLayout,
2390 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002391{
2392 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2393 if (pCB) {
2394 updateCBTracking(cmdBuffer);
2395 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2396 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002397 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002398}
2399
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002400VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2401 VkImage srcImage, VkImageLayout srcImageLayout,
2402 VkBuffer destBuffer,
2403 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002404{
2405 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2406 if (pCB) {
2407 updateCBTracking(cmdBuffer);
2408 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2409 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002410 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002411}
2412
Tony Barbourd1c35722015-04-16 15:59:00 -06002413VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002414{
2415 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2416 if (pCB) {
2417 updateCBTracking(cmdBuffer);
2418 addCmd(pCB, CMD_UPDATEBUFFER);
2419 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002420 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002421}
2422
Tony Barbourd1c35722015-04-16 15:59:00 -06002423VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002424{
2425 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2426 if (pCB) {
2427 updateCBTracking(cmdBuffer);
2428 addCmd(pCB, CMD_FILLBUFFER);
2429 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002430 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002431}
2432
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002433VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2434 VkCmdBuffer cmdBuffer,
2435 VkImage image, VkImageLayout imageLayout,
2436 const VkClearColor *pColor,
2437 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002438{
2439 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2440 if (pCB) {
2441 updateCBTracking(cmdBuffer);
2442 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2443 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002444 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002445}
2446
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002447VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2448 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002449 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002450 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002451{
2452 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2453 if (pCB) {
2454 updateCBTracking(cmdBuffer);
2455 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2456 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002457 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002458}
2459
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002460VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2461 VkImage srcImage, VkImageLayout srcImageLayout,
2462 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002463 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002464{
2465 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2466 if (pCB) {
2467 updateCBTracking(cmdBuffer);
2468 addCmd(pCB, CMD_RESOLVEIMAGE);
2469 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002470 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002471}
2472
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002473VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002474{
2475 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2476 if (pCB) {
2477 updateCBTracking(cmdBuffer);
2478 addCmd(pCB, CMD_SETEVENT);
2479 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002480 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002481}
2482
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002483VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002484{
2485 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2486 if (pCB) {
2487 updateCBTracking(cmdBuffer);
2488 addCmd(pCB, CMD_RESETEVENT);
2489 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002490 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002491}
2492
Tony Barbourd1c35722015-04-16 15:59:00 -06002493VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t eventCount, const VkEvent* pEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002494{
2495 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2496 if (pCB) {
2497 updateCBTracking(cmdBuffer);
2498 addCmd(pCB, CMD_WAITEVENTS);
2499 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002500 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002501}
2502
Tony Barbourd1c35722015-04-16 15:59:00 -06002503VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002504{
2505 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2506 if (pCB) {
2507 updateCBTracking(cmdBuffer);
2508 addCmd(pCB, CMD_PIPELINEBARRIER);
2509 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002510 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002511}
2512
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002513VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002514{
2515 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2516 if (pCB) {
2517 updateCBTracking(cmdBuffer);
2518 addCmd(pCB, CMD_BEGINQUERY);
2519 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002520 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002521}
2522
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002523VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002524{
2525 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2526 if (pCB) {
2527 updateCBTracking(cmdBuffer);
2528 addCmd(pCB, CMD_ENDQUERY);
2529 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002530 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002531}
2532
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002533VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002534{
2535 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2536 if (pCB) {
2537 updateCBTracking(cmdBuffer);
2538 addCmd(pCB, CMD_RESETQUERYPOOL);
2539 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002540 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002541}
2542
Tony Barbourd1c35722015-04-16 15:59:00 -06002543VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002544{
2545 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2546 if (pCB) {
2547 updateCBTracking(cmdBuffer);
2548 addCmd(pCB, CMD_WRITETIMESTAMP);
2549 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002550 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002551}
2552
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002553VK_LAYER_EXPORT void VKAPI vkCmdInitAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002554{
2555 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2556 if (pCB) {
2557 updateCBTracking(cmdBuffer);
2558 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2559 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002560 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002561}
2562
Tony Barbourd1c35722015-04-16 15:59:00 -06002563VK_LAYER_EXPORT void VKAPI vkCmdLoadAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer srcBuffer, VkDeviceSize srcOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002564{
2565 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2566 if (pCB) {
2567 updateCBTracking(cmdBuffer);
2568 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2569 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002570 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002571}
2572
Tony Barbourd1c35722015-04-16 15:59:00 -06002573VK_LAYER_EXPORT void VKAPI vkCmdSaveAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002574{
2575 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2576 if (pCB) {
2577 updateCBTracking(cmdBuffer);
2578 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2579 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002580 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002581}
2582
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002583VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002584{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002585 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002586 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002587 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002588 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002589 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002590 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2591 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002592 }
2593 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002594 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2595 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002596 }
2597 frameBufferMap[*pFramebuffer] = localFBCI;
2598 }
2599 return result;
2600}
2601
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002602VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002603{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002604 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002605 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002606 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002607 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002608 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002609 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2610 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002611 }
2612 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002613 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2614 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002615 }
2616 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002617 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2618 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002619 }
2620 renderPassMap[*pRenderPass] = localRPCI;
2621 }
2622 return result;
2623}
2624
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002625VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002626{
2627 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2628 if (pCB) {
2629 updateCBTracking(cmdBuffer);
2630 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002631 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2632 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourbadda992015-04-06 11:09:26 -06002633 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002634 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourbadda992015-04-06 11:09:26 -06002635 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002636 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002637 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002638}
2639
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002640VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002641{
2642 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2643 if (pCB) {
2644 updateCBTracking(cmdBuffer);
2645 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002646 pCB->activeRenderPass = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002647 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002648 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer, renderPass);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002649}
2650
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002651VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2652 VkInstance instance,
2653 VkFlags msgFlags,
2654 const PFN_vkDbgMsgCallback pfnMsgCallback,
2655 void* pUserData,
2656 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002657{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002658 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002659 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2660 if (VK_SUCCESS == res) {
2661 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2662 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2663 }
2664 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002665}
2666
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002667VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2668 VkInstance instance,
2669 VkDbgMsgCallback msgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002670{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002671 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002672 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2673 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2674 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2675 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002676}
2677
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002678VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002679{
2680 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002681 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2682 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002683 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2684 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002685 return;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002686 }
2687 else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002688 updateCBTracking(cmdBuffer);
2689 addCmd(pCB, CMD_DBGMARKERBEGIN);
2690 }
Jon Ashburneab34492015-06-01 09:37:38 -06002691 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002692}
2693
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002694VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002695{
2696 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002697 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2698 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002699 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2700 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002701 return;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06002702 }
2703 else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002704 updateCBTracking(cmdBuffer);
2705 addCmd(pCB, CMD_DBGMARKEREND);
2706 }
Jon Ashburneab34492015-06-01 09:37:38 -06002707 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2708}
2709
2710VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2711{
2712 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2713 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002714 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2715 "Attempt to use DbgSetObjectTag but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002716 return VK_ERROR_UNAVAILABLE;
2717 }
2718 debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2719}
2720
2721VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2722{
2723 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2724 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002725 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2726 "Attempt to use DbgSetObjectName but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002727 return VK_ERROR_UNAVAILABLE;
2728 }
2729 debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002730}
2731
2732// TODO : Want to pass in a cmdBuffer here based on which state to display
2733void drawStateDumpDotFile(char* outFileName)
2734{
2735 // TODO : Currently just setting cmdBuffer based on global var
2736 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2737 dumpGlobalDotFile(outFileName);
2738}
2739
2740void drawStateDumpCommandBufferDotFile(char* outFileName)
2741{
2742 cbDumpDotFile(outFileName);
2743}
2744
Tobin Ehlis75283bf2015-06-18 15:59:33 -06002745void drawStateDumpPngFile(const VkDevice device, char* outFileName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002746{
2747#if defined(_WIN32)
2748// FIXME: NEED WINDOWS EQUIVALENT
Tobin Ehlis75283bf2015-06-18 15:59:33 -06002749 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002750 "Cannot execute dot program yet on Windows.");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002751#else // WIN32
2752 char dotExe[32] = "/usr/bin/dot";
2753 if( access(dotExe, X_OK) != -1) {
2754 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2755 char dotCmd[1024];
2756 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbourf20f87b2015-04-22 09:02:32 -06002757 int retval = system(dotCmd);
2758 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002759 remove("/tmp/tmp.dot");
2760 }
2761 else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -06002762 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002763 "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002764 }
2765#endif // WIN32
2766}
2767
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002768VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002769{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002770 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002771 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002772
Jon Ashburn8fd08252015-05-28 16:25:02 -06002773 /* loader uses this to force layer initialization; device object is wrapped */
2774 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002775 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002776 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002777 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002778 if (!strcmp(funcName, "vkDestroyDevice"))
2779 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002780 if (!strcmp(funcName, "vkQueueSubmit"))
2781 return (void*) vkQueueSubmit;
2782 if (!strcmp(funcName, "vkDestroyObject"))
2783 return (void*) vkDestroyObject;
2784 if (!strcmp(funcName, "vkCreateBufferView"))
2785 return (void*) vkCreateBufferView;
2786 if (!strcmp(funcName, "vkCreateImageView"))
2787 return (void*) vkCreateImageView;
2788 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2789 return (void*) vkCreateGraphicsPipeline;
2790 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2791 return (void*) vkCreateGraphicsPipelineDerivative;
2792 if (!strcmp(funcName, "vkCreateSampler"))
2793 return (void*) vkCreateSampler;
2794 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2795 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05002796 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2797 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002798 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2799 return (void*) vkCreateDescriptorPool;
2800 if (!strcmp(funcName, "vkResetDescriptorPool"))
2801 return (void*) vkResetDescriptorPool;
2802 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2803 return (void*) vkAllocDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002804 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2805 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002806 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2807 return (void*) vkCreateDynamicViewportState;
2808 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2809 return (void*) vkCreateDynamicRasterState;
2810 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2811 return (void*) vkCreateDynamicColorBlendState;
2812 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2813 return (void*) vkCreateDynamicDepthStencilState;
2814 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2815 return (void*) vkCreateCommandBuffer;
2816 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2817 return (void*) vkBeginCommandBuffer;
2818 if (!strcmp(funcName, "vkEndCommandBuffer"))
2819 return (void*) vkEndCommandBuffer;
2820 if (!strcmp(funcName, "vkResetCommandBuffer"))
2821 return (void*) vkResetCommandBuffer;
2822 if (!strcmp(funcName, "vkCmdBindPipeline"))
2823 return (void*) vkCmdBindPipeline;
2824 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2825 return (void*) vkCmdBindDynamicStateObject;
2826 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2827 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002828 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2829 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002830 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2831 return (void*) vkCmdBindIndexBuffer;
2832 if (!strcmp(funcName, "vkCmdDraw"))
2833 return (void*) vkCmdDraw;
2834 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2835 return (void*) vkCmdDrawIndexed;
2836 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2837 return (void*) vkCmdDrawIndirect;
2838 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2839 return (void*) vkCmdDrawIndexedIndirect;
2840 if (!strcmp(funcName, "vkCmdDispatch"))
2841 return (void*) vkCmdDispatch;
2842 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2843 return (void*) vkCmdDispatchIndirect;
2844 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2845 return (void*) vkCmdCopyBuffer;
2846 if (!strcmp(funcName, "vkCmdCopyImage"))
2847 return (void*) vkCmdCopyImage;
2848 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2849 return (void*) vkCmdCopyBufferToImage;
2850 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2851 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002852 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2853 return (void*) vkCmdUpdateBuffer;
2854 if (!strcmp(funcName, "vkCmdFillBuffer"))
2855 return (void*) vkCmdFillBuffer;
2856 if (!strcmp(funcName, "vkCmdClearColorImage"))
2857 return (void*) vkCmdClearColorImage;
2858 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2859 return (void*) vkCmdClearDepthStencil;
2860 if (!strcmp(funcName, "vkCmdResolveImage"))
2861 return (void*) vkCmdResolveImage;
2862 if (!strcmp(funcName, "vkCmdSetEvent"))
2863 return (void*) vkCmdSetEvent;
2864 if (!strcmp(funcName, "vkCmdResetEvent"))
2865 return (void*) vkCmdResetEvent;
2866 if (!strcmp(funcName, "vkCmdWaitEvents"))
2867 return (void*) vkCmdWaitEvents;
2868 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2869 return (void*) vkCmdPipelineBarrier;
2870 if (!strcmp(funcName, "vkCmdBeginQuery"))
2871 return (void*) vkCmdBeginQuery;
2872 if (!strcmp(funcName, "vkCmdEndQuery"))
2873 return (void*) vkCmdEndQuery;
2874 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2875 return (void*) vkCmdResetQueryPool;
2876 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2877 return (void*) vkCmdWriteTimestamp;
2878 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2879 return (void*) vkCmdInitAtomicCounters;
2880 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2881 return (void*) vkCmdLoadAtomicCounters;
2882 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2883 return (void*) vkCmdSaveAtomicCounters;
2884 if (!strcmp(funcName, "vkCreateFramebuffer"))
2885 return (void*) vkCreateFramebuffer;
2886 if (!strcmp(funcName, "vkCreateRenderPass"))
2887 return (void*) vkCreateRenderPass;
2888 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2889 return (void*) vkCmdBeginRenderPass;
2890 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2891 return (void*) vkCmdEndRenderPass;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002892 if (!strcmp("drawStateDumpDotFile", funcName))
2893 return (void*) drawStateDumpDotFile;
2894 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2895 return (void*) drawStateDumpCommandBufferDotFile;
2896 if (!strcmp("drawStateDumpPngFile", funcName))
2897 return (void*) drawStateDumpPngFile;
Jon Ashburneab34492015-06-01 09:37:38 -06002898
Jon Ashburn747f2b62015-06-18 15:02:58 -06002899 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
2900 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06002901 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06002902 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Jon Ashburneab34492015-06-01 09:37:38 -06002903 return (void*) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06002904 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Jon Ashburneab34492015-06-01 09:37:38 -06002905 return (void*) vkCmdDbgMarkerEnd;
Jon Ashburn747f2b62015-06-18 15:02:58 -06002906 if (!strcmp(funcName, "vkDbgSetObjectTag"))
Jon Ashburneab34492015-06-01 09:37:38 -06002907 return (void*) vkDbgSetObjectTag;
Jon Ashburn747f2b62015-06-18 15:02:58 -06002908 if (!strcmp(funcName, "vkDbgSetObjectName"))
Jon Ashburneab34492015-06-01 09:37:38 -06002909 return (void*) vkDbgSetObjectName;
2910 }
2911 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06002912 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002913 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002914 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002915 }
2916}
2917
2918VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
2919{
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06002920 void *fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002921 if (instance == NULL)
2922 return NULL;
2923
Jon Ashburn8fd08252015-05-28 16:25:02 -06002924 /* loader uses this to force layer initialization; instance object is wrapped */
2925 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002926 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002927 return (void *) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002928 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06002929 if (!strcmp(funcName, "vkCreateInstance"))
2930 return (void *) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002931 if (!strcmp(funcName, "vkDestroyInstance"))
2932 return (void *) vkDestroyInstance;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002933 if (!strcmp(funcName, "vkCreateDevice"))
2934 return (void*) vkCreateDevice;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06002935
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002936 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2937 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06002938 if (fptr)
2939 return fptr;
2940
Jon Ashburn8fd08252015-05-28 16:25:02 -06002941 {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002942 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn8fd08252015-05-28 16:25:02 -06002943 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002944 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002945 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002946 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002947}