blob: 61f8804d6f712a9f9360d6ece4af1abc464b2b65 [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
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600318static bool32_t validate_status(VkCmdBuffer cb, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
319{
Tobin Ehlis97866202015-06-10 12:57:07 -0600320 if (cmdBufferMap.find(cb) != cmdBufferMap.end()) {
321 GLOBAL_CB_NODE* pNode = cmdBufferMap[cb];
322 // If non-zero enable mask is present, check it against status but if enable_mask
323 // is 0 then no enable required so we should always just check status
324 if ((!enable_mask) || (enable_mask & pNode->status)) {
325 if ((pNode->status & status_mask) != status_flag) {
326 char str[1024];
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600327 sprintf(str, "CB object 0x%" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(cb), str);
328 layerCbMsg(msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, error_code, "DS", str);
Tobin Ehlis97866202015-06-10 12:57:07 -0600329 return VK_FALSE;
330 }
331 }
332 return VK_TRUE;
333 }
334 else {
335 // If we do not find it print an error
336 char str[1024];
337 sprintf(str, "Unable to obtain status for non-existent CB object 0x%" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(cb));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600338 layerCbMsg(msg_flags, (VkObjectType) 0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis97866202015-06-10 12:57:07 -0600339 return VK_FALSE;
340 }
341}
342static bool32_t validate_draw_state_flags(VkCmdBuffer cb) {
343 bool32_t result1, result2, result3, result4;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600344 result1 = validate_status(cb, CBSTATUS_NONE, CBSTATUS_VIEWPORT_BOUND, CBSTATUS_VIEWPORT_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
345 result2 = validate_status(cb, CBSTATUS_NONE, CBSTATUS_RASTER_BOUND, CBSTATUS_RASTER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");
346 result3 = validate_status(cb, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_COLOR_BLEND_BOUND, CBSTATUS_COLOR_BLEND_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");
347 result4 = validate_status(cb, CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE, CBSTATUS_DEPTH_STENCIL_BOUND, CBSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");
Tobin Ehlis97866202015-06-10 12:57:07 -0600348 return ((result1 == VK_TRUE) && (result2 == VK_TRUE) && (result3 == VK_TRUE) && (result4 == VK_TRUE));
349}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600350// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600351static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600352{
353 GLOBAL_CB_NODE* pCB = getCBNode(cb);
354 if (pCB) {
355 loader_platform_thread_lock_mutex(&globalLock);
356 char str[4*1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600357 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600358 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600359 sprintf(str, "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600360 layerCbMsg(VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
361 layerCbMsg(VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", dynamic_display(pCB->lastBoundDynamicState[i]->pCreateInfo, " ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600362 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600363 } else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600364 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600365 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600373 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600561 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, 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);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600618 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600619 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);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600634 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600635 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);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600651 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 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);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600668 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 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);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600718 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, VK_NULL_HANDLE, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600757 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600796 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600806 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600814 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, 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()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600825 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600945 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600996 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001055 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001066 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001080 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001323 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001332 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001337 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001343 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001362 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001365 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001370 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001374 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001378 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001383 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001386 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001392 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001393 }
1394 else {
1395 sprintf(tmp_str, "FYI: No descriptors in descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001396 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001397 }
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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001408 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 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 Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001412 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 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
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001490 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportFlags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001491 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{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001519 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06001520 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};
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001559#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 1
1560static const VkExtensionProperties dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1561 {
1562 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1563 "DrawState",
1564 0x10,
1565 "Sample layer: DrawState",
1566// 0,
1567// NULL,
1568 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001569};
1570
1571VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001572 VkExtensionInfoType infoType,
1573 uint32_t extensionIndex,
1574 size_t* pDataSize,
1575 void* pData)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001576{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001577 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Jon Ashburneb2728b2015-04-10 14:33:07 -06001578 uint32_t *count;
1579
1580 if (pDataSize == NULL)
1581 return VK_ERROR_INVALID_POINTER;
1582
1583 switch (infoType) {
1584 case VK_EXTENSION_INFO_TYPE_COUNT:
1585 *pDataSize = sizeof(uint32_t);
1586 if (pData == NULL)
1587 return VK_SUCCESS;
1588 count = (uint32_t *) pData;
1589 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1590 break;
1591 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1592 *pDataSize = sizeof(VkExtensionProperties);
1593 if (pData == NULL)
1594 return VK_SUCCESS;
1595 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1596 return VK_ERROR_INVALID_VALUE;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001597 memcpy((VkExtensionProperties *) pData, &dsExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburneb2728b2015-04-10 14:33:07 -06001598 break;
1599 default:
1600 return VK_ERROR_INVALID_VALUE;
1601 };
1602
1603 return VK_SUCCESS;
1604}
1605
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001606VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001607{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001608 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001609 for (uint32_t i=0; i < cmdBufferCount; i++) {
1610 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001611 pCB = getCBNode(pCmdBuffers[i]);
1612 loader_platform_thread_lock_mutex(&globalLock);
1613 if (CB_UPDATE_COMPLETE != pCB->state) {
1614 // Flag error for using CB w/o vkEndCommandBuffer() called
1615 char str[1024];
1616 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001617 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, pCB->cmdBuffer, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS", str);
Tobin Ehlise90b1712015-05-27 14:30:06 -06001618 loader_platform_thread_unlock_mutex(&globalLock);
1619 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001620 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001621 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001622 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001623
1624 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) queue;
1625 VkLayerDispatchTable *pTable = tableMap[pDisp];
1626 VkResult result = pTable->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001627 return result;
1628}
1629
Mike Stroyan230e6252015-04-17 12:36:38 -06001630VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001631{
1632 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Jon Ashburne0fa2282015-05-20 09:00:28 -06001633 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1634 VkLayerDispatchTable *pTable = tableMap[pDisp];
1635 VkResult result = pTable->DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001636 return result;
1637}
1638
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001639VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001640{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001641 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1642 VkLayerDispatchTable *pTable = tableMap[pDisp];
1643 VkResult result = pTable->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001644 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001645 loader_platform_thread_lock_mutex(&globalLock);
1646 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1647 pNewNode->buffer = *pView;
1648 pNewNode->createInfo = *pCreateInfo;
1649 bufferMap[*pView] = pNewNode;
1650 loader_platform_thread_unlock_mutex(&globalLock);
1651 }
1652 return result;
1653}
1654
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001655VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001656{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001657 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1658 VkLayerDispatchTable *pTable = tableMap[pDisp];
1659 VkResult result = pTable->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001660 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001661 loader_platform_thread_lock_mutex(&globalLock);
1662 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1663 pNewNode->image = *pView;
1664 pNewNode->createInfo = *pCreateInfo;
1665 imageMap[*pView] = pNewNode;
1666 loader_platform_thread_unlock_mutex(&globalLock);
1667 }
1668 return result;
1669}
1670
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001671static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001672{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001673 // Create LL HEAD for this Pipeline
1674 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001675 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1676 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1677 pPipeNode->pipeline = *pPipeline;
1678 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001679 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001680}
1681
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001682VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001684 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1685 VkLayerDispatchTable *pTable = tableMap[pDisp];
1686 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001687 // Create LL HEAD for this Pipeline
1688 char str[1024];
1689 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001690 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001691
1692 track_pipeline(pCreateInfo, pPipeline);
1693
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001694 return result;
1695}
1696
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001697VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1698 VkDevice device,
1699 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1700 VkPipeline basePipeline,
1701 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001702{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001703 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1704 VkLayerDispatchTable *pTable = tableMap[pDisp];
1705 VkResult result = pTable->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001706 // Create LL HEAD for this Pipeline
1707 char str[1024];
1708 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001709 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001710
1711 track_pipeline(pCreateInfo, pPipeline);
1712
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001713 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001714
1715 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001716}
1717
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001718VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001719{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001720 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1721 VkLayerDispatchTable *pTable = tableMap[pDisp];
1722 VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001723 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001724 loader_platform_thread_lock_mutex(&globalLock);
1725 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1726 pNewNode->sampler = *pSampler;
1727 pNewNode->createInfo = *pCreateInfo;
1728 sampleMap[*pSampler] = pNewNode;
1729 loader_platform_thread_unlock_mutex(&globalLock);
1730 }
1731 return result;
1732}
1733
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001734VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001735{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001736 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1737 VkLayerDispatchTable *pTable = tableMap[pDisp];
1738 VkResult result = pTable->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001739 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001740 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1741 if (NULL == pNewNode) {
1742 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001743 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001744 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001745 }
1746 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001747 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1748 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1749 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001750 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001751 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001752 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001753 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001754 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001755 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1756 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001757 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001758 }
1759 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001760 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001762 uint32_t j = 0;
1763 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001764 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001765 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001766 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001767 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001768 }
1769 }
1770 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001772 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1773 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001774 // Put new node at Head of global Layer list
1775 loader_platform_thread_lock_mutex(&globalLock);
1776 layoutMap[*pSetLayout] = pNewNode;
1777 loader_platform_thread_unlock_mutex(&globalLock);
1778 }
1779 return result;
1780}
1781
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001782VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001783{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001784 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1785 VkLayerDispatchTable *pTable = tableMap[pDisp];
1786 VkResult result = pTable->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001787 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001788 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001789 }
1790 return result;
1791}
1792
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001793VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001794{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001795 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1796 VkLayerDispatchTable *pTable = tableMap[pDisp];
1797 VkResult result = pTable->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001798 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001799 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001800 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001801 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001802 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001803 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001804 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001805 if (NULL == pNewNode) {
1806 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001807 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001808 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001809 }
1810 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001811 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001812 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1813 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001815 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1816 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001817 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1818 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001819 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001821 pNewNode->pool = *pDescriptorPool;
1822 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001823 }
1824 loader_platform_thread_unlock_mutex(&globalLock);
1825 }
1826 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001827 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001828 }
1829 return result;
1830}
1831
Mike Stroyan230e6252015-04-17 12:36:38 -06001832VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001833{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001834 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1835 VkLayerDispatchTable *pTable = tableMap[pDisp];
1836 VkResult result = pTable->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001837 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001838 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001839 }
1840 return result;
1841}
1842
Mike Stroyan230e6252015-04-17 12:36:38 -06001843VK_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 -06001844{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001845 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1846 VkLayerDispatchTable *pTable = tableMap[pDisp];
1847 VkResult result = pTable->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001849 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1850 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001851 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001852 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001853 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001854 }
1855 else {
1856 for (uint32_t i = 0; i < *pCount; i++) {
1857 char str[1024];
1858 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001859 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001860 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001861 SET_NODE* pNewNode = new SET_NODE;
1862 if (NULL == pNewNode) {
1863 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001864 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001865 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001866 }
1867 else {
1868 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001869 // Insert set at head of Set LL for this pool
1870 pNewNode->pNext = pPoolNode->pSets;
1871 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001872 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1873 if (NULL == pLayout) {
1874 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001875 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001876 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001877 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001878 pNewNode->pLayout = pLayout;
1879 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001880 pNewNode->set = pDescriptorSets[i];
1881 pNewNode->setUsage = setUsage;
1882 pNewNode->descriptorCount = pLayout->endIndex + 1;
1883 if (pNewNode->descriptorCount) {
1884 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1885 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1886 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1887 }
1888 setMap[pDescriptorSets[i]] = pNewNode;
1889 }
1890 }
1891 }
1892 }
1893 return result;
1894}
1895
Mike Stroyan230e6252015-04-17 12:36:38 -06001896VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001897{
1898 for (uint32_t i = 0; i < count; i++) {
1899 clearDescriptorSet(pDescriptorSets[i]);
1900 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001901 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1902 VkLayerDispatchTable *pTable = tableMap[pDisp];
1903 pTable->ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001904}
1905
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001906VK_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 -06001907{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001908 if (dsUpdate(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
Jon Ashburne0fa2282015-05-20 09:00:28 -06001909 dsUpdate(VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
1910 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1911 VkLayerDispatchTable *pTable = tableMap[pDisp];
1912 return pTable->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
1913 }
1914 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001915}
1916
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001917VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001918{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001919 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1920 VkLayerDispatchTable *pTable = tableMap[pDisp];
1921 VkResult result = pTable->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001922 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001923 return result;
1924}
1925
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001926VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001927{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001928 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1929 VkLayerDispatchTable *pTable = tableMap[pDisp];
1930 VkResult result = pTable->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001931 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001932 return result;
1933}
1934
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001935VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001936{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001937 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1938 VkLayerDispatchTable *pTable = tableMap[pDisp];
1939 VkResult result = pTable->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001940 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001941 return result;
1942}
1943
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001944VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001945{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001946 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1947 VkLayerDispatchTable *pTable = tableMap[pDisp];
1948 VkResult result = pTable->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001949 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001950 return result;
1951}
1952
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001953VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001954{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001955 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1956 VkLayerDispatchTable *pTable = tableMap[pDisp];
1957 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001958 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001959 loader_platform_thread_lock_mutex(&globalLock);
1960 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1961 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1962 pCB->cmdBuffer = *pCmdBuffer;
1963 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001964 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001965 pCB->lastVtxBinding = MAX_BINDING;
1966 cmdBufferMap[*pCmdBuffer] = pCB;
1967 loader_platform_thread_unlock_mutex(&globalLock);
1968 updateCBTracking(*pCmdBuffer);
1969 }
1970 return result;
1971}
1972
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001973VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001974{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001975 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
1976 VkLayerDispatchTable *pTable = tableMap[pDisp];
1977 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001978 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001979 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1980 if (pCB) {
1981 if (CB_NEW != pCB->state)
1982 resetCB(cmdBuffer);
1983 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001984 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001985 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001986 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001987 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001988 }
1989 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001990 }
1991 else {
1992 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001993 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001994 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001995 }
1996 updateCBTracking(cmdBuffer);
1997 }
1998 return result;
1999}
2000
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002001VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002002{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002003 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2004 VkLayerDispatchTable *pTable = tableMap[pDisp];
2005 VkResult result = pTable->EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002006 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002007 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2008 if (pCB) {
2009 pCB->state = CB_UPDATE_COMPLETE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002010 // Reset CB status flags
2011 pCB->status = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002012 printCB(cmdBuffer);
2013 }
2014 else {
2015 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002016 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002017 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002018 }
2019 updateCBTracking(cmdBuffer);
2020 //cbDumpDotFile("cb_dump.dot");
2021 }
2022 return result;
2023}
2024
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002025VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002026{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002027 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2028 VkLayerDispatchTable *pTable = tableMap[pDisp];
2029 VkResult result = pTable->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002030 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002031 resetCB(cmdBuffer);
2032 updateCBTracking(cmdBuffer);
2033 }
2034 return result;
2035}
2036
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002037VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002038{
2039 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2040 if (pCB) {
2041 updateCBTracking(cmdBuffer);
2042 addCmd(pCB, CMD_BINDPIPELINE);
2043 PIPELINE_NODE* pPN = getPipeline(pipeline);
2044 if (pPN) {
2045 pCB->lastBoundPipeline = pipeline;
2046 loader_platform_thread_lock_mutex(&globalLock);
2047 g_lastBoundPipeline = pPN;
2048 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002049 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002050 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2051 VkLayerDispatchTable *pTable = tableMap[pDisp];
2052 pTable->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002053 }
2054 else {
2055 char str[1024];
2056 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002057 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002058 }
2059 }
2060 else {
2061 char str[1024];
2062 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002063 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002064 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002065}
2066
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002067VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002068{
2069 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002070 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2071 VkLayerDispatchTable *pTable = tableMap[pDisp];
2072 pTable->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002073}
2074
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002075VK_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 -06002076{
2077 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2078 if (pCB) {
2079 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002080 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002081 if (validateBoundPipeline(cmdBuffer)) {
2082 for (uint32_t i=0; i<setCount; i++) {
2083 if (getSetNode(pDescriptorSets[i])) {
2084 loader_platform_thread_lock_mutex(&globalLock);
2085 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2086 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2087 g_lastBoundDescriptorSet = pDescriptorSets[i];
2088 loader_platform_thread_unlock_mutex(&globalLock);
2089 char str[1024];
2090 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002091 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002092 }
2093 else {
2094 char str[1024];
2095 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002096 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002097 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002098 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002099 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2100 VkLayerDispatchTable *pTable = tableMap[pDisp];
2101 pTable->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002102 }
2103 }
2104 else {
2105 char str[1024];
2106 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002107 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002108 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002109}
2110
Tony Barbour8205d902015-04-16 15:59:00 -06002111VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002112{
2113 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2114 if (pCB) {
2115 updateCBTracking(cmdBuffer);
2116 addCmd(pCB, CMD_BINDINDEXBUFFER);
2117 // TODO : Track idxBuffer binding
2118 }
2119 else {
2120 char str[1024];
2121 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002122 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002123 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002124 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2125 VkLayerDispatchTable *pTable = tableMap[pDisp];
2126 pTable->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002127}
2128
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002129VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2130 VkCmdBuffer cmdBuffer,
2131 uint32_t startBinding,
2132 uint32_t bindingCount,
2133 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002134 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002135{
2136 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2137 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002138 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002139 updateCBTracking(cmdBuffer);
2140 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002141 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002142 if (validateBoundPipeline(cmdBuffer)) {
Jon Ashburne0fa2282015-05-20 09:00:28 -06002143 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2144 VkLayerDispatchTable *pTable = tableMap[pDisp];
2145 pTable->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002146 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002147 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002148 char str[1024];
2149 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002150 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002151 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002152}
2153
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002154VK_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 -06002155{
2156 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002157 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002158 if (pCB) {
2159 updateCBTracking(cmdBuffer);
2160 addCmd(pCB, CMD_DRAW);
2161 pCB->drawCount[DRAW]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002162 loader_platform_thread_lock_mutex(&globalLock);
2163 valid = validate_draw_state_flags(cmdBuffer);
2164 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002165 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002166 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002167 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002168 synchAndPrintDSConfig(cmdBuffer);
2169 }
2170 else {
2171 char str[1024];
2172 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002173 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002174 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002175 if (valid) {
2176 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2177 VkLayerDispatchTable *pTable = tableMap[pDisp];
2178 pTable->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2179 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002180}
2181
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002182VK_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 -06002183{
2184 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002185 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002186 if (pCB) {
2187 updateCBTracking(cmdBuffer);
2188 addCmd(pCB, CMD_DRAWINDEXED);
2189 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002190 loader_platform_thread_lock_mutex(&globalLock);
2191 valid = validate_draw_state_flags(cmdBuffer);
2192 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002193 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002194 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002195 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002196 synchAndPrintDSConfig(cmdBuffer);
2197 }
2198 else {
2199 char str[1024];
2200 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002201 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002202 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002203 if (valid) {
2204 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2205 VkLayerDispatchTable *pTable = tableMap[pDisp];
2206 pTable->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2207 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002208}
2209
Tony Barbour8205d902015-04-16 15:59:00 -06002210VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002211{
2212 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002213 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002214 if (pCB) {
2215 updateCBTracking(cmdBuffer);
2216 addCmd(pCB, CMD_DRAWINDIRECT);
2217 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002218 loader_platform_thread_lock_mutex(&globalLock);
2219 valid = validate_draw_state_flags(cmdBuffer);
2220 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002221 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002222 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002223 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002224 synchAndPrintDSConfig(cmdBuffer);
2225 }
2226 else {
2227 char str[1024];
2228 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002229 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002230 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002231 if (valid) {
2232 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2233 VkLayerDispatchTable *pTable = tableMap[pDisp];
2234 pTable->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2235 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002236}
2237
Tony Barbour8205d902015-04-16 15:59:00 -06002238VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002239{
2240 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002241 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002242 if (pCB) {
2243 updateCBTracking(cmdBuffer);
2244 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2245 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002246 loader_platform_thread_lock_mutex(&globalLock);
2247 valid = validate_draw_state_flags(cmdBuffer);
2248 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002249 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002250 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002251 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002252 synchAndPrintDSConfig(cmdBuffer);
2253 }
2254 else {
2255 char str[1024];
2256 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002257 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002258 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002259 if (valid) {
2260 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2261 VkLayerDispatchTable *pTable = tableMap[pDisp];
2262 pTable->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2263 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002264}
2265
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002266VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002267{
2268 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2269 if (pCB) {
2270 updateCBTracking(cmdBuffer);
2271 addCmd(pCB, CMD_DISPATCH);
2272 }
2273 else {
2274 char str[1024];
2275 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002276 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002277 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002278 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2279 VkLayerDispatchTable *pTable = tableMap[pDisp];
2280 pTable->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002281}
2282
Tony Barbour8205d902015-04-16 15:59:00 -06002283VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002284{
2285 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2286 if (pCB) {
2287 updateCBTracking(cmdBuffer);
2288 addCmd(pCB, CMD_DISPATCHINDIRECT);
2289 }
2290 else {
2291 char str[1024];
2292 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002293 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002294 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002295 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2296 VkLayerDispatchTable *pTable = tableMap[pDisp];
2297 pTable->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002298}
2299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002300VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002301{
2302 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2303 if (pCB) {
2304 updateCBTracking(cmdBuffer);
2305 addCmd(pCB, CMD_COPYBUFFER);
2306 }
2307 else {
2308 char str[1024];
2309 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002310 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002311 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002312 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2313 VkLayerDispatchTable *pTable = tableMap[pDisp];
2314 pTable->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002315}
2316
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002317VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2318 VkImage srcImage,
2319 VkImageLayout srcImageLayout,
2320 VkImage destImage,
2321 VkImageLayout destImageLayout,
2322 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002323{
2324 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2325 if (pCB) {
2326 updateCBTracking(cmdBuffer);
2327 addCmd(pCB, CMD_COPYIMAGE);
2328 }
2329 else {
2330 char str[1024];
2331 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002332 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002333 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002334 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2335 VkLayerDispatchTable *pTable = tableMap[pDisp];
2336 pTable->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002337}
2338
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002339VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2340 VkImage srcImage, VkImageLayout srcImageLayout,
2341 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002342 uint32_t regionCount, const VkImageBlit* pRegions,
2343 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002344{
2345 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2346 if (pCB) {
2347 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002348 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002349 }
2350 else {
2351 char str[1024];
2352 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002353 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002354 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002355 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2356 VkLayerDispatchTable *pTable = tableMap[pDisp];
2357 pTable->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002358}
2359
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002360VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2361 VkBuffer srcBuffer,
2362 VkImage destImage, VkImageLayout destImageLayout,
2363 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002364{
2365 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2366 if (pCB) {
2367 updateCBTracking(cmdBuffer);
2368 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2369 }
2370 else {
2371 char str[1024];
2372 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002373 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002374 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002375 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2376 VkLayerDispatchTable *pTable = tableMap[pDisp];
2377 pTable->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002378}
2379
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002380VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2381 VkImage srcImage, VkImageLayout srcImageLayout,
2382 VkBuffer destBuffer,
2383 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002384{
2385 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2386 if (pCB) {
2387 updateCBTracking(cmdBuffer);
2388 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2389 }
2390 else {
2391 char str[1024];
2392 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002393 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002394 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002395 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2396 VkLayerDispatchTable *pTable = tableMap[pDisp];
2397 pTable->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002398}
2399
Tony Barbour8205d902015-04-16 15:59:00 -06002400VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002401{
2402 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2403 if (pCB) {
2404 updateCBTracking(cmdBuffer);
2405 addCmd(pCB, CMD_UPDATEBUFFER);
2406 }
2407 else {
2408 char str[1024];
2409 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002410 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002411 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002412 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2413 VkLayerDispatchTable *pTable = tableMap[pDisp];
2414 pTable->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002415}
2416
Tony Barbour8205d902015-04-16 15:59:00 -06002417VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002418{
2419 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2420 if (pCB) {
2421 updateCBTracking(cmdBuffer);
2422 addCmd(pCB, CMD_FILLBUFFER);
2423 }
2424 else {
2425 char str[1024];
2426 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002427 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002428 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002429 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2430 VkLayerDispatchTable *pTable = tableMap[pDisp];
2431 pTable->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002432}
2433
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002434VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2435 VkCmdBuffer cmdBuffer,
2436 VkImage image, VkImageLayout imageLayout,
2437 const VkClearColor *pColor,
2438 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
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_CLEARCOLORIMAGE);
2444 }
2445 else {
2446 char str[1024];
2447 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002448 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 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->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453}
2454
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002455VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2456 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002457 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002458 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002459{
2460 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2461 if (pCB) {
2462 updateCBTracking(cmdBuffer);
2463 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2464 }
2465 else {
2466 char str[1024];
2467 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002468 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002469 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002470 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2471 VkLayerDispatchTable *pTable = tableMap[pDisp];
2472 pTable->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002473}
2474
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002475VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2476 VkImage srcImage, VkImageLayout srcImageLayout,
2477 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002478 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002479{
2480 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2481 if (pCB) {
2482 updateCBTracking(cmdBuffer);
2483 addCmd(pCB, CMD_RESOLVEIMAGE);
2484 }
2485 else {
2486 char str[1024];
2487 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002488 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002489 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002490 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2491 VkLayerDispatchTable *pTable = tableMap[pDisp];
2492 pTable->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002493}
2494
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002495VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002496{
2497 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2498 if (pCB) {
2499 updateCBTracking(cmdBuffer);
2500 addCmd(pCB, CMD_SETEVENT);
2501 }
2502 else {
2503 char str[1024];
2504 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002505 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002506 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002507 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2508 VkLayerDispatchTable *pTable = tableMap[pDisp];
2509 pTable->CmdSetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002510}
2511
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002512VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513{
2514 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2515 if (pCB) {
2516 updateCBTracking(cmdBuffer);
2517 addCmd(pCB, CMD_RESETEVENT);
2518 }
2519 else {
2520 char str[1024];
2521 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002522 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002523 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002524 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2525 VkLayerDispatchTable *pTable = tableMap[pDisp];
2526 pTable->CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002527}
2528
Tony Barbour8205d902015-04-16 15:59:00 -06002529VK_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 -06002530{
2531 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2532 if (pCB) {
2533 updateCBTracking(cmdBuffer);
2534 addCmd(pCB, CMD_WAITEVENTS);
2535 }
2536 else {
2537 char str[1024];
2538 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002539 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002540 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002541 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2542 VkLayerDispatchTable *pTable = tableMap[pDisp];
2543 pTable->CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002544}
2545
Tony Barbour8205d902015-04-16 15:59:00 -06002546VK_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 -06002547{
2548 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2549 if (pCB) {
2550 updateCBTracking(cmdBuffer);
2551 addCmd(pCB, CMD_PIPELINEBARRIER);
2552 }
2553 else {
2554 char str[1024];
2555 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002556 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002557 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002558 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2559 VkLayerDispatchTable *pTable = tableMap[pDisp];
2560 pTable->CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002561}
2562
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002563VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002564{
2565 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2566 if (pCB) {
2567 updateCBTracking(cmdBuffer);
2568 addCmd(pCB, CMD_BEGINQUERY);
2569 }
2570 else {
2571 char str[1024];
2572 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002573 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002574 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002575 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2576 VkLayerDispatchTable *pTable = tableMap[pDisp];
2577 pTable->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002578}
2579
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002580VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002581{
2582 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2583 if (pCB) {
2584 updateCBTracking(cmdBuffer);
2585 addCmd(pCB, CMD_ENDQUERY);
2586 }
2587 else {
2588 char str[1024];
2589 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002590 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002591 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002592 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2593 VkLayerDispatchTable *pTable = tableMap[pDisp];
2594 pTable->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002595}
2596
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002597VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002598{
2599 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2600 if (pCB) {
2601 updateCBTracking(cmdBuffer);
2602 addCmd(pCB, CMD_RESETQUERYPOOL);
2603 }
2604 else {
2605 char str[1024];
2606 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002607 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002608 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002609 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2610 VkLayerDispatchTable *pTable = tableMap[pDisp];
2611 pTable->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002612}
2613
Tony Barbour8205d902015-04-16 15:59:00 -06002614VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002615{
2616 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2617 if (pCB) {
2618 updateCBTracking(cmdBuffer);
2619 addCmd(pCB, CMD_WRITETIMESTAMP);
2620 }
2621 else {
2622 char str[1024];
2623 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002624 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002626 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2627 VkLayerDispatchTable *pTable = tableMap[pDisp];
2628 pTable->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002629}
2630
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002631VK_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 -06002632{
2633 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2634 if (pCB) {
2635 updateCBTracking(cmdBuffer);
2636 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2637 }
2638 else {
2639 char str[1024];
2640 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002641 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002642 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002643 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2644 VkLayerDispatchTable *pTable = tableMap[pDisp];
2645 pTable->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646}
2647
Tony Barbour8205d902015-04-16 15:59:00 -06002648VK_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 -06002649{
2650 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2651 if (pCB) {
2652 updateCBTracking(cmdBuffer);
2653 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2654 }
2655 else {
2656 char str[1024];
2657 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002658 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002659 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002660 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2661 VkLayerDispatchTable *pTable = tableMap[pDisp];
2662 pTable->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663}
2664
Tony Barbour8205d902015-04-16 15:59:00 -06002665VK_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 -06002666{
2667 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2668 if (pCB) {
2669 updateCBTracking(cmdBuffer);
2670 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2671 }
2672 else {
2673 char str[1024];
2674 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002675 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002676 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002677 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2678 VkLayerDispatchTable *pTable = tableMap[pDisp];
2679 pTable->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002680}
2681
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002682VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002683{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002684 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2685 VkLayerDispatchTable *pTable = tableMap[pDisp];
2686 VkResult result = pTable->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002687 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002688 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002689 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002690 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002691 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2692 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002693 }
2694 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002695 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2696 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002697 }
2698 frameBufferMap[*pFramebuffer] = localFBCI;
2699 }
2700 return result;
2701}
2702
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002703VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
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->CreateRenderPass(device, pCreateInfo, pRenderPass);
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 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002711 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002712 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2713 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002714 }
2715 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002716 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2717 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002718 }
2719 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002720 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2721 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002722 }
2723 renderPassMap[*pRenderPass] = localRPCI;
2724 }
2725 return result;
2726}
2727
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002728VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002729{
2730 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2731 if (pCB) {
2732 updateCBTracking(cmdBuffer);
2733 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002734 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2735 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002736 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002737 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002738 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002739 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002740 char str[1024];
2741 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002742 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002743 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002744 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2745 VkLayerDispatchTable *pTable = tableMap[pDisp];
2746 pTable->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002747}
2748
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002749VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
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_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002755 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002756 }
2757 else {
2758 char str[1024];
2759 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002760 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002761 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002762 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2763 VkLayerDispatchTable *pTable = tableMap[pDisp];
2764 pTable->CmdEndRenderPass(cmdBuffer, renderPass);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002765}
2766
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002767VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2768 VkInstance instance,
2769 VkFlags msgFlags,
2770 const PFN_vkDbgMsgCallback pfnMsgCallback,
2771 void* pUserData,
2772 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002773{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002774 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2775 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2776 return layer_create_msg_callback(instance, pTable, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002777}
2778
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002779VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2780 VkInstance instance,
2781 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002782{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002783 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2784 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2785 return layer_destroy_msg_callback(instance, pTable, msgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002786}
2787
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002788VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002789{
2790 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2791 if (pCB) {
2792 updateCBTracking(cmdBuffer);
2793 addCmd(pCB, CMD_DBGMARKERBEGIN);
2794 }
2795 else {
2796 char str[1024];
2797 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002798 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002799 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002800 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2801 VkLayerDispatchTable *pTable = tableMap[pDisp];
2802 pTable->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002803}
2804
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002805VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002806{
2807 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2808 if (pCB) {
2809 updateCBTracking(cmdBuffer);
2810 addCmd(pCB, CMD_DBGMARKEREND);
2811 }
2812 else {
2813 char str[1024];
2814 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002815 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002816 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002817 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2818 VkLayerDispatchTable *pTable = tableMap[pDisp];
2819 pTable->CmdDbgMarkerEnd(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002820}
2821
2822// TODO : Want to pass in a cmdBuffer here based on which state to display
2823void drawStateDumpDotFile(char* outFileName)
2824{
2825 // TODO : Currently just setting cmdBuffer based on global var
2826 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2827 dumpGlobalDotFile(outFileName);
2828}
2829
2830void drawStateDumpCommandBufferDotFile(char* outFileName)
2831{
2832 cbDumpDotFile(outFileName);
2833}
2834
2835void drawStateDumpPngFile(char* outFileName)
2836{
2837#if defined(_WIN32)
2838// FIXME: NEED WINDOWS EQUIVALENT
2839 char str[1024];
2840 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002841 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002842#else // WIN32
2843 char dotExe[32] = "/usr/bin/dot";
2844 if( access(dotExe, X_OK) != -1) {
2845 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2846 char dotCmd[1024];
2847 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002848 int retval = system(dotCmd);
2849 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002850 remove("/tmp/tmp.dot");
2851 }
2852 else {
2853 char str[1024];
2854 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002855 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856 }
2857#endif // WIN32
2858}
2859
Jon Ashburn1245cec2015-05-18 13:20:15 -06002860VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002861{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002862 VkBaseLayerObject* devw = (VkBaseLayerObject *) dev;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002863
Jon Ashburn1245cec2015-05-18 13:20:15 -06002864 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002865 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002866
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002867 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002868 initDeviceTable((const VkBaseLayerObject *) dev);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002869
Jon Ashburn1245cec2015-05-18 13:20:15 -06002870 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
2871 return (void *) vkGetDeviceProcAddr;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002872 if (!strcmp(funcName, "vkDestroyDevice"))
2873 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002874 if (!strcmp(funcName, "vkQueueSubmit"))
2875 return (void*) vkQueueSubmit;
2876 if (!strcmp(funcName, "vkDestroyObject"))
2877 return (void*) vkDestroyObject;
2878 if (!strcmp(funcName, "vkCreateBufferView"))
2879 return (void*) vkCreateBufferView;
2880 if (!strcmp(funcName, "vkCreateImageView"))
2881 return (void*) vkCreateImageView;
2882 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2883 return (void*) vkCreateGraphicsPipeline;
2884 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2885 return (void*) vkCreateGraphicsPipelineDerivative;
2886 if (!strcmp(funcName, "vkCreateSampler"))
2887 return (void*) vkCreateSampler;
2888 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2889 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002890 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2891 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002892 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2893 return (void*) vkCreateDescriptorPool;
2894 if (!strcmp(funcName, "vkResetDescriptorPool"))
2895 return (void*) vkResetDescriptorPool;
2896 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2897 return (void*) vkAllocDescriptorSets;
2898 if (!strcmp(funcName, "vkClearDescriptorSets"))
2899 return (void*) vkClearDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002900 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2901 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002902 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2903 return (void*) vkCreateDynamicViewportState;
2904 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2905 return (void*) vkCreateDynamicRasterState;
2906 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2907 return (void*) vkCreateDynamicColorBlendState;
2908 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2909 return (void*) vkCreateDynamicDepthStencilState;
2910 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2911 return (void*) vkCreateCommandBuffer;
2912 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2913 return (void*) vkBeginCommandBuffer;
2914 if (!strcmp(funcName, "vkEndCommandBuffer"))
2915 return (void*) vkEndCommandBuffer;
2916 if (!strcmp(funcName, "vkResetCommandBuffer"))
2917 return (void*) vkResetCommandBuffer;
2918 if (!strcmp(funcName, "vkCmdBindPipeline"))
2919 return (void*) vkCmdBindPipeline;
2920 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2921 return (void*) vkCmdBindDynamicStateObject;
2922 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2923 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002924 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2925 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002926 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2927 return (void*) vkCmdBindIndexBuffer;
2928 if (!strcmp(funcName, "vkCmdDraw"))
2929 return (void*) vkCmdDraw;
2930 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2931 return (void*) vkCmdDrawIndexed;
2932 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2933 return (void*) vkCmdDrawIndirect;
2934 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2935 return (void*) vkCmdDrawIndexedIndirect;
2936 if (!strcmp(funcName, "vkCmdDispatch"))
2937 return (void*) vkCmdDispatch;
2938 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2939 return (void*) vkCmdDispatchIndirect;
2940 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2941 return (void*) vkCmdCopyBuffer;
2942 if (!strcmp(funcName, "vkCmdCopyImage"))
2943 return (void*) vkCmdCopyImage;
2944 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2945 return (void*) vkCmdCopyBufferToImage;
2946 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2947 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002948 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2949 return (void*) vkCmdUpdateBuffer;
2950 if (!strcmp(funcName, "vkCmdFillBuffer"))
2951 return (void*) vkCmdFillBuffer;
2952 if (!strcmp(funcName, "vkCmdClearColorImage"))
2953 return (void*) vkCmdClearColorImage;
2954 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2955 return (void*) vkCmdClearDepthStencil;
2956 if (!strcmp(funcName, "vkCmdResolveImage"))
2957 return (void*) vkCmdResolveImage;
2958 if (!strcmp(funcName, "vkCmdSetEvent"))
2959 return (void*) vkCmdSetEvent;
2960 if (!strcmp(funcName, "vkCmdResetEvent"))
2961 return (void*) vkCmdResetEvent;
2962 if (!strcmp(funcName, "vkCmdWaitEvents"))
2963 return (void*) vkCmdWaitEvents;
2964 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2965 return (void*) vkCmdPipelineBarrier;
2966 if (!strcmp(funcName, "vkCmdBeginQuery"))
2967 return (void*) vkCmdBeginQuery;
2968 if (!strcmp(funcName, "vkCmdEndQuery"))
2969 return (void*) vkCmdEndQuery;
2970 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2971 return (void*) vkCmdResetQueryPool;
2972 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2973 return (void*) vkCmdWriteTimestamp;
2974 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2975 return (void*) vkCmdInitAtomicCounters;
2976 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2977 return (void*) vkCmdLoadAtomicCounters;
2978 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2979 return (void*) vkCmdSaveAtomicCounters;
2980 if (!strcmp(funcName, "vkCreateFramebuffer"))
2981 return (void*) vkCreateFramebuffer;
2982 if (!strcmp(funcName, "vkCreateRenderPass"))
2983 return (void*) vkCreateRenderPass;
2984 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2985 return (void*) vkCmdBeginRenderPass;
2986 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2987 return (void*) vkCmdEndRenderPass;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002988 if (!strcmp(funcName, "vkDbgCreateMsgCallback"))
2989 return (void*) vkDbgCreateMsgCallback;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002990 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2991 return (void*) vkCmdDbgMarkerBegin;
2992 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2993 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002994 if (!strcmp("drawStateDumpDotFile", funcName))
2995 return (void*) drawStateDumpDotFile;
2996 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2997 return (void*) drawStateDumpCommandBufferDotFile;
2998 if (!strcmp("drawStateDumpPngFile", funcName))
2999 return (void*) drawStateDumpPngFile;
3000 else {
Jon Ashburn1245cec2015-05-18 13:20:15 -06003001 if (devw->pGPA == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003002 return NULL;
Jon Ashburn1245cec2015-05-18 13:20:15 -06003003 return devw->pGPA((VkObject)devw->nextObject, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003004 }
3005}
3006
3007VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3008{
3009 VkBaseLayerObject* instw = (VkBaseLayerObject *) instance;
3010 if (instance == NULL)
3011 return NULL;
3012
Jon Ashburnd9564002015-05-07 10:27:37 -06003013 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburne0fa2282015-05-20 09:00:28 -06003014 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003015
3016 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
3017 return (void *) vkGetInstanceProcAddr;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003018 if (!strcmp(funcName, "vkDestroyInstance"))
3019 return (void *) vkDestroyInstance;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003020 if (!strcmp(funcName, "vkCreateDevice"))
3021 return (void*) vkCreateDevice;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003022 else {
3023 if (instw->pGPA == NULL)
3024 return NULL;
3025 return instw->pGPA((VkObject) instw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003026 }
3027}