blob: 34971f432358e27ae76ab2e64183529e4aa29037 [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"
Jon Ashburnf0615e22015-05-25 14:11:37 -060043#include "vk_debug_marker_layer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060044// The following is #included again to catch certain OS-specific functions
45// being used:
46#include "loader_platform.h"
47#include "layers_msg.h"
48
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060049unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
50unordered_map<VkImageView, IMAGE_NODE*> imageMap;
51unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
52unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
53unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
54unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
55unordered_map<VkDescriptorSet, SET_NODE*> setMap;
56unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060057// Map for layout chains
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060058unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
59unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
60unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060061
Jon Ashburne0fa2282015-05-20 09:00:28 -060062static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;
Jon Ashburnf0615e22015-05-25 14:11:37 -060063static std::unordered_map<void *, VkLayerDebugMarkerDispatchTable *> tableDebugMarkerMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060064static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;
65
Tobin Ehlis63bb9482015-03-17 16:24:32 -060066static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060067
Tobin Ehlis63bb9482015-03-17 16:24:32 -060068// TODO : This can be much smarter, using separate locks for separate global data
69static int globalLockInitialized = 0;
70static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060071#define MAX_TID 513
72static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
73static uint32_t g_maxTID = 0;
74// Map actual TID to an index value and return that index
75// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
76static uint32_t getTIDIndex() {
77 loader_platform_thread_id tid = loader_platform_get_thread_id();
78 for (uint32_t i = 0; i < g_maxTID; i++) {
79 if (tid == g_tidMapping[i])
80 return i;
81 }
82 // Don't yet have mapping, set it and return newly set index
83 uint32_t retVal = (uint32_t) g_maxTID;
84 g_tidMapping[g_maxTID++] = tid;
85 assert(g_maxTID < MAX_TID);
86 return retVal;
87}
88// Return a string representation of CMD_TYPE enum
89static string cmdTypeToString(CMD_TYPE cmd)
90{
91 switch (cmd)
92 {
93 case CMD_BINDPIPELINE:
94 return "CMD_BINDPIPELINE";
95 case CMD_BINDPIPELINEDELTA:
96 return "CMD_BINDPIPELINEDELTA";
97 case CMD_BINDDYNAMICSTATEOBJECT:
98 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060099 case CMD_BINDDESCRIPTORSETS:
100 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600101 case CMD_BINDINDEXBUFFER:
102 return "CMD_BINDINDEXBUFFER";
103 case CMD_BINDVERTEXBUFFER:
104 return "CMD_BINDVERTEXBUFFER";
105 case CMD_DRAW:
106 return "CMD_DRAW";
107 case CMD_DRAWINDEXED:
108 return "CMD_DRAWINDEXED";
109 case CMD_DRAWINDIRECT:
110 return "CMD_DRAWINDIRECT";
111 case CMD_DRAWINDEXEDINDIRECT:
112 return "CMD_DRAWINDEXEDINDIRECT";
113 case CMD_DISPATCH:
114 return "CMD_DISPATCH";
115 case CMD_DISPATCHINDIRECT:
116 return "CMD_DISPATCHINDIRECT";
117 case CMD_COPYBUFFER:
118 return "CMD_COPYBUFFER";
119 case CMD_COPYIMAGE:
120 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600121 case CMD_BLITIMAGE:
122 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600123 case CMD_COPYBUFFERTOIMAGE:
124 return "CMD_COPYBUFFERTOIMAGE";
125 case CMD_COPYIMAGETOBUFFER:
126 return "CMD_COPYIMAGETOBUFFER";
127 case CMD_CLONEIMAGEDATA:
128 return "CMD_CLONEIMAGEDATA";
129 case CMD_UPDATEBUFFER:
130 return "CMD_UPDATEBUFFER";
131 case CMD_FILLBUFFER:
132 return "CMD_FILLBUFFER";
133 case CMD_CLEARCOLORIMAGE:
134 return "CMD_CLEARCOLORIMAGE";
135 case CMD_CLEARCOLORIMAGERAW:
136 return "CMD_CLEARCOLORIMAGERAW";
137 case CMD_CLEARDEPTHSTENCIL:
138 return "CMD_CLEARDEPTHSTENCIL";
139 case CMD_RESOLVEIMAGE:
140 return "CMD_RESOLVEIMAGE";
141 case CMD_SETEVENT:
142 return "CMD_SETEVENT";
143 case CMD_RESETEVENT:
144 return "CMD_RESETEVENT";
145 case CMD_WAITEVENTS:
146 return "CMD_WAITEVENTS";
147 case CMD_PIPELINEBARRIER:
148 return "CMD_PIPELINEBARRIER";
149 case CMD_BEGINQUERY:
150 return "CMD_BEGINQUERY";
151 case CMD_ENDQUERY:
152 return "CMD_ENDQUERY";
153 case CMD_RESETQUERYPOOL:
154 return "CMD_RESETQUERYPOOL";
155 case CMD_WRITETIMESTAMP:
156 return "CMD_WRITETIMESTAMP";
157 case CMD_INITATOMICCOUNTERS:
158 return "CMD_INITATOMICCOUNTERS";
159 case CMD_LOADATOMICCOUNTERS:
160 return "CMD_LOADATOMICCOUNTERS";
161 case CMD_SAVEATOMICCOUNTERS:
162 return "CMD_SAVEATOMICCOUNTERS";
163 case CMD_BEGINRENDERPASS:
164 return "CMD_BEGINRENDERPASS";
165 case CMD_ENDRENDERPASS:
166 return "CMD_ENDRENDERPASS";
167 case CMD_DBGMARKERBEGIN:
168 return "CMD_DBGMARKERBEGIN";
169 case CMD_DBGMARKEREND:
170 return "CMD_DBGMARKEREND";
171 default:
172 return "UNKNOWN";
173 }
174}
175// Block of code at start here for managing/tracking Pipeline state that this layer cares about
176// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600177#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600178#define MAX_SLOTS 2048
179#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
180
181static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
182
183// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
184// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
185// to that same cmd buffer by separate thread are not changing state from underneath us
186// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600188// Track the last group of CBs touched for displaying to dot file
189static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
190static uint32_t g_lastTouchedCBIndex = 0;
191// Track the last global DrawState of interest touched by any thread
192static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
193static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600194static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600195static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600196#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
197
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600198//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600199
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600201{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600202 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600203 size_t scSize = 0;
204 size_t vpSize = 0;
205 loader_platform_thread_lock_mutex(&globalLock);
206 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
207 pStateNode->stateObj = state;
208 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600209 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600210 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
211 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
212 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
213 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
214 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
215 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600216 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
217 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
218 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600220 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600221 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600223 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600224 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600225 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600226 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600227 break;
228 default:
229 assert(0);
230 break;
231 }
232 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
233 dynamicStateMap[state] = pStateNode;
234 loader_platform_thread_unlock_mutex(&globalLock);
235}
236// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600237static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600238{
David Pinedof5997ab2015-04-27 16:36:17 -0600239 if (dynamicStateMap.size() <= 0)
240 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600241 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600242 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243 delete[] (*ii).second->create_info.vpci.pScissors;
244 delete[] (*ii).second->create_info.vpci.pViewports;
245 }
246 delete (*ii).second;
247 }
248}
249// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600250static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251{
David Pinedof5997ab2015-04-27 16:36:17 -0600252 if (sampleMap.size() <= 0)
253 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600254 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600255 delete (*ii).second;
256 }
257}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600258static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600259{
260 loader_platform_thread_lock_mutex(&globalLock);
261 if (imageMap.find(view) == imageMap.end()) {
262 loader_platform_thread_unlock_mutex(&globalLock);
263 return NULL;
264 }
265 else {
266 loader_platform_thread_unlock_mutex(&globalLock);
267 return &imageMap[view]->createInfo;
268 }
269}
270// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600271static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600272{
David Pinedof5997ab2015-04-27 16:36:17 -0600273 if (imageMap.size() <= 0)
274 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600275 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600276 delete (*ii).second;
277 }
278}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600279static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600280{
281 loader_platform_thread_lock_mutex(&globalLock);
282 if (bufferMap.find(view) == bufferMap.end()) {
283 loader_platform_thread_unlock_mutex(&globalLock);
284 return NULL;
285 }
286 else {
287 loader_platform_thread_unlock_mutex(&globalLock);
288 return &bufferMap[view]->createInfo;
289 }
290}
291// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600292static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600293{
David Pinedof5997ab2015-04-27 16:36:17 -0600294 if (bufferMap.size() <= 0)
295 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600296 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600297 delete (*ii).second;
298 }
299}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600302static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600303{
304 g_lastCmdBuffer[getTIDIndex()] = cb;
305 GLOBAL_CB_NODE* pCB = getCBNode(cb);
306 loader_platform_thread_lock_mutex(&globalLock);
307 g_lastGlobalCB = pCB;
308 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
309 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
310 if (g_pLastTouchedCB[i] == pCB) {
311 loader_platform_thread_unlock_mutex(&globalLock);
312 return;
313 }
314 }
315 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
316 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
317 loader_platform_thread_unlock_mutex(&globalLock);
318}
Tobin Ehlis97866202015-06-10 12:57:07 -0600319// Check object status for selected flag state
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600320static 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)
321{
Tobin Ehlis97866202015-06-10 12:57:07 -0600322 if (cmdBufferMap.find(cb) != cmdBufferMap.end()) {
323 GLOBAL_CB_NODE* pNode = cmdBufferMap[cb];
324 // If non-zero enable mask is present, check it against status but if enable_mask
325 // is 0 then no enable required so we should always just check status
326 if ((!enable_mask) || (enable_mask & pNode->status)) {
327 if ((pNode->status & status_mask) != status_flag) {
328 char str[1024];
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600329 sprintf(str, "CB object 0x%" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(cb), str);
330 layerCbMsg(msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, error_code, "DS", str);
Tobin Ehlis97866202015-06-10 12:57:07 -0600331 return VK_FALSE;
332 }
333 }
334 return VK_TRUE;
335 }
336 else {
337 // If we do not find it print an error
338 char str[1024];
339 sprintf(str, "Unable to obtain status for non-existent CB object 0x%" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(cb));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600340 layerCbMsg(msg_flags, (VkObjectType) 0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis97866202015-06-10 12:57:07 -0600341 return VK_FALSE;
342 }
343}
344static bool32_t validate_draw_state_flags(VkCmdBuffer cb) {
345 bool32_t result1, result2, result3, result4;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600346 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");
347 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");
348 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");
349 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 -0600350 return ((result1 == VK_TRUE) && (result2 == VK_TRUE) && (result3 == VK_TRUE) && (result4 == VK_TRUE));
351}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600352// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600353static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600354{
355 GLOBAL_CB_NODE* pCB = getCBNode(cb);
356 if (pCB) {
357 loader_platform_thread_lock_mutex(&globalLock);
358 char str[4*1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600359 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600360 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600361 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 -0600362 layerCbMsg(VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
363 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 -0600364 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600365 } else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600366 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600367 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600368 }
369 }
370 loader_platform_thread_unlock_mutex(&globalLock);
371 }
372 else {
373 char str[1024];
374 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600375 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 -0600376 }
377}
378// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600379static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600380{
381 loader_platform_thread_lock_mutex(&globalLock);
382 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
383 loader_platform_thread_unlock_mutex(&globalLock);
384 return NULL;
385 }
386 loader_platform_thread_unlock_mutex(&globalLock);
387 return pipelineMap[pipeline];
388}
389
390// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600391static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600392{
393 loader_platform_thread_lock_mutex(&globalLock);
394 if (sampleMap.find(sampler) == sampleMap.end()) {
395 loader_platform_thread_unlock_mutex(&globalLock);
396 return NULL;
397 }
398 loader_platform_thread_unlock_mutex(&globalLock);
399 return &sampleMap[sampler]->createInfo;
400}
401
402// Init the pipeline mapping info based on pipeline create info LL tree
403// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600404static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600405{
406 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600407 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600408 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600409 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600410 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600411 size_t bufferSize = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600412 VkPipelineVertexInputCreateInfo* pVICI = NULL;
413 VkPipelineCbStateCreateInfo* pCBCI = NULL;
414 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600415 while (pTrav) {
416 switch (pTrav->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600417 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600418 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600419 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600420 case VK_SHADER_STAGE_VERTEX:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600421 pPrev->pNext = &pPipeline->vsCI;
422 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600423 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600424 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600426 pPrev->pNext = &pPipeline->tcsCI;
427 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600428 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600429 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600431 pPrev->pNext = &pPipeline->tesCI;
432 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600433 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600434 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600435 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600436 pPrev->pNext = &pPipeline->gsCI;
437 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600438 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600439 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600440 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600441 pPrev->pNext = &pPipeline->fsCI;
442 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600443 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600444 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600445 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600446 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600447 break;
448 default:
449 // TODO : Flag error
450 break;
451 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600452 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600453 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600454 pPrev->pNext = &pPipeline->vertexInputCI;
455 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600456 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600457 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600458 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600459 pPipeline->vtxBindingCount = pVICI->bindingCount;
460 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600461 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
462 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
Tobin Ehlis9a70e5d2015-06-09 10:48:55 -0600463 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexBindingDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600464 }
465 pPipeline->vtxAttributeCount = pVICI->attributeCount;
466 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600467 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
468 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
469 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600470 }
471 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600472 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600473 pPrev->pNext = &pPipeline->iaStateCI;
474 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600475 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600476 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600477 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600478 pPrev->pNext = &pPipeline->tessStateCI;
479 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600480 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600481 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600482 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600483 pPrev->pNext = &pPipeline->vpStateCI;
484 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600485 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600486 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600487 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600488 pPrev->pNext = &pPipeline->rsStateCI;
489 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600490 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600491 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600492 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600493 pPrev->pNext = &pPipeline->msStateCI;
494 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600495 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600496 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600497 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600498 pPrev->pNext = &pPipeline->cbStateCI;
499 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600500 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600501 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600502 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600503 pPipeline->attachmentCount = pCBCI->attachmentCount;
504 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600505 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
506 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
507 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600508 }
509 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600510 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600511 pPrev->pNext = &pPipeline->dsStateCI;
512 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600513 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600514 break;
515 default:
516 assert(0);
517 break;
518 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600519 pTrav = (GENERIC_HEADER*)pTrav->pNext;
520 }
521 pipelineMap[pPipeline->pipeline] = pPipeline;
522}
523// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600524static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600525{
David Pinedof5997ab2015-04-27 16:36:17 -0600526 if (pipelineMap.size() <= 0)
527 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600528 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600529 if ((*ii).second->pVertexBindingDescriptions) {
530 delete[] (*ii).second->pVertexBindingDescriptions;
531 }
532 if ((*ii).second->pVertexAttributeDescriptions) {
533 delete[] (*ii).second->pVertexAttributeDescriptions;
534 }
535 if ((*ii).second->pAttachments) {
536 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600537 }
538 delete (*ii).second;
539 }
540}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600541// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600542static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600543{
544 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600545 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600546 if (pPipe->msStateCI.multisampleEnable)
547 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600548 }
549 return 1;
550}
551// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600552static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600553{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600554 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600555 // Verify that any MSAA request in PSO matches sample# in bound FB
556 uint32_t psoNumSamples = getNumSamples(pipeline);
557 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600558 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
559 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis63826ec2015-05-21 09:06:56 -0600560 if ((psoNumSamples != pFBCI->sampleCount) || (psoNumSamples != pRPCI->sampleCount)) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600561 char str[1024];
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600562 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 -0600563 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 -0600564 }
565 } else {
566 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
567 // Verify and flag error as appropriate
568 }
569 // TODO : Add more checks here
570 } else {
571 // TODO : Validate non-gfx pipeline updates
572 }
573}
574
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600575// Block of code at start here specifically for managing/tracking DSs
576
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600577// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600578static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600579{
580 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600581 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600582 loader_platform_thread_unlock_mutex(&globalLock);
583 return NULL;
584 }
585 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600586 return poolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600587}
588// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600589static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600590{
591 loader_platform_thread_lock_mutex(&globalLock);
592 if (setMap.find(set) == setMap.end()) {
593 loader_platform_thread_unlock_mutex(&globalLock);
594 return NULL;
595 }
596 loader_platform_thread_unlock_mutex(&globalLock);
597 return setMap[set];
598}
599
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600600static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600601 loader_platform_thread_lock_mutex(&globalLock);
602 if (layoutMap.find(layout) == layoutMap.end()) {
603 loader_platform_thread_unlock_mutex(&globalLock);
604 return NULL;
605 }
606 loader_platform_thread_unlock_mutex(&globalLock);
607 return layoutMap[layout];
608}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600609// Return 1 if update struct is of valid type, 0 otherwise
610static bool32_t validUpdateStruct(const GENERIC_HEADER* pUpdateStruct)
611{
612 char str[1024];
613 switch (pUpdateStruct->sType)
614 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800615 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
616 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600617 return 1;
618 default:
619 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 -0600620 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 -0600621 return 0;
622 }
623}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600624// For given update struct, return binding
625static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600626{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600627 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600628 switch (pUpdateStruct->sType)
629 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800630 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
631 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
632 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
633 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600634 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600635 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 -0600636 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 -0600637 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600638 }
639}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600640// Return count for given update struct
641static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600642{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600643 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600644 switch (pUpdateStruct->sType)
645 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800646 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
647 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
648 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600649 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800650 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600651 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600652 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 -0600653 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 -0600654 return 0;
655 }
656}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600657// Return count for given update struct
658static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
659{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600660 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600661 switch (pUpdateStruct->sType)
662 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800663 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
664 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
665 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600666 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800667 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600668 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600669 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 -0600670 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 -0600671 return 0;
672 }
673}
674// For given Layout Node and binding, return index where that binding begins
675static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
676{
677 uint32_t offsetIndex = 0;
678 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800679 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600680 }
681 return offsetIndex;
682}
683// For given layout node and binding, return last index that is updated
684static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
685{
686 uint32_t offsetIndex = 0;
687 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800688 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600689 }
690 return offsetIndex-1;
691}
692// For given layout and update, return the first overall index of the layout that is update
693static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
694{
695 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
696}
697// For given layout and update, return the last overall index of the layout that is update
698static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
699{
700 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
701}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600702// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600703static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600704{
705 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600706 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600707 uint32_t i = 0;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600708 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600709 switch (pUpdateStruct->sType)
710 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800711 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
712 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600713 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800714 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
715 /* no need to validate */
716 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600717 break;
718 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600719 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 -0600720 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 -0600721 return 0;
722 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600723 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600724 if (pLayout->pTypes[i] != actualType)
725 return 0;
726 }
727 return 1;
728}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600729// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
730// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
731// NOTE : Calls to this function should be wrapped in mutex
732static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
733{
734 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800735 VkWriteDescriptorSet* pWDS = NULL;
736 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600737 size_t array_size = 0;
738 size_t base_array_size = 0;
739 size_t total_array_size = 0;
740 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600741 char str[1024];
742 switch (pUpdate->sType)
743 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800744 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
745 pWDS = new VkWriteDescriptorSet;
746 pNewNode = (GENERIC_HEADER*)pWDS;
747 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
748 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
749 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
750 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600751 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800752 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
753 pCDS = new VkCopyDescriptorSet;
754 pUpdate = (GENERIC_HEADER*)pCDS;
755 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600756 break;
757 default:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600758 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 -0600759 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600760 return NULL;
761 }
762 // Make sure that pNext for the end of shadow copy is NULL
763 pNewNode->pNext = NULL;
764 return pNewNode;
765}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800766// update DS mappings based on ppUpdateArray
767static bool32_t dsUpdate(VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600768{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800769 const VkWriteDescriptorSet *pWDS = NULL;
770 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600771 bool32_t result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800772
773 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
774 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
775 else
776 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
777
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600778 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600779 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600780 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600781 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600782 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600783 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800784 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
785 SET_NODE* pSet = setMap[ds]; // getSetNode() without locking
786 g_lastBoundDescriptorSet = pSet->set;
787 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600788 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600789 // First verify valid update struct
790 if (!validUpdateStruct(pUpdate)) {
791 result = 0;
792 break;
793 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600794 // Make sure that binding is within bounds
795 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600796 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600797 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 -0600798 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 -0600799 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600800 }
801 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600802 // Next verify that update falls within size of given binding
803 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600804 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 -0600805 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600806 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
807 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 -0600808 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 -0600809 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600810 }
811 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600812 // Layout bindings match w/ update ok, now verify that update is of the right type
813 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600814 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600815 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600816 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 -0600817 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600818 }
819 else {
820 // Save the update info
821 // TODO : Info message that update successful
822 // Create new update struct for this set's shadow copy
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600823 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600824 if (NULL == pNewNode) {
825 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600826 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600827 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 -0600828 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829 }
830 else {
831 // Insert shadow node into LL of updates for this set
832 pNewNode->pNext = pSet->pUpdateStructs;
833 pSet->pUpdateStructs = pNewNode;
834 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600835 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
836 assert(j<pSet->descriptorCount);
837 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600838 }
839 }
840 }
841 }
842 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600843 }
844 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600845 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600846}
847// Free the shadowed update node for this Set
848// NOTE : Calls to this function should be wrapped in mutex
849static void freeShadowUpdateTree(SET_NODE* pSet)
850{
851 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
852 pSet->pUpdateStructs = NULL;
853 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
854 // Clear the descriptor mappings as they will now be invalid
855 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
856 while(pShadowUpdate) {
857 pFreeUpdate = pShadowUpdate;
858 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
859 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800860 VkWriteDescriptorSet * pWDS = NULL;
861 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600862 void** ppToFree = NULL;
863 switch (pFreeUpdate->sType)
864 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800865 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
866 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
867 if (pWDS->pDescriptors)
868 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600869 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800870 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600871 break;
872 default:
873 assert(0);
874 break;
875 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600876 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600877 }
878}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600879// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600881static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600882{
David Pinedof5997ab2015-04-27 16:36:17 -0600883 if (poolMap.size() <= 0)
884 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600885 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600886 SET_NODE* pSet = (*ii).second->pSets;
887 SET_NODE* pFreeSet = pSet;
888 while (pSet) {
889 pFreeSet = pSet;
890 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600891 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600892 // Free Update shadow struct tree
893 freeShadowUpdateTree(pFreeSet);
894 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200895 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600896 }
897 delete pFreeSet;
898 }
899 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200900 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600901 }
902 delete (*ii).second;
903 }
904}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600905// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600906// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600907static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600908{
David Pinedof5997ab2015-04-27 16:36:17 -0600909 if (layoutMap.size() <= 0)
910 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600911 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600912 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600913 if (pLayout->createInfo.pBinding) {
914 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
915 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
916 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
917 }
918 delete[] pLayout->createInfo.pBinding;
919 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600920 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200921 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600922 }
923 delete pLayout;
924 }
925}
926// Currently clearing a set is removing all previous updates to that set
927// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600928static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600929{
930 SET_NODE* pSet = getSetNode(set);
931 if (!pSet) {
932 // TODO : Return error
933 }
934 else {
935 loader_platform_thread_lock_mutex(&globalLock);
936 freeShadowUpdateTree(pSet);
937 loader_platform_thread_unlock_mutex(&globalLock);
938 }
939}
940
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600941static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600942{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600943 POOL_NODE* pPool = getPoolNode(pool);
944 if (!pPool) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600945 char str[1024];
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600946 sprintf(str, "Unable to find pool node for pool %p specified in vkResetDescriptorPool() call", (void*)pool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600947 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 -0600948 }
949 else
950 {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600951 // For every set off of this pool, clear it
952 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600953 while (pSet) {
954 clearDescriptorSet(pSet->set);
955 }
956 }
957}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600958// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600959static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600960{
961 loader_platform_thread_lock_mutex(&globalLock);
962 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
963 loader_platform_thread_unlock_mutex(&globalLock);
964 return NULL;
965 }
966 loader_platform_thread_unlock_mutex(&globalLock);
967 return cmdBufferMap[cb];
968}
969// Free all CB Nodes
970// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600971static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600972{
David Pinedof5997ab2015-04-27 16:36:17 -0600973 if (cmdBufferMap.size() <= 0)
974 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600975 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -0600976 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
977 while (!cmd_node_list.empty()) {
978 CMD_NODE* cmd_node = cmd_node_list.back();
979 delete cmd_node;
980 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600981 }
982 delete (*ii).second;
983 }
984}
985static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
986{
987 CMD_NODE* pCmd = new CMD_NODE;
988 if (pCmd) {
989 // init cmd node and append to end of cmd LL
990 memset(pCmd, 0, sizeof(CMD_NODE));
991 pCmd->cmdNumber = ++pCB->numCmds;
992 pCmd->type = cmd;
993 pCB->pCmds.push_back(pCmd);
994 }
995 else {
996 char str[1024];
997 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 -0600998 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 -0600999 }
1000}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001001static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001002{
1003 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1004 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001005 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1006 while (!cmd_list.empty()) {
1007 delete cmd_list.back();
1008 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001009 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001010 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001011 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001012 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001013 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001014 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1015 pCB->cmdBuffer = cb;
1016 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001017 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001018 pCB->lastVtxBinding = MAX_BINDING;
1019 }
1020}
Tobin Ehlis97866202015-06-10 12:57:07 -06001021// Set PSO-related status bits for CB
1022static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1023{
1024 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1025 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1026 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1027 }
1028 }
1029 if (pPipe->dsStateCI.depthWriteEnable) {
1030 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1031 }
1032}
1033// Set dyn-state related status bits for an object node
1034static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, VkStateBindPoint stateBindPoint) {
1035 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1036 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1037 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1038 pNode->status |= CBSTATUS_RASTER_BOUND;
1039 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1040 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1041 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1042 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1043 }
1044}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001045// Set the last bound dynamic state of given type
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001046static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001047{
1048 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1049 if (pCB) {
1050 updateCBTracking(cmdBuffer);
1051 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis97866202015-06-10 12:57:07 -06001052 set_cb_dyn_status(pCB, sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001053 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1054 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1055 char str[1024];
1056 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001057 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001058 }
1059 else {
1060 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1061 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1062 }
1063 loader_platform_thread_unlock_mutex(&globalLock);
1064 }
1065 else {
1066 char str[1024];
1067 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001068 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 -06001069 }
1070}
1071// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001072static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001073{
1074 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1075 if (pCB) {
1076 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1077 if (!pPipeTrav) {
1078 // nothing to print
1079 }
1080 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001081 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001082 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001083 }
1084 }
1085}
1086// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001087static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001088{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001089#if 0
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001090 SET_NODE* pSet = getSetNode(ds);
1091 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001092 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001093 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001094 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1095 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001096 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001097 fprintf(pOutFile, "%s", pGVstr);
1098 free(pGVstr);
1099 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1100 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001101 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001102 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001103 ++layout_index;
1104 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001105 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001106 fprintf(pOutFile, "%s", pGVstr);
1107 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001108 if (pSet->pUpdateStructs) {
1109 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1110 fprintf(pOutFile, "%s", pGVstr);
1111 free(pGVstr);
1112 }
1113 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001114 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1115 uint32_t i = 0;
1116 for (i=0; i < pSet->descriptorCount; i++) {
1117 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118 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 -06001119 }
1120 }
1121#define NUM_COLORS 7
1122 vector<string> edgeColors;
1123 edgeColors.push_back("0000ff");
1124 edgeColors.push_back("ff00ff");
1125 edgeColors.push_back("ffff00");
1126 edgeColors.push_back("00ff00");
1127 edgeColors.push_back("000000");
1128 edgeColors.push_back("00ffff");
1129 edgeColors.push_back("ff0000");
1130 uint32_t colorIdx = 0;
1131 fprintf(pOutFile, "</TABLE>>\n];\n");
1132 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001133 VkUpdateSamplers* pUS = NULL;
1134 VkUpdateSamplerTextures* pUST = NULL;
1135 VkUpdateImages* pUI = NULL;
1136 VkUpdateBuffers* pUB = NULL;
1137 VkUpdateAsCopy* pUAC = NULL;
1138 VkSamplerCreateInfo* pSCI = NULL;
1139 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001140 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001141 void** ppNextPtr = NULL;
1142 void* pSaveNext = NULL;
1143 for (i=0; i < pSet->descriptorCount; i++) {
1144 if (pSet->ppDescriptors[i]) {
1145 switch (pSet->ppDescriptors[i]->sType)
1146 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001147 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001148 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001149 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001150 if (pSCI) {
1151 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001152 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001153 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1154 }
1155 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001156 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001157 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001158 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001159 if (pSCI) {
1160 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001161 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001162 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1163 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001164 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001165 if (pIVCI) {
1166 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001167 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001168 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1169 }
1170 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001171 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001172 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001173 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001174 if (pIVCI) {
1175 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001176 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001177 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1178 }
1179 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001180 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001181 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001182 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001183 if (pBVCI) {
1184 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001185 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001186 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1187 }
1188 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001189 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001190 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001191 // TODO : Need to validate this code
1192 // Save off pNext and set to NULL while printing this struct, then restore it
1193 ppNextPtr = (void**)&pUAC->pNext;
1194 pSaveNext = *ppNextPtr;
1195 *ppNextPtr = NULL;
1196 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001197 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001198 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1199 // Restore next ptr
1200 *ppNextPtr = pSaveNext;
1201 break;
1202 default:
1203 break;
1204 }
1205 colorIdx = (colorIdx+1) % NUM_COLORS;
1206 }
1207 }
1208 }
1209 fprintf(pOutFile, "}\n");
1210 fprintf(pOutFile, "}\n");
1211 }
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001212#endif
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001213}
1214// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001215static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001216{
1217 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1218 if (pCB && pCB->lastBoundDescriptorSet) {
1219 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1220 }
1221}
1222// Dump a GraphViz dot file showing the Cmd Buffers
1223static void cbDumpDotFile(string outFileName)
1224{
1225 // Print CB Chain for each CB
1226 FILE* pOutFile;
1227 pOutFile = fopen(outFileName.c_str(), "w");
1228 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1229 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1230 GLOBAL_CB_NODE* pCB = NULL;
1231 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1232 pCB = g_pLastTouchedCB[i];
David Pinedof5997ab2015-04-27 16:36:17 -06001233 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001234 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1235 uint32_t instNum = 0;
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001236 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1237 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001238 if (instNum) {
1239 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1240 }
1241 if (pCB == g_lastGlobalCB) {
1242 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());
1243 }
1244 else {
1245 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());
1246 }
1247 ++instNum;
1248 }
1249 fprintf(pOutFile, "}\n");
1250 }
1251 }
1252 fprintf(pOutFile, "}\n");
1253 fprintf(pOutFile, "}\n"); // close main graph "g"
1254 fclose(pOutFile);
1255}
1256// Dump a GraphViz dot file showing the pipeline for last bound global state
1257static void dumpGlobalDotFile(char *outFileName)
1258{
1259 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1260 if (pPipeTrav) {
1261 FILE* pOutFile;
1262 pOutFile = fopen(outFileName, "w");
1263 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1264 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1265 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001266 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001267 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001268 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001269 fprintf(pOutFile, "%s", pGVstr);
1270 free(pGVstr);
1271 }
1272 }
1273 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1274 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001275 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001276 fprintf(pOutFile, "%s", pGVstr);
1277 free(pGVstr);
1278 fprintf(pOutFile, "}\n");
1279 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1280 fprintf(pOutFile, "}\n"); // close main graph "g"
1281 fclose(pOutFile);
1282 }
1283}
1284// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001285static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001286{
1287 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1288 if (pCB) {
1289 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1290 if (pPipeTrav) {
1291 FILE* pOutFile;
1292 pOutFile = fopen(outFileName.c_str(), "w");
1293 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1294 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1295 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001296 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001297 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001298 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001299 fprintf(pOutFile, "%s", pGVstr);
1300 free(pGVstr);
1301 }
1302 }
1303 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1304 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001305 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001306 fprintf(pOutFile, "%s", pGVstr);
1307 free(pGVstr);
1308 fprintf(pOutFile, "}\n");
1309 dsDumpDot(cb, pOutFile);
1310 fprintf(pOutFile, "}\n"); // close main graph "g"
1311 fclose(pOutFile);
1312 }
1313 }
1314}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001315// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001316static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001317{
1318 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1319 if (pCB && pCB->lastBoundPipeline) {
1320 // First verify that we have a Node for bound pipeline
1321 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1322 char str[1024];
1323 if (!pPipeTrav) {
1324 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001325 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001326 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001327 }
1328 else {
1329 // Verify Vtx binding
1330 if (MAX_BINDING != pCB->lastVtxBinding) {
1331 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1332 if (0 == pPipeTrav->vtxBindingCount) {
1333 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 -06001334 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 -06001335 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001336 }
1337 else {
1338 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 -06001339 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 -06001340 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001341 }
1342 }
1343 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001344 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001345 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001346 }
1347 }
1348 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001349 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001350 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001351 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001352}
1353// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001354static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001355{
1356 char tmp_str[1024];
1357 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.
1358 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001359 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001360 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001361 POOL_NODE* pPool = getPoolNode(pSet->pool);
1362 // Print out pool details
1363 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001364 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001365 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001366 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001367 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001368 // Print out set details
1369 char prefix[10];
1370 uint32_t index = 0;
1371 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001372 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001373 LAYOUT_NODE* pLayout = pSet->pLayout;
1374 // Print layout details
1375 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 -06001376 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001377 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001378 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001379 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001380 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001381 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001382 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1383 if (pUpdate) {
1384 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001385 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001386 sprintf(prefix, " [UC] ");
1387 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001388 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001389 // TODO : If there is a "view" associated with this update, print CI for that view
1390 }
1391 else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001392 if (0 != pSet->descriptorCount) {
1393 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 -06001394 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001395 }
1396 else {
1397 sprintf(tmp_str, "FYI: No descriptors in descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001398 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001399 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001400 }
1401 }
1402}
1403
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001404static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001405{
1406 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001407 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001408 char str[1024];
1409 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001410 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001411 vector<CMD_NODE*> pCmds = pCB->pCmds;
1412 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001413 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001414 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001415 }
1416 }
1417 else {
1418 // Nothing to print
1419 }
1420}
1421
1422
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001423static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001424{
1425 printDSConfig(cb);
1426 printPipeline(cb);
1427 printDynamicState(cb);
1428 static int autoDumpOnce = 0;
1429 if (autoDumpOnce) {
1430 autoDumpOnce = 0;
1431 dumpDotFile(cb, "pipeline_dump.dot");
1432 cbDumpDotFile("cb_dump.dot");
1433#if defined(_WIN32)
1434// FIXME: NEED WINDOWS EQUIVALENT
1435#else // WIN32
1436 // Convert dot to svg if dot available
1437 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001438 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1439 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001440 }
1441#endif // WIN32
1442 }
1443}
1444
Jon Ashburne0fa2282015-05-20 09:00:28 -06001445static VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw)
Jon Ashburnd9564002015-05-07 10:27:37 -06001446{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001447 VkLayerDispatchTable *pTable;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001448 VkLayerDebugMarkerDispatchTable *pDebugMarkerTable;
Jon Ashburne0fa2282015-05-20 09:00:28 -06001449
1450 assert(devw);
1451 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject);
1452
1453 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) *ppDisp);
1454 if (it == tableMap.end())
1455 {
1456 pTable = new VkLayerDispatchTable;
1457 tableMap[(void *) *ppDisp] = pTable;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001458 pDebugMarkerTable = new VkLayerDebugMarkerDispatchTable;
1459 tableDebugMarkerMap[(void *) *ppDisp] = pDebugMarkerTable;
Jon Ashburne0fa2282015-05-20 09:00:28 -06001460 } else
1461 {
1462 return it->second;
1463 }
1464
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001465 layer_initialize_dispatch_table(pTable, devw);
Jon Ashburnf0615e22015-05-25 14:11:37 -06001466
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001467 VkDevice device = (VkDevice) devw->baseObject;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001468 pDebugMarkerTable->CmdDbgMarkerBegin = (PFN_vkCmdDbgMarkerBegin) devw->pGPA(device, "vkCmdDbgMarkerBegin");
1469 pDebugMarkerTable->CmdDbgMarkerEnd = (PFN_vkCmdDbgMarkerEnd) devw->pGPA(device, "vkCmdDbgMarkerEnd");
1470 pDebugMarkerTable->DbgSetObjectTag = (PFN_vkDbgSetObjectTag) devw->pGPA(device, "vkDbgSetObjectTag");
1471 pDebugMarkerTable->DbgSetObjectName = (PFN_vkDbgSetObjectName) devw->pGPA(device, "vkDbgSetObjectName");
1472 pDebugMarkerTable->ext_enabled = false;
Jon Ashburne0fa2282015-05-20 09:00:28 -06001473
1474 return pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -06001475}
1476
Jon Ashburne0fa2282015-05-20 09:00:28 -06001477static VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instw)
Jon Ashburnd9564002015-05-07 10:27:37 -06001478{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001479 VkLayerInstanceDispatchTable *pTable;
1480 assert(instw);
1481 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;
1482
1483 std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap.find((void *) *ppDisp);
1484 if (it == tableInstanceMap.end())
1485 {
1486 pTable = new VkLayerInstanceDispatchTable;
1487 tableInstanceMap[(void *) *ppDisp] = pTable;
1488 } else
1489 {
1490 return it->second;
1491 }
1492
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001493 layer_init_instance_dispatch_table(pTable, instw);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001494
1495 return pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -06001496}
1497
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001498static void initDrawState(void)
1499{
1500 const char *strOpt;
1501 // initialize DrawState options
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001502 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportFlags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001503 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1504
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001505 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001506 {
1507 strOpt = getLayerOption("DrawStateLogFilename");
1508 if (strOpt)
1509 {
1510 g_logFile = fopen(strOpt, "w");
1511 }
1512 if (g_logFile == NULL)
1513 g_logFile = stdout;
1514 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001515
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001516 if (!globalLockInitialized)
1517 {
1518 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001519 // suggestion is to call this during vkCreateInstance(), and then we
1520 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001521 // that the layer have per-instance locks. We need to come back and
1522 // address this soon.
1523 loader_platform_thread_create_mutex(&globalLock);
1524 globalLockInitialized = 1;
1525 }
1526}
1527
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001528VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1529{
1530 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) (*pInstance);
1531 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
1532
1533 loader_platform_thread_once(&g_initOnce, initDrawState);
1534
1535 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1536
1537 if (result == VK_SUCCESS) {
1538 enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
1539 }
1540 return result;
1541}
1542
Jon Ashburne0fa2282015-05-20 09:00:28 -06001543/* hook DestroyInstance to remove tableInstanceMap entry */
1544VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1545{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001546 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06001547 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
1548 VkResult res = pTable->DestroyInstance(instance);
1549 tableInstanceMap.erase(pDisp);
1550 return res;
1551}
1552
Jon Ashburnf0615e22015-05-25 14:11:37 -06001553static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1554{
1555 uint32_t i, ext_idx;
1556 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) device;
1557 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
1558
1559 for (i = 0; i < pCreateInfo->extensionCount; i++) {
1560 if (strcmp(pCreateInfo->pEnabledExtensions[i].name, DEBUG_MARKER_EXTENSION_NAME) == 0) {
1561 /* Found a matching extension name, mark it enabled */
1562 pTable->ext_enabled = true;
1563 }
1564
1565 }
1566}
1567
Tony Barbour8205d902015-04-16 15:59:00 -06001568VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001569{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001570 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu;
1571 VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[*ppDisp];
1572 VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice);
Jon Ashburnf0615e22015-05-25 14:11:37 -06001573 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001574 return result;
1575}
1576
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001577VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001578{
1579 // Free all the memory
1580 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001581 deletePipelines();
1582 deleteSamplers();
1583 deleteImages();
1584 deleteBuffers();
1585 deleteCmdBuffers();
1586 deleteDynamicState();
1587 deletePools();
1588 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001589 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001590
1591 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1592 VkLayerDispatchTable *pTable = tableMap[pDisp];
1593 VkResult result = pTable->DestroyDevice(device);
1594 tableMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001595 return result;
1596}
1597
Jon Ashburneb2728b2015-04-10 14:33:07 -06001598struct extProps {
1599 uint32_t version;
1600 const char * const name;
1601};
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001602#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 1
1603static const VkExtensionProperties dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1604 {
1605 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1606 "DrawState",
1607 0x10,
1608 "Sample layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001609 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001610};
1611
Jon Ashburnf0615e22015-05-25 14:11:37 -06001612//TODO add DEBUG_MARKER to device extension list
Jon Ashburneb2728b2015-04-10 14:33:07 -06001613VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001614 VkExtensionInfoType infoType,
1615 uint32_t extensionIndex,
1616 size_t* pDataSize,
1617 void* pData)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001618{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001619 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Jon Ashburneb2728b2015-04-10 14:33:07 -06001620 uint32_t *count;
1621
1622 if (pDataSize == NULL)
1623 return VK_ERROR_INVALID_POINTER;
1624
1625 switch (infoType) {
1626 case VK_EXTENSION_INFO_TYPE_COUNT:
1627 *pDataSize = sizeof(uint32_t);
1628 if (pData == NULL)
1629 return VK_SUCCESS;
1630 count = (uint32_t *) pData;
1631 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1632 break;
1633 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1634 *pDataSize = sizeof(VkExtensionProperties);
1635 if (pData == NULL)
1636 return VK_SUCCESS;
1637 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1638 return VK_ERROR_INVALID_VALUE;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001639 memcpy((VkExtensionProperties *) pData, &dsExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburneb2728b2015-04-10 14:33:07 -06001640 break;
1641 default:
1642 return VK_ERROR_INVALID_VALUE;
1643 };
1644
1645 return VK_SUCCESS;
1646}
1647
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001648VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001649{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001650 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001651 for (uint32_t i=0; i < cmdBufferCount; i++) {
1652 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001653 pCB = getCBNode(pCmdBuffers[i]);
1654 loader_platform_thread_lock_mutex(&globalLock);
1655 if (CB_UPDATE_COMPLETE != pCB->state) {
1656 // Flag error for using CB w/o vkEndCommandBuffer() called
1657 char str[1024];
1658 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001659 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 -06001660 loader_platform_thread_unlock_mutex(&globalLock);
1661 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001662 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001663 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001664 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001665
1666 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) queue;
1667 VkLayerDispatchTable *pTable = tableMap[pDisp];
1668 VkResult result = pTable->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001669 return result;
1670}
1671
Mike Stroyan230e6252015-04-17 12:36:38 -06001672VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001673{
1674 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Jon Ashburne0fa2282015-05-20 09:00:28 -06001675 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1676 VkLayerDispatchTable *pTable = tableMap[pDisp];
1677 VkResult result = pTable->DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001678 return result;
1679}
1680
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001681VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001682{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001683 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1684 VkLayerDispatchTable *pTable = tableMap[pDisp];
1685 VkResult result = pTable->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001686 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001687 loader_platform_thread_lock_mutex(&globalLock);
1688 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1689 pNewNode->buffer = *pView;
1690 pNewNode->createInfo = *pCreateInfo;
1691 bufferMap[*pView] = pNewNode;
1692 loader_platform_thread_unlock_mutex(&globalLock);
1693 }
1694 return result;
1695}
1696
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001697VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001698{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001699 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1700 VkLayerDispatchTable *pTable = tableMap[pDisp];
1701 VkResult result = pTable->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001702 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001703 loader_platform_thread_lock_mutex(&globalLock);
1704 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1705 pNewNode->image = *pView;
1706 pNewNode->createInfo = *pCreateInfo;
1707 imageMap[*pView] = pNewNode;
1708 loader_platform_thread_unlock_mutex(&globalLock);
1709 }
1710 return result;
1711}
1712
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001713static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001714{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001715 // Create LL HEAD for this Pipeline
1716 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001717 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1718 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1719 pPipeNode->pipeline = *pPipeline;
1720 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001721 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001722}
1723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001724VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001725{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001726 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1727 VkLayerDispatchTable *pTable = tableMap[pDisp];
1728 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001729 // Create LL HEAD for this Pipeline
1730 char str[1024];
1731 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001732 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001733
1734 track_pipeline(pCreateInfo, pPipeline);
1735
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001736 return result;
1737}
1738
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001739VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1740 VkDevice device,
1741 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1742 VkPipeline basePipeline,
1743 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001744{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001745 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1746 VkLayerDispatchTable *pTable = tableMap[pDisp];
1747 VkResult result = pTable->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001748 // Create LL HEAD for this Pipeline
1749 char str[1024];
1750 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001751 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001752
1753 track_pipeline(pCreateInfo, pPipeline);
1754
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001755 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001756
1757 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001758}
1759
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001760VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001762 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1763 VkLayerDispatchTable *pTable = tableMap[pDisp];
1764 VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001765 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001766 loader_platform_thread_lock_mutex(&globalLock);
1767 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1768 pNewNode->sampler = *pSampler;
1769 pNewNode->createInfo = *pCreateInfo;
1770 sampleMap[*pSampler] = pNewNode;
1771 loader_platform_thread_unlock_mutex(&globalLock);
1772 }
1773 return result;
1774}
1775
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001776VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001777{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001778 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1779 VkLayerDispatchTable *pTable = tableMap[pDisp];
1780 VkResult result = pTable->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001781 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001782 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1783 if (NULL == pNewNode) {
1784 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001785 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001786 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 -06001787 }
1788 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001789 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1790 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1791 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001792 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001793 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001794 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001795 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001796 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001797 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1798 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001799 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001800 }
1801 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001802 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001803 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001804 uint32_t j = 0;
1805 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001806 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001807 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001809 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001810 }
1811 }
1812 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001813 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1815 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001816 // Put new node at Head of global Layer list
1817 loader_platform_thread_lock_mutex(&globalLock);
1818 layoutMap[*pSetLayout] = pNewNode;
1819 loader_platform_thread_unlock_mutex(&globalLock);
1820 }
1821 return result;
1822}
1823
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001824VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001826 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1827 VkLayerDispatchTable *pTable = tableMap[pDisp];
1828 VkResult result = pTable->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001829 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001830 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001831 }
1832 return result;
1833}
1834
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001835VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001836{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001837 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1838 VkLayerDispatchTable *pTable = tableMap[pDisp];
1839 VkResult result = pTable->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001840 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001841 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001842 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001843 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001844 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 -06001845 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001846 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847 if (NULL == pNewNode) {
1848 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001849 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001850 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 -06001851 }
1852 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001853 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001854 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1855 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001856 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001857 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1858 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001859 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1860 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001861 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001863 pNewNode->pool = *pDescriptorPool;
1864 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865 }
1866 loader_platform_thread_unlock_mutex(&globalLock);
1867 }
1868 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001869 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001870 }
1871 return result;
1872}
1873
Mike Stroyan230e6252015-04-17 12:36:38 -06001874VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001875{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001876 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1877 VkLayerDispatchTable *pTable = tableMap[pDisp];
1878 VkResult result = pTable->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001879 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001880 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881 }
1882 return result;
1883}
1884
Mike Stroyan230e6252015-04-17 12:36:38 -06001885VK_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 -06001886{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001887 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1888 VkLayerDispatchTable *pTable = tableMap[pDisp];
1889 VkResult result = pTable->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001890 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001891 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1892 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001893 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001894 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001895 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 -06001896 }
1897 else {
1898 for (uint32_t i = 0; i < *pCount; i++) {
1899 char str[1024];
1900 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001901 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 -06001902 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 SET_NODE* pNewNode = new SET_NODE;
1904 if (NULL == pNewNode) {
1905 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001907 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 -06001908 }
1909 else {
1910 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001911 // Insert set at head of Set LL for this pool
1912 pNewNode->pNext = pPoolNode->pSets;
1913 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001914 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1915 if (NULL == pLayout) {
1916 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001917 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 -06001918 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 -06001919 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001920 pNewNode->pLayout = pLayout;
1921 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001922 pNewNode->set = pDescriptorSets[i];
1923 pNewNode->setUsage = setUsage;
1924 pNewNode->descriptorCount = pLayout->endIndex + 1;
1925 if (pNewNode->descriptorCount) {
1926 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1927 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1928 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1929 }
1930 setMap[pDescriptorSets[i]] = pNewNode;
1931 }
1932 }
1933 }
1934 }
1935 return result;
1936}
1937
Mike Stroyan230e6252015-04-17 12:36:38 -06001938VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001939{
1940 for (uint32_t i = 0; i < count; i++) {
1941 clearDescriptorSet(pDescriptorSets[i]);
1942 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001943 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1944 VkLayerDispatchTable *pTable = tableMap[pDisp];
1945 pTable->ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001946}
1947
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001948VK_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 -06001949{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001950 if (dsUpdate(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
Jon Ashburne0fa2282015-05-20 09:00:28 -06001951 dsUpdate(VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
1952 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1953 VkLayerDispatchTable *pTable = tableMap[pDisp];
1954 return pTable->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
1955 }
1956 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001957}
1958
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001959VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001960{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001961 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1962 VkLayerDispatchTable *pTable = tableMap[pDisp];
1963 VkResult result = pTable->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001964 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001965 return result;
1966}
1967
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001968VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001969{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001970 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1971 VkLayerDispatchTable *pTable = tableMap[pDisp];
1972 VkResult result = pTable->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001973 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001974 return result;
1975}
1976
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001977VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001978{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001979 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1980 VkLayerDispatchTable *pTable = tableMap[pDisp];
1981 VkResult result = pTable->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001982 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001983 return result;
1984}
1985
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001986VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001987{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001988 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1989 VkLayerDispatchTable *pTable = tableMap[pDisp];
1990 VkResult result = pTable->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001991 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001992 return result;
1993}
1994
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001995VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001996{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001997 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1998 VkLayerDispatchTable *pTable = tableMap[pDisp];
1999 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002000 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002001 loader_platform_thread_lock_mutex(&globalLock);
2002 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2003 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2004 pCB->cmdBuffer = *pCmdBuffer;
2005 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07002006 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002007 pCB->lastVtxBinding = MAX_BINDING;
2008 cmdBufferMap[*pCmdBuffer] = pCB;
2009 loader_platform_thread_unlock_mutex(&globalLock);
2010 updateCBTracking(*pCmdBuffer);
2011 }
2012 return result;
2013}
2014
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002015VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002016{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002017 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2018 VkLayerDispatchTable *pTable = tableMap[pDisp];
2019 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002020 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002021 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2022 if (pCB) {
2023 if (CB_NEW != pCB->state)
2024 resetCB(cmdBuffer);
2025 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002026 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002027 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002028 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002029 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002030 }
2031 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002032 }
2033 else {
2034 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002035 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002036 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 -06002037 }
2038 updateCBTracking(cmdBuffer);
2039 }
2040 return result;
2041}
2042
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002043VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002044{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002045 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2046 VkLayerDispatchTable *pTable = tableMap[pDisp];
2047 VkResult result = pTable->EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002048 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002049 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2050 if (pCB) {
2051 pCB->state = CB_UPDATE_COMPLETE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002052 // Reset CB status flags
2053 pCB->status = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002054 printCB(cmdBuffer);
2055 }
2056 else {
2057 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002058 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002059 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 -06002060 }
2061 updateCBTracking(cmdBuffer);
2062 //cbDumpDotFile("cb_dump.dot");
2063 }
2064 return result;
2065}
2066
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002067VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002068{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002069 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2070 VkLayerDispatchTable *pTable = tableMap[pDisp];
2071 VkResult result = pTable->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002072 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002073 resetCB(cmdBuffer);
2074 updateCBTracking(cmdBuffer);
2075 }
2076 return result;
2077}
2078
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002079VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002080{
2081 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2082 if (pCB) {
2083 updateCBTracking(cmdBuffer);
2084 addCmd(pCB, CMD_BINDPIPELINE);
2085 PIPELINE_NODE* pPN = getPipeline(pipeline);
2086 if (pPN) {
2087 pCB->lastBoundPipeline = pipeline;
2088 loader_platform_thread_lock_mutex(&globalLock);
2089 g_lastBoundPipeline = pPN;
2090 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002091 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002092 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2093 VkLayerDispatchTable *pTable = tableMap[pDisp];
2094 pTable->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002095 }
2096 else {
2097 char str[1024];
2098 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002099 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002100 }
2101 }
2102 else {
2103 char str[1024];
2104 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002105 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 -06002106 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002107}
2108
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002109VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002110{
2111 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002112 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2113 VkLayerDispatchTable *pTable = tableMap[pDisp];
2114 pTable->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002115}
2116
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002117VK_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 -06002118{
2119 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2120 if (pCB) {
2121 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002122 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002123 if (validateBoundPipeline(cmdBuffer)) {
2124 for (uint32_t i=0; i<setCount; i++) {
2125 if (getSetNode(pDescriptorSets[i])) {
2126 loader_platform_thread_lock_mutex(&globalLock);
2127 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2128 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2129 g_lastBoundDescriptorSet = pDescriptorSets[i];
2130 loader_platform_thread_unlock_mutex(&globalLock);
2131 char str[1024];
2132 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002133 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 -06002134 }
2135 else {
2136 char str[1024];
2137 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002138 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 -06002139 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002140 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002141 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2142 VkLayerDispatchTable *pTable = tableMap[pDisp];
2143 pTable->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002144 }
2145 }
2146 else {
2147 char str[1024];
2148 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002149 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 -06002150 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002151}
2152
Tony Barbour8205d902015-04-16 15:59:00 -06002153VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002154{
2155 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2156 if (pCB) {
2157 updateCBTracking(cmdBuffer);
2158 addCmd(pCB, CMD_BINDINDEXBUFFER);
2159 // TODO : Track idxBuffer binding
2160 }
2161 else {
2162 char str[1024];
2163 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002164 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 -06002165 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002166 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2167 VkLayerDispatchTable *pTable = tableMap[pDisp];
2168 pTable->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002169}
2170
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002171VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2172 VkCmdBuffer cmdBuffer,
2173 uint32_t startBinding,
2174 uint32_t bindingCount,
2175 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002176 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002177{
2178 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2179 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002180 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002181 updateCBTracking(cmdBuffer);
2182 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002183 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002184 if (validateBoundPipeline(cmdBuffer)) {
Jon Ashburne0fa2282015-05-20 09:00:28 -06002185 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2186 VkLayerDispatchTable *pTable = tableMap[pDisp];
2187 pTable->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002188 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002189 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002190 char str[1024];
2191 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002192 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 -06002193 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002194}
2195
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002196VK_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 -06002197{
2198 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002199 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002200 if (pCB) {
2201 updateCBTracking(cmdBuffer);
2202 addCmd(pCB, CMD_DRAW);
2203 pCB->drawCount[DRAW]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002204 loader_platform_thread_lock_mutex(&globalLock);
2205 valid = validate_draw_state_flags(cmdBuffer);
2206 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002207 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002208 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002209 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002210 synchAndPrintDSConfig(cmdBuffer);
2211 }
2212 else {
2213 char str[1024];
2214 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002215 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 -06002216 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002217 if (valid) {
2218 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2219 VkLayerDispatchTable *pTable = tableMap[pDisp];
2220 pTable->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2221 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002222}
2223
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002224VK_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 -06002225{
2226 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002227 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002228 if (pCB) {
2229 updateCBTracking(cmdBuffer);
2230 addCmd(pCB, CMD_DRAWINDEXED);
2231 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002232 loader_platform_thread_lock_mutex(&globalLock);
2233 valid = validate_draw_state_flags(cmdBuffer);
2234 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002235 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002236 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002237 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002238 synchAndPrintDSConfig(cmdBuffer);
2239 }
2240 else {
2241 char str[1024];
2242 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002243 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 -06002244 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002245 if (valid) {
2246 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2247 VkLayerDispatchTable *pTable = tableMap[pDisp];
2248 pTable->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2249 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002250}
2251
Tony Barbour8205d902015-04-16 15:59:00 -06002252VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002253{
2254 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002255 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002256 if (pCB) {
2257 updateCBTracking(cmdBuffer);
2258 addCmd(pCB, CMD_DRAWINDIRECT);
2259 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002260 loader_platform_thread_lock_mutex(&globalLock);
2261 valid = validate_draw_state_flags(cmdBuffer);
2262 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002263 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002264 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002265 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266 synchAndPrintDSConfig(cmdBuffer);
2267 }
2268 else {
2269 char str[1024];
2270 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002271 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 -06002272 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002273 if (valid) {
2274 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2275 VkLayerDispatchTable *pTable = tableMap[pDisp];
2276 pTable->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2277 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002278}
2279
Tony Barbour8205d902015-04-16 15:59:00 -06002280VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002281{
2282 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002283 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002284 if (pCB) {
2285 updateCBTracking(cmdBuffer);
2286 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2287 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002288 loader_platform_thread_lock_mutex(&globalLock);
2289 valid = validate_draw_state_flags(cmdBuffer);
2290 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002291 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002292 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002293 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002294 synchAndPrintDSConfig(cmdBuffer);
2295 }
2296 else {
2297 char str[1024];
2298 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002299 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 -06002300 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002301 if (valid) {
2302 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2303 VkLayerDispatchTable *pTable = tableMap[pDisp];
2304 pTable->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2305 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002306}
2307
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002308VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002309{
2310 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2311 if (pCB) {
2312 updateCBTracking(cmdBuffer);
2313 addCmd(pCB, CMD_DISPATCH);
2314 }
2315 else {
2316 char str[1024];
2317 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002318 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 -06002319 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002320 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2321 VkLayerDispatchTable *pTable = tableMap[pDisp];
2322 pTable->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002323}
2324
Tony Barbour8205d902015-04-16 15:59:00 -06002325VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002326{
2327 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2328 if (pCB) {
2329 updateCBTracking(cmdBuffer);
2330 addCmd(pCB, CMD_DISPATCHINDIRECT);
2331 }
2332 else {
2333 char str[1024];
2334 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002335 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 -06002336 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002337 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2338 VkLayerDispatchTable *pTable = tableMap[pDisp];
2339 pTable->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002340}
2341
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002342VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002343{
2344 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2345 if (pCB) {
2346 updateCBTracking(cmdBuffer);
2347 addCmd(pCB, CMD_COPYBUFFER);
2348 }
2349 else {
2350 char str[1024];
2351 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002352 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 -06002353 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002354 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2355 VkLayerDispatchTable *pTable = tableMap[pDisp];
2356 pTable->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002357}
2358
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002359VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2360 VkImage srcImage,
2361 VkImageLayout srcImageLayout,
2362 VkImage destImage,
2363 VkImageLayout destImageLayout,
2364 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002365{
2366 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2367 if (pCB) {
2368 updateCBTracking(cmdBuffer);
2369 addCmd(pCB, CMD_COPYIMAGE);
2370 }
2371 else {
2372 char str[1024];
2373 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002374 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 -06002375 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002376 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2377 VkLayerDispatchTable *pTable = tableMap[pDisp];
2378 pTable->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002379}
2380
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002381VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2382 VkImage srcImage, VkImageLayout srcImageLayout,
2383 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002384 uint32_t regionCount, const VkImageBlit* pRegions,
2385 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002386{
2387 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2388 if (pCB) {
2389 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002390 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002391 }
2392 else {
2393 char str[1024];
2394 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002395 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 -06002396 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002397 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2398 VkLayerDispatchTable *pTable = tableMap[pDisp];
2399 pTable->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002400}
2401
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002402VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2403 VkBuffer srcBuffer,
2404 VkImage destImage, VkImageLayout destImageLayout,
2405 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002406{
2407 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2408 if (pCB) {
2409 updateCBTracking(cmdBuffer);
2410 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2411 }
2412 else {
2413 char str[1024];
2414 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002415 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 -06002416 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002417 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2418 VkLayerDispatchTable *pTable = tableMap[pDisp];
2419 pTable->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002420}
2421
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002422VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2423 VkImage srcImage, VkImageLayout srcImageLayout,
2424 VkBuffer destBuffer,
2425 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002426{
2427 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2428 if (pCB) {
2429 updateCBTracking(cmdBuffer);
2430 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2431 }
2432 else {
2433 char str[1024];
2434 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002435 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 -06002436 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002437 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2438 VkLayerDispatchTable *pTable = tableMap[pDisp];
2439 pTable->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002440}
2441
Tony Barbour8205d902015-04-16 15:59:00 -06002442VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443{
2444 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2445 if (pCB) {
2446 updateCBTracking(cmdBuffer);
2447 addCmd(pCB, CMD_UPDATEBUFFER);
2448 }
2449 else {
2450 char str[1024];
2451 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002452 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 -06002453 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002454 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2455 VkLayerDispatchTable *pTable = tableMap[pDisp];
2456 pTable->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002457}
2458
Tony Barbour8205d902015-04-16 15:59:00 -06002459VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002460{
2461 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2462 if (pCB) {
2463 updateCBTracking(cmdBuffer);
2464 addCmd(pCB, CMD_FILLBUFFER);
2465 }
2466 else {
2467 char str[1024];
2468 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002469 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 -06002470 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002471 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2472 VkLayerDispatchTable *pTable = tableMap[pDisp];
2473 pTable->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002474}
2475
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002476VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2477 VkCmdBuffer cmdBuffer,
2478 VkImage image, VkImageLayout imageLayout,
2479 const VkClearColor *pColor,
2480 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002481{
2482 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2483 if (pCB) {
2484 updateCBTracking(cmdBuffer);
2485 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2486 }
2487 else {
2488 char str[1024];
2489 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002490 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 -06002491 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002492 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2493 VkLayerDispatchTable *pTable = tableMap[pDisp];
2494 pTable->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002495}
2496
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002497VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2498 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002499 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002500 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002501{
2502 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2503 if (pCB) {
2504 updateCBTracking(cmdBuffer);
2505 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2506 }
2507 else {
2508 char str[1024];
2509 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002510 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 -06002511 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002512 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2513 VkLayerDispatchTable *pTable = tableMap[pDisp];
2514 pTable->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002515}
2516
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002517VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2518 VkImage srcImage, VkImageLayout srcImageLayout,
2519 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002520 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002521{
2522 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2523 if (pCB) {
2524 updateCBTracking(cmdBuffer);
2525 addCmd(pCB, CMD_RESOLVEIMAGE);
2526 }
2527 else {
2528 char str[1024];
2529 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002530 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 -06002531 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002532 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2533 VkLayerDispatchTable *pTable = tableMap[pDisp];
2534 pTable->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002535}
2536
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002537VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002538{
2539 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2540 if (pCB) {
2541 updateCBTracking(cmdBuffer);
2542 addCmd(pCB, CMD_SETEVENT);
2543 }
2544 else {
2545 char str[1024];
2546 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002547 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 -06002548 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002549 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2550 VkLayerDispatchTable *pTable = tableMap[pDisp];
2551 pTable->CmdSetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002552}
2553
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002554VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002555{
2556 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2557 if (pCB) {
2558 updateCBTracking(cmdBuffer);
2559 addCmd(pCB, CMD_RESETEVENT);
2560 }
2561 else {
2562 char str[1024];
2563 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002564 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 -06002565 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002566 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2567 VkLayerDispatchTable *pTable = tableMap[pDisp];
2568 pTable->CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002569}
2570
Tony Barbour8205d902015-04-16 15:59:00 -06002571VK_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 -06002572{
2573 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2574 if (pCB) {
2575 updateCBTracking(cmdBuffer);
2576 addCmd(pCB, CMD_WAITEVENTS);
2577 }
2578 else {
2579 char str[1024];
2580 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002581 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 -06002582 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002583 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2584 VkLayerDispatchTable *pTable = tableMap[pDisp];
2585 pTable->CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002586}
2587
Tony Barbour8205d902015-04-16 15:59:00 -06002588VK_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 -06002589{
2590 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2591 if (pCB) {
2592 updateCBTracking(cmdBuffer);
2593 addCmd(pCB, CMD_PIPELINEBARRIER);
2594 }
2595 else {
2596 char str[1024];
2597 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002598 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 -06002599 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002600 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2601 VkLayerDispatchTable *pTable = tableMap[pDisp];
2602 pTable->CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002603}
2604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002605VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002606{
2607 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2608 if (pCB) {
2609 updateCBTracking(cmdBuffer);
2610 addCmd(pCB, CMD_BEGINQUERY);
2611 }
2612 else {
2613 char str[1024];
2614 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002615 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 -06002616 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002617 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2618 VkLayerDispatchTable *pTable = tableMap[pDisp];
2619 pTable->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002620}
2621
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002622VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002623{
2624 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2625 if (pCB) {
2626 updateCBTracking(cmdBuffer);
2627 addCmd(pCB, CMD_ENDQUERY);
2628 }
2629 else {
2630 char str[1024];
2631 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002632 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 -06002633 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002634 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2635 VkLayerDispatchTable *pTable = tableMap[pDisp];
2636 pTable->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002637}
2638
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002639VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002640{
2641 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2642 if (pCB) {
2643 updateCBTracking(cmdBuffer);
2644 addCmd(pCB, CMD_RESETQUERYPOOL);
2645 }
2646 else {
2647 char str[1024];
2648 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002649 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 -06002650 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002651 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2652 VkLayerDispatchTable *pTable = tableMap[pDisp];
2653 pTable->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002654}
2655
Tony Barbour8205d902015-04-16 15:59:00 -06002656VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002657{
2658 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2659 if (pCB) {
2660 updateCBTracking(cmdBuffer);
2661 addCmd(pCB, CMD_WRITETIMESTAMP);
2662 }
2663 else {
2664 char str[1024];
2665 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002666 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 -06002667 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002668 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2669 VkLayerDispatchTable *pTable = tableMap[pDisp];
2670 pTable->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002671}
2672
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002673VK_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 -06002674{
2675 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2676 if (pCB) {
2677 updateCBTracking(cmdBuffer);
2678 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2679 }
2680 else {
2681 char str[1024];
2682 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002683 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 -06002684 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002685 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2686 VkLayerDispatchTable *pTable = tableMap[pDisp];
2687 pTable->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002688}
2689
Tony Barbour8205d902015-04-16 15:59:00 -06002690VK_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 -06002691{
2692 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2693 if (pCB) {
2694 updateCBTracking(cmdBuffer);
2695 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2696 }
2697 else {
2698 char str[1024];
2699 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002700 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 -06002701 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002702 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2703 VkLayerDispatchTable *pTable = tableMap[pDisp];
2704 pTable->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002705}
2706
Tony Barbour8205d902015-04-16 15:59:00 -06002707VK_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 -06002708{
2709 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2710 if (pCB) {
2711 updateCBTracking(cmdBuffer);
2712 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2713 }
2714 else {
2715 char str[1024];
2716 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002717 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 -06002718 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002719 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2720 VkLayerDispatchTable *pTable = tableMap[pDisp];
2721 pTable->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002722}
2723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002724VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002725{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002726 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2727 VkLayerDispatchTable *pTable = tableMap[pDisp];
2728 VkResult result = pTable->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002729 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002730 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002731 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002732 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002733 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2734 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002735 }
2736 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002737 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2738 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002739 }
2740 frameBufferMap[*pFramebuffer] = localFBCI;
2741 }
2742 return result;
2743}
2744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002745VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002746{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002747 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2748 VkLayerDispatchTable *pTable = tableMap[pDisp];
2749 VkResult result = pTable->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002750 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002751 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002752 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002753 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002754 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2755 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002756 }
2757 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002758 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2759 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002760 }
2761 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002762 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2763 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002764 }
2765 renderPassMap[*pRenderPass] = localRPCI;
2766 }
2767 return result;
2768}
2769
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002770VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002771{
2772 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2773 if (pCB) {
2774 updateCBTracking(cmdBuffer);
2775 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002776 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2777 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002778 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002779 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002780 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002781 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002782 char str[1024];
2783 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002784 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 -06002785 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002786 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2787 VkLayerDispatchTable *pTable = tableMap[pDisp];
2788 pTable->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002789}
2790
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002791VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002792{
2793 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2794 if (pCB) {
2795 updateCBTracking(cmdBuffer);
2796 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002797 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002798 }
2799 else {
2800 char str[1024];
2801 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002802 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 -06002803 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002804 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2805 VkLayerDispatchTable *pTable = tableMap[pDisp];
2806 pTable->CmdEndRenderPass(cmdBuffer, renderPass);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002807}
2808
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002809VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2810 VkInstance instance,
2811 VkFlags msgFlags,
2812 const PFN_vkDbgMsgCallback pfnMsgCallback,
2813 void* pUserData,
2814 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002815{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002816 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2817 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2818 return layer_create_msg_callback(instance, pTable, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002819}
2820
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002821VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2822 VkInstance instance,
2823 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002824{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002825 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2826 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2827 return layer_destroy_msg_callback(instance, pTable, msgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002828}
2829
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002830VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002831{
2832 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburnf0615e22015-05-25 14:11:37 -06002833 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
2834 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
2835 if (!pTable->ext_enabled) {
2836 char str[1024];
2837 sprintf(str, "Attempt to use CmdDbgMarkerBegin but extension disabled!");
2838 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2839 }
2840 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002841 updateCBTracking(cmdBuffer);
2842 addCmd(pCB, CMD_DBGMARKERBEGIN);
2843 }
2844 else {
2845 char str[1024];
2846 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002847 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 -06002848 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002849 pTable->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002850}
2851
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002852VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002853{
2854 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburnf0615e22015-05-25 14:11:37 -06002855 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
2856 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
2857 if (!pTable->ext_enabled) {
2858 char str[1024];
2859 sprintf(str, "Attempt to use CmdDbgMarkerEnd but extension disabled!");
2860 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2861 }
2862 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002863 updateCBTracking(cmdBuffer);
2864 addCmd(pCB, CMD_DBGMARKEREND);
2865 }
2866 else {
2867 char str[1024];
2868 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002869 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 -06002870 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002871 pTable->CmdDbgMarkerEnd(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002872}
2873
2874// TODO : Want to pass in a cmdBuffer here based on which state to display
2875void drawStateDumpDotFile(char* outFileName)
2876{
2877 // TODO : Currently just setting cmdBuffer based on global var
2878 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2879 dumpGlobalDotFile(outFileName);
2880}
2881
2882void drawStateDumpCommandBufferDotFile(char* outFileName)
2883{
2884 cbDumpDotFile(outFileName);
2885}
2886
2887void drawStateDumpPngFile(char* outFileName)
2888{
2889#if defined(_WIN32)
2890// FIXME: NEED WINDOWS EQUIVALENT
2891 char str[1024];
2892 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002893 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002894#else // WIN32
2895 char dotExe[32] = "/usr/bin/dot";
2896 if( access(dotExe, X_OK) != -1) {
2897 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2898 char dotCmd[1024];
2899 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002900 int retval = system(dotCmd);
2901 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002902 remove("/tmp/tmp.dot");
2903 }
2904 else {
2905 char str[1024];
2906 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002907 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002908 }
2909#endif // WIN32
2910}
2911
Jon Ashburn1245cec2015-05-18 13:20:15 -06002912VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002913{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002914 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002915 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002916
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002917 loader_platform_thread_once(&g_initOnce, initDrawState);
2918
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002919 /* loader uses this to force layer initialization; device object is wrapped */
2920 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
2921 initDeviceTable((const VkBaseLayerObject *) dev);
Jon Ashburn1245cec2015-05-18 13:20:15 -06002922 return (void *) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002923 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002924 if (!strcmp(funcName, "vkDestroyDevice"))
2925 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002926 if (!strcmp(funcName, "vkQueueSubmit"))
2927 return (void*) vkQueueSubmit;
2928 if (!strcmp(funcName, "vkDestroyObject"))
2929 return (void*) vkDestroyObject;
2930 if (!strcmp(funcName, "vkCreateBufferView"))
2931 return (void*) vkCreateBufferView;
2932 if (!strcmp(funcName, "vkCreateImageView"))
2933 return (void*) vkCreateImageView;
2934 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2935 return (void*) vkCreateGraphicsPipeline;
2936 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2937 return (void*) vkCreateGraphicsPipelineDerivative;
2938 if (!strcmp(funcName, "vkCreateSampler"))
2939 return (void*) vkCreateSampler;
2940 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2941 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002942 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2943 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002944 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2945 return (void*) vkCreateDescriptorPool;
2946 if (!strcmp(funcName, "vkResetDescriptorPool"))
2947 return (void*) vkResetDescriptorPool;
2948 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2949 return (void*) vkAllocDescriptorSets;
2950 if (!strcmp(funcName, "vkClearDescriptorSets"))
2951 return (void*) vkClearDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002952 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2953 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002954 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2955 return (void*) vkCreateDynamicViewportState;
2956 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2957 return (void*) vkCreateDynamicRasterState;
2958 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2959 return (void*) vkCreateDynamicColorBlendState;
2960 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2961 return (void*) vkCreateDynamicDepthStencilState;
2962 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2963 return (void*) vkCreateCommandBuffer;
2964 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2965 return (void*) vkBeginCommandBuffer;
2966 if (!strcmp(funcName, "vkEndCommandBuffer"))
2967 return (void*) vkEndCommandBuffer;
2968 if (!strcmp(funcName, "vkResetCommandBuffer"))
2969 return (void*) vkResetCommandBuffer;
2970 if (!strcmp(funcName, "vkCmdBindPipeline"))
2971 return (void*) vkCmdBindPipeline;
2972 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2973 return (void*) vkCmdBindDynamicStateObject;
2974 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2975 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002976 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2977 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002978 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2979 return (void*) vkCmdBindIndexBuffer;
2980 if (!strcmp(funcName, "vkCmdDraw"))
2981 return (void*) vkCmdDraw;
2982 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2983 return (void*) vkCmdDrawIndexed;
2984 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2985 return (void*) vkCmdDrawIndirect;
2986 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2987 return (void*) vkCmdDrawIndexedIndirect;
2988 if (!strcmp(funcName, "vkCmdDispatch"))
2989 return (void*) vkCmdDispatch;
2990 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2991 return (void*) vkCmdDispatchIndirect;
2992 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2993 return (void*) vkCmdCopyBuffer;
2994 if (!strcmp(funcName, "vkCmdCopyImage"))
2995 return (void*) vkCmdCopyImage;
2996 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2997 return (void*) vkCmdCopyBufferToImage;
2998 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2999 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003000 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
3001 return (void*) vkCmdUpdateBuffer;
3002 if (!strcmp(funcName, "vkCmdFillBuffer"))
3003 return (void*) vkCmdFillBuffer;
3004 if (!strcmp(funcName, "vkCmdClearColorImage"))
3005 return (void*) vkCmdClearColorImage;
3006 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
3007 return (void*) vkCmdClearDepthStencil;
3008 if (!strcmp(funcName, "vkCmdResolveImage"))
3009 return (void*) vkCmdResolveImage;
3010 if (!strcmp(funcName, "vkCmdSetEvent"))
3011 return (void*) vkCmdSetEvent;
3012 if (!strcmp(funcName, "vkCmdResetEvent"))
3013 return (void*) vkCmdResetEvent;
3014 if (!strcmp(funcName, "vkCmdWaitEvents"))
3015 return (void*) vkCmdWaitEvents;
3016 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
3017 return (void*) vkCmdPipelineBarrier;
3018 if (!strcmp(funcName, "vkCmdBeginQuery"))
3019 return (void*) vkCmdBeginQuery;
3020 if (!strcmp(funcName, "vkCmdEndQuery"))
3021 return (void*) vkCmdEndQuery;
3022 if (!strcmp(funcName, "vkCmdResetQueryPool"))
3023 return (void*) vkCmdResetQueryPool;
3024 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
3025 return (void*) vkCmdWriteTimestamp;
3026 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
3027 return (void*) vkCmdInitAtomicCounters;
3028 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
3029 return (void*) vkCmdLoadAtomicCounters;
3030 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
3031 return (void*) vkCmdSaveAtomicCounters;
3032 if (!strcmp(funcName, "vkCreateFramebuffer"))
3033 return (void*) vkCreateFramebuffer;
3034 if (!strcmp(funcName, "vkCreateRenderPass"))
3035 return (void*) vkCreateRenderPass;
3036 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
3037 return (void*) vkCmdBeginRenderPass;
3038 if (!strcmp(funcName, "vkCmdEndRenderPass"))
3039 return (void*) vkCmdEndRenderPass;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003040 if (!strcmp(funcName, "vkDbgCreateMsgCallback"))
3041 return (void*) vkDbgCreateMsgCallback;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003042 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
3043 return (void*) vkCmdDbgMarkerBegin;
3044 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
3045 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003046 if (!strcmp("drawStateDumpDotFile", funcName))
3047 return (void*) drawStateDumpDotFile;
3048 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
3049 return (void*) drawStateDumpCommandBufferDotFile;
3050 if (!strcmp("drawStateDumpPngFile", funcName))
3051 return (void*) drawStateDumpPngFile;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003052 else
3053 {
3054 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) dev;
3055 VkLayerDispatchTable* pTable = tableMap[*ppDisp];
3056 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003057 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003058 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003059 }
3060}
3061
3062VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3063{
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003064 if (instance == NULL)
3065 return NULL;
3066
Jon Ashburnd9564002015-05-07 10:27:37 -06003067 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003068
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003069 /* loader uses this to force layer initialization; instance object is wrapped */
3070 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
3071 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003072 return (void *) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003073 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003074 if (!strcmp(funcName, "vkCreateInstance"))
3075 return (void *) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003076 if (!strcmp(funcName, "vkDestroyInstance"))
3077 return (void *) vkDestroyInstance;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003078 if (!strcmp(funcName, "vkCreateDevice"))
3079 return (void*) vkCreateDevice;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003080 else
3081 {
3082 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
3083 VkLayerInstanceDispatchTable* pTable = tableInstanceMap[*ppDisp];
3084 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003085 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003086 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003087 }
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003088
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003089}