blob: 4b76f05e1cb61fba2d350a2644cebb7c3e99faa9 [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 Goeltzenleuchter47461fb2015-06-01 14:34:25 -06001602#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001603static 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 Goeltzenleuchter47461fb2015-06-01 14:34:25 -06001609 },
1610 {
1611 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1612 "Validation",
1613 0x10,
1614 "Sample layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001615 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001616};
1617
Jon Ashburnf0615e22015-05-25 14:11:37 -06001618//TODO add DEBUG_MARKER to device extension list
Jon Ashburneb2728b2015-04-10 14:33:07 -06001619VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001620 VkExtensionInfoType infoType,
1621 uint32_t extensionIndex,
1622 size_t* pDataSize,
1623 void* pData)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001624{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001625 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Jon Ashburneb2728b2015-04-10 14:33:07 -06001626 uint32_t *count;
1627
1628 if (pDataSize == NULL)
1629 return VK_ERROR_INVALID_POINTER;
1630
1631 switch (infoType) {
1632 case VK_EXTENSION_INFO_TYPE_COUNT:
1633 *pDataSize = sizeof(uint32_t);
1634 if (pData == NULL)
1635 return VK_SUCCESS;
1636 count = (uint32_t *) pData;
1637 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1638 break;
1639 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1640 *pDataSize = sizeof(VkExtensionProperties);
1641 if (pData == NULL)
1642 return VK_SUCCESS;
1643 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1644 return VK_ERROR_INVALID_VALUE;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001645 memcpy((VkExtensionProperties *) pData, &dsExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburneb2728b2015-04-10 14:33:07 -06001646 break;
1647 default:
1648 return VK_ERROR_INVALID_VALUE;
1649 };
1650
1651 return VK_SUCCESS;
1652}
1653
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001654VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001655{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001656 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001657 for (uint32_t i=0; i < cmdBufferCount; i++) {
1658 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001659 pCB = getCBNode(pCmdBuffers[i]);
1660 loader_platform_thread_lock_mutex(&globalLock);
1661 if (CB_UPDATE_COMPLETE != pCB->state) {
1662 // Flag error for using CB w/o vkEndCommandBuffer() called
1663 char str[1024];
1664 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001665 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 -06001666 loader_platform_thread_unlock_mutex(&globalLock);
1667 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001668 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001669 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001670 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001671
1672 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) queue;
1673 VkLayerDispatchTable *pTable = tableMap[pDisp];
1674 VkResult result = pTable->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001675 return result;
1676}
1677
Mike Stroyan230e6252015-04-17 12:36:38 -06001678VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679{
1680 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Jon Ashburne0fa2282015-05-20 09:00:28 -06001681 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1682 VkLayerDispatchTable *pTable = tableMap[pDisp];
1683 VkResult result = pTable->DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001684 return result;
1685}
1686
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001687VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001688{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001689 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1690 VkLayerDispatchTable *pTable = tableMap[pDisp];
1691 VkResult result = pTable->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001692 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001693 loader_platform_thread_lock_mutex(&globalLock);
1694 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1695 pNewNode->buffer = *pView;
1696 pNewNode->createInfo = *pCreateInfo;
1697 bufferMap[*pView] = pNewNode;
1698 loader_platform_thread_unlock_mutex(&globalLock);
1699 }
1700 return result;
1701}
1702
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001703VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001704{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001705 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1706 VkLayerDispatchTable *pTable = tableMap[pDisp];
1707 VkResult result = pTable->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001708 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001709 loader_platform_thread_lock_mutex(&globalLock);
1710 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1711 pNewNode->image = *pView;
1712 pNewNode->createInfo = *pCreateInfo;
1713 imageMap[*pView] = pNewNode;
1714 loader_platform_thread_unlock_mutex(&globalLock);
1715 }
1716 return result;
1717}
1718
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001719static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001720{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001721 // Create LL HEAD for this Pipeline
1722 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001723 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1724 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1725 pPipeNode->pipeline = *pPipeline;
1726 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001727 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001728}
1729
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001730VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001731{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001732 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1733 VkLayerDispatchTable *pTable = tableMap[pDisp];
1734 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001735 // Create LL HEAD for this Pipeline
1736 char str[1024];
1737 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001738 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001739
1740 track_pipeline(pCreateInfo, pPipeline);
1741
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001742 return result;
1743}
1744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001745VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1746 VkDevice device,
1747 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1748 VkPipeline basePipeline,
1749 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001750{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001751 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1752 VkLayerDispatchTable *pTable = tableMap[pDisp];
1753 VkResult result = pTable->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001754 // Create LL HEAD for this Pipeline
1755 char str[1024];
1756 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001757 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001758
1759 track_pipeline(pCreateInfo, pPipeline);
1760
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001762
1763 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001764}
1765
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001766VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001767{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001768 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1769 VkLayerDispatchTable *pTable = tableMap[pDisp];
1770 VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001771 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001772 loader_platform_thread_lock_mutex(&globalLock);
1773 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1774 pNewNode->sampler = *pSampler;
1775 pNewNode->createInfo = *pCreateInfo;
1776 sampleMap[*pSampler] = pNewNode;
1777 loader_platform_thread_unlock_mutex(&globalLock);
1778 }
1779 return result;
1780}
1781
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001782VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001783{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001784 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1785 VkLayerDispatchTable *pTable = tableMap[pDisp];
1786 VkResult result = pTable->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001787 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001788 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1789 if (NULL == pNewNode) {
1790 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001791 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001792 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 -06001793 }
1794 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001795 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1796 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1797 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001798 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001799 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001800 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001801 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001802 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001803 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1804 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001805 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001806 }
1807 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001808 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001809 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001810 uint32_t j = 0;
1811 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001812 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001813 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001815 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001816 }
1817 }
1818 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001819 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1821 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001822 // Put new node at Head of global Layer list
1823 loader_platform_thread_lock_mutex(&globalLock);
1824 layoutMap[*pSetLayout] = pNewNode;
1825 loader_platform_thread_unlock_mutex(&globalLock);
1826 }
1827 return result;
1828}
1829
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001830VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001831{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001832 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1833 VkLayerDispatchTable *pTable = tableMap[pDisp];
1834 VkResult result = pTable->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001835 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001836 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001837 }
1838 return result;
1839}
1840
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001841VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001842{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001843 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1844 VkLayerDispatchTable *pTable = tableMap[pDisp];
1845 VkResult result = pTable->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001846 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001847 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001848 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001849 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001850 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 -06001851 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001852 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853 if (NULL == pNewNode) {
1854 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001855 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001856 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 -06001857 }
1858 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001859 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001860 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1861 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001863 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1864 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1866 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001867 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001869 pNewNode->pool = *pDescriptorPool;
1870 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871 }
1872 loader_platform_thread_unlock_mutex(&globalLock);
1873 }
1874 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001875 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001876 }
1877 return result;
1878}
1879
Mike Stroyan230e6252015-04-17 12:36:38 -06001880VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001882 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1883 VkLayerDispatchTable *pTable = tableMap[pDisp];
1884 VkResult result = pTable->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001885 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001886 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001887 }
1888 return result;
1889}
1890
Mike Stroyan230e6252015-04-17 12:36:38 -06001891VK_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 -06001892{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001893 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1894 VkLayerDispatchTable *pTable = tableMap[pDisp];
1895 VkResult result = pTable->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001896 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001897 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1898 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001899 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001900 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001901 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 -06001902 }
1903 else {
1904 for (uint32_t i = 0; i < *pCount; i++) {
1905 char str[1024];
1906 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001907 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 -06001908 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001909 SET_NODE* pNewNode = new SET_NODE;
1910 if (NULL == pNewNode) {
1911 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001912 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001913 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 -06001914 }
1915 else {
1916 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001917 // Insert set at head of Set LL for this pool
1918 pNewNode->pNext = pPoolNode->pSets;
1919 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001920 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1921 if (NULL == pLayout) {
1922 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001923 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 -06001924 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 -06001925 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001926 pNewNode->pLayout = pLayout;
1927 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001928 pNewNode->set = pDescriptorSets[i];
1929 pNewNode->setUsage = setUsage;
1930 pNewNode->descriptorCount = pLayout->endIndex + 1;
1931 if (pNewNode->descriptorCount) {
1932 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1933 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1934 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1935 }
1936 setMap[pDescriptorSets[i]] = pNewNode;
1937 }
1938 }
1939 }
1940 }
1941 return result;
1942}
1943
Mike Stroyan230e6252015-04-17 12:36:38 -06001944VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001945{
1946 for (uint32_t i = 0; i < count; i++) {
1947 clearDescriptorSet(pDescriptorSets[i]);
1948 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001949 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1950 VkLayerDispatchTable *pTable = tableMap[pDisp];
1951 pTable->ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001952}
1953
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001954VK_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 -06001955{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001956 if (dsUpdate(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
Jon Ashburne0fa2282015-05-20 09:00:28 -06001957 dsUpdate(VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
1958 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1959 VkLayerDispatchTable *pTable = tableMap[pDisp];
1960 return pTable->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
1961 }
1962 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001963}
1964
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001965VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001966{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001967 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1968 VkLayerDispatchTable *pTable = tableMap[pDisp];
1969 VkResult result = pTable->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001970 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001971 return result;
1972}
1973
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001974VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001976 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1977 VkLayerDispatchTable *pTable = tableMap[pDisp];
1978 VkResult result = pTable->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001979 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001980 return result;
1981}
1982
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001983VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001984{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001985 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1986 VkLayerDispatchTable *pTable = tableMap[pDisp];
1987 VkResult result = pTable->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001988 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001989 return result;
1990}
1991
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001992VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001993{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001994 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1995 VkLayerDispatchTable *pTable = tableMap[pDisp];
1996 VkResult result = pTable->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001997 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001998 return result;
1999}
2000
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002001VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002002{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002003 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2004 VkLayerDispatchTable *pTable = tableMap[pDisp];
2005 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002006 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002007 loader_platform_thread_lock_mutex(&globalLock);
2008 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2009 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2010 pCB->cmdBuffer = *pCmdBuffer;
2011 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07002012 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002013 pCB->lastVtxBinding = MAX_BINDING;
2014 cmdBufferMap[*pCmdBuffer] = pCB;
2015 loader_platform_thread_unlock_mutex(&globalLock);
2016 updateCBTracking(*pCmdBuffer);
2017 }
2018 return result;
2019}
2020
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002021VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002022{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002023 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2024 VkLayerDispatchTable *pTable = tableMap[pDisp];
2025 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002026 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002027 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2028 if (pCB) {
2029 if (CB_NEW != pCB->state)
2030 resetCB(cmdBuffer);
2031 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002032 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002033 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002034 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002035 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002036 }
2037 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002038 }
2039 else {
2040 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002041 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002042 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 -06002043 }
2044 updateCBTracking(cmdBuffer);
2045 }
2046 return result;
2047}
2048
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002049VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002050{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002051 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2052 VkLayerDispatchTable *pTable = tableMap[pDisp];
2053 VkResult result = pTable->EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002054 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002055 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2056 if (pCB) {
2057 pCB->state = CB_UPDATE_COMPLETE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002058 // Reset CB status flags
2059 pCB->status = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002060 printCB(cmdBuffer);
2061 }
2062 else {
2063 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002064 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002065 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 -06002066 }
2067 updateCBTracking(cmdBuffer);
2068 //cbDumpDotFile("cb_dump.dot");
2069 }
2070 return result;
2071}
2072
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002073VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002074{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002075 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2076 VkLayerDispatchTable *pTable = tableMap[pDisp];
2077 VkResult result = pTable->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002078 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002079 resetCB(cmdBuffer);
2080 updateCBTracking(cmdBuffer);
2081 }
2082 return result;
2083}
2084
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002085VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002086{
2087 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2088 if (pCB) {
2089 updateCBTracking(cmdBuffer);
2090 addCmd(pCB, CMD_BINDPIPELINE);
2091 PIPELINE_NODE* pPN = getPipeline(pipeline);
2092 if (pPN) {
2093 pCB->lastBoundPipeline = pipeline;
2094 loader_platform_thread_lock_mutex(&globalLock);
2095 g_lastBoundPipeline = pPN;
2096 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002097 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002098 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2099 VkLayerDispatchTable *pTable = tableMap[pDisp];
2100 pTable->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002101 }
2102 else {
2103 char str[1024];
2104 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002105 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002106 }
2107 }
2108 else {
2109 char str[1024];
2110 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002111 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 -06002112 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002113}
2114
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002115VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002116{
2117 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002118 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2119 VkLayerDispatchTable *pTable = tableMap[pDisp];
2120 pTable->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002121}
2122
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002123VK_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 -06002124{
2125 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2126 if (pCB) {
2127 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002128 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002129 if (validateBoundPipeline(cmdBuffer)) {
2130 for (uint32_t i=0; i<setCount; i++) {
2131 if (getSetNode(pDescriptorSets[i])) {
2132 loader_platform_thread_lock_mutex(&globalLock);
2133 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2134 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2135 g_lastBoundDescriptorSet = pDescriptorSets[i];
2136 loader_platform_thread_unlock_mutex(&globalLock);
2137 char str[1024];
2138 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002139 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 -06002140 }
2141 else {
2142 char str[1024];
2143 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002144 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 -06002145 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002146 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002147 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2148 VkLayerDispatchTable *pTable = tableMap[pDisp];
2149 pTable->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002150 }
2151 }
2152 else {
2153 char str[1024];
2154 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002155 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 -06002156 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002157}
2158
Tony Barbour8205d902015-04-16 15:59:00 -06002159VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002160{
2161 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2162 if (pCB) {
2163 updateCBTracking(cmdBuffer);
2164 addCmd(pCB, CMD_BINDINDEXBUFFER);
2165 // TODO : Track idxBuffer binding
2166 }
2167 else {
2168 char str[1024];
2169 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002170 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 -06002171 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002172 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2173 VkLayerDispatchTable *pTable = tableMap[pDisp];
2174 pTable->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002175}
2176
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002177VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2178 VkCmdBuffer cmdBuffer,
2179 uint32_t startBinding,
2180 uint32_t bindingCount,
2181 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002182 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002183{
2184 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2185 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002186 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002187 updateCBTracking(cmdBuffer);
2188 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002189 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002190 if (validateBoundPipeline(cmdBuffer)) {
Jon Ashburne0fa2282015-05-20 09:00:28 -06002191 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2192 VkLayerDispatchTable *pTable = tableMap[pDisp];
2193 pTable->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002194 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002195 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002196 char str[1024];
2197 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002198 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 -06002199 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002200}
2201
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002202VK_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 -06002203{
2204 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002205 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002206 if (pCB) {
2207 updateCBTracking(cmdBuffer);
2208 addCmd(pCB, CMD_DRAW);
2209 pCB->drawCount[DRAW]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002210 loader_platform_thread_lock_mutex(&globalLock);
2211 valid = validate_draw_state_flags(cmdBuffer);
2212 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002213 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002214 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002215 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002216 synchAndPrintDSConfig(cmdBuffer);
2217 }
2218 else {
2219 char str[1024];
2220 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002221 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 -06002222 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002223 if (valid) {
2224 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2225 VkLayerDispatchTable *pTable = tableMap[pDisp];
2226 pTable->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2227 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002228}
2229
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002230VK_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 -06002231{
2232 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002233 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002234 if (pCB) {
2235 updateCBTracking(cmdBuffer);
2236 addCmd(pCB, CMD_DRAWINDEXED);
2237 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002238 loader_platform_thread_lock_mutex(&globalLock);
2239 valid = validate_draw_state_flags(cmdBuffer);
2240 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002241 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002242 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002243 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002244 synchAndPrintDSConfig(cmdBuffer);
2245 }
2246 else {
2247 char str[1024];
2248 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002249 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 -06002250 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002251 if (valid) {
2252 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2253 VkLayerDispatchTable *pTable = tableMap[pDisp];
2254 pTable->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2255 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002256}
2257
Tony Barbour8205d902015-04-16 15:59:00 -06002258VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002259{
2260 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002261 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002262 if (pCB) {
2263 updateCBTracking(cmdBuffer);
2264 addCmd(pCB, CMD_DRAWINDIRECT);
2265 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002266 loader_platform_thread_lock_mutex(&globalLock);
2267 valid = validate_draw_state_flags(cmdBuffer);
2268 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002269 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002270 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002271 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002272 synchAndPrintDSConfig(cmdBuffer);
2273 }
2274 else {
2275 char str[1024];
2276 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002277 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 -06002278 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002279 if (valid) {
2280 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2281 VkLayerDispatchTable *pTable = tableMap[pDisp];
2282 pTable->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2283 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002284}
2285
Tony Barbour8205d902015-04-16 15:59:00 -06002286VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002287{
2288 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002289 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002290 if (pCB) {
2291 updateCBTracking(cmdBuffer);
2292 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2293 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002294 loader_platform_thread_lock_mutex(&globalLock);
2295 valid = validate_draw_state_flags(cmdBuffer);
2296 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002297 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002298 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002299 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002300 synchAndPrintDSConfig(cmdBuffer);
2301 }
2302 else {
2303 char str[1024];
2304 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002305 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 -06002306 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002307 if (valid) {
2308 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2309 VkLayerDispatchTable *pTable = tableMap[pDisp];
2310 pTable->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2311 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002312}
2313
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002314VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002315{
2316 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2317 if (pCB) {
2318 updateCBTracking(cmdBuffer);
2319 addCmd(pCB, CMD_DISPATCH);
2320 }
2321 else {
2322 char str[1024];
2323 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002324 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 -06002325 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002326 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2327 VkLayerDispatchTable *pTable = tableMap[pDisp];
2328 pTable->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002329}
2330
Tony Barbour8205d902015-04-16 15:59:00 -06002331VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002332{
2333 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2334 if (pCB) {
2335 updateCBTracking(cmdBuffer);
2336 addCmd(pCB, CMD_DISPATCHINDIRECT);
2337 }
2338 else {
2339 char str[1024];
2340 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002341 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 -06002342 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002343 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2344 VkLayerDispatchTable *pTable = tableMap[pDisp];
2345 pTable->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002346}
2347
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002348VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002349{
2350 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2351 if (pCB) {
2352 updateCBTracking(cmdBuffer);
2353 addCmd(pCB, CMD_COPYBUFFER);
2354 }
2355 else {
2356 char str[1024];
2357 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002358 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 -06002359 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002360 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2361 VkLayerDispatchTable *pTable = tableMap[pDisp];
2362 pTable->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002363}
2364
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002365VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2366 VkImage srcImage,
2367 VkImageLayout srcImageLayout,
2368 VkImage destImage,
2369 VkImageLayout destImageLayout,
2370 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002371{
2372 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2373 if (pCB) {
2374 updateCBTracking(cmdBuffer);
2375 addCmd(pCB, CMD_COPYIMAGE);
2376 }
2377 else {
2378 char str[1024];
2379 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002380 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 -06002381 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002382 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2383 VkLayerDispatchTable *pTable = tableMap[pDisp];
2384 pTable->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002385}
2386
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002387VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2388 VkImage srcImage, VkImageLayout srcImageLayout,
2389 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002390 uint32_t regionCount, const VkImageBlit* pRegions,
2391 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002392{
2393 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2394 if (pCB) {
2395 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002396 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002397 }
2398 else {
2399 char str[1024];
2400 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002401 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 -06002402 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002403 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2404 VkLayerDispatchTable *pTable = tableMap[pDisp];
2405 pTable->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002406}
2407
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002408VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2409 VkBuffer srcBuffer,
2410 VkImage destImage, VkImageLayout destImageLayout,
2411 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002412{
2413 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2414 if (pCB) {
2415 updateCBTracking(cmdBuffer);
2416 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2417 }
2418 else {
2419 char str[1024];
2420 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002421 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 -06002422 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002423 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2424 VkLayerDispatchTable *pTable = tableMap[pDisp];
2425 pTable->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002426}
2427
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002428VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2429 VkImage srcImage, VkImageLayout srcImageLayout,
2430 VkBuffer destBuffer,
2431 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002432{
2433 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2434 if (pCB) {
2435 updateCBTracking(cmdBuffer);
2436 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2437 }
2438 else {
2439 char str[1024];
2440 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002441 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 -06002442 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002443 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2444 VkLayerDispatchTable *pTable = tableMap[pDisp];
2445 pTable->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002446}
2447
Tony Barbour8205d902015-04-16 15:59:00 -06002448VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002449{
2450 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2451 if (pCB) {
2452 updateCBTracking(cmdBuffer);
2453 addCmd(pCB, CMD_UPDATEBUFFER);
2454 }
2455 else {
2456 char str[1024];
2457 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002458 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 -06002459 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002460 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2461 VkLayerDispatchTable *pTable = tableMap[pDisp];
2462 pTable->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463}
2464
Tony Barbour8205d902015-04-16 15:59:00 -06002465VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002466{
2467 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2468 if (pCB) {
2469 updateCBTracking(cmdBuffer);
2470 addCmd(pCB, CMD_FILLBUFFER);
2471 }
2472 else {
2473 char str[1024];
2474 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002475 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 -06002476 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002477 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2478 VkLayerDispatchTable *pTable = tableMap[pDisp];
2479 pTable->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002480}
2481
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002482VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2483 VkCmdBuffer cmdBuffer,
2484 VkImage image, VkImageLayout imageLayout,
2485 const VkClearColor *pColor,
2486 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002487{
2488 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2489 if (pCB) {
2490 updateCBTracking(cmdBuffer);
2491 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2492 }
2493 else {
2494 char str[1024];
2495 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002496 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 -06002497 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002498 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2499 VkLayerDispatchTable *pTable = tableMap[pDisp];
2500 pTable->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002501}
2502
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002503VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2504 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002505 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002506 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002507{
2508 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2509 if (pCB) {
2510 updateCBTracking(cmdBuffer);
2511 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2512 }
2513 else {
2514 char str[1024];
2515 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002516 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 -06002517 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002518 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2519 VkLayerDispatchTable *pTable = tableMap[pDisp];
2520 pTable->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002521}
2522
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002523VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2524 VkImage srcImage, VkImageLayout srcImageLayout,
2525 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002526 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002527{
2528 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2529 if (pCB) {
2530 updateCBTracking(cmdBuffer);
2531 addCmd(pCB, CMD_RESOLVEIMAGE);
2532 }
2533 else {
2534 char str[1024];
2535 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002536 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 -06002537 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002538 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2539 VkLayerDispatchTable *pTable = tableMap[pDisp];
2540 pTable->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002541}
2542
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002543VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002544{
2545 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2546 if (pCB) {
2547 updateCBTracking(cmdBuffer);
2548 addCmd(pCB, CMD_SETEVENT);
2549 }
2550 else {
2551 char str[1024];
2552 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002553 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 -06002554 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002555 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2556 VkLayerDispatchTable *pTable = tableMap[pDisp];
2557 pTable->CmdSetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002558}
2559
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002560VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002561{
2562 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2563 if (pCB) {
2564 updateCBTracking(cmdBuffer);
2565 addCmd(pCB, CMD_RESETEVENT);
2566 }
2567 else {
2568 char str[1024];
2569 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002570 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 -06002571 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002572 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2573 VkLayerDispatchTable *pTable = tableMap[pDisp];
2574 pTable->CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002575}
2576
Tony Barbour8205d902015-04-16 15:59:00 -06002577VK_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 -06002578{
2579 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2580 if (pCB) {
2581 updateCBTracking(cmdBuffer);
2582 addCmd(pCB, CMD_WAITEVENTS);
2583 }
2584 else {
2585 char str[1024];
2586 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002587 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 -06002588 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002589 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2590 VkLayerDispatchTable *pTable = tableMap[pDisp];
2591 pTable->CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002592}
2593
Tony Barbour8205d902015-04-16 15:59:00 -06002594VK_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 -06002595{
2596 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2597 if (pCB) {
2598 updateCBTracking(cmdBuffer);
2599 addCmd(pCB, CMD_PIPELINEBARRIER);
2600 }
2601 else {
2602 char str[1024];
2603 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002604 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 -06002605 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002606 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2607 VkLayerDispatchTable *pTable = tableMap[pDisp];
2608 pTable->CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002609}
2610
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002611VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002612{
2613 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2614 if (pCB) {
2615 updateCBTracking(cmdBuffer);
2616 addCmd(pCB, CMD_BEGINQUERY);
2617 }
2618 else {
2619 char str[1024];
2620 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002621 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 -06002622 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002623 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2624 VkLayerDispatchTable *pTable = tableMap[pDisp];
2625 pTable->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002626}
2627
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002628VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002629{
2630 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2631 if (pCB) {
2632 updateCBTracking(cmdBuffer);
2633 addCmd(pCB, CMD_ENDQUERY);
2634 }
2635 else {
2636 char str[1024];
2637 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002638 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 -06002639 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002640 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2641 VkLayerDispatchTable *pTable = tableMap[pDisp];
2642 pTable->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002643}
2644
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002645VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646{
2647 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2648 if (pCB) {
2649 updateCBTracking(cmdBuffer);
2650 addCmd(pCB, CMD_RESETQUERYPOOL);
2651 }
2652 else {
2653 char str[1024];
2654 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002655 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 -06002656 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002657 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2658 VkLayerDispatchTable *pTable = tableMap[pDisp];
2659 pTable->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002660}
2661
Tony Barbour8205d902015-04-16 15:59:00 -06002662VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663{
2664 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2665 if (pCB) {
2666 updateCBTracking(cmdBuffer);
2667 addCmd(pCB, CMD_WRITETIMESTAMP);
2668 }
2669 else {
2670 char str[1024];
2671 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002672 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 -06002673 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002674 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2675 VkLayerDispatchTable *pTable = tableMap[pDisp];
2676 pTable->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002677}
2678
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002679VK_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 -06002680{
2681 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2682 if (pCB) {
2683 updateCBTracking(cmdBuffer);
2684 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2685 }
2686 else {
2687 char str[1024];
2688 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002689 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 -06002690 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002691 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2692 VkLayerDispatchTable *pTable = tableMap[pDisp];
2693 pTable->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002694}
2695
Tony Barbour8205d902015-04-16 15:59:00 -06002696VK_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 -06002697{
2698 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2699 if (pCB) {
2700 updateCBTracking(cmdBuffer);
2701 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2702 }
2703 else {
2704 char str[1024];
2705 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002706 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 -06002707 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002708 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2709 VkLayerDispatchTable *pTable = tableMap[pDisp];
2710 pTable->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002711}
2712
Tony Barbour8205d902015-04-16 15:59:00 -06002713VK_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 -06002714{
2715 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2716 if (pCB) {
2717 updateCBTracking(cmdBuffer);
2718 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2719 }
2720 else {
2721 char str[1024];
2722 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002723 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 -06002724 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002725 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2726 VkLayerDispatchTable *pTable = tableMap[pDisp];
2727 pTable->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002728}
2729
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002730VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002731{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002732 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2733 VkLayerDispatchTable *pTable = tableMap[pDisp];
2734 VkResult result = pTable->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002735 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002736 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002737 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002738 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002739 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2740 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002741 }
2742 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002743 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2744 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002745 }
2746 frameBufferMap[*pFramebuffer] = localFBCI;
2747 }
2748 return result;
2749}
2750
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002751VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002752{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002753 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2754 VkLayerDispatchTable *pTable = tableMap[pDisp];
2755 VkResult result = pTable->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002756 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002757 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002758 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002759 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002760 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2761 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002762 }
2763 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002764 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2765 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002766 }
2767 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002768 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2769 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002770 }
2771 renderPassMap[*pRenderPass] = localRPCI;
2772 }
2773 return result;
2774}
2775
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002776VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002777{
2778 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2779 if (pCB) {
2780 updateCBTracking(cmdBuffer);
2781 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002782 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2783 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002784 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002785 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002786 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002787 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002788 char str[1024];
2789 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002790 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 -06002791 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002792 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2793 VkLayerDispatchTable *pTable = tableMap[pDisp];
2794 pTable->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002795}
2796
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002797VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002798{
2799 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2800 if (pCB) {
2801 updateCBTracking(cmdBuffer);
2802 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002803 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002804 }
2805 else {
2806 char str[1024];
2807 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002808 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 -06002809 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002810 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2811 VkLayerDispatchTable *pTable = tableMap[pDisp];
2812 pTable->CmdEndRenderPass(cmdBuffer, renderPass);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002813}
2814
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002815VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2816 VkInstance instance,
2817 VkFlags msgFlags,
2818 const PFN_vkDbgMsgCallback pfnMsgCallback,
2819 void* pUserData,
2820 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002821{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002822 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2823 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2824 return layer_create_msg_callback(instance, pTable, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002825}
2826
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002827VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2828 VkInstance instance,
2829 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002830{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002831 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2832 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2833 return layer_destroy_msg_callback(instance, pTable, msgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002834}
2835
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002836VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002837{
2838 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburnf0615e22015-05-25 14:11:37 -06002839 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
2840 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
2841 if (!pTable->ext_enabled) {
2842 char str[1024];
2843 sprintf(str, "Attempt to use CmdDbgMarkerBegin but extension disabled!");
2844 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2845 }
2846 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002847 updateCBTracking(cmdBuffer);
2848 addCmd(pCB, CMD_DBGMARKERBEGIN);
2849 }
2850 else {
2851 char str[1024];
2852 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002853 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 -06002854 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002855 pTable->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856}
2857
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002858VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002859{
2860 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburnf0615e22015-05-25 14:11:37 -06002861 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
2862 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
2863 if (!pTable->ext_enabled) {
2864 char str[1024];
2865 sprintf(str, "Attempt to use CmdDbgMarkerEnd but extension disabled!");
2866 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2867 }
2868 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002869 updateCBTracking(cmdBuffer);
2870 addCmd(pCB, CMD_DBGMARKEREND);
2871 }
2872 else {
2873 char str[1024];
2874 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002875 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 -06002876 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002877 pTable->CmdDbgMarkerEnd(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002878}
2879
2880// TODO : Want to pass in a cmdBuffer here based on which state to display
2881void drawStateDumpDotFile(char* outFileName)
2882{
2883 // TODO : Currently just setting cmdBuffer based on global var
2884 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2885 dumpGlobalDotFile(outFileName);
2886}
2887
2888void drawStateDumpCommandBufferDotFile(char* outFileName)
2889{
2890 cbDumpDotFile(outFileName);
2891}
2892
2893void drawStateDumpPngFile(char* outFileName)
2894{
2895#if defined(_WIN32)
2896// FIXME: NEED WINDOWS EQUIVALENT
2897 char str[1024];
2898 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002899 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002900#else // WIN32
2901 char dotExe[32] = "/usr/bin/dot";
2902 if( access(dotExe, X_OK) != -1) {
2903 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2904 char dotCmd[1024];
2905 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002906 int retval = system(dotCmd);
2907 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002908 remove("/tmp/tmp.dot");
2909 }
2910 else {
2911 char str[1024];
2912 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002913 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002914 }
2915#endif // WIN32
2916}
2917
Jon Ashburn1245cec2015-05-18 13:20:15 -06002918VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002919{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002920 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002921 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002922
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002923 loader_platform_thread_once(&g_initOnce, initDrawState);
2924
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002925 /* loader uses this to force layer initialization; device object is wrapped */
2926 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
2927 initDeviceTable((const VkBaseLayerObject *) dev);
Jon Ashburn1245cec2015-05-18 13:20:15 -06002928 return (void *) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002929 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002930 if (!strcmp(funcName, "vkDestroyDevice"))
2931 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002932 if (!strcmp(funcName, "vkQueueSubmit"))
2933 return (void*) vkQueueSubmit;
2934 if (!strcmp(funcName, "vkDestroyObject"))
2935 return (void*) vkDestroyObject;
2936 if (!strcmp(funcName, "vkCreateBufferView"))
2937 return (void*) vkCreateBufferView;
2938 if (!strcmp(funcName, "vkCreateImageView"))
2939 return (void*) vkCreateImageView;
2940 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2941 return (void*) vkCreateGraphicsPipeline;
2942 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2943 return (void*) vkCreateGraphicsPipelineDerivative;
2944 if (!strcmp(funcName, "vkCreateSampler"))
2945 return (void*) vkCreateSampler;
2946 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2947 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002948 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2949 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002950 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2951 return (void*) vkCreateDescriptorPool;
2952 if (!strcmp(funcName, "vkResetDescriptorPool"))
2953 return (void*) vkResetDescriptorPool;
2954 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2955 return (void*) vkAllocDescriptorSets;
2956 if (!strcmp(funcName, "vkClearDescriptorSets"))
2957 return (void*) vkClearDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002958 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2959 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002960 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2961 return (void*) vkCreateDynamicViewportState;
2962 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2963 return (void*) vkCreateDynamicRasterState;
2964 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2965 return (void*) vkCreateDynamicColorBlendState;
2966 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2967 return (void*) vkCreateDynamicDepthStencilState;
2968 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2969 return (void*) vkCreateCommandBuffer;
2970 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2971 return (void*) vkBeginCommandBuffer;
2972 if (!strcmp(funcName, "vkEndCommandBuffer"))
2973 return (void*) vkEndCommandBuffer;
2974 if (!strcmp(funcName, "vkResetCommandBuffer"))
2975 return (void*) vkResetCommandBuffer;
2976 if (!strcmp(funcName, "vkCmdBindPipeline"))
2977 return (void*) vkCmdBindPipeline;
2978 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2979 return (void*) vkCmdBindDynamicStateObject;
2980 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2981 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002982 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2983 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002984 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2985 return (void*) vkCmdBindIndexBuffer;
2986 if (!strcmp(funcName, "vkCmdDraw"))
2987 return (void*) vkCmdDraw;
2988 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2989 return (void*) vkCmdDrawIndexed;
2990 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2991 return (void*) vkCmdDrawIndirect;
2992 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2993 return (void*) vkCmdDrawIndexedIndirect;
2994 if (!strcmp(funcName, "vkCmdDispatch"))
2995 return (void*) vkCmdDispatch;
2996 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2997 return (void*) vkCmdDispatchIndirect;
2998 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2999 return (void*) vkCmdCopyBuffer;
3000 if (!strcmp(funcName, "vkCmdCopyImage"))
3001 return (void*) vkCmdCopyImage;
3002 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
3003 return (void*) vkCmdCopyBufferToImage;
3004 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
3005 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003006 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
3007 return (void*) vkCmdUpdateBuffer;
3008 if (!strcmp(funcName, "vkCmdFillBuffer"))
3009 return (void*) vkCmdFillBuffer;
3010 if (!strcmp(funcName, "vkCmdClearColorImage"))
3011 return (void*) vkCmdClearColorImage;
3012 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
3013 return (void*) vkCmdClearDepthStencil;
3014 if (!strcmp(funcName, "vkCmdResolveImage"))
3015 return (void*) vkCmdResolveImage;
3016 if (!strcmp(funcName, "vkCmdSetEvent"))
3017 return (void*) vkCmdSetEvent;
3018 if (!strcmp(funcName, "vkCmdResetEvent"))
3019 return (void*) vkCmdResetEvent;
3020 if (!strcmp(funcName, "vkCmdWaitEvents"))
3021 return (void*) vkCmdWaitEvents;
3022 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
3023 return (void*) vkCmdPipelineBarrier;
3024 if (!strcmp(funcName, "vkCmdBeginQuery"))
3025 return (void*) vkCmdBeginQuery;
3026 if (!strcmp(funcName, "vkCmdEndQuery"))
3027 return (void*) vkCmdEndQuery;
3028 if (!strcmp(funcName, "vkCmdResetQueryPool"))
3029 return (void*) vkCmdResetQueryPool;
3030 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
3031 return (void*) vkCmdWriteTimestamp;
3032 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
3033 return (void*) vkCmdInitAtomicCounters;
3034 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
3035 return (void*) vkCmdLoadAtomicCounters;
3036 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
3037 return (void*) vkCmdSaveAtomicCounters;
3038 if (!strcmp(funcName, "vkCreateFramebuffer"))
3039 return (void*) vkCreateFramebuffer;
3040 if (!strcmp(funcName, "vkCreateRenderPass"))
3041 return (void*) vkCreateRenderPass;
3042 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
3043 return (void*) vkCmdBeginRenderPass;
3044 if (!strcmp(funcName, "vkCmdEndRenderPass"))
3045 return (void*) vkCmdEndRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003046 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
3047 return (void*) vkCmdDbgMarkerBegin;
3048 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
3049 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003050 if (!strcmp("drawStateDumpDotFile", funcName))
3051 return (void*) drawStateDumpDotFile;
3052 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
3053 return (void*) drawStateDumpCommandBufferDotFile;
3054 if (!strcmp("drawStateDumpPngFile", funcName))
3055 return (void*) drawStateDumpPngFile;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003056 else
3057 {
3058 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) dev;
3059 VkLayerDispatchTable* pTable = tableMap[*ppDisp];
3060 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003061 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003062 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003063 }
3064}
3065
3066VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3067{
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003068 void *fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003069 if (instance == NULL)
3070 return NULL;
3071
Jon Ashburnd9564002015-05-07 10:27:37 -06003072 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003073
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003074 /* loader uses this to force layer initialization; instance object is wrapped */
3075 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
3076 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003077 return (void *) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003078 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003079 if (!strcmp(funcName, "vkCreateInstance"))
3080 return (void *) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003081 if (!strcmp(funcName, "vkDestroyInstance"))
3082 return (void *) vkDestroyInstance;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003083 if (!strcmp(funcName, "vkCreateDevice"))
3084 return (void*) vkCreateDevice;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003085
3086 fptr = msg_callback_get_proc_addr(funcName);
3087 if (fptr)
3088 return fptr;
3089
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003090 {
3091 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
3092 VkLayerInstanceDispatchTable* pTable = tableInstanceMap[*ppDisp];
3093 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003094 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003095 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003096 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003097}