blob: fc7afa505e4f9707b028a40993801b443f1ee8a4 [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060036#include "vk_struct_graphviz_helper.h"
Tony Barboura938abb2015-04-22 11:36:22 -060037#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060038#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060039#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060040#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060041#include "draw_state.h"
42#include "layers_config.h"
43// The following is #included again to catch certain OS-specific functions
44// being used:
45#include "loader_platform.h"
46#include "layers_msg.h"
47
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060048unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
49unordered_map<VkImageView, IMAGE_NODE*> imageMap;
50unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
51unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
52unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
53unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
54unordered_map<VkDescriptorSet, SET_NODE*> setMap;
55unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060056// Map for layout chains
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060057unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
58unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
59unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060060
Jon Ashburne0fa2282015-05-20 09:00:28 -060061static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;
62static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;
63
Tobin Ehlis63bb9482015-03-17 16:24:32 -060064static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060065
Tobin Ehlis63bb9482015-03-17 16:24:32 -060066// TODO : This can be much smarter, using separate locks for separate global data
67static int globalLockInitialized = 0;
68static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060069#define MAX_TID 513
70static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
71static uint32_t g_maxTID = 0;
72// Map actual TID to an index value and return that index
73// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
74static uint32_t getTIDIndex() {
75 loader_platform_thread_id tid = loader_platform_get_thread_id();
76 for (uint32_t i = 0; i < g_maxTID; i++) {
77 if (tid == g_tidMapping[i])
78 return i;
79 }
80 // Don't yet have mapping, set it and return newly set index
81 uint32_t retVal = (uint32_t) g_maxTID;
82 g_tidMapping[g_maxTID++] = tid;
83 assert(g_maxTID < MAX_TID);
84 return retVal;
85}
86// Return a string representation of CMD_TYPE enum
87static string cmdTypeToString(CMD_TYPE cmd)
88{
89 switch (cmd)
90 {
91 case CMD_BINDPIPELINE:
92 return "CMD_BINDPIPELINE";
93 case CMD_BINDPIPELINEDELTA:
94 return "CMD_BINDPIPELINEDELTA";
95 case CMD_BINDDYNAMICSTATEOBJECT:
96 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060097 case CMD_BINDDESCRIPTORSETS:
98 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -060099 case CMD_BINDINDEXBUFFER:
100 return "CMD_BINDINDEXBUFFER";
101 case CMD_BINDVERTEXBUFFER:
102 return "CMD_BINDVERTEXBUFFER";
103 case CMD_DRAW:
104 return "CMD_DRAW";
105 case CMD_DRAWINDEXED:
106 return "CMD_DRAWINDEXED";
107 case CMD_DRAWINDIRECT:
108 return "CMD_DRAWINDIRECT";
109 case CMD_DRAWINDEXEDINDIRECT:
110 return "CMD_DRAWINDEXEDINDIRECT";
111 case CMD_DISPATCH:
112 return "CMD_DISPATCH";
113 case CMD_DISPATCHINDIRECT:
114 return "CMD_DISPATCHINDIRECT";
115 case CMD_COPYBUFFER:
116 return "CMD_COPYBUFFER";
117 case CMD_COPYIMAGE:
118 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600119 case CMD_BLITIMAGE:
120 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600121 case CMD_COPYBUFFERTOIMAGE:
122 return "CMD_COPYBUFFERTOIMAGE";
123 case CMD_COPYIMAGETOBUFFER:
124 return "CMD_COPYIMAGETOBUFFER";
125 case CMD_CLONEIMAGEDATA:
126 return "CMD_CLONEIMAGEDATA";
127 case CMD_UPDATEBUFFER:
128 return "CMD_UPDATEBUFFER";
129 case CMD_FILLBUFFER:
130 return "CMD_FILLBUFFER";
131 case CMD_CLEARCOLORIMAGE:
132 return "CMD_CLEARCOLORIMAGE";
133 case CMD_CLEARCOLORIMAGERAW:
134 return "CMD_CLEARCOLORIMAGERAW";
135 case CMD_CLEARDEPTHSTENCIL:
136 return "CMD_CLEARDEPTHSTENCIL";
137 case CMD_RESOLVEIMAGE:
138 return "CMD_RESOLVEIMAGE";
139 case CMD_SETEVENT:
140 return "CMD_SETEVENT";
141 case CMD_RESETEVENT:
142 return "CMD_RESETEVENT";
143 case CMD_WAITEVENTS:
144 return "CMD_WAITEVENTS";
145 case CMD_PIPELINEBARRIER:
146 return "CMD_PIPELINEBARRIER";
147 case CMD_BEGINQUERY:
148 return "CMD_BEGINQUERY";
149 case CMD_ENDQUERY:
150 return "CMD_ENDQUERY";
151 case CMD_RESETQUERYPOOL:
152 return "CMD_RESETQUERYPOOL";
153 case CMD_WRITETIMESTAMP:
154 return "CMD_WRITETIMESTAMP";
155 case CMD_INITATOMICCOUNTERS:
156 return "CMD_INITATOMICCOUNTERS";
157 case CMD_LOADATOMICCOUNTERS:
158 return "CMD_LOADATOMICCOUNTERS";
159 case CMD_SAVEATOMICCOUNTERS:
160 return "CMD_SAVEATOMICCOUNTERS";
161 case CMD_BEGINRENDERPASS:
162 return "CMD_BEGINRENDERPASS";
163 case CMD_ENDRENDERPASS:
164 return "CMD_ENDRENDERPASS";
165 case CMD_DBGMARKERBEGIN:
166 return "CMD_DBGMARKERBEGIN";
167 case CMD_DBGMARKEREND:
168 return "CMD_DBGMARKEREND";
169 default:
170 return "UNKNOWN";
171 }
172}
173// Block of code at start here for managing/tracking Pipeline state that this layer cares about
174// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600175#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600176#define MAX_SLOTS 2048
177#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
178
179static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
180
181// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
182// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
183// to that same cmd buffer by separate thread are not changing state from underneath us
184// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600185static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600186// Track the last group of CBs touched for displaying to dot file
187static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
188static uint32_t g_lastTouchedCBIndex = 0;
189// Track the last global DrawState of interest touched by any thread
190static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
191static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600192static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600193static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600194#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
195
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600196//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600197
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600198static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600199{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600201 size_t scSize = 0;
202 size_t vpSize = 0;
203 loader_platform_thread_lock_mutex(&globalLock);
204 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
205 pStateNode->stateObj = state;
206 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600207 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600208 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
209 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
210 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
211 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
212 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
213 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600214 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
215 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
216 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600217 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600218 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600219 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600220 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600221 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600222 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600223 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600224 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600225 break;
226 default:
227 assert(0);
228 break;
229 }
230 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
231 dynamicStateMap[state] = pStateNode;
232 loader_platform_thread_unlock_mutex(&globalLock);
233}
234// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600235static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600236{
David Pinedof5997ab2015-04-27 16:36:17 -0600237 if (dynamicStateMap.size() <= 0)
238 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600239 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600240 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600241 delete[] (*ii).second->create_info.vpci.pScissors;
242 delete[] (*ii).second->create_info.vpci.pViewports;
243 }
244 delete (*ii).second;
245 }
246}
247// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600248static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600249{
David Pinedof5997ab2015-04-27 16:36:17 -0600250 if (sampleMap.size() <= 0)
251 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600252 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600253 delete (*ii).second;
254 }
255}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600256static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600257{
258 loader_platform_thread_lock_mutex(&globalLock);
259 if (imageMap.find(view) == imageMap.end()) {
260 loader_platform_thread_unlock_mutex(&globalLock);
261 return NULL;
262 }
263 else {
264 loader_platform_thread_unlock_mutex(&globalLock);
265 return &imageMap[view]->createInfo;
266 }
267}
268// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600269static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600270{
David Pinedof5997ab2015-04-27 16:36:17 -0600271 if (imageMap.size() <= 0)
272 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600273 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600274 delete (*ii).second;
275 }
276}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600277static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600278{
279 loader_platform_thread_lock_mutex(&globalLock);
280 if (bufferMap.find(view) == bufferMap.end()) {
281 loader_platform_thread_unlock_mutex(&globalLock);
282 return NULL;
283 }
284 else {
285 loader_platform_thread_unlock_mutex(&globalLock);
286 return &bufferMap[view]->createInfo;
287 }
288}
289// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600290static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600291{
David Pinedof5997ab2015-04-27 16:36:17 -0600292 if (bufferMap.size() <= 0)
293 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600294 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600295 delete (*ii).second;
296 }
297}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600298static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301{
302 g_lastCmdBuffer[getTIDIndex()] = cb;
303 GLOBAL_CB_NODE* pCB = getCBNode(cb);
304 loader_platform_thread_lock_mutex(&globalLock);
305 g_lastGlobalCB = pCB;
306 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
307 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
308 if (g_pLastTouchedCB[i] == pCB) {
309 loader_platform_thread_unlock_mutex(&globalLock);
310 return;
311 }
312 }
313 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
314 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
315 loader_platform_thread_unlock_mutex(&globalLock);
316}
Tobin Ehlis97866202015-06-10 12:57:07 -0600317// Check object status for selected flag state
318static bool32_t validate_status(VkCmdBuffer cb, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VK_DBG_MSG_TYPE error_level, DRAW_STATE_ERROR error_code, const char* fail_msg) {
319 if (cmdBufferMap.find(cb) != cmdBufferMap.end()) {
320 GLOBAL_CB_NODE* pNode = cmdBufferMap[cb];
321 // If non-zero enable mask is present, check it against status but if enable_mask
322 // is 0 then no enable required so we should always just check status
323 if ((!enable_mask) || (enable_mask & pNode->status)) {
324 if ((pNode->status & status_mask) != status_flag) {
325 char str[1024];
326 sprintf(str, "CB object 0x%" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(cb), fail_msg);
327 layerCbMsg(error_level, VK_VALIDATION_LEVEL_0, cb, 0, error_code, "DS", str);
328 return VK_FALSE;
329 }
330 }
331 return VK_TRUE;
332 }
333 else {
334 // If we do not find it print an error
335 char str[1024];
336 sprintf(str, "Unable to obtain status for non-existent CB object 0x%" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(cb));
337 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
338 return VK_FALSE;
339 }
340}
341static bool32_t validate_draw_state_flags(VkCmdBuffer cb) {
342 bool32_t result1, result2, result3, result4;
343 result1 = validate_status(cb, CBSTATUS_NONE, CBSTATUS_VIEWPORT_BOUND, CBSTATUS_VIEWPORT_BOUND, VK_DBG_MSG_ERROR, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
344 result2 = validate_status(cb, CBSTATUS_NONE, CBSTATUS_RASTER_BOUND, CBSTATUS_RASTER_BOUND, VK_DBG_MSG_ERROR, DRAWSTATE_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");
345 result3 = validate_status(cb, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_COLOR_BLEND_BOUND, CBSTATUS_COLOR_BLEND_BOUND, VK_DBG_MSG_ERROR, DRAWSTATE_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");
346 result4 = validate_status(cb, CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE, CBSTATUS_DEPTH_STENCIL_BOUND, CBSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_MSG_ERROR, DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");
347 return ((result1 == VK_TRUE) && (result2 == VK_TRUE) && (result3 == VK_TRUE) && (result4 == VK_TRUE));
348}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600349// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600350static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600351{
352 GLOBAL_CB_NODE* pCB = getCBNode(cb);
353 if (pCB) {
354 loader_platform_thread_lock_mutex(&globalLock);
355 char str[4*1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600356 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600357 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600358 sprintf(str, "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600359 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
360 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", dynamic_display(pCB->lastBoundDynamicState[i]->pCreateInfo, " ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600361 break;
362 }
363 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600364 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600366 }
367 }
368 loader_platform_thread_unlock_mutex(&globalLock);
369 }
370 else {
371 char str[1024];
372 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600373 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600374 }
375}
376// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600377static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600378{
379 loader_platform_thread_lock_mutex(&globalLock);
380 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
381 loader_platform_thread_unlock_mutex(&globalLock);
382 return NULL;
383 }
384 loader_platform_thread_unlock_mutex(&globalLock);
385 return pipelineMap[pipeline];
386}
387
388// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600389static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600390{
391 loader_platform_thread_lock_mutex(&globalLock);
392 if (sampleMap.find(sampler) == sampleMap.end()) {
393 loader_platform_thread_unlock_mutex(&globalLock);
394 return NULL;
395 }
396 loader_platform_thread_unlock_mutex(&globalLock);
397 return &sampleMap[sampler]->createInfo;
398}
399
400// Init the pipeline mapping info based on pipeline create info LL tree
401// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600402static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600403{
404 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600405 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600406 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600407 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600408 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600409 size_t bufferSize = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600410 VkPipelineVertexInputCreateInfo* pVICI = NULL;
411 VkPipelineCbStateCreateInfo* pCBCI = NULL;
412 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600413 while (pTrav) {
414 switch (pTrav->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600415 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600416 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600417 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 case VK_SHADER_STAGE_VERTEX:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600419 pPrev->pNext = &pPipeline->vsCI;
420 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600421 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600422 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600423 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600424 pPrev->pNext = &pPipeline->tcsCI;
425 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600426 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600427 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600428 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600429 pPrev->pNext = &pPipeline->tesCI;
430 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600431 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600432 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600433 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600434 pPrev->pNext = &pPipeline->gsCI;
435 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600436 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600437 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600438 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600439 pPrev->pNext = &pPipeline->fsCI;
440 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600441 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600442 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600443 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600444 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600445 break;
446 default:
447 // TODO : Flag error
448 break;
449 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600450 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600451 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600452 pPrev->pNext = &pPipeline->vertexInputCI;
453 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600454 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600455 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600456 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600457 pPipeline->vtxBindingCount = pVICI->bindingCount;
458 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600459 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
460 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
Tobin Ehlis9a70e5d2015-06-09 10:48:55 -0600461 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexBindingDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600462 }
463 pPipeline->vtxAttributeCount = pVICI->attributeCount;
464 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600465 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
466 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
467 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600468 }
469 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600471 pPrev->pNext = &pPipeline->iaStateCI;
472 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600473 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600474 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600475 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600476 pPrev->pNext = &pPipeline->tessStateCI;
477 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600478 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600479 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600480 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600481 pPrev->pNext = &pPipeline->vpStateCI;
482 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600483 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600484 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600485 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600486 pPrev->pNext = &pPipeline->rsStateCI;
487 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600488 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600489 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600490 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600491 pPrev->pNext = &pPipeline->msStateCI;
492 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600493 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600494 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600495 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600496 pPrev->pNext = &pPipeline->cbStateCI;
497 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600498 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600499 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600500 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600501 pPipeline->attachmentCount = pCBCI->attachmentCount;
502 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600503 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
504 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
505 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600506 }
507 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600508 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600509 pPrev->pNext = &pPipeline->dsStateCI;
510 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600511 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600512 break;
513 default:
514 assert(0);
515 break;
516 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600517 pTrav = (GENERIC_HEADER*)pTrav->pNext;
518 }
519 pipelineMap[pPipeline->pipeline] = pPipeline;
520}
521// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600522static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600523{
David Pinedof5997ab2015-04-27 16:36:17 -0600524 if (pipelineMap.size() <= 0)
525 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600526 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600527 if ((*ii).second->pVertexBindingDescriptions) {
528 delete[] (*ii).second->pVertexBindingDescriptions;
529 }
530 if ((*ii).second->pVertexAttributeDescriptions) {
531 delete[] (*ii).second->pVertexAttributeDescriptions;
532 }
533 if ((*ii).second->pAttachments) {
534 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600535 }
536 delete (*ii).second;
537 }
538}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600539// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600540static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600541{
542 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600543 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600544 if (pPipe->msStateCI.multisampleEnable)
545 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600546 }
547 return 1;
548}
549// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600550static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600551{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600552 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600553 // Verify that any MSAA request in PSO matches sample# in bound FB
554 uint32_t psoNumSamples = getNumSamples(pipeline);
555 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600556 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
557 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis63826ec2015-05-21 09:06:56 -0600558 if ((psoNumSamples != pFBCI->sampleCount) || (psoNumSamples != pRPCI->sampleCount)) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600559 char str[1024];
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600560 sprintf(str, "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);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600561 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600562 }
563 } else {
564 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
565 // Verify and flag error as appropriate
566 }
567 // TODO : Add more checks here
568 } else {
569 // TODO : Validate non-gfx pipeline updates
570 }
571}
572
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600573// Block of code at start here specifically for managing/tracking DSs
574
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600575// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600576static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600577{
578 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600579 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600580 loader_platform_thread_unlock_mutex(&globalLock);
581 return NULL;
582 }
583 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600584 return poolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600585}
586// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600587static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600588{
589 loader_platform_thread_lock_mutex(&globalLock);
590 if (setMap.find(set) == setMap.end()) {
591 loader_platform_thread_unlock_mutex(&globalLock);
592 return NULL;
593 }
594 loader_platform_thread_unlock_mutex(&globalLock);
595 return setMap[set];
596}
597
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600598static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600599 loader_platform_thread_lock_mutex(&globalLock);
600 if (layoutMap.find(layout) == layoutMap.end()) {
601 loader_platform_thread_unlock_mutex(&globalLock);
602 return NULL;
603 }
604 loader_platform_thread_unlock_mutex(&globalLock);
605 return layoutMap[layout];
606}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600607// Return 1 if update struct is of valid type, 0 otherwise
608static bool32_t validUpdateStruct(const GENERIC_HEADER* pUpdateStruct)
609{
610 char str[1024];
611 switch (pUpdateStruct->sType)
612 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800613 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
614 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600615 return 1;
616 default:
617 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
618 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
619 return 0;
620 }
621}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600622// For given update struct, return binding
623static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600624{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600625 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600626 switch (pUpdateStruct->sType)
627 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800628 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
629 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
630 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
631 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600632 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600633 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
634 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
635 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600636 }
637}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600638// Return count for given update struct
639static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600640{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600641 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600642 switch (pUpdateStruct->sType)
643 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800644 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
645 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
646 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600647 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800648 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600649 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600650 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
651 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600652 return 0;
653 }
654}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600655// Return count for given update struct
656static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
657{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600658 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600659 switch (pUpdateStruct->sType)
660 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800661 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
662 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
663 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600664 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800665 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600666 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600667 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
668 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600669 return 0;
670 }
671}
672// For given Layout Node and binding, return index where that binding begins
673static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
674{
675 uint32_t offsetIndex = 0;
676 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800677 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600678 }
679 return offsetIndex;
680}
681// For given layout node and binding, return last index that is updated
682static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
683{
684 uint32_t offsetIndex = 0;
685 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800686 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600687 }
688 return offsetIndex-1;
689}
690// For given layout and update, return the first overall index of the layout that is update
691static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
692{
693 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
694}
695// For given layout and update, return the last overall index of the layout that is update
696static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
697{
698 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
699}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600700// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600701static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600702{
703 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600704 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600705 uint32_t i = 0;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600706 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600707 switch (pUpdateStruct->sType)
708 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800709 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
710 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600711 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800712 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
713 /* no need to validate */
714 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600715 break;
716 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600717 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
718 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600719 return 0;
720 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600721 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600722 if (pLayout->pTypes[i] != actualType)
723 return 0;
724 }
725 return 1;
726}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600727// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
728// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
729// NOTE : Calls to this function should be wrapped in mutex
730static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
731{
732 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800733 VkWriteDescriptorSet* pWDS = NULL;
734 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600735 size_t array_size = 0;
736 size_t base_array_size = 0;
737 size_t total_array_size = 0;
738 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600739 char str[1024];
740 switch (pUpdate->sType)
741 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800742 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
743 pWDS = new VkWriteDescriptorSet;
744 pNewNode = (GENERIC_HEADER*)pWDS;
745 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
746 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
747 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
748 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600749 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800750 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
751 pCDS = new VkCopyDescriptorSet;
752 pUpdate = (GENERIC_HEADER*)pCDS;
753 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600754 break;
755 default:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600756 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600757 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600758 return NULL;
759 }
760 // Make sure that pNext for the end of shadow copy is NULL
761 pNewNode->pNext = NULL;
762 return pNewNode;
763}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800764// update DS mappings based on ppUpdateArray
765static bool32_t dsUpdate(VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600766{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800767 const VkWriteDescriptorSet *pWDS = NULL;
768 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600769 bool32_t result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800770
771 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
772 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
773 else
774 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
775
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600776 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600777 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600778 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600779 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600780 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600781 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800782 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
783 SET_NODE* pSet = setMap[ds]; // getSetNode() without locking
784 g_lastBoundDescriptorSet = pSet->set;
785 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600786 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600787 // First verify valid update struct
788 if (!validUpdateStruct(pUpdate)) {
789 result = 0;
790 break;
791 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600792 // Make sure that binding is within bounds
793 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600794 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600795 sprintf(str, "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, getUpdateBinding(pUpdate), string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600796 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600797 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600798 }
799 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600800 // Next verify that update falls within size of given binding
801 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600802 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600803 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600804 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
805 sprintf(str, "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), getUpdateBinding(pUpdate), DSstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600806 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600807 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600808 }
809 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600810 // Layout bindings match w/ update ok, now verify that update is of the right type
811 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600812 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600813 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600814 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600815 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600816 }
817 else {
818 // Save the update info
819 // TODO : Info message that update successful
820 // Create new update struct for this set's shadow copy
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600821 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600822 if (NULL == pNewNode) {
823 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600824 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
825 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600826 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600827 }
828 else {
829 // Insert shadow node into LL of updates for this set
830 pNewNode->pNext = pSet->pUpdateStructs;
831 pSet->pUpdateStructs = pNewNode;
832 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600833 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
834 assert(j<pSet->descriptorCount);
835 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600836 }
837 }
838 }
839 }
840 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600841 }
842 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600843 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600844}
845// Free the shadowed update node for this Set
846// NOTE : Calls to this function should be wrapped in mutex
847static void freeShadowUpdateTree(SET_NODE* pSet)
848{
849 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
850 pSet->pUpdateStructs = NULL;
851 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
852 // Clear the descriptor mappings as they will now be invalid
853 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
854 while(pShadowUpdate) {
855 pFreeUpdate = pShadowUpdate;
856 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
857 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800858 VkWriteDescriptorSet * pWDS = NULL;
859 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600860 void** ppToFree = NULL;
861 switch (pFreeUpdate->sType)
862 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800863 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
864 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
865 if (pWDS->pDescriptors)
866 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600867 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800868 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600869 break;
870 default:
871 assert(0);
872 break;
873 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600874 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600875 }
876}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600877// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600878// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600879static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880{
David Pinedof5997ab2015-04-27 16:36:17 -0600881 if (poolMap.size() <= 0)
882 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600883 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600884 SET_NODE* pSet = (*ii).second->pSets;
885 SET_NODE* pFreeSet = pSet;
886 while (pSet) {
887 pFreeSet = pSet;
888 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600889 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600890 // Free Update shadow struct tree
891 freeShadowUpdateTree(pFreeSet);
892 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200893 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600894 }
895 delete pFreeSet;
896 }
897 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200898 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600899 }
900 delete (*ii).second;
901 }
902}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600903// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600904// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600905static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600906{
David Pinedof5997ab2015-04-27 16:36:17 -0600907 if (layoutMap.size() <= 0)
908 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600909 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600910 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600911 if (pLayout->createInfo.pBinding) {
912 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
913 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
914 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
915 }
916 delete[] pLayout->createInfo.pBinding;
917 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600918 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200919 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600920 }
921 delete pLayout;
922 }
923}
924// Currently clearing a set is removing all previous updates to that set
925// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600926static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600927{
928 SET_NODE* pSet = getSetNode(set);
929 if (!pSet) {
930 // TODO : Return error
931 }
932 else {
933 loader_platform_thread_lock_mutex(&globalLock);
934 freeShadowUpdateTree(pSet);
935 loader_platform_thread_unlock_mutex(&globalLock);
936 }
937}
938
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600939static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600940{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600941 POOL_NODE* pPool = getPoolNode(pool);
942 if (!pPool) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600943 char str[1024];
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600944 sprintf(str, "Unable to find pool node for pool %p specified in vkResetDescriptorPool() call", (void*)pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600945 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600946 }
947 else
948 {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600949 // For every set off of this pool, clear it
950 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600951 while (pSet) {
952 clearDescriptorSet(pSet->set);
953 }
954 }
955}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600956// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600957static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600958{
959 loader_platform_thread_lock_mutex(&globalLock);
960 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
961 loader_platform_thread_unlock_mutex(&globalLock);
962 return NULL;
963 }
964 loader_platform_thread_unlock_mutex(&globalLock);
965 return cmdBufferMap[cb];
966}
967// Free all CB Nodes
968// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600969static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600970{
David Pinedof5997ab2015-04-27 16:36:17 -0600971 if (cmdBufferMap.size() <= 0)
972 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600973 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -0600974 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
975 while (!cmd_node_list.empty()) {
976 CMD_NODE* cmd_node = cmd_node_list.back();
977 delete cmd_node;
978 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600979 }
980 delete (*ii).second;
981 }
982}
983static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
984{
985 CMD_NODE* pCmd = new CMD_NODE;
986 if (pCmd) {
987 // init cmd node and append to end of cmd LL
988 memset(pCmd, 0, sizeof(CMD_NODE));
989 pCmd->cmdNumber = ++pCB->numCmds;
990 pCmd->type = cmd;
991 pCB->pCmds.push_back(pCmd);
992 }
993 else {
994 char str[1024];
995 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600996 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600997 }
998}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600999static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001000{
1001 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1002 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001003 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1004 while (!cmd_list.empty()) {
1005 delete cmd_list.back();
1006 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001007 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001008 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001009 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001010 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001011 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001012 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1013 pCB->cmdBuffer = cb;
1014 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001015 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001016 pCB->lastVtxBinding = MAX_BINDING;
1017 }
1018}
Tobin Ehlis97866202015-06-10 12:57:07 -06001019// Set PSO-related status bits for CB
1020static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1021{
1022 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1023 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1024 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1025 }
1026 }
1027 if (pPipe->dsStateCI.depthWriteEnable) {
1028 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1029 }
1030}
1031// Set dyn-state related status bits for an object node
1032static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, VkStateBindPoint stateBindPoint) {
1033 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1034 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1035 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1036 pNode->status |= CBSTATUS_RASTER_BOUND;
1037 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1038 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1039 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1040 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1041 }
1042}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001043// Set the last bound dynamic state of given type
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001044static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001045{
1046 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1047 if (pCB) {
1048 updateCBTracking(cmdBuffer);
1049 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis97866202015-06-10 12:57:07 -06001050 set_cb_dyn_status(pCB, sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001051 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1052 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1053 char str[1024];
1054 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001055 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001056 }
1057 else {
1058 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1059 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1060 }
1061 loader_platform_thread_unlock_mutex(&globalLock);
1062 }
1063 else {
1064 char str[1024];
1065 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001066 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001067 }
1068}
1069// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001070static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001071{
1072 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1073 if (pCB) {
1074 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1075 if (!pPipeTrav) {
1076 // nothing to print
1077 }
1078 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001079 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001080 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001081 }
1082 }
1083}
1084// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001085static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001086{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001087#if 0
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001088 SET_NODE* pSet = getSetNode(ds);
1089 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001090 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001091 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001092 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1093 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001094 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001095 fprintf(pOutFile, "%s", pGVstr);
1096 free(pGVstr);
1097 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1098 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001099 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001100 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001101 ++layout_index;
1102 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001103 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001104 fprintf(pOutFile, "%s", pGVstr);
1105 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001106 if (pSet->pUpdateStructs) {
1107 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1108 fprintf(pOutFile, "%s", pGVstr);
1109 free(pGVstr);
1110 }
1111 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001112 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1113 uint32_t i = 0;
1114 for (i=0; i < pSet->descriptorCount; i++) {
1115 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001116 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_VkStructureType(pSet->ppDescriptors[i]->sType));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001117 }
1118 }
1119#define NUM_COLORS 7
1120 vector<string> edgeColors;
1121 edgeColors.push_back("0000ff");
1122 edgeColors.push_back("ff00ff");
1123 edgeColors.push_back("ffff00");
1124 edgeColors.push_back("00ff00");
1125 edgeColors.push_back("000000");
1126 edgeColors.push_back("00ffff");
1127 edgeColors.push_back("ff0000");
1128 uint32_t colorIdx = 0;
1129 fprintf(pOutFile, "</TABLE>>\n];\n");
1130 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001131 VkUpdateSamplers* pUS = NULL;
1132 VkUpdateSamplerTextures* pUST = NULL;
1133 VkUpdateImages* pUI = NULL;
1134 VkUpdateBuffers* pUB = NULL;
1135 VkUpdateAsCopy* pUAC = NULL;
1136 VkSamplerCreateInfo* pSCI = NULL;
1137 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001138 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001139 void** ppNextPtr = NULL;
1140 void* pSaveNext = NULL;
1141 for (i=0; i < pSet->descriptorCount; i++) {
1142 if (pSet->ppDescriptors[i]) {
1143 switch (pSet->ppDescriptors[i]->sType)
1144 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001145 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001146 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001147 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001148 if (pSCI) {
1149 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001150 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001151 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1152 }
1153 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001154 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001155 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001156 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001157 if (pSCI) {
1158 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001159 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001160 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1161 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001162 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001163 if (pIVCI) {
1164 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001165 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001166 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1167 }
1168 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001169 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001170 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001171 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001172 if (pIVCI) {
1173 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001174 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001175 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1176 }
1177 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001178 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001179 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001180 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001181 if (pBVCI) {
1182 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001183 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001184 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1185 }
1186 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001187 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001188 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001189 // TODO : Need to validate this code
1190 // Save off pNext and set to NULL while printing this struct, then restore it
1191 ppNextPtr = (void**)&pUAC->pNext;
1192 pSaveNext = *ppNextPtr;
1193 *ppNextPtr = NULL;
1194 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001195 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001196 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1197 // Restore next ptr
1198 *ppNextPtr = pSaveNext;
1199 break;
1200 default:
1201 break;
1202 }
1203 colorIdx = (colorIdx+1) % NUM_COLORS;
1204 }
1205 }
1206 }
1207 fprintf(pOutFile, "}\n");
1208 fprintf(pOutFile, "}\n");
1209 }
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001210#endif
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001211}
1212// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001213static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001214{
1215 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1216 if (pCB && pCB->lastBoundDescriptorSet) {
1217 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1218 }
1219}
1220// Dump a GraphViz dot file showing the Cmd Buffers
1221static void cbDumpDotFile(string outFileName)
1222{
1223 // Print CB Chain for each CB
1224 FILE* pOutFile;
1225 pOutFile = fopen(outFileName.c_str(), "w");
1226 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1227 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1228 GLOBAL_CB_NODE* pCB = NULL;
1229 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1230 pCB = g_pLastTouchedCB[i];
David Pinedof5997ab2015-04-27 16:36:17 -06001231 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001232 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1233 uint32_t instNum = 0;
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001234 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1235 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001236 if (instNum) {
1237 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1238 }
1239 if (pCB == g_lastGlobalCB) {
1240 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());
1241 }
1242 else {
1243 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());
1244 }
1245 ++instNum;
1246 }
1247 fprintf(pOutFile, "}\n");
1248 }
1249 }
1250 fprintf(pOutFile, "}\n");
1251 fprintf(pOutFile, "}\n"); // close main graph "g"
1252 fclose(pOutFile);
1253}
1254// Dump a GraphViz dot file showing the pipeline for last bound global state
1255static void dumpGlobalDotFile(char *outFileName)
1256{
1257 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1258 if (pPipeTrav) {
1259 FILE* pOutFile;
1260 pOutFile = fopen(outFileName, "w");
1261 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1262 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1263 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001264 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001265 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001266 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001267 fprintf(pOutFile, "%s", pGVstr);
1268 free(pGVstr);
1269 }
1270 }
1271 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1272 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001273 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001274 fprintf(pOutFile, "%s", pGVstr);
1275 free(pGVstr);
1276 fprintf(pOutFile, "}\n");
1277 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1278 fprintf(pOutFile, "}\n"); // close main graph "g"
1279 fclose(pOutFile);
1280 }
1281}
1282// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001283static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001284{
1285 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1286 if (pCB) {
1287 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1288 if (pPipeTrav) {
1289 FILE* pOutFile;
1290 pOutFile = fopen(outFileName.c_str(), "w");
1291 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1292 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1293 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001294 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001295 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001296 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001297 fprintf(pOutFile, "%s", pGVstr);
1298 free(pGVstr);
1299 }
1300 }
1301 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1302 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001303 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001304 fprintf(pOutFile, "%s", pGVstr);
1305 free(pGVstr);
1306 fprintf(pOutFile, "}\n");
1307 dsDumpDot(cb, pOutFile);
1308 fprintf(pOutFile, "}\n"); // close main graph "g"
1309 fclose(pOutFile);
1310 }
1311 }
1312}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001313// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001314static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001315{
1316 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1317 if (pCB && pCB->lastBoundPipeline) {
1318 // First verify that we have a Node for bound pipeline
1319 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1320 char str[1024];
1321 if (!pPipeTrav) {
1322 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001323 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001324 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001325 }
1326 else {
1327 // Verify Vtx binding
1328 if (MAX_BINDING != pCB->lastVtxBinding) {
1329 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1330 if (0 == pPipeTrav->vtxBindingCount) {
1331 sprintf(str, "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001332 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001333 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001334 }
1335 else {
1336 sprintf(str, "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001337 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001338 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001339 }
1340 }
1341 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001342 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001343 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001344 }
1345 }
1346 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001347 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001348 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001349 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001350}
1351// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001352static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001353{
1354 char tmp_str[1024];
1355 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.
1356 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001357 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001358 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001359 POOL_NODE* pPool = getPoolNode(pSet->pool);
1360 // Print out pool details
1361 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001362 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001363 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001364 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001365 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001366 // Print out set details
1367 char prefix[10];
1368 uint32_t index = 0;
1369 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001370 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001371 LAYOUT_NODE* pLayout = pSet->pLayout;
1372 // Print layout details
1373 sprintf(tmp_str, "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001374 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001375 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001376 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001377 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001378 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001379 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001380 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1381 if (pUpdate) {
1382 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001383 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001384 sprintf(prefix, " [UC] ");
1385 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001386 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001387 // TODO : If there is a "view" associated with this update, print CI for that view
1388 }
1389 else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001390 if (0 != pSet->descriptorCount) {
1391 sprintf(tmp_str, "No Update Chain for descriptor set %p which has %u descriptors (vkUpdateDescriptors has not been called)", (void*)pSet->set, pSet->descriptorCount);
1392 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
1393 }
1394 else {
1395 sprintf(tmp_str, "FYI: No descriptors in descriptor set %p.", (void*)pSet->set);
1396 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
1397 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001398 }
1399 }
1400}
1401
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001402static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001403{
1404 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001405 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001406 char str[1024];
1407 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001408 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001409 vector<CMD_NODE*> pCmds = pCB->pCmds;
1410 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001411 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001412 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001413 }
1414 }
1415 else {
1416 // Nothing to print
1417 }
1418}
1419
1420
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001421static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001422{
1423 printDSConfig(cb);
1424 printPipeline(cb);
1425 printDynamicState(cb);
1426 static int autoDumpOnce = 0;
1427 if (autoDumpOnce) {
1428 autoDumpOnce = 0;
1429 dumpDotFile(cb, "pipeline_dump.dot");
1430 cbDumpDotFile("cb_dump.dot");
1431#if defined(_WIN32)
1432// FIXME: NEED WINDOWS EQUIVALENT
1433#else // WIN32
1434 // Convert dot to svg if dot available
1435 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001436 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1437 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001438 }
1439#endif // WIN32
1440 }
1441}
1442
Jon Ashburne0fa2282015-05-20 09:00:28 -06001443static VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw)
Jon Ashburnd9564002015-05-07 10:27:37 -06001444{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001445 VkLayerDispatchTable *pTable;
1446
1447 assert(devw);
1448 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject);
1449
1450 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) *ppDisp);
1451 if (it == tableMap.end())
1452 {
1453 pTable = new VkLayerDispatchTable;
1454 tableMap[(void *) *ppDisp] = pTable;
1455 } else
1456 {
1457 return it->second;
1458 }
1459
1460 layer_initialize_dispatch_table(pTable, (PFN_vkGetDeviceProcAddr) devw->pGPA, (VkDevice) devw->nextObject);
1461
1462 return pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -06001463}
1464
Jon Ashburne0fa2282015-05-20 09:00:28 -06001465static VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instw)
Jon Ashburnd9564002015-05-07 10:27:37 -06001466{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001467 VkLayerInstanceDispatchTable *pTable;
1468 assert(instw);
1469 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;
1470
1471 std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap.find((void *) *ppDisp);
1472 if (it == tableInstanceMap.end())
1473 {
1474 pTable = new VkLayerInstanceDispatchTable;
1475 tableInstanceMap[(void *) *ppDisp] = pTable;
1476 } else
1477 {
1478 return it->second;
1479 }
1480
1481 layer_init_instance_dispatch_table(pTable, (PFN_vkGetInstanceProcAddr) instw->pGPA, (VkInstance) instw->nextObject);
1482
1483 return pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -06001484}
1485
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001486static void initDrawState(void)
1487{
1488 const char *strOpt;
1489 // initialize DrawState options
1490 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1491 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1492
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001493 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001494 {
1495 strOpt = getLayerOption("DrawStateLogFilename");
1496 if (strOpt)
1497 {
1498 g_logFile = fopen(strOpt, "w");
1499 }
1500 if (g_logFile == NULL)
1501 g_logFile = stdout;
1502 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001503
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001504 if (!globalLockInitialized)
1505 {
1506 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001507 // suggestion is to call this during vkCreateInstance(), and then we
1508 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001509 // that the layer have per-instance locks. We need to come back and
1510 // address this soon.
1511 loader_platform_thread_create_mutex(&globalLock);
1512 globalLockInitialized = 1;
1513 }
1514}
1515
Jon Ashburne0fa2282015-05-20 09:00:28 -06001516/* hook DestroyInstance to remove tableInstanceMap entry */
1517VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1518{
1519 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
1520 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
1521 VkResult res = pTable->DestroyInstance(instance);
1522 tableInstanceMap.erase(pDisp);
1523 return res;
1524}
1525
Tony Barbour8205d902015-04-16 15:59:00 -06001526VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001527{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001528 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu;
1529 VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[*ppDisp];
1530 VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001531 return result;
1532}
1533
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001534VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001535{
1536 // Free all the memory
1537 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001538 deletePipelines();
1539 deleteSamplers();
1540 deleteImages();
1541 deleteBuffers();
1542 deleteCmdBuffers();
1543 deleteDynamicState();
1544 deletePools();
1545 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001546 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001547
1548 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1549 VkLayerDispatchTable *pTable = tableMap[pDisp];
1550 VkResult result = pTable->DestroyDevice(device);
1551 tableMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001552 return result;
1553}
1554
Jon Ashburneb2728b2015-04-10 14:33:07 -06001555struct extProps {
1556 uint32_t version;
1557 const char * const name;
1558};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001559#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001560static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1561 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001562 0x10, "DrawState",
1563 0x10, "Validation",
1564 0x10, "drawStateDumpDotFile",
1565 0x10, "drawStateDumpCommandBufferDotFile",
1566 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001567};
1568
1569VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1570 VkExtensionInfoType infoType,
1571 uint32_t extensionIndex,
1572 size_t* pDataSize,
1573 void* pData)
1574{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001575 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1576 VkExtensionProperties *ext_props;
1577 uint32_t *count;
1578
1579 if (pDataSize == NULL)
1580 return VK_ERROR_INVALID_POINTER;
1581
1582 switch (infoType) {
1583 case VK_EXTENSION_INFO_TYPE_COUNT:
1584 *pDataSize = sizeof(uint32_t);
1585 if (pData == NULL)
1586 return VK_SUCCESS;
1587 count = (uint32_t *) pData;
1588 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1589 break;
1590 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1591 *pDataSize = sizeof(VkExtensionProperties);
1592 if (pData == NULL)
1593 return VK_SUCCESS;
1594 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1595 return VK_ERROR_INVALID_VALUE;
1596 ext_props = (VkExtensionProperties *) pData;
1597 ext_props->version = dsExts[extensionIndex].version;
1598 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1599 VK_MAX_EXTENSION_NAME);
1600 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1601 break;
1602 default:
1603 return VK_ERROR_INVALID_VALUE;
1604 };
1605
1606 return VK_SUCCESS;
1607}
1608
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001609VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001610{
1611 if (gpu != NULL)
1612 {
Jon Ashburne0fa2282015-05-20 09:00:28 -06001613 VkLayerInstanceDispatchTable* pTable = initInstanceTable((const VkBaseLayerObject *) gpu);
1614
1615 VkResult result = pTable->EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001616 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001617 } else {
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001618 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001619 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001620 // This layer compatible with all GPUs
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001621 *pLayerCount = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001622 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001623 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001624 }
1625}
1626
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001627VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001628{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001629 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001630 for (uint32_t i=0; i < cmdBufferCount; i++) {
1631 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001632 pCB = getCBNode(pCmdBuffers[i]);
1633 loader_platform_thread_lock_mutex(&globalLock);
1634 if (CB_UPDATE_COMPLETE != pCB->state) {
1635 // Flag error for using CB w/o vkEndCommandBuffer() called
1636 char str[1024];
1637 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
1638 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS", str);
Tobin Ehlise90b1712015-05-27 14:30:06 -06001639 loader_platform_thread_unlock_mutex(&globalLock);
1640 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001641 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001642 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001643 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001644
1645 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) queue;
1646 VkLayerDispatchTable *pTable = tableMap[pDisp];
1647 VkResult result = pTable->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001648 return result;
1649}
1650
Mike Stroyan230e6252015-04-17 12:36:38 -06001651VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001652{
1653 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Jon Ashburne0fa2282015-05-20 09:00:28 -06001654 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1655 VkLayerDispatchTable *pTable = tableMap[pDisp];
1656 VkResult result = pTable->DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001657 return result;
1658}
1659
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001660VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001661{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001662 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1663 VkLayerDispatchTable *pTable = tableMap[pDisp];
1664 VkResult result = pTable->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001665 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001666 loader_platform_thread_lock_mutex(&globalLock);
1667 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1668 pNewNode->buffer = *pView;
1669 pNewNode->createInfo = *pCreateInfo;
1670 bufferMap[*pView] = pNewNode;
1671 loader_platform_thread_unlock_mutex(&globalLock);
1672 }
1673 return result;
1674}
1675
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001676VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001677{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001678 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1679 VkLayerDispatchTable *pTable = tableMap[pDisp];
1680 VkResult result = pTable->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001682 loader_platform_thread_lock_mutex(&globalLock);
1683 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1684 pNewNode->image = *pView;
1685 pNewNode->createInfo = *pCreateInfo;
1686 imageMap[*pView] = pNewNode;
1687 loader_platform_thread_unlock_mutex(&globalLock);
1688 }
1689 return result;
1690}
1691
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001692static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001693{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001694 // Create LL HEAD for this Pipeline
1695 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001696 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1697 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1698 pPipeNode->pipeline = *pPipeline;
1699 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001700 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001701}
1702
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001703VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001704{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001705 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1706 VkLayerDispatchTable *pTable = tableMap[pDisp];
1707 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001708 // Create LL HEAD for this Pipeline
1709 char str[1024];
1710 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001711 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001712
1713 track_pipeline(pCreateInfo, pPipeline);
1714
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001715 return result;
1716}
1717
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001718VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1719 VkDevice device,
1720 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1721 VkPipeline basePipeline,
1722 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001723{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001724 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1725 VkLayerDispatchTable *pTable = tableMap[pDisp];
1726 VkResult result = pTable->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001727 // Create LL HEAD for this Pipeline
1728 char str[1024];
1729 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001730 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001731
1732 track_pipeline(pCreateInfo, pPipeline);
1733
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001734 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001735
1736 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001737}
1738
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001739VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001740{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001741 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1742 VkLayerDispatchTable *pTable = tableMap[pDisp];
1743 VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001744 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001745 loader_platform_thread_lock_mutex(&globalLock);
1746 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1747 pNewNode->sampler = *pSampler;
1748 pNewNode->createInfo = *pCreateInfo;
1749 sampleMap[*pSampler] = pNewNode;
1750 loader_platform_thread_unlock_mutex(&globalLock);
1751 }
1752 return result;
1753}
1754
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001755VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001756{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001757 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1758 VkLayerDispatchTable *pTable = tableMap[pDisp];
1759 VkResult result = pTable->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001760 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1762 if (NULL == pNewNode) {
1763 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001764 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1765 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001766 }
1767 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001768 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1769 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1770 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001772 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001773 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001774 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001775 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001776 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1777 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001778 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001779 }
1780 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001781 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001782 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001783 uint32_t j = 0;
1784 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001785 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001786 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001787 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001788 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001789 }
1790 }
1791 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001792 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001793 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1794 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001795 // Put new node at Head of global Layer list
1796 loader_platform_thread_lock_mutex(&globalLock);
1797 layoutMap[*pSetLayout] = pNewNode;
1798 loader_platform_thread_unlock_mutex(&globalLock);
1799 }
1800 return result;
1801}
1802
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001803VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001805 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1806 VkLayerDispatchTable *pTable = tableMap[pDisp];
1807 VkResult result = pTable->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001808 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001809 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001810 }
1811 return result;
1812}
1813
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001814VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001815{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001816 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1817 VkLayerDispatchTable *pTable = tableMap[pDisp];
1818 VkResult result = pTable->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001819 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001820 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001821 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001822 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyan230e6252015-04-17 12:36:38 -06001823 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001824 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001825 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001826 if (NULL == pNewNode) {
1827 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001828 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyan230e6252015-04-17 12:36:38 -06001829 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001830 }
1831 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001832 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001833 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1834 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001836 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1837 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001838 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1839 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001840 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001841 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001842 pNewNode->pool = *pDescriptorPool;
1843 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844 }
1845 loader_platform_thread_unlock_mutex(&globalLock);
1846 }
1847 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001848 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849 }
1850 return result;
1851}
1852
Mike Stroyan230e6252015-04-17 12:36:38 -06001853VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001854{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001855 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1856 VkLayerDispatchTable *pTable = tableMap[pDisp];
1857 VkResult result = pTable->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001858 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001859 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001860 }
1861 return result;
1862}
1863
Mike Stroyan230e6252015-04-17 12:36:38 -06001864VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001866 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1867 VkLayerDispatchTable *pTable = tableMap[pDisp];
1868 VkResult result = pTable->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001869 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001870 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1871 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001872 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001873 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1874 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001875 }
1876 else {
1877 for (uint32_t i = 0; i < *pCount; i++) {
1878 char str[1024];
1879 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001880 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001881 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001882 SET_NODE* pNewNode = new SET_NODE;
1883 if (NULL == pNewNode) {
1884 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001885 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1886 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001887 }
1888 else {
1889 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001890 // Insert set at head of Set LL for this pool
1891 pNewNode->pNext = pPoolNode->pSets;
1892 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001893 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1894 if (NULL == pLayout) {
1895 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001896 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1897 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001898 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001899 pNewNode->pLayout = pLayout;
1900 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001901 pNewNode->set = pDescriptorSets[i];
1902 pNewNode->setUsage = setUsage;
1903 pNewNode->descriptorCount = pLayout->endIndex + 1;
1904 if (pNewNode->descriptorCount) {
1905 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1906 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1907 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1908 }
1909 setMap[pDescriptorSets[i]] = pNewNode;
1910 }
1911 }
1912 }
1913 }
1914 return result;
1915}
1916
Mike Stroyan230e6252015-04-17 12:36:38 -06001917VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001918{
1919 for (uint32_t i = 0; i < count; i++) {
1920 clearDescriptorSet(pDescriptorSets[i]);
1921 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001922 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1923 VkLayerDispatchTable *pTable = tableMap[pDisp];
1924 pTable->ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001925}
1926
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001927VK_LAYER_EXPORT VkResult VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001928{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001929 if (dsUpdate(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
Jon Ashburne0fa2282015-05-20 09:00:28 -06001930 dsUpdate(VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
1931 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1932 VkLayerDispatchTable *pTable = tableMap[pDisp];
1933 return pTable->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
1934 }
1935 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001936}
1937
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001938VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001939{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001940 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1941 VkLayerDispatchTable *pTable = tableMap[pDisp];
1942 VkResult result = pTable->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001943 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001944 return result;
1945}
1946
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001947VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001948{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001949 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1950 VkLayerDispatchTable *pTable = tableMap[pDisp];
1951 VkResult result = pTable->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001952 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001953 return result;
1954}
1955
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001956VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001957{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001958 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1959 VkLayerDispatchTable *pTable = tableMap[pDisp];
1960 VkResult result = pTable->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001961 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001962 return result;
1963}
1964
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001965VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001966{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001967 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1968 VkLayerDispatchTable *pTable = tableMap[pDisp];
1969 VkResult result = pTable->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001970 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001971 return result;
1972}
1973
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001974VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001976 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1977 VkLayerDispatchTable *pTable = tableMap[pDisp];
1978 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001979 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001980 loader_platform_thread_lock_mutex(&globalLock);
1981 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1982 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1983 pCB->cmdBuffer = *pCmdBuffer;
1984 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001985 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001986 pCB->lastVtxBinding = MAX_BINDING;
1987 cmdBufferMap[*pCmdBuffer] = pCB;
1988 loader_platform_thread_unlock_mutex(&globalLock);
1989 updateCBTracking(*pCmdBuffer);
1990 }
1991 return result;
1992}
1993
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001994VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001995{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001996 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
1997 VkLayerDispatchTable *pTable = tableMap[pDisp];
1998 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001999 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002000 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2001 if (pCB) {
2002 if (CB_NEW != pCB->state)
2003 resetCB(cmdBuffer);
2004 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002005 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002006 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002007 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002008 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002009 }
2010 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002011 }
2012 else {
2013 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002014 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
2015 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002016 }
2017 updateCBTracking(cmdBuffer);
2018 }
2019 return result;
2020}
2021
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002022VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002023{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002024 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2025 VkLayerDispatchTable *pTable = tableMap[pDisp];
2026 VkResult result = pTable->EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002027 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002028 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2029 if (pCB) {
2030 pCB->state = CB_UPDATE_COMPLETE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002031 // Reset CB status flags
2032 pCB->status = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002033 printCB(cmdBuffer);
2034 }
2035 else {
2036 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002037 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
2038 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002039 }
2040 updateCBTracking(cmdBuffer);
2041 //cbDumpDotFile("cb_dump.dot");
2042 }
2043 return result;
2044}
2045
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002046VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002047{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002048 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2049 VkLayerDispatchTable *pTable = tableMap[pDisp];
2050 VkResult result = pTable->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002051 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002052 resetCB(cmdBuffer);
2053 updateCBTracking(cmdBuffer);
2054 }
2055 return result;
2056}
2057
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002058VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002059{
2060 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2061 if (pCB) {
2062 updateCBTracking(cmdBuffer);
2063 addCmd(pCB, CMD_BINDPIPELINE);
2064 PIPELINE_NODE* pPN = getPipeline(pipeline);
2065 if (pPN) {
2066 pCB->lastBoundPipeline = pipeline;
2067 loader_platform_thread_lock_mutex(&globalLock);
2068 g_lastBoundPipeline = pPN;
2069 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002070 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002071 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2072 VkLayerDispatchTable *pTable = tableMap[pDisp];
2073 pTable->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002074 }
2075 else {
2076 char str[1024];
2077 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002078 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002079 }
2080 }
2081 else {
2082 char str[1024];
2083 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002084 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002085 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002086}
2087
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002088VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002089{
2090 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002091 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2092 VkLayerDispatchTable *pTable = tableMap[pDisp];
2093 pTable->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002094}
2095
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002096VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002097{
2098 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2099 if (pCB) {
2100 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002101 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002102 if (validateBoundPipeline(cmdBuffer)) {
2103 for (uint32_t i=0; i<setCount; i++) {
2104 if (getSetNode(pDescriptorSets[i])) {
2105 loader_platform_thread_lock_mutex(&globalLock);
2106 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2107 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2108 g_lastBoundDescriptorSet = pDescriptorSets[i];
2109 loader_platform_thread_unlock_mutex(&globalLock);
2110 char str[1024];
2111 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
2112 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002113 }
2114 else {
2115 char str[1024];
2116 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
2117 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
2118 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002119 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002120 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2121 VkLayerDispatchTable *pTable = tableMap[pDisp];
2122 pTable->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002123 }
2124 }
2125 else {
2126 char str[1024];
2127 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002128 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002129 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002130}
2131
Tony Barbour8205d902015-04-16 15:59:00 -06002132VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002133{
2134 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2135 if (pCB) {
2136 updateCBTracking(cmdBuffer);
2137 addCmd(pCB, CMD_BINDINDEXBUFFER);
2138 // TODO : Track idxBuffer binding
2139 }
2140 else {
2141 char str[1024];
2142 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002143 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002144 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002145 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2146 VkLayerDispatchTable *pTable = tableMap[pDisp];
2147 pTable->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002148}
2149
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002150VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2151 VkCmdBuffer cmdBuffer,
2152 uint32_t startBinding,
2153 uint32_t bindingCount,
2154 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002155 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002156{
2157 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2158 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002159 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002160 updateCBTracking(cmdBuffer);
2161 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002162 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002163 if (validateBoundPipeline(cmdBuffer)) {
Jon Ashburne0fa2282015-05-20 09:00:28 -06002164 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2165 VkLayerDispatchTable *pTable = tableMap[pDisp];
2166 pTable->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002167 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002168 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002169 char str[1024];
2170 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002171 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002172 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002173}
2174
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002175VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002176{
2177 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002178 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002179 if (pCB) {
2180 updateCBTracking(cmdBuffer);
2181 addCmd(pCB, CMD_DRAW);
2182 pCB->drawCount[DRAW]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002183 loader_platform_thread_lock_mutex(&globalLock);
2184 valid = validate_draw_state_flags(cmdBuffer);
2185 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002186 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002187 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2188 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002189 synchAndPrintDSConfig(cmdBuffer);
2190 }
2191 else {
2192 char str[1024];
2193 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002194 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002195 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002196 if (valid) {
2197 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2198 VkLayerDispatchTable *pTable = tableMap[pDisp];
2199 pTable->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2200 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002201}
2202
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002203VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002204{
2205 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002206 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002207 if (pCB) {
2208 updateCBTracking(cmdBuffer);
2209 addCmd(pCB, CMD_DRAWINDEXED);
2210 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002211 loader_platform_thread_lock_mutex(&globalLock);
2212 valid = validate_draw_state_flags(cmdBuffer);
2213 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002214 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002215 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2216 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002217 synchAndPrintDSConfig(cmdBuffer);
2218 }
2219 else {
2220 char str[1024];
2221 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002222 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002223 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002224 if (valid) {
2225 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2226 VkLayerDispatchTable *pTable = tableMap[pDisp];
2227 pTable->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2228 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002229}
2230
Tony Barbour8205d902015-04-16 15:59:00 -06002231VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002232{
2233 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002234 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002235 if (pCB) {
2236 updateCBTracking(cmdBuffer);
2237 addCmd(pCB, CMD_DRAWINDIRECT);
2238 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002239 loader_platform_thread_lock_mutex(&globalLock);
2240 valid = validate_draw_state_flags(cmdBuffer);
2241 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002242 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002243 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2244 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002245 synchAndPrintDSConfig(cmdBuffer);
2246 }
2247 else {
2248 char str[1024];
2249 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002250 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002251 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002252 if (valid) {
2253 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2254 VkLayerDispatchTable *pTable = tableMap[pDisp];
2255 pTable->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2256 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002257}
2258
Tony Barbour8205d902015-04-16 15:59:00 -06002259VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002260{
2261 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002262 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002263 if (pCB) {
2264 updateCBTracking(cmdBuffer);
2265 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2266 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002267 loader_platform_thread_lock_mutex(&globalLock);
2268 valid = validate_draw_state_flags(cmdBuffer);
2269 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002270 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002271 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2272 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002273 synchAndPrintDSConfig(cmdBuffer);
2274 }
2275 else {
2276 char str[1024];
2277 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002278 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002279 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002280 if (valid) {
2281 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2282 VkLayerDispatchTable *pTable = tableMap[pDisp];
2283 pTable->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2284 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002285}
2286
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002287VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002288{
2289 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2290 if (pCB) {
2291 updateCBTracking(cmdBuffer);
2292 addCmd(pCB, CMD_DISPATCH);
2293 }
2294 else {
2295 char str[1024];
2296 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002297 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002298 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002299 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2300 VkLayerDispatchTable *pTable = tableMap[pDisp];
2301 pTable->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002302}
2303
Tony Barbour8205d902015-04-16 15:59:00 -06002304VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002305{
2306 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2307 if (pCB) {
2308 updateCBTracking(cmdBuffer);
2309 addCmd(pCB, CMD_DISPATCHINDIRECT);
2310 }
2311 else {
2312 char str[1024];
2313 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002314 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002315 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002316 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2317 VkLayerDispatchTable *pTable = tableMap[pDisp];
2318 pTable->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002319}
2320
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002321VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002322{
2323 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2324 if (pCB) {
2325 updateCBTracking(cmdBuffer);
2326 addCmd(pCB, CMD_COPYBUFFER);
2327 }
2328 else {
2329 char str[1024];
2330 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002331 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002332 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002333 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2334 VkLayerDispatchTable *pTable = tableMap[pDisp];
2335 pTable->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002336}
2337
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002338VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2339 VkImage srcImage,
2340 VkImageLayout srcImageLayout,
2341 VkImage destImage,
2342 VkImageLayout destImageLayout,
2343 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344{
2345 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2346 if (pCB) {
2347 updateCBTracking(cmdBuffer);
2348 addCmd(pCB, CMD_COPYIMAGE);
2349 }
2350 else {
2351 char str[1024];
2352 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002353 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002354 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002355 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2356 VkLayerDispatchTable *pTable = tableMap[pDisp];
2357 pTable->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002358}
2359
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002360VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2361 VkImage srcImage, VkImageLayout srcImageLayout,
2362 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002363 uint32_t regionCount, const VkImageBlit* pRegions,
2364 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002365{
2366 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2367 if (pCB) {
2368 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002369 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002370 }
2371 else {
2372 char str[1024];
2373 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002374 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002375 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002376 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2377 VkLayerDispatchTable *pTable = tableMap[pDisp];
2378 pTable->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002379}
2380
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002381VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2382 VkBuffer srcBuffer,
2383 VkImage destImage, VkImageLayout destImageLayout,
2384 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002385{
2386 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2387 if (pCB) {
2388 updateCBTracking(cmdBuffer);
2389 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2390 }
2391 else {
2392 char str[1024];
2393 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002394 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002395 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002396 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2397 VkLayerDispatchTable *pTable = tableMap[pDisp];
2398 pTable->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002399}
2400
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002401VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2402 VkImage srcImage, VkImageLayout srcImageLayout,
2403 VkBuffer destBuffer,
2404 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002405{
2406 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2407 if (pCB) {
2408 updateCBTracking(cmdBuffer);
2409 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2410 }
2411 else {
2412 char str[1024];
2413 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002414 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002415 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002416 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2417 VkLayerDispatchTable *pTable = tableMap[pDisp];
2418 pTable->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002419}
2420
Tony Barbour8205d902015-04-16 15:59:00 -06002421VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002422{
2423 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2424 if (pCB) {
2425 updateCBTracking(cmdBuffer);
2426 addCmd(pCB, CMD_UPDATEBUFFER);
2427 }
2428 else {
2429 char str[1024];
2430 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002431 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002432 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002433 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2434 VkLayerDispatchTable *pTable = tableMap[pDisp];
2435 pTable->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002436}
2437
Tony Barbour8205d902015-04-16 15:59:00 -06002438VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002439{
2440 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2441 if (pCB) {
2442 updateCBTracking(cmdBuffer);
2443 addCmd(pCB, CMD_FILLBUFFER);
2444 }
2445 else {
2446 char str[1024];
2447 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002448 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002449 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002450 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2451 VkLayerDispatchTable *pTable = tableMap[pDisp];
2452 pTable->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453}
2454
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002455VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2456 VkCmdBuffer cmdBuffer,
2457 VkImage image, VkImageLayout imageLayout,
2458 const VkClearColor *pColor,
2459 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002460{
2461 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2462 if (pCB) {
2463 updateCBTracking(cmdBuffer);
2464 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2465 }
2466 else {
2467 char str[1024];
2468 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002469 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002471 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2472 VkLayerDispatchTable *pTable = tableMap[pDisp];
2473 pTable->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002474}
2475
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002476VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2477 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002478 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002479 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002480{
2481 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2482 if (pCB) {
2483 updateCBTracking(cmdBuffer);
2484 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2485 }
2486 else {
2487 char str[1024];
2488 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002489 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002490 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002491 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2492 VkLayerDispatchTable *pTable = tableMap[pDisp];
2493 pTable->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002494}
2495
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002496VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2497 VkImage srcImage, VkImageLayout srcImageLayout,
2498 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002499 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002500{
2501 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2502 if (pCB) {
2503 updateCBTracking(cmdBuffer);
2504 addCmd(pCB, CMD_RESOLVEIMAGE);
2505 }
2506 else {
2507 char str[1024];
2508 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002509 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002510 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002511 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2512 VkLayerDispatchTable *pTable = tableMap[pDisp];
2513 pTable->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002514}
2515
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002516VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002517{
2518 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2519 if (pCB) {
2520 updateCBTracking(cmdBuffer);
2521 addCmd(pCB, CMD_SETEVENT);
2522 }
2523 else {
2524 char str[1024];
2525 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002526 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002527 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002528 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2529 VkLayerDispatchTable *pTable = tableMap[pDisp];
2530 pTable->CmdSetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531}
2532
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002533VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002534{
2535 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2536 if (pCB) {
2537 updateCBTracking(cmdBuffer);
2538 addCmd(pCB, CMD_RESETEVENT);
2539 }
2540 else {
2541 char str[1024];
2542 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002543 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002544 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002545 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2546 VkLayerDispatchTable *pTable = tableMap[pDisp];
2547 pTable->CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002548}
2549
Tony Barbour8205d902015-04-16 15:59:00 -06002550VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t eventCount, const VkEvent* pEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002551{
2552 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2553 if (pCB) {
2554 updateCBTracking(cmdBuffer);
2555 addCmd(pCB, CMD_WAITEVENTS);
2556 }
2557 else {
2558 char str[1024];
2559 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002560 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002561 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002562 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2563 VkLayerDispatchTable *pTable = tableMap[pDisp];
2564 pTable->CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002565}
2566
Tony Barbour8205d902015-04-16 15:59:00 -06002567VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002568{
2569 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2570 if (pCB) {
2571 updateCBTracking(cmdBuffer);
2572 addCmd(pCB, CMD_PIPELINEBARRIER);
2573 }
2574 else {
2575 char str[1024];
2576 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002577 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002578 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002579 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2580 VkLayerDispatchTable *pTable = tableMap[pDisp];
2581 pTable->CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002582}
2583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002584VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002585{
2586 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2587 if (pCB) {
2588 updateCBTracking(cmdBuffer);
2589 addCmd(pCB, CMD_BEGINQUERY);
2590 }
2591 else {
2592 char str[1024];
2593 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002594 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002595 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002596 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2597 VkLayerDispatchTable *pTable = tableMap[pDisp];
2598 pTable->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002599}
2600
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002601VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002602{
2603 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2604 if (pCB) {
2605 updateCBTracking(cmdBuffer);
2606 addCmd(pCB, CMD_ENDQUERY);
2607 }
2608 else {
2609 char str[1024];
2610 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002611 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002612 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002613 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2614 VkLayerDispatchTable *pTable = tableMap[pDisp];
2615 pTable->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002616}
2617
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002618VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002619{
2620 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2621 if (pCB) {
2622 updateCBTracking(cmdBuffer);
2623 addCmd(pCB, CMD_RESETQUERYPOOL);
2624 }
2625 else {
2626 char str[1024];
2627 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002628 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002629 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002630 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2631 VkLayerDispatchTable *pTable = tableMap[pDisp];
2632 pTable->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002633}
2634
Tony Barbour8205d902015-04-16 15:59:00 -06002635VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002636{
2637 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2638 if (pCB) {
2639 updateCBTracking(cmdBuffer);
2640 addCmd(pCB, CMD_WRITETIMESTAMP);
2641 }
2642 else {
2643 char str[1024];
2644 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002645 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002647 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2648 VkLayerDispatchTable *pTable = tableMap[pDisp];
2649 pTable->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002650}
2651
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002652VK_LAYER_EXPORT void VKAPI vkCmdInitAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002653{
2654 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2655 if (pCB) {
2656 updateCBTracking(cmdBuffer);
2657 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2658 }
2659 else {
2660 char str[1024];
2661 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002662 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002664 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2665 VkLayerDispatchTable *pTable = tableMap[pDisp];
2666 pTable->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002667}
2668
Tony Barbour8205d902015-04-16 15:59:00 -06002669VK_LAYER_EXPORT void VKAPI vkCmdLoadAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer srcBuffer, VkDeviceSize srcOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002670{
2671 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2672 if (pCB) {
2673 updateCBTracking(cmdBuffer);
2674 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2675 }
2676 else {
2677 char str[1024];
2678 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002679 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002680 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002681 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2682 VkLayerDispatchTable *pTable = tableMap[pDisp];
2683 pTable->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002684}
2685
Tony Barbour8205d902015-04-16 15:59:00 -06002686VK_LAYER_EXPORT void VKAPI vkCmdSaveAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002687{
2688 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2689 if (pCB) {
2690 updateCBTracking(cmdBuffer);
2691 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2692 }
2693 else {
2694 char str[1024];
2695 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002696 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002697 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002698 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2699 VkLayerDispatchTable *pTable = tableMap[pDisp];
2700 pTable->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002701}
2702
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002703VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002704{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002705 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2706 VkLayerDispatchTable *pTable = tableMap[pDisp];
2707 VkResult result = pTable->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002708 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002709 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002710 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002711 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002712 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2713 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002714 }
2715 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002716 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2717 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002718 }
2719 frameBufferMap[*pFramebuffer] = localFBCI;
2720 }
2721 return result;
2722}
2723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002724VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002725{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002726 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2727 VkLayerDispatchTable *pTable = tableMap[pDisp];
2728 VkResult result = pTable->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002729 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002730 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002731 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002732 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002733 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2734 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002735 }
2736 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002737 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2738 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002739 }
2740 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002741 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2742 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002743 }
2744 renderPassMap[*pRenderPass] = localRPCI;
2745 }
2746 return result;
2747}
2748
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002749VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002750{
2751 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2752 if (pCB) {
2753 updateCBTracking(cmdBuffer);
2754 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002755 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2756 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002757 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002758 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002759 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002760 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002761 char str[1024];
2762 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002763 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002764 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002765 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2766 VkLayerDispatchTable *pTable = tableMap[pDisp];
2767 pTable->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002768}
2769
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002770VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002771{
2772 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2773 if (pCB) {
2774 updateCBTracking(cmdBuffer);
2775 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002776 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002777 }
2778 else {
2779 char str[1024];
2780 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002781 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002782 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002783 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2784 VkLayerDispatchTable *pTable = tableMap[pDisp];
2785 pTable->CmdEndRenderPass(cmdBuffer, renderPass);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002786}
2787
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002788VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002789{
2790 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002791 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002792 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002793 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002794 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2795 pNewDbgFuncNode->pUserData = pUserData;
2796 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2797 g_pDbgFunctionHead = pNewDbgFuncNode;
2798 // force callbacks if DebugAction hasn't been set already other than initial value
Jon Ashburne0fa2282015-05-20 09:00:28 -06002799 if (g_actionIsDefault) {
2800 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
2801 }
2802
2803 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
2804 VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[*ppDisp];
2805 VkResult result = pInstTable->DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002806 return result;
2807}
2808
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002809VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002810{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002811 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2812 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002813 while (pTrav) {
2814 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2815 pPrev->pNext = pTrav->pNext;
2816 if (g_pDbgFunctionHead == pTrav)
2817 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002818 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002819 break;
2820 }
2821 pPrev = pTrav;
2822 pTrav = pTrav->pNext;
2823 }
2824 if (g_pDbgFunctionHead == NULL)
2825 {
2826 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002827 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002828 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002829 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002830 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002831
2832 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
2833 VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[*ppDisp];
2834 VkResult result = pInstTable->DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002835 return result;
2836}
2837
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002838VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002839{
2840 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2841 if (pCB) {
2842 updateCBTracking(cmdBuffer);
2843 addCmd(pCB, CMD_DBGMARKERBEGIN);
2844 }
2845 else {
2846 char str[1024];
2847 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002848 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002849 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002850 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2851 VkLayerDispatchTable *pTable = tableMap[pDisp];
2852 pTable->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002853}
2854
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002855VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856{
2857 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2858 if (pCB) {
2859 updateCBTracking(cmdBuffer);
2860 addCmd(pCB, CMD_DBGMARKEREND);
2861 }
2862 else {
2863 char str[1024];
2864 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002865 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002866 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002867 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2868 VkLayerDispatchTable *pTable = tableMap[pDisp];
2869 pTable->CmdDbgMarkerEnd(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002870}
2871
2872// TODO : Want to pass in a cmdBuffer here based on which state to display
2873void drawStateDumpDotFile(char* outFileName)
2874{
2875 // TODO : Currently just setting cmdBuffer based on global var
2876 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2877 dumpGlobalDotFile(outFileName);
2878}
2879
2880void drawStateDumpCommandBufferDotFile(char* outFileName)
2881{
2882 cbDumpDotFile(outFileName);
2883}
2884
2885void drawStateDumpPngFile(char* outFileName)
2886{
2887#if defined(_WIN32)
2888// FIXME: NEED WINDOWS EQUIVALENT
2889 char str[1024];
2890 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002891 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002892#else // WIN32
2893 char dotExe[32] = "/usr/bin/dot";
2894 if( access(dotExe, X_OK) != -1) {
2895 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2896 char dotCmd[1024];
2897 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002898 int retval = system(dotCmd);
2899 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002900 remove("/tmp/tmp.dot");
2901 }
2902 else {
2903 char str[1024];
2904 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002905 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002906 }
2907#endif // WIN32
2908}
2909
Jon Ashburn1245cec2015-05-18 13:20:15 -06002910VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002911{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002912 VkBaseLayerObject* devw = (VkBaseLayerObject *) dev;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002913
Jon Ashburn1245cec2015-05-18 13:20:15 -06002914 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002915 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002916
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002917 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002918 initDeviceTable((const VkBaseLayerObject *) dev);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002919
Jon Ashburn1245cec2015-05-18 13:20:15 -06002920 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
2921 return (void *) vkGetDeviceProcAddr;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002922 if (!strcmp(funcName, "vkDestroyDevice"))
2923 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002924 if (!strcmp(funcName, "vkQueueSubmit"))
2925 return (void*) vkQueueSubmit;
2926 if (!strcmp(funcName, "vkDestroyObject"))
2927 return (void*) vkDestroyObject;
2928 if (!strcmp(funcName, "vkCreateBufferView"))
2929 return (void*) vkCreateBufferView;
2930 if (!strcmp(funcName, "vkCreateImageView"))
2931 return (void*) vkCreateImageView;
2932 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2933 return (void*) vkCreateGraphicsPipeline;
2934 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2935 return (void*) vkCreateGraphicsPipelineDerivative;
2936 if (!strcmp(funcName, "vkCreateSampler"))
2937 return (void*) vkCreateSampler;
2938 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2939 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002940 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2941 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002942 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2943 return (void*) vkCreateDescriptorPool;
2944 if (!strcmp(funcName, "vkResetDescriptorPool"))
2945 return (void*) vkResetDescriptorPool;
2946 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2947 return (void*) vkAllocDescriptorSets;
2948 if (!strcmp(funcName, "vkClearDescriptorSets"))
2949 return (void*) vkClearDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002950 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2951 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002952 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2953 return (void*) vkCreateDynamicViewportState;
2954 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2955 return (void*) vkCreateDynamicRasterState;
2956 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2957 return (void*) vkCreateDynamicColorBlendState;
2958 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2959 return (void*) vkCreateDynamicDepthStencilState;
2960 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2961 return (void*) vkCreateCommandBuffer;
2962 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2963 return (void*) vkBeginCommandBuffer;
2964 if (!strcmp(funcName, "vkEndCommandBuffer"))
2965 return (void*) vkEndCommandBuffer;
2966 if (!strcmp(funcName, "vkResetCommandBuffer"))
2967 return (void*) vkResetCommandBuffer;
2968 if (!strcmp(funcName, "vkCmdBindPipeline"))
2969 return (void*) vkCmdBindPipeline;
2970 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2971 return (void*) vkCmdBindDynamicStateObject;
2972 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2973 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002974 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2975 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002976 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2977 return (void*) vkCmdBindIndexBuffer;
2978 if (!strcmp(funcName, "vkCmdDraw"))
2979 return (void*) vkCmdDraw;
2980 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2981 return (void*) vkCmdDrawIndexed;
2982 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2983 return (void*) vkCmdDrawIndirect;
2984 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2985 return (void*) vkCmdDrawIndexedIndirect;
2986 if (!strcmp(funcName, "vkCmdDispatch"))
2987 return (void*) vkCmdDispatch;
2988 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2989 return (void*) vkCmdDispatchIndirect;
2990 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2991 return (void*) vkCmdCopyBuffer;
2992 if (!strcmp(funcName, "vkCmdCopyImage"))
2993 return (void*) vkCmdCopyImage;
2994 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2995 return (void*) vkCmdCopyBufferToImage;
2996 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2997 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002998 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2999 return (void*) vkCmdUpdateBuffer;
3000 if (!strcmp(funcName, "vkCmdFillBuffer"))
3001 return (void*) vkCmdFillBuffer;
3002 if (!strcmp(funcName, "vkCmdClearColorImage"))
3003 return (void*) vkCmdClearColorImage;
3004 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
3005 return (void*) vkCmdClearDepthStencil;
3006 if (!strcmp(funcName, "vkCmdResolveImage"))
3007 return (void*) vkCmdResolveImage;
3008 if (!strcmp(funcName, "vkCmdSetEvent"))
3009 return (void*) vkCmdSetEvent;
3010 if (!strcmp(funcName, "vkCmdResetEvent"))
3011 return (void*) vkCmdResetEvent;
3012 if (!strcmp(funcName, "vkCmdWaitEvents"))
3013 return (void*) vkCmdWaitEvents;
3014 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
3015 return (void*) vkCmdPipelineBarrier;
3016 if (!strcmp(funcName, "vkCmdBeginQuery"))
3017 return (void*) vkCmdBeginQuery;
3018 if (!strcmp(funcName, "vkCmdEndQuery"))
3019 return (void*) vkCmdEndQuery;
3020 if (!strcmp(funcName, "vkCmdResetQueryPool"))
3021 return (void*) vkCmdResetQueryPool;
3022 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
3023 return (void*) vkCmdWriteTimestamp;
3024 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
3025 return (void*) vkCmdInitAtomicCounters;
3026 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
3027 return (void*) vkCmdLoadAtomicCounters;
3028 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
3029 return (void*) vkCmdSaveAtomicCounters;
3030 if (!strcmp(funcName, "vkCreateFramebuffer"))
3031 return (void*) vkCreateFramebuffer;
3032 if (!strcmp(funcName, "vkCreateRenderPass"))
3033 return (void*) vkCreateRenderPass;
3034 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
3035 return (void*) vkCmdBeginRenderPass;
3036 if (!strcmp(funcName, "vkCmdEndRenderPass"))
3037 return (void*) vkCmdEndRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003038 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
3039 return (void*) vkCmdDbgMarkerBegin;
3040 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
3041 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003042 if (!strcmp("drawStateDumpDotFile", funcName))
3043 return (void*) drawStateDumpDotFile;
3044 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
3045 return (void*) drawStateDumpCommandBufferDotFile;
3046 if (!strcmp("drawStateDumpPngFile", funcName))
3047 return (void*) drawStateDumpPngFile;
3048 else {
Jon Ashburn1245cec2015-05-18 13:20:15 -06003049 if (devw->pGPA == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003050 return NULL;
Jon Ashburn1245cec2015-05-18 13:20:15 -06003051 return devw->pGPA((VkObject)devw->nextObject, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003052 }
3053}
3054
3055VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3056{
3057 VkBaseLayerObject* instw = (VkBaseLayerObject *) instance;
3058 if (instance == NULL)
3059 return NULL;
3060
Jon Ashburnd9564002015-05-07 10:27:37 -06003061 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburne0fa2282015-05-20 09:00:28 -06003062 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003063
3064 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
3065 return (void *) vkGetInstanceProcAddr;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003066 if (!strcmp(funcName, "vkDestroyInstance"))
3067 return (void *) vkDestroyInstance;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003068 if (!strcmp(funcName, "vkCreateDevice"))
3069 return (void*) vkCreateDevice;
3070 if (!strcmp(funcName, "vkEnumerateLayers"))
3071 return (void*) vkEnumerateLayers;
3072 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
3073 return (void*) vkDbgRegisterMsgCallback;
3074 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
3075 return (void*) vkDbgUnregisterMsgCallback;
3076 else {
3077 if (instw->pGPA == NULL)
3078 return NULL;
3079 return instw->pGPA((VkObject) instw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003080 }
3081}