blob: 48b65391544659b22fbe7d086de09e3ba49ba2e0 [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
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600102 return my_data->report_data;
103}
104
105debug_report_data *mid(VkInstance object)
106{
107 dispatch_key key = get_dispatch_key(object);
108 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
109#if DISPATCH_MAP_DEBUG
110 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
111#endif
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600112 return my_data->report_data;
113}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600114// Map actual TID to an index value and return that index
115// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
116static uint32_t getTIDIndex() {
117 loader_platform_thread_id tid = loader_platform_get_thread_id();
118 for (uint32_t i = 0; i < g_maxTID; i++) {
119 if (tid == g_tidMapping[i])
120 return i;
121 }
122 // Don't yet have mapping, set it and return newly set index
123 uint32_t retVal = (uint32_t) g_maxTID;
124 g_tidMapping[g_maxTID++] = tid;
125 assert(g_maxTID < MAX_TID);
126 return retVal;
127}
128// Return a string representation of CMD_TYPE enum
129static string cmdTypeToString(CMD_TYPE cmd)
130{
131 switch (cmd)
132 {
133 case CMD_BINDPIPELINE:
134 return "CMD_BINDPIPELINE";
135 case CMD_BINDPIPELINEDELTA:
136 return "CMD_BINDPIPELINEDELTA";
137 case CMD_BINDDYNAMICSTATEOBJECT:
138 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600139 case CMD_BINDDESCRIPTORSETS:
140 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600141 case CMD_BINDINDEXBUFFER:
142 return "CMD_BINDINDEXBUFFER";
143 case CMD_BINDVERTEXBUFFER:
144 return "CMD_BINDVERTEXBUFFER";
145 case CMD_DRAW:
146 return "CMD_DRAW";
147 case CMD_DRAWINDEXED:
148 return "CMD_DRAWINDEXED";
149 case CMD_DRAWINDIRECT:
150 return "CMD_DRAWINDIRECT";
151 case CMD_DRAWINDEXEDINDIRECT:
152 return "CMD_DRAWINDEXEDINDIRECT";
153 case CMD_DISPATCH:
154 return "CMD_DISPATCH";
155 case CMD_DISPATCHINDIRECT:
156 return "CMD_DISPATCHINDIRECT";
157 case CMD_COPYBUFFER:
158 return "CMD_COPYBUFFER";
159 case CMD_COPYIMAGE:
160 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600161 case CMD_BLITIMAGE:
162 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600163 case CMD_COPYBUFFERTOIMAGE:
164 return "CMD_COPYBUFFERTOIMAGE";
165 case CMD_COPYIMAGETOBUFFER:
166 return "CMD_COPYIMAGETOBUFFER";
167 case CMD_CLONEIMAGEDATA:
168 return "CMD_CLONEIMAGEDATA";
169 case CMD_UPDATEBUFFER:
170 return "CMD_UPDATEBUFFER";
171 case CMD_FILLBUFFER:
172 return "CMD_FILLBUFFER";
173 case CMD_CLEARCOLORIMAGE:
174 return "CMD_CLEARCOLORIMAGE";
175 case CMD_CLEARCOLORIMAGERAW:
176 return "CMD_CLEARCOLORIMAGERAW";
177 case CMD_CLEARDEPTHSTENCIL:
178 return "CMD_CLEARDEPTHSTENCIL";
179 case CMD_RESOLVEIMAGE:
180 return "CMD_RESOLVEIMAGE";
181 case CMD_SETEVENT:
182 return "CMD_SETEVENT";
183 case CMD_RESETEVENT:
184 return "CMD_RESETEVENT";
185 case CMD_WAITEVENTS:
186 return "CMD_WAITEVENTS";
187 case CMD_PIPELINEBARRIER:
188 return "CMD_PIPELINEBARRIER";
189 case CMD_BEGINQUERY:
190 return "CMD_BEGINQUERY";
191 case CMD_ENDQUERY:
192 return "CMD_ENDQUERY";
193 case CMD_RESETQUERYPOOL:
194 return "CMD_RESETQUERYPOOL";
195 case CMD_WRITETIMESTAMP:
196 return "CMD_WRITETIMESTAMP";
197 case CMD_INITATOMICCOUNTERS:
198 return "CMD_INITATOMICCOUNTERS";
199 case CMD_LOADATOMICCOUNTERS:
200 return "CMD_LOADATOMICCOUNTERS";
201 case CMD_SAVEATOMICCOUNTERS:
202 return "CMD_SAVEATOMICCOUNTERS";
203 case CMD_BEGINRENDERPASS:
204 return "CMD_BEGINRENDERPASS";
205 case CMD_ENDRENDERPASS:
206 return "CMD_ENDRENDERPASS";
207 case CMD_DBGMARKERBEGIN:
208 return "CMD_DBGMARKERBEGIN";
209 case CMD_DBGMARKEREND:
210 return "CMD_DBGMARKEREND";
211 default:
212 return "UNKNOWN";
213 }
214}
215// Block of code at start here for managing/tracking Pipeline state that this layer cares about
216// Just track 2 shaders for now
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600217#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600218#define MAX_SLOTS 2048
219#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
220
221static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
222
223// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
224// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
225// to that same cmd buffer by separate thread are not changing state from underneath us
226// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600227static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600228// Track the last group of CBs touched for displaying to dot file
229static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
230static uint32_t g_lastTouchedCBIndex = 0;
231// Track the last global DrawState of interest touched by any thread
232static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
233static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600234static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600235static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600236#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
237
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600238//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600239
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600240static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600241{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600242 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600243 size_t scSize = 0;
244 size_t vpSize = 0;
245 loader_platform_thread_lock_mutex(&globalLock);
246 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
247 pStateNode->stateObj = state;
248 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600249 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600250 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
251 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
252 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
253 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
254 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
255 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600256 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
257 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
258 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600259 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600260 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600261 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600262 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600263 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600264 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600265 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600266 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600267 break;
268 default:
269 assert(0);
270 break;
271 }
272 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
273 dynamicStateMap[state] = pStateNode;
274 loader_platform_thread_unlock_mutex(&globalLock);
275}
276// Free all allocated nodes for Dynamic State objs
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600277static void deleteDynamicState()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600278{
David Pinedod8f83d82015-04-27 16:36:17 -0600279 if (dynamicStateMap.size() <= 0)
280 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600281 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600282 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600283 delete[] (*ii).second->create_info.vpci.pScissors;
284 delete[] (*ii).second->create_info.vpci.pViewports;
285 }
286 delete (*ii).second;
287 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600288 dynamicStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600289}
290// Free all sampler nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600291static void deleteSamplers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600292{
David Pinedod8f83d82015-04-27 16:36:17 -0600293 if (sampleMap.size() <= 0)
294 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600295 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600296 delete (*ii).second;
297 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600298 sampleMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600299}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600300static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600301{
302 loader_platform_thread_lock_mutex(&globalLock);
303 if (imageMap.find(view) == imageMap.end()) {
304 loader_platform_thread_unlock_mutex(&globalLock);
305 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600306 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600307 loader_platform_thread_unlock_mutex(&globalLock);
308 return &imageMap[view]->createInfo;
309 }
310}
311// Free all image nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600312static void deleteImages()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600313{
David Pinedod8f83d82015-04-27 16:36:17 -0600314 if (imageMap.size() <= 0)
315 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600316 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600317 delete (*ii).second;
318 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600319 imageMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600320}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600321static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600322{
323 loader_platform_thread_lock_mutex(&globalLock);
324 if (bufferMap.find(view) == bufferMap.end()) {
325 loader_platform_thread_unlock_mutex(&globalLock);
326 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600327 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600328 loader_platform_thread_unlock_mutex(&globalLock);
329 return &bufferMap[view]->createInfo;
330 }
331}
332// Free all buffer nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600333static void deleteBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600334{
David Pinedod8f83d82015-04-27 16:36:17 -0600335 if (bufferMap.size() <= 0)
336 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600337 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600338 delete (*ii).second;
339 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600340 bufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600341}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600342static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600343
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600345{
346 g_lastCmdBuffer[getTIDIndex()] = cb;
347 GLOBAL_CB_NODE* pCB = getCBNode(cb);
348 loader_platform_thread_lock_mutex(&globalLock);
349 g_lastGlobalCB = pCB;
350 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
351 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
352 if (g_pLastTouchedCB[i] == pCB) {
353 loader_platform_thread_unlock_mutex(&globalLock);
354 return;
355 }
356 }
357 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
358 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
359 loader_platform_thread_unlock_mutex(&globalLock);
360}
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600361// Check object status for selected flag state
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600362static bool32_t validate_status(GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600363{
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600364 // If non-zero enable mask is present, check it against status but if enable_mask
365 // is 0 then no enable required so we should always just check status
366 if ((!enable_mask) || (enable_mask & pNode->status)) {
367 if ((pNode->status & status_mask) != status_flag) {
368 log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, pNode->cmdBuffer, 0, error_code, "DS",
369 "CB object 0x%" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(pNode->cmdBuffer), fail_msg);
370 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600371 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600372 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600373 return VK_TRUE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600374}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600375// Print the last bound dynamic state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600376static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600377{
378 GLOBAL_CB_NODE* pCB = getCBNode(cb);
379 if (pCB) {
380 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600381 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600382 if (pCB->lastBoundDynamicState[i]) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600383 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS",
384 "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
385 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS",
386 dynamic_display(pCB->lastBoundDynamicState[i]->pCreateInfo, " ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600387 break;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600388 } else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600389 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
390 "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600391 }
392 }
393 loader_platform_thread_unlock_mutex(&globalLock);
394 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600395}
396// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600398{
399 loader_platform_thread_lock_mutex(&globalLock);
400 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
401 loader_platform_thread_unlock_mutex(&globalLock);
402 return NULL;
403 }
404 loader_platform_thread_unlock_mutex(&globalLock);
405 return pipelineMap[pipeline];
406}
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600407// Validate state stored as flags at time of draw call
408static bool32_t validate_draw_state_flags(GLOBAL_CB_NODE* pCB, bool32_t indexedDraw) {
409 bool32_t result;
410 result = validate_status(pCB, 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");
411 result &= validate_status(pCB, 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");
412 result &= validate_status(pCB, 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");
413 result &= validate_status(pCB, 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");
414 if (indexedDraw)
415 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Index Draw attempted");
416 return result;
417}
418// Validate overall state at the time of a draw call
419static bool32_t validate_draw_state(GLOBAL_CB_NODE* pCB, bool32_t indexedDraw) {
420 // First check flag states
421 bool32_t result = validate_draw_state_flags(pCB, indexedDraw);
422 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
423 // Now complete other state checks
Tobin Ehlis502480b2015-06-24 15:53:07 -0600424 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600425 result = VK_FALSE;
426 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
427 "Pipeline layout from last vkCmdBindDescriptorSets() (%s) does not match PSO Pipeline layout (%s)", pCB->lastBoundPipelineLayout, pPipe->graphicsPipelineCI.layout);
428 }
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -0600429 if (!pCB->activeRenderPass) {
430 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
431 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
432 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600433 return result;
434}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600435// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600436static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600437{
438 loader_platform_thread_lock_mutex(&globalLock);
439 if (sampleMap.find(sampler) == sampleMap.end()) {
440 loader_platform_thread_unlock_mutex(&globalLock);
441 return NULL;
442 }
443 loader_platform_thread_unlock_mutex(&globalLock);
444 return &sampleMap[sampler]->createInfo;
445}
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600446// Verify that create state for a pipeline is valid
447static bool32_t verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
448{
449 // VS is required
450 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
451 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
452 "Invalid Pipeline CreateInfo State: Vtx Shader required");
453 return VK_FALSE;
454 }
455 // Either both or neither TC/TE shaders should be defined
456 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
457 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
458 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
459 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
460 return VK_FALSE;
461 }
462 // Compute shaders should be specified independent of Gfx shaders
463 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
464 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
465 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
466 VK_SHADER_STAGE_FRAGMENT_BIT))) {
467 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
468 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
469 return VK_FALSE;
470 }
471 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
472 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
473 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
474 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
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 must be set as IA topology for tessellation pipelines");
477 return VK_FALSE;
478 }
479 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
480 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
481 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
482 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
483 return VK_FALSE;
484 }
485 return VK_TRUE;
486}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600487// Init the pipeline mapping info based on pipeline create info LL tree
488// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600489static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600490{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600491 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
492 if (pBasePipeline) {
493 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlis9c536442015-06-19 13:00:59 -0600494 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600495 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
496 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600497 // First init create info
Tobin Ehliseba312c2015-04-01 08:40:34 -0600498 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600499 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600500
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600501 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600502 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
503 const VkPipelineCbStateCreateInfo* pCBCI = NULL;
504
505 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
506 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
507
508 switch (pPSSCI->stage) {
509 case VK_SHADER_STAGE_VERTEX:
510 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
511 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600512 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600513 case VK_SHADER_STAGE_TESS_CONTROL:
514 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
515 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600516 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600517 case VK_SHADER_STAGE_TESS_EVALUATION:
518 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
519 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600520 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600521 case VK_SHADER_STAGE_GEOMETRY:
522 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
523 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600524 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600525 case VK_SHADER_STAGE_FRAGMENT:
526 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
527 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600528 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600529 case VK_SHADER_STAGE_COMPUTE:
530 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
531 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600532 break;
533 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600534 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600535 break;
536 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600537 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600538
539 if (pCreateInfo->pVertexInputState != NULL) {
540 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
541 // Copy embedded ptrs
542 pVICI = pCreateInfo->pVertexInputState;
543 pPipeline->vtxBindingCount = pVICI->bindingCount;
544 if (pPipeline->vtxBindingCount) {
545 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
546 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
547 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
548 }
549 pPipeline->vtxAttributeCount = pVICI->attributeCount;
550 if (pPipeline->vtxAttributeCount) {
551 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
552 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
553 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
554 }
555 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
556 }
557 if (pCreateInfo->pIaState != NULL) {
558 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pIaState, sizeof(VkPipelineIaStateCreateInfo));
559 pPipeline->graphicsPipelineCI.pIaState = &pPipeline->iaStateCI;
560 }
561 if (pCreateInfo->pTessState != NULL) {
562 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessState, sizeof(VkPipelineTessStateCreateInfo));
563 pPipeline->graphicsPipelineCI.pTessState = &pPipeline->tessStateCI;
564 }
565 if (pCreateInfo->pVpState != NULL) {
566 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pVpState, sizeof(VkPipelineVpStateCreateInfo));
567 pPipeline->graphicsPipelineCI.pVpState = &pPipeline->vpStateCI;
568 }
569 if (pCreateInfo->pRsState != NULL) {
570 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRsState, sizeof(VkPipelineRsStateCreateInfo));
571 pPipeline->graphicsPipelineCI.pRsState = &pPipeline->rsStateCI;
572 }
573 if (pCreateInfo->pMsState != NULL) {
574 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMsState, sizeof(VkPipelineMsStateCreateInfo));
575 pPipeline->graphicsPipelineCI.pMsState = &pPipeline->msStateCI;
576 }
577 if (pCreateInfo->pCbState != NULL) {
578 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pCbState, sizeof(VkPipelineCbStateCreateInfo));
579 // Copy embedded ptrs
580 pCBCI = pCreateInfo->pCbState;
581 pPipeline->attachmentCount = pCBCI->attachmentCount;
582 if (pPipeline->attachmentCount) {
583 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
584 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
585 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
586 }
587 pPipeline->graphicsPipelineCI.pCbState = &pPipeline->cbStateCI;
588 }
589 if (pCreateInfo->pDsState != NULL) {
590 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDsState, sizeof(VkPipelineDsStateCreateInfo));
591 pPipeline->graphicsPipelineCI.pDsState = &pPipeline->dsStateCI;
592 }
593
594 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
595 if (pCreateInfo->stageCount != 0) {
596 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
597 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
598 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
599 }
600
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600601 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600602}
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600603
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600604// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600605static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600606{
David Pinedod8f83d82015-04-27 16:36:17 -0600607 if (pipelineMap.size() <= 0)
608 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600609 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600610 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
611 delete[] (*ii).second->graphicsPipelineCI.pStages;
612 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600613 if ((*ii).second->pVertexBindingDescriptions) {
614 delete[] (*ii).second->pVertexBindingDescriptions;
615 }
616 if ((*ii).second->pVertexAttributeDescriptions) {
617 delete[] (*ii).second->pVertexAttributeDescriptions;
618 }
619 if ((*ii).second->pAttachments) {
620 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600621 }
622 delete (*ii).second;
623 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600624 pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600625}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600626// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600627static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600628{
629 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600630 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600631 if (pPipe->msStateCI.multisampleEnable)
Tony Barbourdfd533a2015-06-26 10:18:34 -0600632 return pPipe->msStateCI.rasterSamples;
Tobin Ehliseba312c2015-04-01 08:40:34 -0600633 }
634 return 1;
635}
636// Validate state related to the PSO
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600637static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600638{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600639 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600640 // Verify that any MSAA request in PSO matches sample# in bound FB
641 uint32_t psoNumSamples = getNumSamples(pipeline);
642 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600643 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
644 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis7c3ec602015-05-21 09:06:56 -0600645 if ((psoNumSamples != pFBCI->sampleCount) || (psoNumSamples != pRPCI->sampleCount)) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600646 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
647 "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 -0600648 }
649 } else {
650 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
651 // Verify and flag error as appropriate
652 }
653 // TODO : Add more checks here
654 } else {
655 // TODO : Validate non-gfx pipeline updates
656 }
657}
658
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600659// Block of code at start here specifically for managing/tracking DSs
660
Tobin Ehlis793ad302015-04-03 12:01:11 -0600661// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600662static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600663{
664 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600665 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600666 loader_platform_thread_unlock_mutex(&globalLock);
667 return NULL;
668 }
669 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600670 return poolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600671}
672// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600673static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600674{
675 loader_platform_thread_lock_mutex(&globalLock);
676 if (setMap.find(set) == setMap.end()) {
677 loader_platform_thread_unlock_mutex(&globalLock);
678 return NULL;
679 }
680 loader_platform_thread_unlock_mutex(&globalLock);
681 return setMap[set];
682}
683
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600684static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600685 loader_platform_thread_lock_mutex(&globalLock);
686 if (layoutMap.find(layout) == layoutMap.end()) {
687 loader_platform_thread_unlock_mutex(&globalLock);
688 return NULL;
689 }
690 loader_platform_thread_unlock_mutex(&globalLock);
691 return layoutMap[layout];
692}
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600693// Return 1 if update struct is of valid type, 0 otherwise
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600694static bool32_t validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600695{
696 char str[1024];
697 switch (pUpdateStruct->sType)
698 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800699 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
700 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600701 return 1;
702 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600703 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 -0600704 "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 -0600705 return 0;
706 }
707}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600708// For given update struct, return binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600709static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600710{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600711 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600712 switch (pUpdateStruct->sType)
713 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800714 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
715 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
716 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
717 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600718 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600719 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 -0600720 "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 -0600721 return 0xFFFFFFFF;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600722 }
723}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600724// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600725static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600726{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600727 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600728 switch (pUpdateStruct->sType)
729 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800730 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
731 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
732 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600733 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800734 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600735 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600736 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 -0600737 "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 -0600738 return 0;
739 }
740}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600741// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600742static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600743{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600744 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600745 switch (pUpdateStruct->sType)
746 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800747 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
748 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
749 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600750 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800751 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600752 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600753 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 -0600754 "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 -0600755 return 0;
756 }
757}
758// For given Layout Node and binding, return index where that binding begins
759static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
760{
761 uint32_t offsetIndex = 0;
762 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800763 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600764 }
765 return offsetIndex;
766}
767// For given layout node and binding, return last index that is updated
768static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
769{
770 uint32_t offsetIndex = 0;
771 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800772 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600773 }
774 return offsetIndex-1;
775}
776// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600777static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600778{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600779 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlis793ad302015-04-03 12:01:11 -0600780}
781// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600782static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600783{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600784 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600785}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600786// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600787static bool32_t validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600788{
789 // First get actual type of update
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600790 VkDescriptorType actualType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600791 uint32_t i = 0;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600792 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600793 switch (pUpdateStruct->sType)
794 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800795 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
796 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600797 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800798 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
799 /* no need to validate */
800 return 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600801 break;
802 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600803 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 -0600804 "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 -0600805 return 0;
806 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600807 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600808 if (pLayout->pTypes[i] != actualType)
809 return 0;
810 }
811 return 1;
812}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600813// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
814// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
815// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600816static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600817{
818 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800819 VkWriteDescriptorSet* pWDS = NULL;
820 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600821 size_t array_size = 0;
822 size_t base_array_size = 0;
823 size_t total_array_size = 0;
824 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600825 char str[1024];
826 switch (pUpdate->sType)
827 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800828 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
829 pWDS = new VkWriteDescriptorSet;
830 pNewNode = (GENERIC_HEADER*)pWDS;
831 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
832 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
833 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
834 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600835 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800836 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
837 pCDS = new VkCopyDescriptorSet;
838 pUpdate = (GENERIC_HEADER*)pCDS;
839 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600840 break;
841 default:
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600842 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 -0600843 "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 -0600844 return NULL;
845 }
846 // Make sure that pNext for the end of shadow copy is NULL
847 pNewNode->pNext = NULL;
848 return pNewNode;
849}
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800850// update DS mappings based on ppUpdateArray
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600851static bool32_t dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600852{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800853 const VkWriteDescriptorSet *pWDS = NULL;
854 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600855 bool32_t result = 1;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800856
857 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
858 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
859 else
860 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
861
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600862 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600863 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600864 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600865 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600866 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600867 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800868 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
869 SET_NODE* pSet = setMap[ds]; // getSetNode() without locking
870 g_lastBoundDescriptorSet = pSet->set;
871 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600872 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600873 // First verify valid update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600874 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600875 result = 0;
876 break;
877 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600878 // Make sure that binding is within bounds
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600879 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600880 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 -0600881 "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 -0600882 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600883 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600884 // Next verify that update falls within size of given binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600885 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600886 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 -0600887 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600888 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600889 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 -0600890 "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 -0600891 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600892 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600893 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600894 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600895 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
896 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600897 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600898 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600899 // Save the update info
900 // TODO : Info message that update successful
901 // Create new update struct for this set's shadow copy
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600902 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600903 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600904 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
905 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600906 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600907 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600908 // Insert shadow node into LL of updates for this set
909 pNewNode->pNext = pSet->pUpdateStructs;
910 pSet->pUpdateStructs = pNewNode;
911 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600912 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600913 assert(j<pSet->descriptorCount);
914 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600915 }
916 }
917 }
918 }
919 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600920 }
921 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600922 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600923}
924// Free the shadowed update node for this Set
925// NOTE : Calls to this function should be wrapped in mutex
926static void freeShadowUpdateTree(SET_NODE* pSet)
927{
928 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
929 pSet->pUpdateStructs = NULL;
930 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
931 // Clear the descriptor mappings as they will now be invalid
932 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
933 while(pShadowUpdate) {
934 pFreeUpdate = pShadowUpdate;
935 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
936 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800937 VkWriteDescriptorSet * pWDS = NULL;
938 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600939 void** ppToFree = NULL;
940 switch (pFreeUpdate->sType)
941 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800942 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
943 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
944 if (pWDS->pDescriptors)
945 delete[] pWDS->pDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600946 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800947 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600948 break;
949 default:
950 assert(0);
951 break;
952 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600953 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600954 }
955}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600956// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600957// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600958static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600959{
David Pinedod8f83d82015-04-27 16:36:17 -0600960 if (poolMap.size() <= 0)
961 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600962 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600963 SET_NODE* pSet = (*ii).second->pSets;
964 SET_NODE* pFreeSet = pSet;
965 while (pSet) {
966 pFreeSet = pSet;
967 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600968 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600969 // Free Update shadow struct tree
970 freeShadowUpdateTree(pFreeSet);
971 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +1200972 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600973 }
974 delete pFreeSet;
975 }
976 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes02038792015-06-04 10:49:27 +1200977 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600978 }
979 delete (*ii).second;
980 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600981 poolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600982}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600983// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600984// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600985static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600986{
David Pinedod8f83d82015-04-27 16:36:17 -0600987 if (layoutMap.size() <= 0)
988 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600989 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600990 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600991 if (pLayout->createInfo.pBinding) {
992 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
993 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
994 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
995 }
996 delete[] pLayout->createInfo.pBinding;
997 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600998 if (pLayout->pTypes) {
Chris Forbes02038792015-06-04 10:49:27 +1200999 delete[] pLayout->pTypes;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001000 }
1001 delete pLayout;
1002 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001003 layoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001004}
1005// Currently clearing a set is removing all previous updates to that set
1006// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001007static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001008{
1009 SET_NODE* pSet = getSetNode(set);
1010 if (!pSet) {
1011 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06001012 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001013 loader_platform_thread_lock_mutex(&globalLock);
1014 freeShadowUpdateTree(pSet);
1015 loader_platform_thread_unlock_mutex(&globalLock);
1016 }
1017}
1018
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001019static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001020{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001021 POOL_NODE* pPool = getPoolNode(pool);
1022 if (!pPool) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001023 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool, 0, DRAWSTATE_INVALID_POOL, "DS",
1024 "Unable to find pool node for pool %p specified in vkResetDescriptorPool() call", (void*)pool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001025 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001026 // For every set off of this pool, clear it
1027 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001028 while (pSet) {
1029 clearDescriptorSet(pSet->set);
1030 }
1031 }
1032}
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001033// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001034static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001035{
1036 loader_platform_thread_lock_mutex(&globalLock);
1037 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1038 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001039 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1040 "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001041 return NULL;
1042 }
1043 loader_platform_thread_unlock_mutex(&globalLock);
1044 return cmdBufferMap[cb];
1045}
1046// Free all CB Nodes
1047// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001048static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001049{
David Pinedod8f83d82015-04-27 16:36:17 -06001050 if (cmdBufferMap.size() <= 0)
1051 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001052 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06001053 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1054 while (!cmd_node_list.empty()) {
1055 CMD_NODE* cmd_node = cmd_node_list.back();
1056 delete cmd_node;
1057 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001058 }
1059 delete (*ii).second;
1060 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001061 cmdBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001062}
Tobin Ehlis9c536442015-06-19 13:00:59 -06001063static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1064{
1065 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, DRAWSTATE_NO_BEGIN_CMD_BUFFER, "DS",
1066 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1067}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001068static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1069{
1070 CMD_NODE* pCmd = new CMD_NODE;
1071 if (pCmd) {
1072 // init cmd node and append to end of cmd LL
1073 memset(pCmd, 0, sizeof(CMD_NODE));
1074 pCmd->cmdNumber = ++pCB->numCmds;
1075 pCmd->type = cmd;
1076 pCB->pCmds.push_back(pCmd);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001077 } else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001078 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1079 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001080 }
1081}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001082static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001083{
1084 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1085 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001086 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1087 while (!cmd_list.empty()) {
1088 delete cmd_list.back();
1089 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001090 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001091 pCB->pCmds.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001092 // Reset CB state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001093 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001094 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001095 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1096 pCB->cmdBuffer = cb;
1097 pCB->flags = saveFlags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001098 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001099 pCB->lastVtxBinding = MAX_BINDING;
1100 }
1101}
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001102// Set PSO-related status bits for CB
1103static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1104{
1105 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1106 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1107 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1108 }
1109 }
1110 if (pPipe->dsStateCI.depthWriteEnable) {
1111 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1112 }
1113}
1114// Set dyn-state related status bits for an object node
1115static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, VkStateBindPoint stateBindPoint) {
1116 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1117 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1118 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1119 pNode->status |= CBSTATUS_RASTER_BOUND;
1120 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1121 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1122 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1123 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1124 }
1125}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001126// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001127static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001128{
1129 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1130 if (pCB) {
1131 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1132 if (!pPipeTrav) {
1133 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06001134 } else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001135 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1136 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001137 }
1138 }
1139}
1140// Common Dot dumping code
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001141static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001142{
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001143#if 0
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001144 SET_NODE* pSet = getSetNode(ds);
1145 if (pSet) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001146 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001147 char tmp_str[4*1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001148 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1149 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001150 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001151 fprintf(pOutFile, "%s", pGVstr);
1152 free(pGVstr);
1153 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1154 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001155 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001156 uint32_t layout_index = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001157 ++layout_index;
1158 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001159 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001160 fprintf(pOutFile, "%s", pGVstr);
1161 free(pGVstr);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001162 if (pSet->pUpdateStructs) {
1163 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1164 fprintf(pOutFile, "%s", pGVstr);
1165 free(pGVstr);
1166 }
1167 if (pSet->ppDescriptors) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001168 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1169 uint32_t i = 0;
1170 for (i=0; i < pSet->descriptorCount; i++) {
1171 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001172 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 -06001173 }
1174 }
1175#define NUM_COLORS 7
1176 vector<string> edgeColors;
1177 edgeColors.push_back("0000ff");
1178 edgeColors.push_back("ff00ff");
1179 edgeColors.push_back("ffff00");
1180 edgeColors.push_back("00ff00");
1181 edgeColors.push_back("000000");
1182 edgeColors.push_back("00ffff");
1183 edgeColors.push_back("ff0000");
1184 uint32_t colorIdx = 0;
1185 fprintf(pOutFile, "</TABLE>>\n];\n");
1186 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001187 VkUpdateSamplers* pUS = NULL;
1188 VkUpdateSamplerTextures* pUST = NULL;
1189 VkUpdateImages* pUI = NULL;
1190 VkUpdateBuffers* pUB = NULL;
1191 VkUpdateAsCopy* pUAC = NULL;
1192 VkSamplerCreateInfo* pSCI = NULL;
1193 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001194 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001195 void** ppNextPtr = NULL;
1196 void* pSaveNext = NULL;
1197 for (i=0; i < pSet->descriptorCount; i++) {
1198 if (pSet->ppDescriptors[i]) {
1199 switch (pSet->ppDescriptors[i]->sType)
1200 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001201 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001202 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001203 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001204 if (pSCI) {
1205 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001206 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001207 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1208 }
1209 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001210 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001211 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterf39b3ec2015-04-09 11:43:10 -06001212 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001213 if (pSCI) {
1214 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001215 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001216 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1217 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001218 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001219 if (pIVCI) {
1220 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001221 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001222 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1223 }
1224 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001225 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001226 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001227 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001228 if (pIVCI) {
1229 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001230 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001231 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1232 }
1233 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001234 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001235 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001236 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001237 if (pBVCI) {
1238 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001239 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001240 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1241 }
1242 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001243 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001244 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001245 // TODO : Need to validate this code
1246 // Save off pNext and set to NULL while printing this struct, then restore it
1247 ppNextPtr = (void**)&pUAC->pNext;
1248 pSaveNext = *ppNextPtr;
1249 *ppNextPtr = NULL;
1250 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001251 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001252 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1253 // Restore next ptr
1254 *ppNextPtr = pSaveNext;
1255 break;
1256 default:
1257 break;
1258 }
1259 colorIdx = (colorIdx+1) % NUM_COLORS;
1260 }
1261 }
1262 }
1263 fprintf(pOutFile, "}\n");
1264 fprintf(pOutFile, "}\n");
1265 }
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001266#endif
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001267}
1268// Dump subgraph w/ DS info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001269static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001270{
1271 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1272 if (pCB && pCB->lastBoundDescriptorSet) {
1273 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1274 }
1275}
1276// Dump a GraphViz dot file showing the Cmd Buffers
1277static void cbDumpDotFile(string outFileName)
1278{
1279 // Print CB Chain for each CB
1280 FILE* pOutFile;
1281 pOutFile = fopen(outFileName.c_str(), "w");
1282 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1283 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1284 GLOBAL_CB_NODE* pCB = NULL;
1285 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1286 pCB = g_pLastTouchedCB[i];
David Pinedod8f83d82015-04-27 16:36:17 -06001287 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001288 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1289 uint32_t instNum = 0;
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001290 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1291 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001292 if (instNum) {
1293 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1294 }
1295 if (pCB == g_lastGlobalCB) {
1296 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());
Tobin Ehlisce132d82015-06-19 15:07:05 -06001297 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001298 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());
1299 }
1300 ++instNum;
1301 }
1302 fprintf(pOutFile, "}\n");
1303 }
1304 }
1305 fprintf(pOutFile, "}\n");
1306 fprintf(pOutFile, "}\n"); // close main graph "g"
1307 fclose(pOutFile);
1308}
1309// Dump a GraphViz dot file showing the pipeline for last bound global state
1310static void dumpGlobalDotFile(char *outFileName)
1311{
1312 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1313 if (pPipeTrav) {
1314 FILE* pOutFile;
1315 pOutFile = fopen(outFileName, "w");
1316 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1317 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1318 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001319 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001320 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001321 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001322 fprintf(pOutFile, "%s", pGVstr);
1323 free(pGVstr);
1324 }
1325 }
1326 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1327 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001328 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001329 fprintf(pOutFile, "%s", pGVstr);
1330 free(pGVstr);
1331 fprintf(pOutFile, "}\n");
1332 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1333 fprintf(pOutFile, "}\n"); // close main graph "g"
1334 fclose(pOutFile);
1335 }
1336}
1337// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001338static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001339{
1340 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1341 if (pCB) {
1342 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1343 if (pPipeTrav) {
1344 FILE* pOutFile;
1345 pOutFile = fopen(outFileName.c_str(), "w");
1346 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1347 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1348 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001349 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001350 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001351 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001352 fprintf(pOutFile, "%s", pGVstr);
1353 free(pGVstr);
1354 }
1355 }
1356 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1357 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001358 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001359 fprintf(pOutFile, "%s", pGVstr);
1360 free(pGVstr);
1361 fprintf(pOutFile, "}\n");
1362 dsDumpDot(cb, pOutFile);
1363 fprintf(pOutFile, "}\n"); // close main graph "g"
1364 fclose(pOutFile);
1365 }
1366 }
1367}
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001368// Verify bound Pipeline State Object
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001369static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001370{
1371 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1372 if (pCB && pCB->lastBoundPipeline) {
1373 // First verify that we have a Node for bound pipeline
1374 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1375 char str[1024];
1376 if (!pPipeTrav) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001377 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1378 "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001379 return false;
Tobin Ehlisce132d82015-06-19 15:07:05 -06001380 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001381 // Verify Vtx binding
1382 if (MAX_BINDING != pCB->lastVtxBinding) {
1383 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1384 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001385 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1386 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001387 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001388 }
1389 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001390 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
1391 "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 -06001392 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001393 }
1394 }
1395 else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001396 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1397 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001398 }
1399 }
1400 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001401 return true;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001402 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001403 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001404}
1405// Print details of DS config to stdout
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001406static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001407{
1408 char tmp_str[1024];
1409 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.
1410 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06001411 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001412 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001413 POOL_NODE* pPool = getPoolNode(pSet->pool);
1414 // Print out pool details
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001415 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1416 "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001417 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001418 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1419 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001420 // Print out set details
1421 char prefix[10];
1422 uint32_t index = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001423 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1424 "Details for descriptor set %p.", (void*)pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001425 LAYOUT_NODE* pLayout = pSet->pLayout;
1426 // Print layout details
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001427 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1428 "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001429 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001430 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001431 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1432 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06001433 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001434 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1435 if (pUpdate) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001436 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1437 "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001438 sprintf(prefix, " [UC] ");
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001439 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1440 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001441 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06001442 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001443 if (0 != pSet->descriptorCount) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001444 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1445 "No Update Chain for descriptor set %p which has %u descriptors (vkUpdateDescriptors has not been called)", (void*)pSet->set, pSet->descriptorCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001446 } else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001447 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1448 "FYI: No descriptors in descriptor set %p.", (void*)pSet->set);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001449 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001450 }
1451 }
1452}
1453
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001454static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001455{
1456 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001457 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001458 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS",
1459 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001460 vector<CMD_NODE*> pCmds = pCB->pCmds;
1461 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001462 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, DRAWSTATE_NONE, "DS",
1463 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001464 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06001465 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001466 // Nothing to print
1467 }
1468}
1469
1470
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001471static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001472{
1473 printDSConfig(cb);
1474 printPipeline(cb);
1475 printDynamicState(cb);
1476 static int autoDumpOnce = 0;
1477 if (autoDumpOnce) {
1478 autoDumpOnce = 0;
1479 dumpDotFile(cb, "pipeline_dump.dot");
1480 cbDumpDotFile("cb_dump.dot");
1481#if defined(_WIN32)
1482// FIXME: NEED WINDOWS EQUIVALENT
1483#else // WIN32
1484 // Convert dot to svg if dot available
1485 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbourf20f87b2015-04-22 09:02:32 -06001486 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1487 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001488 }
1489#endif // WIN32
1490 }
1491}
1492
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001493static void init_draw_state(layer_data *my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001494{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001495 uint32_t report_flags = 0;
1496 uint32_t debug_action = 0;
1497 FILE *log_output = NULL;
1498 const char *option_str;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001499 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001500 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1501 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001502
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001503 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001504 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001505 option_str = getLayerOption("DrawStateLogFilename");
1506 if (option_str)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001507 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001508 log_output = fopen(option_str, "w");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001509 }
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001510 if (log_output == NULL)
1511 log_output = stdout;
1512
1513 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 -06001514 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001515
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001516 if (!globalLockInitialized)
1517 {
1518 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001519 // suggestion is to call this during vkCreateInstance(), and then we
1520 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001521 // that the layer have per-instance locks. We need to come back and
1522 // address this soon.
1523 loader_platform_thread_create_mutex(&globalLock);
1524 globalLockInitialized = 1;
1525 }
1526}
1527
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001528VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1529{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001530 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001531 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1532
1533 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001534 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1535 my_data->report_data = debug_report_create_instance(
1536 pTable,
1537 *pInstance,
1538 pCreateInfo->extensionCount,
1539 pCreateInfo->pEnabledExtensions);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001540
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001541 init_draw_state(my_data);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001542 }
1543 return result;
1544}
1545
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001546/* hook DestroyInstance to remove tableInstanceMap entry */
1547VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1548{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001549 dispatch_key key = get_dispatch_key(instance);
1550 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1551 VkResult res = pTable->DestroyInstance(instance);
1552
1553 // Clean up logging callback, if any
1554 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1555 if (my_data->logging_callback) {
1556 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1557 }
1558
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001559 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001560 layer_data_map.erase(pTable);
1561
1562 draw_state_instance_table_map.erase(key);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001563 return res;
1564}
1565
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001566static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1567{
1568 uint32_t i, ext_idx;
Jon Ashburn747f2b62015-06-18 15:02:58 -06001569 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburneab34492015-06-01 09:37:38 -06001570 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001571
1572 for (i = 0; i < pCreateInfo->extensionCount; i++) {
1573 if (strcmp(pCreateInfo->pEnabledExtensions[i].name, DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06001574 /* Found a matching extension name, mark it enabled and init dispatch table*/
1575 initDebugMarkerTable(device);
1576 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001577 }
1578
1579 }
1580}
1581
Tony Barbourd1c35722015-04-16 15:59:00 -06001582VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001583{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06001584 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1585 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001586 if (result == VK_SUCCESS) {
1587 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1588 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1589 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1590 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001591 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001592 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001593 return result;
1594}
1595
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001596VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001597{
1598 // Free all the memory
1599 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001600 deletePipelines();
1601 deleteSamplers();
1602 deleteImages();
1603 deleteBuffers();
1604 deleteCmdBuffers();
1605 deleteDynamicState();
1606 deletePools();
1607 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001608 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001609
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001610 dispatch_key key = get_dispatch_key(device);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001611 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1612 VkResult result = pDisp->DestroyDevice(device);
1613 deviceExtMap.erase(pDisp);
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001614 draw_state_device_table_map.erase(key);
Jon Ashburneab34492015-06-01 09:37:38 -06001615 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001616 return result;
1617}
1618
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001619struct extProps {
1620 uint32_t version;
1621 const char * const name;
1622};
Jon Ashburna050a8a2015-06-15 16:08:39 -06001623#define DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE 3
1624static const VkExtensionProperties dsDevExts[DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001625 {
1626 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1627 "DrawState",
1628 0x10,
1629 "Sample layer: DrawState",
Courtney Goeltzenleuchter491d59d2015-06-01 14:34:25 -06001630 },
1631 {
1632 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1633 "Validation",
1634 0x10,
1635 "Sample layer: DrawState",
Jon Ashburna050a8a2015-06-15 16:08:39 -06001636 },
1637 {
1638 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1639 DEBUG_MARKER_EXTENSION_NAME,
1640 0x10,
1641 "Sample layer: DrawState",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001642 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001643};
1644
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001645//TODO add DEBUG_MARKER to device extension list
Tony Barbour59a47322015-06-24 16:06:58 -06001646VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionCount(
1647 VkPhysicalDevice gpu,
1648 uint32_t* pCount)
Jon Ashburn2b850e52015-06-15 12:21:02 -06001649{
Tony Barbour59a47322015-06-24 16:06:58 -06001650 *pCount = DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE;
1651 return VK_SUCCESS;
1652}
Jon Ashburn2b850e52015-06-15 12:21:02 -06001653
Tony Barbour59a47322015-06-24 16:06:58 -06001654VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1655 VkPhysicalDevice gpu,
1656 uint32_t extensionIndex,
1657 VkExtensionProperties* pProperties)
1658{
1659 if (extensionIndex >= DRAW_STATE_LAYER_DEV_EXT_ARRAY_SIZE)
1660 return VK_ERROR_INVALID_VALUE;
1661 memcpy(pProperties, &dsDevExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn2b850e52015-06-15 12:21:02 -06001662
1663 return VK_SUCCESS;
1664}
1665
Jon Ashburna050a8a2015-06-15 16:08:39 -06001666#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 2
1667static const VkExtensionProperties dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1668 {
1669 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1670 "DrawState",
1671 0x10,
1672 "Sample layer: DrawState",
1673 },
1674 {
1675 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1676 "Validation",
1677 0x10,
1678 "Sample layer: DrawState",
1679 }
1680};
Tony Barbour59a47322015-06-24 16:06:58 -06001681VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionCount(
1682 uint32_t* pCount)
1683{
1684 *pCount = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1685 return VK_SUCCESS;
1686}
Jon Ashburna050a8a2015-06-15 16:08:39 -06001687
Tony Barbour59a47322015-06-24 16:06:58 -06001688VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001689 uint32_t extensionIndex,
Tony Barbour59a47322015-06-24 16:06:58 -06001690 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001691{
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001692 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Tony Barbour59a47322015-06-24 16:06:58 -06001693 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1694 return VK_ERROR_INVALID_VALUE;
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001695
Tony Barbour59a47322015-06-24 16:06:58 -06001696 memcpy(pProperties, &dsExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001697
1698 return VK_SUCCESS;
1699}
1700
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001701VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001702{
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001703 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001704 for (uint32_t i=0; i < cmdBufferCount; i++) {
1705 // Validate that cmd buffers have been updated
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001706 pCB = getCBNode(pCmdBuffers[i]);
1707 loader_platform_thread_lock_mutex(&globalLock);
1708 if (CB_UPDATE_COMPLETE != pCB->state) {
1709 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001710 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, pCB->cmdBuffer, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1711 "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001712 loader_platform_thread_unlock_mutex(&globalLock);
1713 return VK_ERROR_UNKNOWN;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001714 }
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06001715 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001716 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001717
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001718 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001719 return result;
1720}
1721
Mike Stroyanb050c682015-04-17 12:36:38 -06001722VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001723{
1724 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001725 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyObject(device, objType, object);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001726 return result;
1727}
1728
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001729VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001730{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001731 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001732 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001733 loader_platform_thread_lock_mutex(&globalLock);
1734 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1735 pNewNode->buffer = *pView;
1736 pNewNode->createInfo = *pCreateInfo;
1737 bufferMap[*pView] = pNewNode;
1738 loader_platform_thread_unlock_mutex(&globalLock);
1739 }
1740 return result;
1741}
1742
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001743VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001744{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001745 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001746 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001747 loader_platform_thread_lock_mutex(&globalLock);
1748 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1749 pNewNode->image = *pView;
1750 pNewNode->createInfo = *pCreateInfo;
1751 imageMap[*pView] = pNewNode;
1752 loader_platform_thread_unlock_mutex(&globalLock);
1753 }
1754 return result;
1755}
1756
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001757VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001758{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001759 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
1760 // The order of operations here is a little convoluted but gets the job done
1761 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1762 // 2. Create state is then validated (which uses flags setup during shadowing)
1763 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1764 loader_platform_thread_lock_mutex(&globalLock);
1765 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfo, NULL);
1766 bool32_t valid = verifyPipelineCreateState(device, pPipeNode);
1767 loader_platform_thread_unlock_mutex(&globalLock);
1768 if (VK_TRUE == valid) {
1769 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
1770 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS",
1771 "Created Gfx Pipeline %p", (void*)*pPipeline);
1772 loader_platform_thread_lock_mutex(&globalLock);
1773 pPipeNode->pipeline = *pPipeline;
1774 pipelineMap[pPipeNode->pipeline] = pPipeNode;
1775 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001776 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001777 if (pPipeNode) {
1778 // If we allocated a pipeNode, need to clean it up here
1779 delete[] pPipeNode->pVertexBindingDescriptions;
1780 delete[] pPipeNode->pVertexAttributeDescriptions;
1781 delete[] pPipeNode->pAttachments;
1782 delete pPipeNode;
1783 }
1784 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001785 return result;
1786}
1787
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001788VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1789 VkDevice device,
1790 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1791 VkPipeline basePipeline,
1792 VkPipeline* pPipeline)
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001793{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001794 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
1795 loader_platform_thread_lock_mutex(&globalLock);
1796 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfo, NULL);
1797 bool32_t valid = verifyPipelineCreateState(device, pipelineMap[basePipeline]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001798 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001799 if (VK_TRUE == valid) {
1800 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
1801 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS",
1802 "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
1803 loader_platform_thread_lock_mutex(&globalLock);
1804 pPipeNode->pipeline = *pPipeline;
1805 pipelineMap[pPipeNode->pipeline] = pPipeNode;
1806 loader_platform_thread_unlock_mutex(&globalLock);
1807 }
1808 else { // Skipped pipeline creation due to bad CreateInfo data
1809 if (pPipeNode) {
1810 // If we allocated a pipeNode, need to clean it up here
1811 delete[] pPipeNode->pVertexBindingDescriptions;
1812 delete[] pPipeNode->pVertexAttributeDescriptions;
1813 delete[] pPipeNode->pAttachments;
1814 delete pPipeNode;
1815 }
1816 }
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001817 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001818}
1819
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001820VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001821{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001822 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001823 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001824 loader_platform_thread_lock_mutex(&globalLock);
1825 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1826 pNewNode->sampler = *pSampler;
1827 pNewNode->createInfo = *pCreateInfo;
1828 sampleMap[*pSampler] = pNewNode;
1829 loader_platform_thread_unlock_mutex(&globalLock);
1830 }
1831 return result;
1832}
1833
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001834VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001835{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001836 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001837 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001838 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1839 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001840 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1841 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001842 }
1843 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001844 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1845 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1846 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001847 uint32_t totalCount = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001848 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001849 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001850 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001851 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001852 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1853 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001854 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001855 }
1856 if (totalCount > 0) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001857 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001858 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001859 uint32_t j = 0;
1860 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001861 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001862 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001863 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001864 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001865 }
1866 }
1867 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001868 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001869 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1870 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001871 // Put new node at Head of global Layer list
1872 loader_platform_thread_lock_mutex(&globalLock);
1873 layoutMap[*pSetLayout] = pNewNode;
1874 loader_platform_thread_unlock_mutex(&globalLock);
1875 }
1876 return result;
1877}
1878
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001879VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001880{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001881 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001882 if (VK_SUCCESS == result) {
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001883 // TODO : Need to capture the pipeline layout
Tobin Ehlis793ad302015-04-03 12:01:11 -06001884 }
1885 return result;
1886}
1887
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001888VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001889{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001890 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001891 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001892 // Insert this pool into Global Pool LL at head
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001893 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1894 "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001895 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001896 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001897 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001898 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1899 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisce132d82015-06-19 15:07:05 -06001900 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001901 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001902 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1903 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001904 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001905 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1906 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001907 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1908 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001909 pNewNode->poolUsage = poolUsage;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001910 pNewNode->maxSets = maxSets;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001911 pNewNode->pool = *pDescriptorPool;
1912 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001913 }
1914 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001915 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001916 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001917 }
1918 return result;
1919}
1920
Mike Stroyanb050c682015-04-17 12:36:38 -06001921VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001922{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001923 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001924 if (VK_SUCCESS == result) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001925 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001926 }
1927 return result;
1928}
1929
Mike Stroyanb050c682015-04-17 12:36:38 -06001930VK_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 -06001931{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001932 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 -06001933 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001934 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1935 if (!pPoolNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001936 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS",
1937 "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001938 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001939 for (uint32_t i = 0; i < *pCount; i++) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001940 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
1941 "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001942 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001943 SET_NODE* pNewNode = new SET_NODE;
1944 if (NULL == pNewNode) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001945 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1946 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisce132d82015-06-19 15:07:05 -06001947 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001948 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001949 // Insert set at head of Set LL for this pool
1950 pNewNode->pNext = pPoolNode->pSets;
1951 pPoolNode->pSets = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001952 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1953 if (NULL == pLayout) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001954 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1955 "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001956 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001957 pNewNode->pLayout = pLayout;
1958 pNewNode->pool = descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001959 pNewNode->set = pDescriptorSets[i];
1960 pNewNode->setUsage = setUsage;
1961 pNewNode->descriptorCount = pLayout->endIndex + 1;
1962 if (pNewNode->descriptorCount) {
1963 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1964 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1965 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1966 }
1967 setMap[pDescriptorSets[i]] = pNewNode;
1968 }
1969 }
1970 }
1971 }
1972 return result;
1973}
1974
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001975VK_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 -06001976{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001977 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1978 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001979 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001980 }
1981 return VK_ERROR_UNKNOWN;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001982}
1983
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001984VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001985{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001986 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001987 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001988 return result;
1989}
1990
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001991VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001992{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001993 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001994 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001995 return result;
1996}
1997
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001998VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001999{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002000 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06002001 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002002 return result;
2003}
2004
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06002005VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
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)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06002008 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002009 return result;
2010}
2011
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002012VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002013{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002014 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002015 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002016 loader_platform_thread_lock_mutex(&globalLock);
2017 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2018 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2019 pCB->cmdBuffer = *pCmdBuffer;
2020 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07002021 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002022 pCB->lastVtxBinding = MAX_BINDING;
2023 cmdBufferMap[*pCmdBuffer] = pCB;
2024 loader_platform_thread_unlock_mutex(&globalLock);
2025 updateCBTracking(*pCmdBuffer);
2026 }
2027 return result;
2028}
2029
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002030VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002031{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002032 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002033 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002034 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2035 if (pCB) {
2036 if (CB_NEW != pCB->state)
2037 resetCB(cmdBuffer);
2038 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002039 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002040 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002041 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002042 if (pCbGfxBI->renderPassContinue.renderPass)
2043 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
2044 else
2045 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
2046 "You cannot use a NULL RenderPass object in vkCmdBeginCommandBuffer()");
Tobin Ehliseba312c2015-04-01 08:40:34 -06002047 }
2048 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002049 } else {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002050 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
2051 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002052 }
2053 updateCBTracking(cmdBuffer);
2054 }
2055 return result;
2056}
2057
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002058VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002059{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002060 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2061 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2062 if (pCB) {
2063 if (pCB->state == CB_UPDATE_ACTIVE) {
2064 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2065 if (VK_SUCCESS == result) {
2066 updateCBTracking(cmdBuffer);
2067 pCB->state = CB_UPDATE_COMPLETE;
2068 // Reset CB status flags
2069 pCB->status = 0;
2070 printCB(cmdBuffer);
2071 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002072 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002073 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002074 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002075 }
2076 return result;
2077}
2078
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002079VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002080{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002081 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002082 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002083 resetCB(cmdBuffer);
2084 updateCBTracking(cmdBuffer);
2085 }
2086 return result;
2087}
2088
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002089VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002090{
2091 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2092 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002093 if (pCB->state == CB_UPDATE_ACTIVE) {
2094 updateCBTracking(cmdBuffer);
2095 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis6d58e6d2015-06-23 08:46:18 -06002096 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
2097 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2098 "Incorrectly binding compute pipeline (%p) during active RenderPass (%p)", (void*)pipeline, (void*)pCB->activeRenderPass);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002099 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
2100 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2101 "Incorrectly binding graphics pipeline (%p) without an active RenderPass", (void*)pipeline);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002102 } else {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002103 PIPELINE_NODE* pPN = getPipeline(pipeline);
2104 if (pPN) {
2105 pCB->lastBoundPipeline = pipeline;
2106 loader_platform_thread_lock_mutex(&globalLock);
2107 set_cb_pso_status(pCB, pPN);
2108 g_lastBoundPipeline = pPN;
2109 loader_platform_thread_unlock_mutex(&globalLock);
2110 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2111 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2112 } else {
2113 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2114 "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
2115 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002116 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002117 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002118 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002119 }
2120 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002121}
2122
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002123VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002124{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002125 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2126 if (pCB) {
2127 if (pCB->state == CB_UPDATE_ACTIVE) {
2128 updateCBTracking(cmdBuffer);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002129 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
2130 if (!pCB->activeRenderPass) {
2131 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2132 "Incorrect call to vkCmdBindDynamicStateObject() without an active RenderPass.");
2133 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002134 loader_platform_thread_lock_mutex(&globalLock);
2135 set_cb_dyn_status(pCB, stateBindPoint);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002136 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
Tobin Ehlisc01988b2015-06-23 10:52:08 -06002137 VkObjectType stateType;
2138 switch (stateBindPoint) {
2139 case VK_STATE_BIND_POINT_VIEWPORT:
2140 stateType = VK_OBJECT_TYPE_DYNAMIC_VP_STATE;
2141 break;
2142 case VK_STATE_BIND_POINT_RASTER:
2143 stateType = VK_OBJECT_TYPE_DYNAMIC_RS_STATE;
2144 break;
2145 case VK_STATE_BIND_POINT_COLOR_BLEND:
2146 stateType = VK_OBJECT_TYPE_DYNAMIC_CB_STATE;
2147 break;
2148 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
2149 stateType = VK_OBJECT_TYPE_DYNAMIC_DS_STATE;
2150 break;
2151 default:
2152 stateType = (VkObjectType) 0;
2153 }
2154 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, stateType, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002155 "Unable to find dynamic state object %p, was it ever created?", (void*)state);
2156 } else {
2157 pCB->lastBoundDynamicState[stateBindPoint] = dynamicStateMap[state];
2158 g_lastBoundDynamicState[stateBindPoint] = dynamicStateMap[state];
2159 }
2160 loader_platform_thread_unlock_mutex(&globalLock);
2161 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2162 } else {
2163 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicStateObject()");
2164 }
2165 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002166}
2167
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06002168VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002169{
2170 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2171 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002172 if (pCB->state == CB_UPDATE_ACTIVE) {
2173 updateCBTracking(cmdBuffer);
2174 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002175 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
2176 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2177 "Incorrectly binding compute DescriptorSets during active RenderPass (%p)", (void*)pCB->activeRenderPass);
2178 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
2179 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2180 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2181 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002182 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002183 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2184 if (pSet) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002185 loader_platform_thread_lock_mutex(&globalLock);
2186 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002187 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002188 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2189 g_lastBoundDescriptorSet = pDescriptorSets[i];
2190 loader_platform_thread_unlock_mutex(&globalLock);
2191 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS",
2192 "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002193 if (!pSet->pUpdateStructs)
2194 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2195 "DS %p bound but it was never updated. You may want to either update it or not bind it.", (void*)pDescriptorSets[i]);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002196 } else {
2197 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS",
2198 "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
2199 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002200 }
Tobin Ehlis7ae7c6a2015-06-22 18:00:14 -06002201 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002202 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002203 } else {
2204 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002205 }
2206 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002207}
2208
Tony Barbourd1c35722015-04-16 15:59:00 -06002209VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002210{
2211 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2212 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002213 if (pCB->state == CB_UPDATE_ACTIVE) {
2214 updateCBTracking(cmdBuffer);
2215 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002216 if (!pCB->activeRenderPass) {
2217 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2218 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2219 } else {
2220 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2221 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
2222 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2223 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002224 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002225 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2226 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002227 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002228}
2229
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002230VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2231 VkCmdBuffer cmdBuffer,
2232 uint32_t startBinding,
2233 uint32_t bindingCount,
2234 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002235 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002236{
2237 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2238 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002239 if (pCB->state == CB_UPDATE_ACTIVE) {
2240 /* TODO: Need to track all the vertex buffers, not just last one */
2241 updateCBTracking(cmdBuffer);
2242 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002243 if (!pCB->activeRenderPass) {
2244 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2245 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2246 } else {
2247 pCB->lastVtxBinding = startBinding + bindingCount -1;
2248 if (validateBoundPipeline(cmdBuffer)) {
2249 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2250 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002251 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002252 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002253 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002254 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002255 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002256}
2257
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002258VK_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 -06002259{
2260 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002261 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002262 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002263 if (pCB->state == CB_UPDATE_ACTIVE) {
2264 updateCBTracking(cmdBuffer);
2265 addCmd(pCB, CMD_DRAW);
2266 pCB->drawCount[DRAW]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002267 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002268 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2269 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2270 synchAndPrintDSConfig(cmdBuffer);
2271 if (valid) {
2272 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2273 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002274 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002275 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2276 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002277 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002278}
2279
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002280VK_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 -06002281{
2282 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002283 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002284 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002285 if (pCB->state == CB_UPDATE_ACTIVE) {
2286 updateCBTracking(cmdBuffer);
2287 addCmd(pCB, CMD_DRAWINDEXED);
2288 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002289 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002290 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2291 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2292 synchAndPrintDSConfig(cmdBuffer);
2293 if (valid) {
2294 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2295 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002296 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002297 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2298 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002299 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002300}
2301
Tony Barbourd1c35722015-04-16 15:59:00 -06002302VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002303{
2304 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002305 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002306 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002307 if (pCB->state == CB_UPDATE_ACTIVE) {
2308 updateCBTracking(cmdBuffer);
2309 addCmd(pCB, CMD_DRAWINDIRECT);
2310 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002311 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002312 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2313 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2314 synchAndPrintDSConfig(cmdBuffer);
2315 if (valid) {
2316 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2317 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002318 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002319 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2320 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002321 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002322}
2323
Tony Barbourd1c35722015-04-16 15:59:00 -06002324VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002325{
2326 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlise382c5a2015-06-10 12:57:07 -06002327 bool32_t valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002328 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002329 if (pCB->state == CB_UPDATE_ACTIVE) {
2330 updateCBTracking(cmdBuffer);
2331 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2332 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002333 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002334 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS",
2335 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2336 synchAndPrintDSConfig(cmdBuffer);
2337 if (valid) {
2338 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2339 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002340 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002341 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2342 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002343 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002344}
2345
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002346VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002347{
2348 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2349 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002350 if (pCB->state == CB_UPDATE_ACTIVE) {
2351 updateCBTracking(cmdBuffer);
2352 addCmd(pCB, CMD_DISPATCH);
2353 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002354 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002355 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2356 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002357 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002358}
2359
Tony Barbourd1c35722015-04-16 15:59:00 -06002360VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002361{
2362 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2363 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002364 if (pCB->state == CB_UPDATE_ACTIVE) {
2365 updateCBTracking(cmdBuffer);
2366 addCmd(pCB, CMD_DISPATCHINDIRECT);
2367 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002368 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002369 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2370 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002371 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002372}
2373
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002374VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002375{
2376 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2377 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002378 if (pCB->state == CB_UPDATE_ACTIVE) {
2379 updateCBTracking(cmdBuffer);
2380 addCmd(pCB, CMD_COPYBUFFER);
2381 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002382 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002383 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2384 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002385 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002386}
2387
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002388VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2389 VkImage srcImage,
2390 VkImageLayout srcImageLayout,
2391 VkImage destImage,
2392 VkImageLayout destImageLayout,
2393 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002394{
2395 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2396 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002397 if (pCB->state == CB_UPDATE_ACTIVE) {
2398 updateCBTracking(cmdBuffer);
2399 addCmd(pCB, CMD_COPYIMAGE);
2400 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002401 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002402 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2403 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002404 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002405}
2406
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002407VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2408 VkImage srcImage, VkImageLayout srcImageLayout,
2409 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002410 uint32_t regionCount, const VkImageBlit* pRegions,
2411 VkTexFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002412{
2413 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2414 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002415 if (pCB->state == CB_UPDATE_ACTIVE) {
2416 updateCBTracking(cmdBuffer);
2417 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehliseac83792015-06-23 10:41:13 -06002418 if (pCB->activeRenderPass) {
2419 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2420 "Incorrectly issuing CmdBlitImage during active RenderPass (%p)", (void*)pCB->activeRenderPass);
2421 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06002422 else
2423 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002424 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002425 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2426 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002427 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002428}
2429
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002430VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2431 VkBuffer srcBuffer,
2432 VkImage destImage, VkImageLayout destImageLayout,
2433 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002434{
2435 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2436 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002437 if (pCB->state == CB_UPDATE_ACTIVE) {
2438 updateCBTracking(cmdBuffer);
2439 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2440 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002441 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002442 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2443 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002444 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002445}
2446
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002447VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2448 VkImage srcImage, VkImageLayout srcImageLayout,
2449 VkBuffer destBuffer,
2450 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002451{
2452 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2453 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002454 if (pCB->state == CB_UPDATE_ACTIVE) {
2455 updateCBTracking(cmdBuffer);
2456 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2457 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002458 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002459 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2460 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002461 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002462}
2463
Tony Barbourd1c35722015-04-16 15:59:00 -06002464VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002465{
2466 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2467 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002468 if (pCB->state == CB_UPDATE_ACTIVE) {
2469 updateCBTracking(cmdBuffer);
2470 addCmd(pCB, CMD_UPDATEBUFFER);
2471 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002472 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002473 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2474 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002475 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002476}
2477
Tony Barbourd1c35722015-04-16 15:59:00 -06002478VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002479{
2480 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2481 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002482 if (pCB->state == CB_UPDATE_ACTIVE) {
2483 updateCBTracking(cmdBuffer);
2484 addCmd(pCB, CMD_FILLBUFFER);
2485 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002486 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002487 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2488 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002489 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490}
2491
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002492VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2493 VkCmdBuffer cmdBuffer,
2494 VkImage image, VkImageLayout imageLayout,
2495 const VkClearColor *pColor,
2496 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002497{
2498 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2499 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002500 if (pCB->state == CB_UPDATE_ACTIVE) {
2501 updateCBTracking(cmdBuffer);
2502 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2503 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002504 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002505 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2506 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002507 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002508}
2509
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002510VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2511 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002512 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002513 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002514{
2515 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2516 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002517 if (pCB->state == CB_UPDATE_ACTIVE) {
2518 updateCBTracking(cmdBuffer);
2519 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2520 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002521 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002522 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2523 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002524 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002525}
2526
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002527VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2528 VkImage srcImage, VkImageLayout srcImageLayout,
2529 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002530 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002531{
2532 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2533 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002534 if (pCB->state == CB_UPDATE_ACTIVE) {
2535 updateCBTracking(cmdBuffer);
2536 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002537 if (pCB->activeRenderPass) {
2538 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2539 "Cannot call vkCmdResolveImage() during an active RenderPass (%p).", (void*)pCB->activeRenderPass);
2540 }
2541 else
2542 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002543 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002544 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2545 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002546 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002547}
2548
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002549VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002550{
2551 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2552 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002553 if (pCB->state == CB_UPDATE_ACTIVE) {
2554 updateCBTracking(cmdBuffer);
2555 addCmd(pCB, CMD_SETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002556 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002557 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002558 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2559 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002560 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002561}
2562
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002563VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002564{
2565 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2566 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002567 if (pCB->state == CB_UPDATE_ACTIVE) {
2568 updateCBTracking(cmdBuffer);
2569 addCmd(pCB, CMD_RESETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002570 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002571 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002572 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2573 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002574 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002575}
2576
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002577VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags destStageMask, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002578{
2579 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2580 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002581 if (pCB->state == CB_UPDATE_ACTIVE) {
2582 updateCBTracking(cmdBuffer);
2583 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002584 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002585 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002586 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2587 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002588 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002589}
2590
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002591VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags destStageMask, bool32_t byRegion, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002592{
2593 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2594 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002595 if (pCB->state == CB_UPDATE_ACTIVE) {
2596 updateCBTracking(cmdBuffer);
2597 addCmd(pCB, CMD_PIPELINEBARRIER);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002598 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, sourceStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002599 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002600 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2601 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002602 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002603}
2604
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002605VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002606{
2607 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2608 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002609 if (pCB->state == CB_UPDATE_ACTIVE) {
2610 updateCBTracking(cmdBuffer);
2611 addCmd(pCB, CMD_BEGINQUERY);
2612 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002613 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002614 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2615 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002616 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002617}
2618
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002619VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002620{
2621 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2622 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002623 if (pCB->state == CB_UPDATE_ACTIVE) {
2624 updateCBTracking(cmdBuffer);
2625 addCmd(pCB, CMD_ENDQUERY);
2626 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002627 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002628 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2629 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002630 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002631}
2632
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002633VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002634{
2635 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2636 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002637 if (pCB->state == CB_UPDATE_ACTIVE) {
2638 updateCBTracking(cmdBuffer);
2639 addCmd(pCB, CMD_RESETQUERYPOOL);
2640 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002641 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002642 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2643 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002644 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002645}
2646
Tony Barbourd1c35722015-04-16 15:59:00 -06002647VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002648{
2649 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2650 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002651 if (pCB->state == CB_UPDATE_ACTIVE) {
2652 updateCBTracking(cmdBuffer);
2653 addCmd(pCB, CMD_WRITETIMESTAMP);
2654 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002655 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002656 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2657 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002658 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002659}
2660
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002661VK_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 -06002662{
2663 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2664 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002665 if (pCB->state == CB_UPDATE_ACTIVE) {
2666 updateCBTracking(cmdBuffer);
2667 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2668 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002669 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002670 report_error_no_cb_begin(cmdBuffer, "vkCmdInitAtomicCounters()");
2671 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002672 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002673}
2674
Tony Barbourd1c35722015-04-16 15:59:00 -06002675VK_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 -06002676{
2677 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2678 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002679 if (pCB->state == CB_UPDATE_ACTIVE) {
2680 updateCBTracking(cmdBuffer);
2681 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2682 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002683 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002684 report_error_no_cb_begin(cmdBuffer, "vkCmdLoadAtomicCounters()");
2685 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002686 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002687}
2688
Tony Barbourd1c35722015-04-16 15:59:00 -06002689VK_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 -06002690{
2691 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2692 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002693 if (pCB->state == CB_UPDATE_ACTIVE) {
2694 updateCBTracking(cmdBuffer);
2695 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2696 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002697 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002698 report_error_no_cb_begin(cmdBuffer, "vkCmdSaveAtomicCounters()");
2699 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002700 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002701}
2702
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002703VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002704{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002705 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002706 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002707 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002708 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002709 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002710 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2711 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002712 }
2713 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002714 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2715 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002716 }
2717 frameBufferMap[*pFramebuffer] = localFBCI;
2718 }
2719 return result;
2720}
2721
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002722VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002723{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002724 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002725 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002726 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002727 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002728 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002729 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2730 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002731 }
2732 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002733 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2734 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002735 }
2736 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002737 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2738 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002739 }
2740 renderPassMap[*pRenderPass] = localRPCI;
2741 }
2742 return result;
2743}
2744
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002745VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002746{
2747 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2748 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002749 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002750 if (pCB->activeRenderPass) {
2751 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2752 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%p). You must first call vkCmdEndRenderPass().", (void*)pCB->activeRenderPass);
2753 } else {
2754 updateCBTracking(cmdBuffer);
2755 addCmd(pCB, CMD_BEGINRENDERPASS);
2756 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2757 pCB->framebuffer = pRenderPassBegin->framebuffer;
2758 if (pCB->lastBoundPipeline) {
2759 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2760 }
2761 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis259730a2015-06-23 16:13:03 -06002762 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06002763 } else {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002764 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
2765 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06002766 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002767 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002768}
2769
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002770VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002771{
2772 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2773 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002774 if (renderPass) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002775 if (!pCB->activeRenderPass) {
2776 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2777 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
2778 } else {
2779 updateCBTracking(cmdBuffer);
2780 addCmd(pCB, CMD_ENDRENDERPASS);
2781 pCB->activeRenderPass = 0;
2782 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer, renderPass);
2783 }
Tobin Ehlis59a9c832015-06-23 16:13:03 -06002784 } else {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002785 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
2786 "You cannot use a NULL RenderPass object in vkCmdEndRenderPass()");
2787 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002788 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002789}
2790
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002791VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2792 VkInstance instance,
2793 VkFlags msgFlags,
2794 const PFN_vkDbgMsgCallback pfnMsgCallback,
2795 void* pUserData,
2796 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002797{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002798 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002799 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2800 if (VK_SUCCESS == res) {
2801 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2802 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2803 }
2804 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002805}
2806
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002807VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2808 VkInstance instance,
2809 VkDbgMsgCallback msgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002810{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002811 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002812 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2813 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2814 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2815 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002816}
2817
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002818VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002819{
2820 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002821 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2822 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002823 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2824 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002825 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06002826 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002827 updateCBTracking(cmdBuffer);
2828 addCmd(pCB, CMD_DBGMARKERBEGIN);
2829 }
Jon Ashburneab34492015-06-01 09:37:38 -06002830 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002831}
2832
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002833VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002834{
2835 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002836 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2837 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002838 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2839 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002840 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06002841 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002842 updateCBTracking(cmdBuffer);
2843 addCmd(pCB, CMD_DBGMARKEREND);
2844 }
Jon Ashburneab34492015-06-01 09:37:38 -06002845 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2846}
2847
2848VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2849{
2850 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2851 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002852 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2853 "Attempt to use DbgSetObjectTag but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002854 return VK_ERROR_UNAVAILABLE;
2855 }
2856 debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2857}
2858
2859VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2860{
2861 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2862 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002863 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2864 "Attempt to use DbgSetObjectName but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002865 return VK_ERROR_UNAVAILABLE;
2866 }
2867 debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002868}
2869
2870// TODO : Want to pass in a cmdBuffer here based on which state to display
2871void drawStateDumpDotFile(char* outFileName)
2872{
2873 // TODO : Currently just setting cmdBuffer based on global var
2874 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2875 dumpGlobalDotFile(outFileName);
2876}
2877
2878void drawStateDumpCommandBufferDotFile(char* outFileName)
2879{
2880 cbDumpDotFile(outFileName);
2881}
2882
Tobin Ehlis75283bf2015-06-18 15:59:33 -06002883void drawStateDumpPngFile(const VkDevice device, char* outFileName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002884{
2885#if defined(_WIN32)
2886// FIXME: NEED WINDOWS EQUIVALENT
Tobin Ehlis75283bf2015-06-18 15:59:33 -06002887 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 -06002888 "Cannot execute dot program yet on Windows.");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002889#else // WIN32
2890 char dotExe[32] = "/usr/bin/dot";
2891 if( access(dotExe, X_OK) != -1) {
2892 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2893 char dotCmd[1024];
2894 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbourf20f87b2015-04-22 09:02:32 -06002895 int retval = system(dotCmd);
2896 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002897 remove("/tmp/tmp.dot");
Tobin Ehlisce132d82015-06-19 15:07:05 -06002898 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -06002899 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 -06002900 "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002901 }
2902#endif // WIN32
2903}
2904
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002905VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002906{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002907 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002908 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002909
Jon Ashburn8fd08252015-05-28 16:25:02 -06002910 /* loader uses this to force layer initialization; device object is wrapped */
2911 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002912 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002913 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002914 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06002915 if (!strcmp(funcName, "vkCreateDevice"))
2916 return (void*) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002917 if (!strcmp(funcName, "vkDestroyDevice"))
2918 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002919 if (!strcmp(funcName, "vkQueueSubmit"))
2920 return (void*) vkQueueSubmit;
2921 if (!strcmp(funcName, "vkDestroyObject"))
2922 return (void*) vkDestroyObject;
2923 if (!strcmp(funcName, "vkCreateBufferView"))
2924 return (void*) vkCreateBufferView;
2925 if (!strcmp(funcName, "vkCreateImageView"))
2926 return (void*) vkCreateImageView;
2927 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2928 return (void*) vkCreateGraphicsPipeline;
2929 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2930 return (void*) vkCreateGraphicsPipelineDerivative;
2931 if (!strcmp(funcName, "vkCreateSampler"))
2932 return (void*) vkCreateSampler;
2933 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2934 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05002935 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2936 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002937 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2938 return (void*) vkCreateDescriptorPool;
2939 if (!strcmp(funcName, "vkResetDescriptorPool"))
2940 return (void*) vkResetDescriptorPool;
2941 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2942 return (void*) vkAllocDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08002943 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2944 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002945 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2946 return (void*) vkCreateDynamicViewportState;
2947 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2948 return (void*) vkCreateDynamicRasterState;
2949 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2950 return (void*) vkCreateDynamicColorBlendState;
2951 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2952 return (void*) vkCreateDynamicDepthStencilState;
2953 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2954 return (void*) vkCreateCommandBuffer;
2955 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2956 return (void*) vkBeginCommandBuffer;
2957 if (!strcmp(funcName, "vkEndCommandBuffer"))
2958 return (void*) vkEndCommandBuffer;
2959 if (!strcmp(funcName, "vkResetCommandBuffer"))
2960 return (void*) vkResetCommandBuffer;
Tony Barbour59a47322015-06-24 16:06:58 -06002961 if (!strcmp(funcName, "vkGetGlobalExtensionCount"))
2962 return (void*) vkGetGlobalExtensionCount;
2963 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
2964 return (void*) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002965 if (!strcmp(funcName, "vkCmdBindPipeline"))
2966 return (void*) vkCmdBindPipeline;
2967 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2968 return (void*) vkCmdBindDynamicStateObject;
2969 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2970 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002971 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2972 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002973 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2974 return (void*) vkCmdBindIndexBuffer;
2975 if (!strcmp(funcName, "vkCmdDraw"))
2976 return (void*) vkCmdDraw;
2977 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2978 return (void*) vkCmdDrawIndexed;
2979 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2980 return (void*) vkCmdDrawIndirect;
2981 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2982 return (void*) vkCmdDrawIndexedIndirect;
2983 if (!strcmp(funcName, "vkCmdDispatch"))
2984 return (void*) vkCmdDispatch;
2985 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2986 return (void*) vkCmdDispatchIndirect;
2987 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2988 return (void*) vkCmdCopyBuffer;
2989 if (!strcmp(funcName, "vkCmdCopyImage"))
2990 return (void*) vkCmdCopyImage;
2991 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2992 return (void*) vkCmdCopyBufferToImage;
2993 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2994 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002995 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2996 return (void*) vkCmdUpdateBuffer;
2997 if (!strcmp(funcName, "vkCmdFillBuffer"))
2998 return (void*) vkCmdFillBuffer;
2999 if (!strcmp(funcName, "vkCmdClearColorImage"))
3000 return (void*) vkCmdClearColorImage;
3001 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
3002 return (void*) vkCmdClearDepthStencil;
3003 if (!strcmp(funcName, "vkCmdResolveImage"))
3004 return (void*) vkCmdResolveImage;
3005 if (!strcmp(funcName, "vkCmdSetEvent"))
3006 return (void*) vkCmdSetEvent;
3007 if (!strcmp(funcName, "vkCmdResetEvent"))
3008 return (void*) vkCmdResetEvent;
3009 if (!strcmp(funcName, "vkCmdWaitEvents"))
3010 return (void*) vkCmdWaitEvents;
3011 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
3012 return (void*) vkCmdPipelineBarrier;
3013 if (!strcmp(funcName, "vkCmdBeginQuery"))
3014 return (void*) vkCmdBeginQuery;
3015 if (!strcmp(funcName, "vkCmdEndQuery"))
3016 return (void*) vkCmdEndQuery;
3017 if (!strcmp(funcName, "vkCmdResetQueryPool"))
3018 return (void*) vkCmdResetQueryPool;
3019 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
3020 return (void*) vkCmdWriteTimestamp;
3021 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
3022 return (void*) vkCmdInitAtomicCounters;
3023 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
3024 return (void*) vkCmdLoadAtomicCounters;
3025 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
3026 return (void*) vkCmdSaveAtomicCounters;
3027 if (!strcmp(funcName, "vkCreateFramebuffer"))
3028 return (void*) vkCreateFramebuffer;
3029 if (!strcmp(funcName, "vkCreateRenderPass"))
3030 return (void*) vkCreateRenderPass;
3031 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
3032 return (void*) vkCmdBeginRenderPass;
3033 if (!strcmp(funcName, "vkCmdEndRenderPass"))
3034 return (void*) vkCmdEndRenderPass;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003035 if (!strcmp("drawStateDumpDotFile", funcName))
3036 return (void*) drawStateDumpDotFile;
3037 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
3038 return (void*) drawStateDumpCommandBufferDotFile;
3039 if (!strcmp("drawStateDumpPngFile", funcName))
3040 return (void*) drawStateDumpPngFile;
Jon Ashburneab34492015-06-01 09:37:38 -06003041
Jon Ashburn747f2b62015-06-18 15:02:58 -06003042 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3043 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06003044 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06003045 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Jon Ashburneab34492015-06-01 09:37:38 -06003046 return (void*) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003047 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Jon Ashburneab34492015-06-01 09:37:38 -06003048 return (void*) vkCmdDbgMarkerEnd;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003049 if (!strcmp(funcName, "vkDbgSetObjectTag"))
Jon Ashburneab34492015-06-01 09:37:38 -06003050 return (void*) vkDbgSetObjectTag;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003051 if (!strcmp(funcName, "vkDbgSetObjectName"))
Jon Ashburneab34492015-06-01 09:37:38 -06003052 return (void*) vkDbgSetObjectName;
3053 }
3054 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06003055 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003056 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003057 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003058 }
3059}
3060
3061VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3062{
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003063 void *fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003064 if (instance == NULL)
3065 return NULL;
3066
Jon Ashburn8fd08252015-05-28 16:25:02 -06003067 /* loader uses this to force layer initialization; instance object is wrapped */
3068 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003069 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003070 return (void *) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003071 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003072 if (!strcmp(funcName, "vkCreateInstance"))
3073 return (void *) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003074 if (!strcmp(funcName, "vkDestroyInstance"))
3075 return (void *) vkDestroyInstance;
Tony Barbour59a47322015-06-24 16:06:58 -06003076 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionCount"))
3077 return (void*) vkGetPhysicalDeviceExtensionCount;
3078 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
3079 return (void*) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003080
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003081 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3082 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003083 if (fptr)
3084 return fptr;
3085
Jon Ashburn8fd08252015-05-28 16:25:02 -06003086 {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003087 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn8fd08252015-05-28 16:25:02 -06003088 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003089 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003090 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003091 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003092}