blob: 72b87f3659fed512d97178c5abafea51452fb772 [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
Jon Ashburne0fa2282015-05-20 09:00:28 -06001528/* hook DestroyInstance to remove tableInstanceMap entry */
1529VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1530{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001531 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06001532 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
1533 VkResult res = pTable->DestroyInstance(instance);
1534 tableInstanceMap.erase(pDisp);
1535 return res;
1536}
1537
Jon Ashburnf0615e22015-05-25 14:11:37 -06001538static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1539{
1540 uint32_t i, ext_idx;
1541 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) device;
1542 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
1543
1544 for (i = 0; i < pCreateInfo->extensionCount; i++) {
1545 if (strcmp(pCreateInfo->pEnabledExtensions[i].name, DEBUG_MARKER_EXTENSION_NAME) == 0) {
1546 /* Found a matching extension name, mark it enabled */
1547 pTable->ext_enabled = true;
1548 }
1549
1550 }
1551}
1552
Tony Barbour8205d902015-04-16 15:59:00 -06001553VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001554{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001555 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu;
1556 VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[*ppDisp];
1557 VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice);
Jon Ashburnf0615e22015-05-25 14:11:37 -06001558 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001559 return result;
1560}
1561
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001562VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001563{
1564 // Free all the memory
1565 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001566 deletePipelines();
1567 deleteSamplers();
1568 deleteImages();
1569 deleteBuffers();
1570 deleteCmdBuffers();
1571 deleteDynamicState();
1572 deletePools();
1573 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001574 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001575
1576 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1577 VkLayerDispatchTable *pTable = tableMap[pDisp];
1578 VkResult result = pTable->DestroyDevice(device);
1579 tableMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001580 return result;
1581}
1582
Jon Ashburneb2728b2015-04-10 14:33:07 -06001583struct extProps {
1584 uint32_t version;
1585 const char * const name;
1586};
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001587#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 1
1588static const VkExtensionProperties dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1589 {
1590 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1591 "DrawState",
1592 0x10,
1593 "Sample layer: DrawState",
1594// 0,
1595// NULL,
1596 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001597};
1598
Jon Ashburnf0615e22015-05-25 14:11:37 -06001599//TODO add DEBUG_MARKER to device extension list
Jon Ashburneb2728b2015-04-10 14:33:07 -06001600VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001601 VkExtensionInfoType infoType,
1602 uint32_t extensionIndex,
1603 size_t* pDataSize,
1604 void* pData)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001605{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001606 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Jon Ashburneb2728b2015-04-10 14:33:07 -06001607 uint32_t *count;
1608
1609 if (pDataSize == NULL)
1610 return VK_ERROR_INVALID_POINTER;
1611
1612 switch (infoType) {
1613 case VK_EXTENSION_INFO_TYPE_COUNT:
1614 *pDataSize = sizeof(uint32_t);
1615 if (pData == NULL)
1616 return VK_SUCCESS;
1617 count = (uint32_t *) pData;
1618 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1619 break;
1620 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1621 *pDataSize = sizeof(VkExtensionProperties);
1622 if (pData == NULL)
1623 return VK_SUCCESS;
1624 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1625 return VK_ERROR_INVALID_VALUE;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001626 memcpy((VkExtensionProperties *) pData, &dsExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburneb2728b2015-04-10 14:33:07 -06001627 break;
1628 default:
1629 return VK_ERROR_INVALID_VALUE;
1630 };
1631
1632 return VK_SUCCESS;
1633}
1634
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001635VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001636{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001637 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001638 for (uint32_t i=0; i < cmdBufferCount; i++) {
1639 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001640 pCB = getCBNode(pCmdBuffers[i]);
1641 loader_platform_thread_lock_mutex(&globalLock);
1642 if (CB_UPDATE_COMPLETE != pCB->state) {
1643 // Flag error for using CB w/o vkEndCommandBuffer() called
1644 char str[1024];
1645 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001646 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 -06001647 loader_platform_thread_unlock_mutex(&globalLock);
1648 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001649 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001650 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001651 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001652
1653 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) queue;
1654 VkLayerDispatchTable *pTable = tableMap[pDisp];
1655 VkResult result = pTable->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001656 return result;
1657}
1658
Mike Stroyan230e6252015-04-17 12:36:38 -06001659VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001660{
1661 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Jon Ashburne0fa2282015-05-20 09:00:28 -06001662 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1663 VkLayerDispatchTable *pTable = tableMap[pDisp];
1664 VkResult result = pTable->DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001665 return result;
1666}
1667
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001668VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001669{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001670 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1671 VkLayerDispatchTable *pTable = tableMap[pDisp];
1672 VkResult result = pTable->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001673 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674 loader_platform_thread_lock_mutex(&globalLock);
1675 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1676 pNewNode->buffer = *pView;
1677 pNewNode->createInfo = *pCreateInfo;
1678 bufferMap[*pView] = pNewNode;
1679 loader_platform_thread_unlock_mutex(&globalLock);
1680 }
1681 return result;
1682}
1683
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001684VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001685{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001686 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1687 VkLayerDispatchTable *pTable = tableMap[pDisp];
1688 VkResult result = pTable->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001689 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001690 loader_platform_thread_lock_mutex(&globalLock);
1691 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1692 pNewNode->image = *pView;
1693 pNewNode->createInfo = *pCreateInfo;
1694 imageMap[*pView] = pNewNode;
1695 loader_platform_thread_unlock_mutex(&globalLock);
1696 }
1697 return result;
1698}
1699
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001700static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001701{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001702 // Create LL HEAD for this Pipeline
1703 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001704 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1705 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1706 pPipeNode->pipeline = *pPipeline;
1707 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001708 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001709}
1710
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001711VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001712{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001713 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1714 VkLayerDispatchTable *pTable = tableMap[pDisp];
1715 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001716 // Create LL HEAD for this Pipeline
1717 char str[1024];
1718 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001719 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001720
1721 track_pipeline(pCreateInfo, pPipeline);
1722
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001723 return result;
1724}
1725
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001726VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1727 VkDevice device,
1728 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1729 VkPipeline basePipeline,
1730 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001731{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001732 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1733 VkLayerDispatchTable *pTable = tableMap[pDisp];
1734 VkResult result = pTable->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001735 // Create LL HEAD for this Pipeline
1736 char str[1024];
1737 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
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
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001742 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001743
1744 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001745}
1746
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001747VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001748{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001749 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1750 VkLayerDispatchTable *pTable = tableMap[pDisp];
1751 VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001752 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001753 loader_platform_thread_lock_mutex(&globalLock);
1754 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1755 pNewNode->sampler = *pSampler;
1756 pNewNode->createInfo = *pCreateInfo;
1757 sampleMap[*pSampler] = pNewNode;
1758 loader_platform_thread_unlock_mutex(&globalLock);
1759 }
1760 return result;
1761}
1762
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001763VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001764{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001765 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1766 VkLayerDispatchTable *pTable = tableMap[pDisp];
1767 VkResult result = pTable->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001768 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001769 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1770 if (NULL == pNewNode) {
1771 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001772 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001773 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 -06001774 }
1775 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001776 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1777 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1778 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001779 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001780 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001781 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001782 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001783 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001784 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1785 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001786 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001787 }
1788 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001789 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001790 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001791 uint32_t j = 0;
1792 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001793 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001794 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001795 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001796 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001797 }
1798 }
1799 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001800 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001801 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1802 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001803 // Put new node at Head of global Layer list
1804 loader_platform_thread_lock_mutex(&globalLock);
1805 layoutMap[*pSetLayout] = pNewNode;
1806 loader_platform_thread_unlock_mutex(&globalLock);
1807 }
1808 return result;
1809}
1810
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001811VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001812{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001813 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1814 VkLayerDispatchTable *pTable = tableMap[pDisp];
1815 VkResult result = pTable->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001816 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001817 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001818 }
1819 return result;
1820}
1821
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001822VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001823{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001824 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1825 VkLayerDispatchTable *pTable = tableMap[pDisp];
1826 VkResult result = pTable->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001827 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001828 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001829 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001830 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001831 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 -06001832 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001833 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001834 if (NULL == pNewNode) {
1835 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001836 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001837 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 -06001838 }
1839 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001840 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001841 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1842 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001843 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001844 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1845 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001846 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1847 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001848 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001850 pNewNode->pool = *pDescriptorPool;
1851 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001852 }
1853 loader_platform_thread_unlock_mutex(&globalLock);
1854 }
1855 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001856 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001857 }
1858 return result;
1859}
1860
Mike Stroyan230e6252015-04-17 12:36:38 -06001861VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001863 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1864 VkLayerDispatchTable *pTable = tableMap[pDisp];
1865 VkResult result = pTable->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001866 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001867 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868 }
1869 return result;
1870}
1871
Mike Stroyan230e6252015-04-17 12:36:38 -06001872VK_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 -06001873{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001874 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1875 VkLayerDispatchTable *pTable = tableMap[pDisp];
1876 VkResult result = pTable->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001877 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001878 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1879 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001880 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001881 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001882 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 -06001883 }
1884 else {
1885 for (uint32_t i = 0; i < *pCount; i++) {
1886 char str[1024];
1887 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001888 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 -06001889 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001890 SET_NODE* pNewNode = new SET_NODE;
1891 if (NULL == pNewNode) {
1892 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001893 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001894 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 -06001895 }
1896 else {
1897 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001898 // Insert set at head of Set LL for this pool
1899 pNewNode->pNext = pPoolNode->pSets;
1900 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001901 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1902 if (NULL == pLayout) {
1903 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001904 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 -06001905 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 -06001906 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001907 pNewNode->pLayout = pLayout;
1908 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001909 pNewNode->set = pDescriptorSets[i];
1910 pNewNode->setUsage = setUsage;
1911 pNewNode->descriptorCount = pLayout->endIndex + 1;
1912 if (pNewNode->descriptorCount) {
1913 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1914 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1915 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1916 }
1917 setMap[pDescriptorSets[i]] = pNewNode;
1918 }
1919 }
1920 }
1921 }
1922 return result;
1923}
1924
Mike Stroyan230e6252015-04-17 12:36:38 -06001925VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001926{
1927 for (uint32_t i = 0; i < count; i++) {
1928 clearDescriptorSet(pDescriptorSets[i]);
1929 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001930 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1931 VkLayerDispatchTable *pTable = tableMap[pDisp];
1932 pTable->ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001933}
1934
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001935VK_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 -06001936{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001937 if (dsUpdate(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
Jon Ashburne0fa2282015-05-20 09:00:28 -06001938 dsUpdate(VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
1939 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1940 VkLayerDispatchTable *pTable = tableMap[pDisp];
1941 return pTable->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
1942 }
1943 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001944}
1945
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001946VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001947{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001948 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1949 VkLayerDispatchTable *pTable = tableMap[pDisp];
1950 VkResult result = pTable->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001951 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001952 return result;
1953}
1954
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001955VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001956{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001957 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1958 VkLayerDispatchTable *pTable = tableMap[pDisp];
1959 VkResult result = pTable->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001960 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001961 return result;
1962}
1963
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001964VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001965{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001966 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1967 VkLayerDispatchTable *pTable = tableMap[pDisp];
1968 VkResult result = pTable->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001969 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001970 return result;
1971}
1972
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001973VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001974{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001975 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1976 VkLayerDispatchTable *pTable = tableMap[pDisp];
1977 VkResult result = pTable->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001978 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001979 return result;
1980}
1981
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001982VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001983{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001984 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1985 VkLayerDispatchTable *pTable = tableMap[pDisp];
1986 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001987 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001988 loader_platform_thread_lock_mutex(&globalLock);
1989 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1990 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1991 pCB->cmdBuffer = *pCmdBuffer;
1992 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001993 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001994 pCB->lastVtxBinding = MAX_BINDING;
1995 cmdBufferMap[*pCmdBuffer] = pCB;
1996 loader_platform_thread_unlock_mutex(&globalLock);
1997 updateCBTracking(*pCmdBuffer);
1998 }
1999 return result;
2000}
2001
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002002VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002003{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002004 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2005 VkLayerDispatchTable *pTable = tableMap[pDisp];
2006 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002007 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002008 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2009 if (pCB) {
2010 if (CB_NEW != pCB->state)
2011 resetCB(cmdBuffer);
2012 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002013 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002014 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002015 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002016 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002017 }
2018 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002019 }
2020 else {
2021 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002022 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002023 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 -06002024 }
2025 updateCBTracking(cmdBuffer);
2026 }
2027 return result;
2028}
2029
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002030VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002031{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002032 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2033 VkLayerDispatchTable *pTable = tableMap[pDisp];
2034 VkResult result = pTable->EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002035 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002036 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2037 if (pCB) {
2038 pCB->state = CB_UPDATE_COMPLETE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002039 // Reset CB status flags
2040 pCB->status = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002041 printCB(cmdBuffer);
2042 }
2043 else {
2044 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002045 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002046 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 -06002047 }
2048 updateCBTracking(cmdBuffer);
2049 //cbDumpDotFile("cb_dump.dot");
2050 }
2051 return result;
2052}
2053
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002054VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002055{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002056 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2057 VkLayerDispatchTable *pTable = tableMap[pDisp];
2058 VkResult result = pTable->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002059 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002060 resetCB(cmdBuffer);
2061 updateCBTracking(cmdBuffer);
2062 }
2063 return result;
2064}
2065
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002066VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002067{
2068 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2069 if (pCB) {
2070 updateCBTracking(cmdBuffer);
2071 addCmd(pCB, CMD_BINDPIPELINE);
2072 PIPELINE_NODE* pPN = getPipeline(pipeline);
2073 if (pPN) {
2074 pCB->lastBoundPipeline = pipeline;
2075 loader_platform_thread_lock_mutex(&globalLock);
2076 g_lastBoundPipeline = pPN;
2077 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002078 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002079 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2080 VkLayerDispatchTable *pTable = tableMap[pDisp];
2081 pTable->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002082 }
2083 else {
2084 char str[1024];
2085 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002086 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002087 }
2088 }
2089 else {
2090 char str[1024];
2091 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002092 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 -06002093 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002094}
2095
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002096VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002097{
2098 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002099 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2100 VkLayerDispatchTable *pTable = tableMap[pDisp];
2101 pTable->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002102}
2103
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002104VK_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 -06002105{
2106 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2107 if (pCB) {
2108 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002109 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002110 if (validateBoundPipeline(cmdBuffer)) {
2111 for (uint32_t i=0; i<setCount; i++) {
2112 if (getSetNode(pDescriptorSets[i])) {
2113 loader_platform_thread_lock_mutex(&globalLock);
2114 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2115 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2116 g_lastBoundDescriptorSet = pDescriptorSets[i];
2117 loader_platform_thread_unlock_mutex(&globalLock);
2118 char str[1024];
2119 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002120 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 -06002121 }
2122 else {
2123 char str[1024];
2124 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002125 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 -06002126 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002127 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002128 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2129 VkLayerDispatchTable *pTable = tableMap[pDisp];
2130 pTable->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002131 }
2132 }
2133 else {
2134 char str[1024];
2135 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002136 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 -06002137 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002138}
2139
Tony Barbour8205d902015-04-16 15:59:00 -06002140VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002141{
2142 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2143 if (pCB) {
2144 updateCBTracking(cmdBuffer);
2145 addCmd(pCB, CMD_BINDINDEXBUFFER);
2146 // TODO : Track idxBuffer binding
2147 }
2148 else {
2149 char str[1024];
2150 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002151 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 -06002152 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002153 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2154 VkLayerDispatchTable *pTable = tableMap[pDisp];
2155 pTable->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002156}
2157
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002158VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2159 VkCmdBuffer cmdBuffer,
2160 uint32_t startBinding,
2161 uint32_t bindingCount,
2162 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002163 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002164{
2165 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2166 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002167 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002168 updateCBTracking(cmdBuffer);
2169 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002170 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002171 if (validateBoundPipeline(cmdBuffer)) {
Jon Ashburne0fa2282015-05-20 09:00:28 -06002172 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2173 VkLayerDispatchTable *pTable = tableMap[pDisp];
2174 pTable->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002175 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002176 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002177 char str[1024];
2178 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002179 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 -06002180 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002181}
2182
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002183VK_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 -06002184{
2185 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002186 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002187 if (pCB) {
2188 updateCBTracking(cmdBuffer);
2189 addCmd(pCB, CMD_DRAW);
2190 pCB->drawCount[DRAW]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002191 loader_platform_thread_lock_mutex(&globalLock);
2192 valid = validate_draw_state_flags(cmdBuffer);
2193 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002194 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002195 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002196 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002197 synchAndPrintDSConfig(cmdBuffer);
2198 }
2199 else {
2200 char str[1024];
2201 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002202 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 -06002203 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002204 if (valid) {
2205 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2206 VkLayerDispatchTable *pTable = tableMap[pDisp];
2207 pTable->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2208 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002209}
2210
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002211VK_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 -06002212{
2213 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002214 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002215 if (pCB) {
2216 updateCBTracking(cmdBuffer);
2217 addCmd(pCB, CMD_DRAWINDEXED);
2218 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002219 loader_platform_thread_lock_mutex(&globalLock);
2220 valid = validate_draw_state_flags(cmdBuffer);
2221 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002222 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002223 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002224 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002225 synchAndPrintDSConfig(cmdBuffer);
2226 }
2227 else {
2228 char str[1024];
2229 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002230 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 -06002231 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002232 if (valid) {
2233 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2234 VkLayerDispatchTable *pTable = tableMap[pDisp];
2235 pTable->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2236 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002237}
2238
Tony Barbour8205d902015-04-16 15:59:00 -06002239VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002240{
2241 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002242 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002243 if (pCB) {
2244 updateCBTracking(cmdBuffer);
2245 addCmd(pCB, CMD_DRAWINDIRECT);
2246 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002247 loader_platform_thread_lock_mutex(&globalLock);
2248 valid = validate_draw_state_flags(cmdBuffer);
2249 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002250 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002251 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002252 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002253 synchAndPrintDSConfig(cmdBuffer);
2254 }
2255 else {
2256 char str[1024];
2257 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002258 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 -06002259 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002260 if (valid) {
2261 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2262 VkLayerDispatchTable *pTable = tableMap[pDisp];
2263 pTable->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2264 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002265}
2266
Tony Barbour8205d902015-04-16 15:59:00 -06002267VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002268{
2269 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002270 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002271 if (pCB) {
2272 updateCBTracking(cmdBuffer);
2273 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2274 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002275 loader_platform_thread_lock_mutex(&globalLock);
2276 valid = validate_draw_state_flags(cmdBuffer);
2277 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002278 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002279 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002280 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002281 synchAndPrintDSConfig(cmdBuffer);
2282 }
2283 else {
2284 char str[1024];
2285 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002286 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 -06002287 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002288 if (valid) {
2289 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2290 VkLayerDispatchTable *pTable = tableMap[pDisp];
2291 pTable->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2292 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002293}
2294
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002295VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002296{
2297 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2298 if (pCB) {
2299 updateCBTracking(cmdBuffer);
2300 addCmd(pCB, CMD_DISPATCH);
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 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2308 VkLayerDispatchTable *pTable = tableMap[pDisp];
2309 pTable->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002310}
2311
Tony Barbour8205d902015-04-16 15:59:00 -06002312VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002313{
2314 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2315 if (pCB) {
2316 updateCBTracking(cmdBuffer);
2317 addCmd(pCB, CMD_DISPATCHINDIRECT);
2318 }
2319 else {
2320 char str[1024];
2321 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002322 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 -06002323 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002324 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2325 VkLayerDispatchTable *pTable = tableMap[pDisp];
2326 pTable->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002327}
2328
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002329VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002330{
2331 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2332 if (pCB) {
2333 updateCBTracking(cmdBuffer);
2334 addCmd(pCB, CMD_COPYBUFFER);
2335 }
2336 else {
2337 char str[1024];
2338 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002339 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 -06002340 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002341 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2342 VkLayerDispatchTable *pTable = tableMap[pDisp];
2343 pTable->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344}
2345
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002346VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2347 VkImage srcImage,
2348 VkImageLayout srcImageLayout,
2349 VkImage destImage,
2350 VkImageLayout destImageLayout,
2351 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002352{
2353 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2354 if (pCB) {
2355 updateCBTracking(cmdBuffer);
2356 addCmd(pCB, CMD_COPYIMAGE);
2357 }
2358 else {
2359 char str[1024];
2360 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002361 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 -06002362 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002363 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2364 VkLayerDispatchTable *pTable = tableMap[pDisp];
2365 pTable->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002366}
2367
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002368VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2369 VkImage srcImage, VkImageLayout srcImageLayout,
2370 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002371 uint32_t regionCount, const VkImageBlit* pRegions,
2372 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002373{
2374 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2375 if (pCB) {
2376 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002377 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002378 }
2379 else {
2380 char str[1024];
2381 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002382 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 -06002383 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002384 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2385 VkLayerDispatchTable *pTable = tableMap[pDisp];
2386 pTable->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002387}
2388
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002389VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2390 VkBuffer srcBuffer,
2391 VkImage destImage, VkImageLayout destImageLayout,
2392 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002393{
2394 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2395 if (pCB) {
2396 updateCBTracking(cmdBuffer);
2397 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2398 }
2399 else {
2400 char str[1024];
2401 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002402 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 -06002403 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002404 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2405 VkLayerDispatchTable *pTable = tableMap[pDisp];
2406 pTable->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002407}
2408
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002409VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2410 VkImage srcImage, VkImageLayout srcImageLayout,
2411 VkBuffer destBuffer,
2412 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002413{
2414 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2415 if (pCB) {
2416 updateCBTracking(cmdBuffer);
2417 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2418 }
2419 else {
2420 char str[1024];
2421 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002422 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 -06002423 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002424 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2425 VkLayerDispatchTable *pTable = tableMap[pDisp];
2426 pTable->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002427}
2428
Tony Barbour8205d902015-04-16 15:59:00 -06002429VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002430{
2431 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2432 if (pCB) {
2433 updateCBTracking(cmdBuffer);
2434 addCmd(pCB, CMD_UPDATEBUFFER);
2435 }
2436 else {
2437 char str[1024];
2438 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002439 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 -06002440 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002441 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2442 VkLayerDispatchTable *pTable = tableMap[pDisp];
2443 pTable->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002444}
2445
Tony Barbour8205d902015-04-16 15:59:00 -06002446VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447{
2448 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2449 if (pCB) {
2450 updateCBTracking(cmdBuffer);
2451 addCmd(pCB, CMD_FILLBUFFER);
2452 }
2453 else {
2454 char str[1024];
2455 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002456 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 -06002457 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002458 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2459 VkLayerDispatchTable *pTable = tableMap[pDisp];
2460 pTable->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002461}
2462
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002463VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2464 VkCmdBuffer cmdBuffer,
2465 VkImage image, VkImageLayout imageLayout,
2466 const VkClearColor *pColor,
2467 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002468{
2469 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2470 if (pCB) {
2471 updateCBTracking(cmdBuffer);
2472 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2473 }
2474 else {
2475 char str[1024];
2476 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002477 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 -06002478 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002479 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2480 VkLayerDispatchTable *pTable = tableMap[pDisp];
2481 pTable->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002482}
2483
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002484VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2485 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002486 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002487 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002488{
2489 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2490 if (pCB) {
2491 updateCBTracking(cmdBuffer);
2492 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2493 }
2494 else {
2495 char str[1024];
2496 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002497 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 -06002498 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002499 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2500 VkLayerDispatchTable *pTable = tableMap[pDisp];
2501 pTable->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002502}
2503
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002504VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2505 VkImage srcImage, VkImageLayout srcImageLayout,
2506 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002507 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002508{
2509 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2510 if (pCB) {
2511 updateCBTracking(cmdBuffer);
2512 addCmd(pCB, CMD_RESOLVEIMAGE);
2513 }
2514 else {
2515 char str[1024];
2516 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002517 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 -06002518 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002519 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2520 VkLayerDispatchTable *pTable = tableMap[pDisp];
2521 pTable->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002522}
2523
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002524VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002525{
2526 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2527 if (pCB) {
2528 updateCBTracking(cmdBuffer);
2529 addCmd(pCB, CMD_SETEVENT);
2530 }
2531 else {
2532 char str[1024];
2533 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002534 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 -06002535 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002536 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2537 VkLayerDispatchTable *pTable = tableMap[pDisp];
2538 pTable->CmdSetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002539}
2540
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002541VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002542{
2543 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2544 if (pCB) {
2545 updateCBTracking(cmdBuffer);
2546 addCmd(pCB, CMD_RESETEVENT);
2547 }
2548 else {
2549 char str[1024];
2550 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002551 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 -06002552 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002553 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2554 VkLayerDispatchTable *pTable = tableMap[pDisp];
2555 pTable->CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002556}
2557
Tony Barbour8205d902015-04-16 15:59:00 -06002558VK_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 -06002559{
2560 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2561 if (pCB) {
2562 updateCBTracking(cmdBuffer);
2563 addCmd(pCB, CMD_WAITEVENTS);
2564 }
2565 else {
2566 char str[1024];
2567 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002568 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 -06002569 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002570 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2571 VkLayerDispatchTable *pTable = tableMap[pDisp];
2572 pTable->CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002573}
2574
Tony Barbour8205d902015-04-16 15:59:00 -06002575VK_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 -06002576{
2577 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2578 if (pCB) {
2579 updateCBTracking(cmdBuffer);
2580 addCmd(pCB, CMD_PIPELINEBARRIER);
2581 }
2582 else {
2583 char str[1024];
2584 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002585 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 -06002586 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002587 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2588 VkLayerDispatchTable *pTable = tableMap[pDisp];
2589 pTable->CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002590}
2591
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002592VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002593{
2594 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2595 if (pCB) {
2596 updateCBTracking(cmdBuffer);
2597 addCmd(pCB, CMD_BEGINQUERY);
2598 }
2599 else {
2600 char str[1024];
2601 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002602 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 -06002603 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002604 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2605 VkLayerDispatchTable *pTable = tableMap[pDisp];
2606 pTable->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002607}
2608
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002609VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002610{
2611 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2612 if (pCB) {
2613 updateCBTracking(cmdBuffer);
2614 addCmd(pCB, CMD_ENDQUERY);
2615 }
2616 else {
2617 char str[1024];
2618 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002619 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 -06002620 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002621 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2622 VkLayerDispatchTable *pTable = tableMap[pDisp];
2623 pTable->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002624}
2625
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002626VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002627{
2628 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2629 if (pCB) {
2630 updateCBTracking(cmdBuffer);
2631 addCmd(pCB, CMD_RESETQUERYPOOL);
2632 }
2633 else {
2634 char str[1024];
2635 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002636 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 -06002637 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002638 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2639 VkLayerDispatchTable *pTable = tableMap[pDisp];
2640 pTable->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002641}
2642
Tony Barbour8205d902015-04-16 15:59:00 -06002643VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002644{
2645 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2646 if (pCB) {
2647 updateCBTracking(cmdBuffer);
2648 addCmd(pCB, CMD_WRITETIMESTAMP);
2649 }
2650 else {
2651 char str[1024];
2652 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002653 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 -06002654 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002655 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2656 VkLayerDispatchTable *pTable = tableMap[pDisp];
2657 pTable->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002658}
2659
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002660VK_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 -06002661{
2662 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2663 if (pCB) {
2664 updateCBTracking(cmdBuffer);
2665 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2666 }
2667 else {
2668 char str[1024];
2669 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002670 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 -06002671 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002672 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2673 VkLayerDispatchTable *pTable = tableMap[pDisp];
2674 pTable->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002675}
2676
Tony Barbour8205d902015-04-16 15:59:00 -06002677VK_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 -06002678{
2679 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2680 if (pCB) {
2681 updateCBTracking(cmdBuffer);
2682 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2683 }
2684 else {
2685 char str[1024];
2686 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002687 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 -06002688 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002689 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2690 VkLayerDispatchTable *pTable = tableMap[pDisp];
2691 pTable->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002692}
2693
Tony Barbour8205d902015-04-16 15:59:00 -06002694VK_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 -06002695{
2696 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2697 if (pCB) {
2698 updateCBTracking(cmdBuffer);
2699 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2700 }
2701 else {
2702 char str[1024];
2703 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002704 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 -06002705 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002706 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2707 VkLayerDispatchTable *pTable = tableMap[pDisp];
2708 pTable->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002709}
2710
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002711VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002712{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002713 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2714 VkLayerDispatchTable *pTable = tableMap[pDisp];
2715 VkResult result = pTable->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002716 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002717 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002718 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002719 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002720 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2721 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002722 }
2723 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002724 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2725 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002726 }
2727 frameBufferMap[*pFramebuffer] = localFBCI;
2728 }
2729 return result;
2730}
2731
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002732VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002733{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002734 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2735 VkLayerDispatchTable *pTable = tableMap[pDisp];
2736 VkResult result = pTable->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002737 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002738 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002739 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002740 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002741 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2742 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002743 }
2744 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002745 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2746 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002747 }
2748 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002749 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2750 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002751 }
2752 renderPassMap[*pRenderPass] = localRPCI;
2753 }
2754 return result;
2755}
2756
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002757VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002758{
2759 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2760 if (pCB) {
2761 updateCBTracking(cmdBuffer);
2762 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002763 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2764 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002765 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002766 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002767 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002768 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002769 char str[1024];
2770 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002771 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 -06002772 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002773 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2774 VkLayerDispatchTable *pTable = tableMap[pDisp];
2775 pTable->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002776}
2777
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002778VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002779{
2780 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2781 if (pCB) {
2782 updateCBTracking(cmdBuffer);
2783 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002784 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002785 }
2786 else {
2787 char str[1024];
2788 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002789 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 -06002790 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002791 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2792 VkLayerDispatchTable *pTable = tableMap[pDisp];
2793 pTable->CmdEndRenderPass(cmdBuffer, renderPass);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002794}
2795
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002796VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2797 VkInstance instance,
2798 VkFlags msgFlags,
2799 const PFN_vkDbgMsgCallback pfnMsgCallback,
2800 void* pUserData,
2801 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002802{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002803 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2804 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2805 return layer_create_msg_callback(instance, pTable, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002806}
2807
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002808VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2809 VkInstance instance,
2810 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002811{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002812 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2813 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2814 return layer_destroy_msg_callback(instance, pTable, msgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002815}
2816
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002817VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002818{
2819 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburnf0615e22015-05-25 14:11:37 -06002820 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
2821 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
2822 if (!pTable->ext_enabled) {
2823 char str[1024];
2824 sprintf(str, "Attempt to use CmdDbgMarkerBegin but extension disabled!");
2825 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2826 }
2827 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002828 updateCBTracking(cmdBuffer);
2829 addCmd(pCB, CMD_DBGMARKERBEGIN);
2830 }
2831 else {
2832 char str[1024];
2833 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002834 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 -06002835 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002836 pTable->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002837}
2838
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002839VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002840{
2841 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburnf0615e22015-05-25 14:11:37 -06002842 VkLayerDebugMarkerDispatchTable *pDisp = *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
2843 VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
2844 if (!pTable->ext_enabled) {
2845 char str[1024];
2846 sprintf(str, "Attempt to use CmdDbgMarkerEnd but extension disabled!");
2847 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2848 }
2849 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002850 updateCBTracking(cmdBuffer);
2851 addCmd(pCB, CMD_DBGMARKEREND);
2852 }
2853 else {
2854 char str[1024];
2855 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002856 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 -06002857 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002858 pTable->CmdDbgMarkerEnd(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002859}
2860
2861// TODO : Want to pass in a cmdBuffer here based on which state to display
2862void drawStateDumpDotFile(char* outFileName)
2863{
2864 // TODO : Currently just setting cmdBuffer based on global var
2865 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2866 dumpGlobalDotFile(outFileName);
2867}
2868
2869void drawStateDumpCommandBufferDotFile(char* outFileName)
2870{
2871 cbDumpDotFile(outFileName);
2872}
2873
2874void drawStateDumpPngFile(char* outFileName)
2875{
2876#if defined(_WIN32)
2877// FIXME: NEED WINDOWS EQUIVALENT
2878 char str[1024];
2879 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002880 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002881#else // WIN32
2882 char dotExe[32] = "/usr/bin/dot";
2883 if( access(dotExe, X_OK) != -1) {
2884 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2885 char dotCmd[1024];
2886 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002887 int retval = system(dotCmd);
2888 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002889 remove("/tmp/tmp.dot");
2890 }
2891 else {
2892 char str[1024];
2893 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002894 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002895 }
2896#endif // WIN32
2897}
2898
Jon Ashburn1245cec2015-05-18 13:20:15 -06002899VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002900{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002901 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002902 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002903
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002904 loader_platform_thread_once(&g_initOnce, initDrawState);
2905
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002906 /* loader uses this to force layer initialization; device object is wrapped */
2907 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
2908 initDeviceTable((const VkBaseLayerObject *) dev);
Jon Ashburn1245cec2015-05-18 13:20:15 -06002909 return (void *) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002910 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002911 if (!strcmp(funcName, "vkDestroyDevice"))
2912 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002913 if (!strcmp(funcName, "vkQueueSubmit"))
2914 return (void*) vkQueueSubmit;
2915 if (!strcmp(funcName, "vkDestroyObject"))
2916 return (void*) vkDestroyObject;
2917 if (!strcmp(funcName, "vkCreateBufferView"))
2918 return (void*) vkCreateBufferView;
2919 if (!strcmp(funcName, "vkCreateImageView"))
2920 return (void*) vkCreateImageView;
2921 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2922 return (void*) vkCreateGraphicsPipeline;
2923 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2924 return (void*) vkCreateGraphicsPipelineDerivative;
2925 if (!strcmp(funcName, "vkCreateSampler"))
2926 return (void*) vkCreateSampler;
2927 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2928 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002929 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2930 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002931 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2932 return (void*) vkCreateDescriptorPool;
2933 if (!strcmp(funcName, "vkResetDescriptorPool"))
2934 return (void*) vkResetDescriptorPool;
2935 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2936 return (void*) vkAllocDescriptorSets;
2937 if (!strcmp(funcName, "vkClearDescriptorSets"))
2938 return (void*) vkClearDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002939 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2940 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002941 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2942 return (void*) vkCreateDynamicViewportState;
2943 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2944 return (void*) vkCreateDynamicRasterState;
2945 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2946 return (void*) vkCreateDynamicColorBlendState;
2947 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2948 return (void*) vkCreateDynamicDepthStencilState;
2949 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2950 return (void*) vkCreateCommandBuffer;
2951 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2952 return (void*) vkBeginCommandBuffer;
2953 if (!strcmp(funcName, "vkEndCommandBuffer"))
2954 return (void*) vkEndCommandBuffer;
2955 if (!strcmp(funcName, "vkResetCommandBuffer"))
2956 return (void*) vkResetCommandBuffer;
2957 if (!strcmp(funcName, "vkCmdBindPipeline"))
2958 return (void*) vkCmdBindPipeline;
2959 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2960 return (void*) vkCmdBindDynamicStateObject;
2961 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2962 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002963 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2964 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002965 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2966 return (void*) vkCmdBindIndexBuffer;
2967 if (!strcmp(funcName, "vkCmdDraw"))
2968 return (void*) vkCmdDraw;
2969 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2970 return (void*) vkCmdDrawIndexed;
2971 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2972 return (void*) vkCmdDrawIndirect;
2973 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2974 return (void*) vkCmdDrawIndexedIndirect;
2975 if (!strcmp(funcName, "vkCmdDispatch"))
2976 return (void*) vkCmdDispatch;
2977 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2978 return (void*) vkCmdDispatchIndirect;
2979 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2980 return (void*) vkCmdCopyBuffer;
2981 if (!strcmp(funcName, "vkCmdCopyImage"))
2982 return (void*) vkCmdCopyImage;
2983 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2984 return (void*) vkCmdCopyBufferToImage;
2985 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2986 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002987 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2988 return (void*) vkCmdUpdateBuffer;
2989 if (!strcmp(funcName, "vkCmdFillBuffer"))
2990 return (void*) vkCmdFillBuffer;
2991 if (!strcmp(funcName, "vkCmdClearColorImage"))
2992 return (void*) vkCmdClearColorImage;
2993 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2994 return (void*) vkCmdClearDepthStencil;
2995 if (!strcmp(funcName, "vkCmdResolveImage"))
2996 return (void*) vkCmdResolveImage;
2997 if (!strcmp(funcName, "vkCmdSetEvent"))
2998 return (void*) vkCmdSetEvent;
2999 if (!strcmp(funcName, "vkCmdResetEvent"))
3000 return (void*) vkCmdResetEvent;
3001 if (!strcmp(funcName, "vkCmdWaitEvents"))
3002 return (void*) vkCmdWaitEvents;
3003 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
3004 return (void*) vkCmdPipelineBarrier;
3005 if (!strcmp(funcName, "vkCmdBeginQuery"))
3006 return (void*) vkCmdBeginQuery;
3007 if (!strcmp(funcName, "vkCmdEndQuery"))
3008 return (void*) vkCmdEndQuery;
3009 if (!strcmp(funcName, "vkCmdResetQueryPool"))
3010 return (void*) vkCmdResetQueryPool;
3011 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
3012 return (void*) vkCmdWriteTimestamp;
3013 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
3014 return (void*) vkCmdInitAtomicCounters;
3015 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
3016 return (void*) vkCmdLoadAtomicCounters;
3017 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
3018 return (void*) vkCmdSaveAtomicCounters;
3019 if (!strcmp(funcName, "vkCreateFramebuffer"))
3020 return (void*) vkCreateFramebuffer;
3021 if (!strcmp(funcName, "vkCreateRenderPass"))
3022 return (void*) vkCreateRenderPass;
3023 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
3024 return (void*) vkCmdBeginRenderPass;
3025 if (!strcmp(funcName, "vkCmdEndRenderPass"))
3026 return (void*) vkCmdEndRenderPass;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003027 if (!strcmp(funcName, "vkDbgCreateMsgCallback"))
3028 return (void*) vkDbgCreateMsgCallback;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003029 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
3030 return (void*) vkCmdDbgMarkerBegin;
3031 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
3032 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003033 if (!strcmp("drawStateDumpDotFile", funcName))
3034 return (void*) drawStateDumpDotFile;
3035 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
3036 return (void*) drawStateDumpCommandBufferDotFile;
3037 if (!strcmp("drawStateDumpPngFile", funcName))
3038 return (void*) drawStateDumpPngFile;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003039 else
3040 {
3041 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) dev;
3042 VkLayerDispatchTable* pTable = tableMap[*ppDisp];
3043 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003044 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003045 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003046 }
3047}
3048
3049VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3050{
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003051 if (instance == NULL)
3052 return NULL;
3053
Jon Ashburnd9564002015-05-07 10:27:37 -06003054 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003055
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003056 /* loader uses this to force layer initialization; instance object is wrapped */
3057 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
3058 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003059 return (void *) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003060 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06003061 if (!strcmp(funcName, "vkDestroyInstance"))
3062 return (void *) vkDestroyInstance;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003063 if (!strcmp(funcName, "vkCreateDevice"))
3064 return (void*) vkCreateDevice;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003065 else
3066 {
3067 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
3068 VkLayerInstanceDispatchTable* pTable = tableInstanceMap[*ppDisp];
3069 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003070 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003071 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003072 }
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003073
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003074}