blob: 65401950330ccac30096c0cfcbfbaa7ea83e04db [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"
Jon Ashburn6f8cd632015-06-01 09:37:38 -060048#include "layers_debug_marker_table.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060049
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060050unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
51unordered_map<VkImageView, IMAGE_NODE*> imageMap;
52unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
53unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
54unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
55unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
56unordered_map<VkDescriptorSet, SET_NODE*> setMap;
57unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060058// Map for layout chains
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060059unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
60unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
61unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060062
Jon Ashburn6f8cd632015-06-01 09:37:38 -060063struct devExts {
64 bool debug_marker_enabled;
65};
66
Jon Ashburne0fa2282015-05-20 09:00:28 -060067static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;
68static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;
Jon Ashburn6f8cd632015-06-01 09:37:38 -060069static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060070
Tobin Ehlis63bb9482015-03-17 16:24:32 -060071static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060072
Tobin Ehlis63bb9482015-03-17 16:24:32 -060073// TODO : This can be much smarter, using separate locks for separate global data
74static int globalLockInitialized = 0;
75static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060076#define MAX_TID 513
77static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
78static uint32_t g_maxTID = 0;
79// Map actual TID to an index value and return that index
80// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
81static uint32_t getTIDIndex() {
82 loader_platform_thread_id tid = loader_platform_get_thread_id();
83 for (uint32_t i = 0; i < g_maxTID; i++) {
84 if (tid == g_tidMapping[i])
85 return i;
86 }
87 // Don't yet have mapping, set it and return newly set index
88 uint32_t retVal = (uint32_t) g_maxTID;
89 g_tidMapping[g_maxTID++] = tid;
90 assert(g_maxTID < MAX_TID);
91 return retVal;
92}
93// Return a string representation of CMD_TYPE enum
94static string cmdTypeToString(CMD_TYPE cmd)
95{
96 switch (cmd)
97 {
98 case CMD_BINDPIPELINE:
99 return "CMD_BINDPIPELINE";
100 case CMD_BINDPIPELINEDELTA:
101 return "CMD_BINDPIPELINEDELTA";
102 case CMD_BINDDYNAMICSTATEOBJECT:
103 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600104 case CMD_BINDDESCRIPTORSETS:
105 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600106 case CMD_BINDINDEXBUFFER:
107 return "CMD_BINDINDEXBUFFER";
108 case CMD_BINDVERTEXBUFFER:
109 return "CMD_BINDVERTEXBUFFER";
110 case CMD_DRAW:
111 return "CMD_DRAW";
112 case CMD_DRAWINDEXED:
113 return "CMD_DRAWINDEXED";
114 case CMD_DRAWINDIRECT:
115 return "CMD_DRAWINDIRECT";
116 case CMD_DRAWINDEXEDINDIRECT:
117 return "CMD_DRAWINDEXEDINDIRECT";
118 case CMD_DISPATCH:
119 return "CMD_DISPATCH";
120 case CMD_DISPATCHINDIRECT:
121 return "CMD_DISPATCHINDIRECT";
122 case CMD_COPYBUFFER:
123 return "CMD_COPYBUFFER";
124 case CMD_COPYIMAGE:
125 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600126 case CMD_BLITIMAGE:
127 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600128 case CMD_COPYBUFFERTOIMAGE:
129 return "CMD_COPYBUFFERTOIMAGE";
130 case CMD_COPYIMAGETOBUFFER:
131 return "CMD_COPYIMAGETOBUFFER";
132 case CMD_CLONEIMAGEDATA:
133 return "CMD_CLONEIMAGEDATA";
134 case CMD_UPDATEBUFFER:
135 return "CMD_UPDATEBUFFER";
136 case CMD_FILLBUFFER:
137 return "CMD_FILLBUFFER";
138 case CMD_CLEARCOLORIMAGE:
139 return "CMD_CLEARCOLORIMAGE";
140 case CMD_CLEARCOLORIMAGERAW:
141 return "CMD_CLEARCOLORIMAGERAW";
142 case CMD_CLEARDEPTHSTENCIL:
143 return "CMD_CLEARDEPTHSTENCIL";
144 case CMD_RESOLVEIMAGE:
145 return "CMD_RESOLVEIMAGE";
146 case CMD_SETEVENT:
147 return "CMD_SETEVENT";
148 case CMD_RESETEVENT:
149 return "CMD_RESETEVENT";
150 case CMD_WAITEVENTS:
151 return "CMD_WAITEVENTS";
152 case CMD_PIPELINEBARRIER:
153 return "CMD_PIPELINEBARRIER";
154 case CMD_BEGINQUERY:
155 return "CMD_BEGINQUERY";
156 case CMD_ENDQUERY:
157 return "CMD_ENDQUERY";
158 case CMD_RESETQUERYPOOL:
159 return "CMD_RESETQUERYPOOL";
160 case CMD_WRITETIMESTAMP:
161 return "CMD_WRITETIMESTAMP";
162 case CMD_INITATOMICCOUNTERS:
163 return "CMD_INITATOMICCOUNTERS";
164 case CMD_LOADATOMICCOUNTERS:
165 return "CMD_LOADATOMICCOUNTERS";
166 case CMD_SAVEATOMICCOUNTERS:
167 return "CMD_SAVEATOMICCOUNTERS";
168 case CMD_BEGINRENDERPASS:
169 return "CMD_BEGINRENDERPASS";
170 case CMD_ENDRENDERPASS:
171 return "CMD_ENDRENDERPASS";
172 case CMD_DBGMARKERBEGIN:
173 return "CMD_DBGMARKERBEGIN";
174 case CMD_DBGMARKEREND:
175 return "CMD_DBGMARKEREND";
176 default:
177 return "UNKNOWN";
178 }
179}
180// Block of code at start here for managing/tracking Pipeline state that this layer cares about
181// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600182#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600183#define MAX_SLOTS 2048
184#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
185
186static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
187
188// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
189// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
190// to that same cmd buffer by separate thread are not changing state from underneath us
191// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600193// Track the last group of CBs touched for displaying to dot file
194static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
195static uint32_t g_lastTouchedCBIndex = 0;
196// Track the last global DrawState of interest touched by any thread
197static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
198static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600199static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600201#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
202
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600203//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600204
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600205static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600206{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600207 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600208 size_t scSize = 0;
209 size_t vpSize = 0;
210 loader_platform_thread_lock_mutex(&globalLock);
211 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
212 pStateNode->stateObj = state;
213 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600214 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600215 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
216 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
217 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
218 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
219 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
220 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600221 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
222 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
223 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600224 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600225 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600226 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600227 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600228 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600229 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600230 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600231 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600232 break;
233 default:
234 assert(0);
235 break;
236 }
237 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
238 dynamicStateMap[state] = pStateNode;
239 loader_platform_thread_unlock_mutex(&globalLock);
240}
241// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600242static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243{
David Pinedof5997ab2015-04-27 16:36:17 -0600244 if (dynamicStateMap.size() <= 0)
245 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600246 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600247 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600248 delete[] (*ii).second->create_info.vpci.pScissors;
249 delete[] (*ii).second->create_info.vpci.pViewports;
250 }
251 delete (*ii).second;
252 }
253}
254// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600255static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600256{
David Pinedof5997ab2015-04-27 16:36:17 -0600257 if (sampleMap.size() <= 0)
258 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600259 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600260 delete (*ii).second;
261 }
262}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600263static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600264{
265 loader_platform_thread_lock_mutex(&globalLock);
266 if (imageMap.find(view) == imageMap.end()) {
267 loader_platform_thread_unlock_mutex(&globalLock);
268 return NULL;
269 }
270 else {
271 loader_platform_thread_unlock_mutex(&globalLock);
272 return &imageMap[view]->createInfo;
273 }
274}
275// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600276static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600277{
David Pinedof5997ab2015-04-27 16:36:17 -0600278 if (imageMap.size() <= 0)
279 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600280 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281 delete (*ii).second;
282 }
283}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600284static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600285{
286 loader_platform_thread_lock_mutex(&globalLock);
287 if (bufferMap.find(view) == bufferMap.end()) {
288 loader_platform_thread_unlock_mutex(&globalLock);
289 return NULL;
290 }
291 else {
292 loader_platform_thread_unlock_mutex(&globalLock);
293 return &bufferMap[view]->createInfo;
294 }
295}
296// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600297static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600298{
David Pinedof5997ab2015-04-27 16:36:17 -0600299 if (bufferMap.size() <= 0)
300 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600301 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600302 delete (*ii).second;
303 }
304}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600305static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600306
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600308{
309 g_lastCmdBuffer[getTIDIndex()] = cb;
310 GLOBAL_CB_NODE* pCB = getCBNode(cb);
311 loader_platform_thread_lock_mutex(&globalLock);
312 g_lastGlobalCB = pCB;
313 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
314 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
315 if (g_pLastTouchedCB[i] == pCB) {
316 loader_platform_thread_unlock_mutex(&globalLock);
317 return;
318 }
319 }
320 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
321 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
322 loader_platform_thread_unlock_mutex(&globalLock);
323}
Tobin Ehlis97866202015-06-10 12:57:07 -0600324// Check object status for selected flag state
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600325static 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)
326{
Tobin Ehlis97866202015-06-10 12:57:07 -0600327 if (cmdBufferMap.find(cb) != cmdBufferMap.end()) {
328 GLOBAL_CB_NODE* pNode = cmdBufferMap[cb];
329 // If non-zero enable mask is present, check it against status but if enable_mask
330 // is 0 then no enable required so we should always just check status
331 if ((!enable_mask) || (enable_mask & pNode->status)) {
332 if ((pNode->status & status_mask) != status_flag) {
333 char str[1024];
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600334 sprintf(str, "CB object 0x%" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(cb), str);
335 layerCbMsg(msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, error_code, "DS", str);
Tobin Ehlis97866202015-06-10 12:57:07 -0600336 return VK_FALSE;
337 }
338 }
339 return VK_TRUE;
340 }
341 else {
342 // If we do not find it print an error
343 char str[1024];
344 sprintf(str, "Unable to obtain status for non-existent CB object 0x%" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(cb));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600345 layerCbMsg(msg_flags, (VkObjectType) 0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis97866202015-06-10 12:57:07 -0600346 return VK_FALSE;
347 }
348}
349static bool32_t validate_draw_state_flags(VkCmdBuffer cb) {
350 bool32_t result1, result2, result3, result4;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600351 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");
352 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");
353 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");
354 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 -0600355 return ((result1 == VK_TRUE) && (result2 == VK_TRUE) && (result3 == VK_TRUE) && (result4 == VK_TRUE));
356}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600357// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600358static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600359{
360 GLOBAL_CB_NODE* pCB = getCBNode(cb);
361 if (pCB) {
362 loader_platform_thread_lock_mutex(&globalLock);
363 char str[4*1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600364 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600365 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600366 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 -0600367 layerCbMsg(VK_DBG_REPORT_INFO_BIT, pCB->lastBoundDynamicState[i]->objType, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
368 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 -0600369 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600370 } else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600371 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600372 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600373 }
374 }
375 loader_platform_thread_unlock_mutex(&globalLock);
376 }
377 else {
378 char str[1024];
379 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600380 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 -0600381 }
382}
383// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600384static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600385{
386 loader_platform_thread_lock_mutex(&globalLock);
387 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
388 loader_platform_thread_unlock_mutex(&globalLock);
389 return NULL;
390 }
391 loader_platform_thread_unlock_mutex(&globalLock);
392 return pipelineMap[pipeline];
393}
394
395// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600396static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600397{
398 loader_platform_thread_lock_mutex(&globalLock);
399 if (sampleMap.find(sampler) == sampleMap.end()) {
400 loader_platform_thread_unlock_mutex(&globalLock);
401 return NULL;
402 }
403 loader_platform_thread_unlock_mutex(&globalLock);
404 return &sampleMap[sampler]->createInfo;
405}
406
407// Init the pipeline mapping info based on pipeline create info LL tree
408// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600410{
411 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600412 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600413 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600414 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600415 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600416 size_t bufferSize = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600417 VkPipelineVertexInputCreateInfo* pVICI = NULL;
418 VkPipelineCbStateCreateInfo* pCBCI = NULL;
419 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600420 while (pTrav) {
421 switch (pTrav->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600422 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600423 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600424 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 case VK_SHADER_STAGE_VERTEX:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600426 pPrev->pNext = &pPipeline->vsCI;
427 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600428 memcpy(&pPipeline->vsCI, 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_CONTROL:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600431 pPrev->pNext = &pPipeline->tcsCI;
432 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600433 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600434 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600435 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600436 pPrev->pNext = &pPipeline->tesCI;
437 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600438 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600439 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600440 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600441 pPrev->pNext = &pPipeline->gsCI;
442 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600443 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600444 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600445 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600446 pPrev->pNext = &pPipeline->fsCI;
447 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600448 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600449 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600450 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600451 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600452 break;
453 default:
454 // TODO : Flag error
455 break;
456 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600457 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600458 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600459 pPrev->pNext = &pPipeline->vertexInputCI;
460 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600461 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600462 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600463 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600464 pPipeline->vtxBindingCount = pVICI->bindingCount;
465 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
467 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
Tobin Ehlis9a70e5d2015-06-09 10:48:55 -0600468 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexBindingDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600469 }
470 pPipeline->vtxAttributeCount = pVICI->attributeCount;
471 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600472 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
473 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
474 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600475 }
476 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600477 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600478 pPrev->pNext = &pPipeline->iaStateCI;
479 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600480 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600481 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600482 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600483 pPrev->pNext = &pPipeline->tessStateCI;
484 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600485 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600486 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600487 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600488 pPrev->pNext = &pPipeline->vpStateCI;
489 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600490 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600491 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600492 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600493 pPrev->pNext = &pPipeline->rsStateCI;
494 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600495 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600496 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600497 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600498 pPrev->pNext = &pPipeline->msStateCI;
499 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600500 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600501 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600502 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600503 pPrev->pNext = &pPipeline->cbStateCI;
504 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600505 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600506 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600507 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600508 pPipeline->attachmentCount = pCBCI->attachmentCount;
509 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600510 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
511 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
512 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600513 }
514 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600515 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600516 pPrev->pNext = &pPipeline->dsStateCI;
517 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600518 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600519 break;
520 default:
521 assert(0);
522 break;
523 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600524 pTrav = (GENERIC_HEADER*)pTrav->pNext;
525 }
526 pipelineMap[pPipeline->pipeline] = pPipeline;
527}
528// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600529static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600530{
David Pinedof5997ab2015-04-27 16:36:17 -0600531 if (pipelineMap.size() <= 0)
532 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600533 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600534 if ((*ii).second->pVertexBindingDescriptions) {
535 delete[] (*ii).second->pVertexBindingDescriptions;
536 }
537 if ((*ii).second->pVertexAttributeDescriptions) {
538 delete[] (*ii).second->pVertexAttributeDescriptions;
539 }
540 if ((*ii).second->pAttachments) {
541 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600542 }
543 delete (*ii).second;
544 }
545}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600546// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600547static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600548{
549 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600550 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600551 if (pPipe->msStateCI.multisampleEnable)
552 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600553 }
554 return 1;
555}
556// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600557static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600558{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600559 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600560 // Verify that any MSAA request in PSO matches sample# in bound FB
561 uint32_t psoNumSamples = getNumSamples(pipeline);
562 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600563 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
564 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis63826ec2015-05-21 09:06:56 -0600565 if ((psoNumSamples != pFBCI->sampleCount) || (psoNumSamples != pRPCI->sampleCount)) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600566 char str[1024];
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600567 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 -0600568 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 -0600569 }
570 } else {
571 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
572 // Verify and flag error as appropriate
573 }
574 // TODO : Add more checks here
575 } else {
576 // TODO : Validate non-gfx pipeline updates
577 }
578}
579
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600580// Block of code at start here specifically for managing/tracking DSs
581
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600582// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600583static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600584{
585 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600586 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600587 loader_platform_thread_unlock_mutex(&globalLock);
588 return NULL;
589 }
590 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600591 return poolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600592}
593// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600594static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600595{
596 loader_platform_thread_lock_mutex(&globalLock);
597 if (setMap.find(set) == setMap.end()) {
598 loader_platform_thread_unlock_mutex(&globalLock);
599 return NULL;
600 }
601 loader_platform_thread_unlock_mutex(&globalLock);
602 return setMap[set];
603}
604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600605static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600606 loader_platform_thread_lock_mutex(&globalLock);
607 if (layoutMap.find(layout) == layoutMap.end()) {
608 loader_platform_thread_unlock_mutex(&globalLock);
609 return NULL;
610 }
611 loader_platform_thread_unlock_mutex(&globalLock);
612 return layoutMap[layout];
613}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600614// Return 1 if update struct is of valid type, 0 otherwise
615static bool32_t validUpdateStruct(const GENERIC_HEADER* pUpdateStruct)
616{
617 char str[1024];
618 switch (pUpdateStruct->sType)
619 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800620 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
621 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600622 return 1;
623 default:
624 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 -0600625 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 -0600626 return 0;
627 }
628}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600629// For given update struct, return binding
630static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600631{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600632 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600633 switch (pUpdateStruct->sType)
634 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800635 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
636 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
637 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
638 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600639 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600640 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 -0600641 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 -0600642 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600643 }
644}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600645// Return count for given update struct
646static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600647{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600648 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600649 switch (pUpdateStruct->sType)
650 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800651 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
652 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
653 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600654 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800655 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600656 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600657 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 -0600658 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 -0600659 return 0;
660 }
661}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600662// Return count for given update struct
663static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
664{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600665 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600666 switch (pUpdateStruct->sType)
667 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800668 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
669 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
670 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600671 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800672 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600673 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600674 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 -0600675 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 -0600676 return 0;
677 }
678}
679// For given Layout Node and binding, return index where that binding begins
680static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
681{
682 uint32_t offsetIndex = 0;
683 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800684 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600685 }
686 return offsetIndex;
687}
688// For given layout node and binding, return last index that is updated
689static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
690{
691 uint32_t offsetIndex = 0;
692 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800693 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600694 }
695 return offsetIndex-1;
696}
697// For given layout and update, return the first overall index of the layout that is update
698static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
699{
700 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
701}
702// For given layout and update, return the last overall index of the layout that is update
703static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
704{
705 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
706}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600707// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600708static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600709{
710 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600711 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600712 uint32_t i = 0;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600713 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600714 switch (pUpdateStruct->sType)
715 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800716 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
717 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600718 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800719 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
720 /* no need to validate */
721 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600722 break;
723 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600724 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 -0600725 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 -0600726 return 0;
727 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600728 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600729 if (pLayout->pTypes[i] != actualType)
730 return 0;
731 }
732 return 1;
733}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600734// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
735// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
736// NOTE : Calls to this function should be wrapped in mutex
737static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
738{
739 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800740 VkWriteDescriptorSet* pWDS = NULL;
741 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600742 size_t array_size = 0;
743 size_t base_array_size = 0;
744 size_t total_array_size = 0;
745 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600746 char str[1024];
747 switch (pUpdate->sType)
748 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800749 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
750 pWDS = new VkWriteDescriptorSet;
751 pNewNode = (GENERIC_HEADER*)pWDS;
752 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
753 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
754 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
755 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600756 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800757 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
758 pCDS = new VkCopyDescriptorSet;
759 pUpdate = (GENERIC_HEADER*)pCDS;
760 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600761 break;
762 default:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600763 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 -0600764 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600765 return NULL;
766 }
767 // Make sure that pNext for the end of shadow copy is NULL
768 pNewNode->pNext = NULL;
769 return pNewNode;
770}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800771// update DS mappings based on ppUpdateArray
772static bool32_t dsUpdate(VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600773{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800774 const VkWriteDescriptorSet *pWDS = NULL;
775 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600776 bool32_t result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800777
778 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
779 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
780 else
781 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
782
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600783 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600784 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600785 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600786 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600787 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600788 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800789 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
790 SET_NODE* pSet = setMap[ds]; // getSetNode() without locking
791 g_lastBoundDescriptorSet = pSet->set;
792 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600793 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600794 // First verify valid update struct
795 if (!validUpdateStruct(pUpdate)) {
796 result = 0;
797 break;
798 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600799 // Make sure that binding is within bounds
800 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600801 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600802 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 -0600803 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 -0600804 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600805 }
806 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600807 // Next verify that update falls within size of given binding
808 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600809 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 -0600810 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600811 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
812 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 -0600813 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 -0600814 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600815 }
816 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600817 // Layout bindings match w/ update ok, now verify that update is of the right type
818 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600819 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600820 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600821 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 -0600822 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600823 }
824 else {
825 // Save the update info
826 // TODO : Info message that update successful
827 // Create new update struct for this set's shadow copy
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600828 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829 if (NULL == pNewNode) {
830 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600831 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600832 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 -0600833 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600834 }
835 else {
836 // Insert shadow node into LL of updates for this set
837 pNewNode->pNext = pSet->pUpdateStructs;
838 pSet->pUpdateStructs = pNewNode;
839 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600840 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
841 assert(j<pSet->descriptorCount);
842 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600843 }
844 }
845 }
846 }
847 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600848 }
849 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600850 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600851}
852// Free the shadowed update node for this Set
853// NOTE : Calls to this function should be wrapped in mutex
854static void freeShadowUpdateTree(SET_NODE* pSet)
855{
856 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
857 pSet->pUpdateStructs = NULL;
858 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
859 // Clear the descriptor mappings as they will now be invalid
860 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
861 while(pShadowUpdate) {
862 pFreeUpdate = pShadowUpdate;
863 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
864 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800865 VkWriteDescriptorSet * pWDS = NULL;
866 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600867 void** ppToFree = NULL;
868 switch (pFreeUpdate->sType)
869 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800870 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
871 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
872 if (pWDS->pDescriptors)
873 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600874 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800875 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600876 break;
877 default:
878 assert(0);
879 break;
880 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600881 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600882 }
883}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600884// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600885// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600886static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600887{
David Pinedof5997ab2015-04-27 16:36:17 -0600888 if (poolMap.size() <= 0)
889 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600890 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600891 SET_NODE* pSet = (*ii).second->pSets;
892 SET_NODE* pFreeSet = pSet;
893 while (pSet) {
894 pFreeSet = pSet;
895 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600896 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600897 // Free Update shadow struct tree
898 freeShadowUpdateTree(pFreeSet);
899 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200900 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600901 }
902 delete pFreeSet;
903 }
904 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200905 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600906 }
907 delete (*ii).second;
908 }
909}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600910// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600911// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600912static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600913{
David Pinedof5997ab2015-04-27 16:36:17 -0600914 if (layoutMap.size() <= 0)
915 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600916 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600917 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600918 if (pLayout->createInfo.pBinding) {
919 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
920 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
921 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
922 }
923 delete[] pLayout->createInfo.pBinding;
924 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600925 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200926 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600927 }
928 delete pLayout;
929 }
930}
931// Currently clearing a set is removing all previous updates to that set
932// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600933static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600934{
935 SET_NODE* pSet = getSetNode(set);
936 if (!pSet) {
937 // TODO : Return error
938 }
939 else {
940 loader_platform_thread_lock_mutex(&globalLock);
941 freeShadowUpdateTree(pSet);
942 loader_platform_thread_unlock_mutex(&globalLock);
943 }
944}
945
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600946static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600947{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600948 POOL_NODE* pPool = getPoolNode(pool);
949 if (!pPool) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600950 char str[1024];
Tobin Ehlis28be0be2015-05-22 12:38:16 -0600951 sprintf(str, "Unable to find pool node for pool %p specified in vkResetDescriptorPool() call", (void*)pool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600952 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 -0600953 }
954 else
955 {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600956 // For every set off of this pool, clear it
957 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600958 while (pSet) {
959 clearDescriptorSet(pSet->set);
960 }
961 }
962}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600963// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600964static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600965{
966 loader_platform_thread_lock_mutex(&globalLock);
967 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
968 loader_platform_thread_unlock_mutex(&globalLock);
969 return NULL;
970 }
971 loader_platform_thread_unlock_mutex(&globalLock);
972 return cmdBufferMap[cb];
973}
974// Free all CB Nodes
975// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600976static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600977{
David Pinedof5997ab2015-04-27 16:36:17 -0600978 if (cmdBufferMap.size() <= 0)
979 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600980 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -0600981 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
982 while (!cmd_node_list.empty()) {
983 CMD_NODE* cmd_node = cmd_node_list.back();
984 delete cmd_node;
985 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600986 }
987 delete (*ii).second;
988 }
989}
990static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
991{
992 CMD_NODE* pCmd = new CMD_NODE;
993 if (pCmd) {
994 // init cmd node and append to end of cmd LL
995 memset(pCmd, 0, sizeof(CMD_NODE));
996 pCmd->cmdNumber = ++pCB->numCmds;
997 pCmd->type = cmd;
998 pCB->pCmds.push_back(pCmd);
999 }
1000 else {
1001 char str[1024];
1002 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 -06001003 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 -06001004 }
1005}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001006static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001007{
1008 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1009 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001010 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1011 while (!cmd_list.empty()) {
1012 delete cmd_list.back();
1013 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001014 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001015 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001016 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001017 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001018 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1020 pCB->cmdBuffer = cb;
1021 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001022 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023 pCB->lastVtxBinding = MAX_BINDING;
1024 }
1025}
Tobin Ehlis97866202015-06-10 12:57:07 -06001026// Set PSO-related status bits for CB
1027static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1028{
1029 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1030 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1031 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1032 }
1033 }
1034 if (pPipe->dsStateCI.depthWriteEnable) {
1035 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1036 }
1037}
1038// Set dyn-state related status bits for an object node
1039static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, VkStateBindPoint stateBindPoint) {
1040 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1041 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1042 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1043 pNode->status |= CBSTATUS_RASTER_BOUND;
1044 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1045 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1046 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1047 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1048 }
1049}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001050// Set the last bound dynamic state of given type
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001051static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001052{
1053 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1054 if (pCB) {
1055 updateCBTracking(cmdBuffer);
1056 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis97866202015-06-10 12:57:07 -06001057 set_cb_dyn_status(pCB, sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001058 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1059 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1060 char str[1024];
1061 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001062 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001063 }
1064 else {
1065 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1066 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1067 }
1068 loader_platform_thread_unlock_mutex(&globalLock);
1069 }
1070 else {
1071 char str[1024];
1072 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001073 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 -06001074 }
1075}
1076// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001077static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001078{
1079 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1080 if (pCB) {
1081 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1082 if (!pPipeTrav) {
1083 // nothing to print
1084 }
1085 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001086 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001087 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001088 }
1089 }
1090}
1091// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001092static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001093{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001094#if 0
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001095 SET_NODE* pSet = getSetNode(ds);
1096 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001097 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001098 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001099 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1100 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001101 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001102 fprintf(pOutFile, "%s", pGVstr);
1103 free(pGVstr);
1104 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1105 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001106 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001107 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001108 ++layout_index;
1109 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001110 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001111 fprintf(pOutFile, "%s", pGVstr);
1112 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001113 if (pSet->pUpdateStructs) {
1114 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1115 fprintf(pOutFile, "%s", pGVstr);
1116 free(pGVstr);
1117 }
1118 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001119 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1120 uint32_t i = 0;
1121 for (i=0; i < pSet->descriptorCount; i++) {
1122 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001123 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 -06001124 }
1125 }
1126#define NUM_COLORS 7
1127 vector<string> edgeColors;
1128 edgeColors.push_back("0000ff");
1129 edgeColors.push_back("ff00ff");
1130 edgeColors.push_back("ffff00");
1131 edgeColors.push_back("00ff00");
1132 edgeColors.push_back("000000");
1133 edgeColors.push_back("00ffff");
1134 edgeColors.push_back("ff0000");
1135 uint32_t colorIdx = 0;
1136 fprintf(pOutFile, "</TABLE>>\n];\n");
1137 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001138 VkUpdateSamplers* pUS = NULL;
1139 VkUpdateSamplerTextures* pUST = NULL;
1140 VkUpdateImages* pUI = NULL;
1141 VkUpdateBuffers* pUB = NULL;
1142 VkUpdateAsCopy* pUAC = NULL;
1143 VkSamplerCreateInfo* pSCI = NULL;
1144 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001145 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001146 void** ppNextPtr = NULL;
1147 void* pSaveNext = NULL;
1148 for (i=0; i < pSet->descriptorCount; i++) {
1149 if (pSet->ppDescriptors[i]) {
1150 switch (pSet->ppDescriptors[i]->sType)
1151 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001152 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001153 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001154 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001155 if (pSCI) {
1156 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001157 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001158 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1159 }
1160 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001161 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001162 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001163 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001164 if (pSCI) {
1165 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001166 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001167 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1168 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001169 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001170 if (pIVCI) {
1171 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001172 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001173 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1174 }
1175 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001176 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001177 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001178 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001179 if (pIVCI) {
1180 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001181 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001182 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1183 }
1184 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001185 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001186 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001187 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001188 if (pBVCI) {
1189 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001190 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001191 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1192 }
1193 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001194 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001195 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001196 // TODO : Need to validate this code
1197 // Save off pNext and set to NULL while printing this struct, then restore it
1198 ppNextPtr = (void**)&pUAC->pNext;
1199 pSaveNext = *ppNextPtr;
1200 *ppNextPtr = NULL;
1201 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001202 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001203 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1204 // Restore next ptr
1205 *ppNextPtr = pSaveNext;
1206 break;
1207 default:
1208 break;
1209 }
1210 colorIdx = (colorIdx+1) % NUM_COLORS;
1211 }
1212 }
1213 }
1214 fprintf(pOutFile, "}\n");
1215 fprintf(pOutFile, "}\n");
1216 }
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001217#endif
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001218}
1219// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001221{
1222 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1223 if (pCB && pCB->lastBoundDescriptorSet) {
1224 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1225 }
1226}
1227// Dump a GraphViz dot file showing the Cmd Buffers
1228static void cbDumpDotFile(string outFileName)
1229{
1230 // Print CB Chain for each CB
1231 FILE* pOutFile;
1232 pOutFile = fopen(outFileName.c_str(), "w");
1233 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1234 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1235 GLOBAL_CB_NODE* pCB = NULL;
1236 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1237 pCB = g_pLastTouchedCB[i];
David Pinedof5997ab2015-04-27 16:36:17 -06001238 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001239 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1240 uint32_t instNum = 0;
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001241 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1242 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001243 if (instNum) {
1244 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1245 }
1246 if (pCB == g_lastGlobalCB) {
1247 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());
1248 }
1249 else {
1250 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());
1251 }
1252 ++instNum;
1253 }
1254 fprintf(pOutFile, "}\n");
1255 }
1256 }
1257 fprintf(pOutFile, "}\n");
1258 fprintf(pOutFile, "}\n"); // close main graph "g"
1259 fclose(pOutFile);
1260}
1261// Dump a GraphViz dot file showing the pipeline for last bound global state
1262static void dumpGlobalDotFile(char *outFileName)
1263{
1264 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1265 if (pPipeTrav) {
1266 FILE* pOutFile;
1267 pOutFile = fopen(outFileName, "w");
1268 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1269 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1270 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001271 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001272 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001273 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001274 fprintf(pOutFile, "%s", pGVstr);
1275 free(pGVstr);
1276 }
1277 }
1278 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1279 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001280 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001281 fprintf(pOutFile, "%s", pGVstr);
1282 free(pGVstr);
1283 fprintf(pOutFile, "}\n");
1284 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1285 fprintf(pOutFile, "}\n"); // close main graph "g"
1286 fclose(pOutFile);
1287 }
1288}
1289// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001290static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001291{
1292 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1293 if (pCB) {
1294 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1295 if (pPipeTrav) {
1296 FILE* pOutFile;
1297 pOutFile = fopen(outFileName.c_str(), "w");
1298 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1299 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1300 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001301 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001302 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001303 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001304 fprintf(pOutFile, "%s", pGVstr);
1305 free(pGVstr);
1306 }
1307 }
1308 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1309 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001310 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001311 fprintf(pOutFile, "%s", pGVstr);
1312 free(pGVstr);
1313 fprintf(pOutFile, "}\n");
1314 dsDumpDot(cb, pOutFile);
1315 fprintf(pOutFile, "}\n"); // close main graph "g"
1316 fclose(pOutFile);
1317 }
1318 }
1319}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001320// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001321static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001322{
1323 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1324 if (pCB && pCB->lastBoundPipeline) {
1325 // First verify that we have a Node for bound pipeline
1326 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1327 char str[1024];
1328 if (!pPipeTrav) {
1329 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001330 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001331 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001332 }
1333 else {
1334 // Verify Vtx binding
1335 if (MAX_BINDING != pCB->lastVtxBinding) {
1336 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1337 if (0 == pPipeTrav->vtxBindingCount) {
1338 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 -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 else {
1343 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 -06001344 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 -06001345 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001346 }
1347 }
1348 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001349 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001350 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001351 }
1352 }
1353 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001354 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001355 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001356 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001357}
1358// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001359static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001360{
1361 char tmp_str[1024];
1362 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.
1363 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001364 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001365 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001366 POOL_NODE* pPool = getPoolNode(pSet->pool);
1367 // Print out pool details
1368 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001369 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001370 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001371 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001372 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001373 // Print out set details
1374 char prefix[10];
1375 uint32_t index = 0;
1376 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001377 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001378 LAYOUT_NODE* pLayout = pSet->pLayout;
1379 // Print layout details
1380 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 -06001381 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001382 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001383 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001384 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001385 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001386 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001387 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1388 if (pUpdate) {
1389 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001390 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001391 sprintf(prefix, " [UC] ");
1392 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001393 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001394 // TODO : If there is a "view" associated with this update, print CI for that view
1395 }
1396 else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001397 if (0 != pSet->descriptorCount) {
1398 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 -06001399 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001400 }
1401 else {
1402 sprintf(tmp_str, "FYI: No descriptors in descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001403 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001404 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001405 }
1406 }
1407}
1408
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001409static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001410{
1411 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001412 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001413 char str[1024];
1414 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001415 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001416 vector<CMD_NODE*> pCmds = pCB->pCmds;
1417 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001418 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001419 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001420 }
1421 }
1422 else {
1423 // Nothing to print
1424 }
1425}
1426
1427
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001428static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001429{
1430 printDSConfig(cb);
1431 printPipeline(cb);
1432 printDynamicState(cb);
1433 static int autoDumpOnce = 0;
1434 if (autoDumpOnce) {
1435 autoDumpOnce = 0;
1436 dumpDotFile(cb, "pipeline_dump.dot");
1437 cbDumpDotFile("cb_dump.dot");
1438#if defined(_WIN32)
1439// FIXME: NEED WINDOWS EQUIVALENT
1440#else // WIN32
1441 // Convert dot to svg if dot available
1442 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001443 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1444 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001445 }
1446#endif // WIN32
1447 }
1448}
1449
Jon Ashburne0fa2282015-05-20 09:00:28 -06001450static VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw)
Jon Ashburnd9564002015-05-07 10:27:37 -06001451{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001452 VkLayerDispatchTable *pTable;
1453
1454 assert(devw);
1455 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject);
1456
1457 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) *ppDisp);
1458 if (it == tableMap.end())
1459 {
1460 pTable = new VkLayerDispatchTable;
1461 tableMap[(void *) *ppDisp] = pTable;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001462
Jon Ashburne0fa2282015-05-20 09:00:28 -06001463 } else
1464 {
1465 return it->second;
1466 }
1467
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001468 layer_initialize_dispatch_table(pTable, devw);
Jon Ashburnf0615e22015-05-25 14:11:37 -06001469
Jon Ashburne0fa2282015-05-20 09:00:28 -06001470 return pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -06001471}
1472
Jon Ashburne0fa2282015-05-20 09:00:28 -06001473static VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instw)
Jon Ashburnd9564002015-05-07 10:27:37 -06001474{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001475 VkLayerInstanceDispatchTable *pTable;
1476 assert(instw);
1477 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;
1478
1479 std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap.find((void *) *ppDisp);
1480 if (it == tableInstanceMap.end())
1481 {
1482 pTable = new VkLayerInstanceDispatchTable;
1483 tableInstanceMap[(void *) *ppDisp] = pTable;
1484 } else
1485 {
1486 return it->second;
1487 }
1488
Jon Ashburn4f2575f2015-05-28 16:25:02 -06001489 layer_init_instance_dispatch_table(pTable, instw);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001490
1491 return pTable;
Jon Ashburnd9564002015-05-07 10:27:37 -06001492}
1493
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001494static void initDrawState(void)
1495{
1496 const char *strOpt;
1497 // initialize DrawState options
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001498 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportFlags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001499 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1500
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001501 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001502 {
1503 strOpt = getLayerOption("DrawStateLogFilename");
1504 if (strOpt)
1505 {
1506 g_logFile = fopen(strOpt, "w");
1507 }
1508 if (g_logFile == NULL)
1509 g_logFile = stdout;
1510 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001511
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001512 if (!globalLockInitialized)
1513 {
1514 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001515 // suggestion is to call this during vkCreateInstance(), and then we
1516 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001517 // that the layer have per-instance locks. We need to come back and
1518 // address this soon.
1519 loader_platform_thread_create_mutex(&globalLock);
1520 globalLockInitialized = 1;
1521 }
1522}
1523
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001524VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1525{
1526 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) (*pInstance);
1527 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
1528
1529 loader_platform_thread_once(&g_initOnce, initDrawState);
1530
1531 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1532
1533 if (result == VK_SUCCESS) {
1534 enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001535
1536 debug_report_init_instance_extension_dispatch_table(
1537 pTable,
1538 pTable->GetInstanceProcAddr,
1539 *pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001540 }
1541 return result;
1542}
1543
Jon Ashburne0fa2282015-05-20 09:00:28 -06001544/* hook DestroyInstance to remove tableInstanceMap entry */
1545VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1546{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001547 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06001548 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
1549 VkResult res = pTable->DestroyInstance(instance);
1550 tableInstanceMap.erase(pDisp);
1551 return res;
1552}
1553
Jon Ashburnf0615e22015-05-25 14:11:37 -06001554static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1555{
1556 uint32_t i, ext_idx;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001557 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1558 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001559
1560 for (i = 0; i < pCreateInfo->extensionCount; i++) {
1561 if (strcmp(pCreateInfo->pEnabledExtensions[i].name, DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001562 /* Found a matching extension name, mark it enabled and init dispatch table*/
1563 initDebugMarkerTable(device);
1564 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001565 }
1566
1567 }
1568}
1569
Tony Barbour8205d902015-04-16 15:59:00 -06001570VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001571{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001572 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu;
1573 VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[*ppDisp];
1574 VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice);
Jon Ashburnf0615e22015-05-25 14:11:37 -06001575 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001576 return result;
1577}
1578
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001579VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001580{
1581 // Free all the memory
1582 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001583 deletePipelines();
1584 deleteSamplers();
1585 deleteImages();
1586 deleteBuffers();
1587 deleteCmdBuffers();
1588 deleteDynamicState();
1589 deletePools();
1590 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001591 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001592
1593 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1594 VkLayerDispatchTable *pTable = tableMap[pDisp];
1595 VkResult result = pTable->DestroyDevice(device);
1596 tableMap.erase(pDisp);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001597 tableDebugMarkerMap.erase(pDisp);
1598 deviceExtMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001599 return result;
1600}
1601
Jon Ashburneb2728b2015-04-10 14:33:07 -06001602struct extProps {
1603 uint32_t version;
1604 const char * const name;
1605};
Courtney Goeltzenleuchter47461fb2015-06-01 14:34:25 -06001606#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 2
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001607static const VkExtensionProperties dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1608 {
1609 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1610 "DrawState",
1611 0x10,
1612 "Sample layer: DrawState",
Courtney Goeltzenleuchter47461fb2015-06-01 14:34:25 -06001613 },
1614 {
1615 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
1616 "Validation",
1617 0x10,
1618 "Sample layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001619 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001620};
1621
Jon Ashburnf0615e22015-05-25 14:11:37 -06001622//TODO add DEBUG_MARKER to device extension list
Jon Ashburneb2728b2015-04-10 14:33:07 -06001623VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001624 VkExtensionInfoType infoType,
1625 uint32_t extensionIndex,
1626 size_t* pDataSize,
1627 void* pData)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001628{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001629 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
Jon Ashburneb2728b2015-04-10 14:33:07 -06001630 uint32_t *count;
1631
1632 if (pDataSize == NULL)
1633 return VK_ERROR_INVALID_POINTER;
1634
1635 switch (infoType) {
1636 case VK_EXTENSION_INFO_TYPE_COUNT:
1637 *pDataSize = sizeof(uint32_t);
1638 if (pData == NULL)
1639 return VK_SUCCESS;
1640 count = (uint32_t *) pData;
1641 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1642 break;
1643 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1644 *pDataSize = sizeof(VkExtensionProperties);
1645 if (pData == NULL)
1646 return VK_SUCCESS;
1647 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1648 return VK_ERROR_INVALID_VALUE;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001649 memcpy((VkExtensionProperties *) pData, &dsExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburneb2728b2015-04-10 14:33:07 -06001650 break;
1651 default:
1652 return VK_ERROR_INVALID_VALUE;
1653 };
1654
1655 return VK_SUCCESS;
1656}
1657
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001658VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001659{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001660 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001661 for (uint32_t i=0; i < cmdBufferCount; i++) {
1662 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001663 pCB = getCBNode(pCmdBuffers[i]);
1664 loader_platform_thread_lock_mutex(&globalLock);
1665 if (CB_UPDATE_COMPLETE != pCB->state) {
1666 // Flag error for using CB w/o vkEndCommandBuffer() called
1667 char str[1024];
1668 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001669 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 -06001670 loader_platform_thread_unlock_mutex(&globalLock);
1671 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001672 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001673 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001675
1676 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) queue;
1677 VkLayerDispatchTable *pTable = tableMap[pDisp];
1678 VkResult result = pTable->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679 return result;
1680}
1681
Mike Stroyan230e6252015-04-17 12:36:38 -06001682VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683{
1684 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Jon Ashburne0fa2282015-05-20 09:00:28 -06001685 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1686 VkLayerDispatchTable *pTable = tableMap[pDisp];
1687 VkResult result = pTable->DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001688 return result;
1689}
1690
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001691VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001692{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001693 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1694 VkLayerDispatchTable *pTable = tableMap[pDisp];
1695 VkResult result = pTable->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001696 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001697 loader_platform_thread_lock_mutex(&globalLock);
1698 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1699 pNewNode->buffer = *pView;
1700 pNewNode->createInfo = *pCreateInfo;
1701 bufferMap[*pView] = pNewNode;
1702 loader_platform_thread_unlock_mutex(&globalLock);
1703 }
1704 return result;
1705}
1706
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001707VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001708{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001709 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1710 VkLayerDispatchTable *pTable = tableMap[pDisp];
1711 VkResult result = pTable->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001712 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001713 loader_platform_thread_lock_mutex(&globalLock);
1714 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1715 pNewNode->image = *pView;
1716 pNewNode->createInfo = *pCreateInfo;
1717 imageMap[*pView] = pNewNode;
1718 loader_platform_thread_unlock_mutex(&globalLock);
1719 }
1720 return result;
1721}
1722
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001723static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001724{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001725 // Create LL HEAD for this Pipeline
1726 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001727 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1728 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1729 pPipeNode->pipeline = *pPipeline;
1730 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001731 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001732}
1733
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001734VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001735{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001736 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1737 VkLayerDispatchTable *pTable = tableMap[pDisp];
1738 VkResult result = pTable->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001739 // Create LL HEAD for this Pipeline
1740 char str[1024];
1741 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001742 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001743
1744 track_pipeline(pCreateInfo, pPipeline);
1745
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001746 return result;
1747}
1748
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001749VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1750 VkDevice device,
1751 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1752 VkPipeline basePipeline,
1753 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001754{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001755 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1756 VkLayerDispatchTable *pTable = tableMap[pDisp];
1757 VkResult result = pTable->CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001758 // Create LL HEAD for this Pipeline
1759 char str[1024];
1760 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001761 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001762
1763 track_pipeline(pCreateInfo, pPipeline);
1764
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001765 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001766
1767 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001768}
1769
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001770VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001772 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1773 VkLayerDispatchTable *pTable = tableMap[pDisp];
1774 VkResult result = pTable->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001775 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001776 loader_platform_thread_lock_mutex(&globalLock);
1777 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1778 pNewNode->sampler = *pSampler;
1779 pNewNode->createInfo = *pCreateInfo;
1780 sampleMap[*pSampler] = pNewNode;
1781 loader_platform_thread_unlock_mutex(&globalLock);
1782 }
1783 return result;
1784}
1785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001786VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001787{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001788 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1789 VkLayerDispatchTable *pTable = tableMap[pDisp];
1790 VkResult result = pTable->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001791 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001792 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1793 if (NULL == pNewNode) {
1794 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001795 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001796 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 -06001797 }
1798 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001799 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1800 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1801 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001802 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001803 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001804 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001805 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001806 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001807 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1808 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001809 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001810 }
1811 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001812 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001813 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001814 uint32_t j = 0;
1815 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001816 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001817 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001818 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001819 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 }
1821 }
1822 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001823 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001824 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1825 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001826 // Put new node at Head of global Layer list
1827 loader_platform_thread_lock_mutex(&globalLock);
1828 layoutMap[*pSetLayout] = pNewNode;
1829 loader_platform_thread_unlock_mutex(&globalLock);
1830 }
1831 return result;
1832}
1833
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001834VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001836 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1837 VkLayerDispatchTable *pTable = tableMap[pDisp];
1838 VkResult result = pTable->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001839 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001840 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001841 }
1842 return result;
1843}
1844
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001845VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001846{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001847 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1848 VkLayerDispatchTable *pTable = tableMap[pDisp];
1849 VkResult result = pTable->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001850 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001851 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001852 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001853 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001854 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 -06001855 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001856 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001857 if (NULL == pNewNode) {
1858 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001859 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001860 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 -06001861 }
1862 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001863 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001864 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1865 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001866 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001867 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1868 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001869 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1870 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001871 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001872 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001873 pNewNode->pool = *pDescriptorPool;
1874 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001875 }
1876 loader_platform_thread_unlock_mutex(&globalLock);
1877 }
1878 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001879 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001880 }
1881 return result;
1882}
1883
Mike Stroyan230e6252015-04-17 12:36:38 -06001884VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001885{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001886 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1887 VkLayerDispatchTable *pTable = tableMap[pDisp];
1888 VkResult result = pTable->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001889 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001890 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001891 }
1892 return result;
1893}
1894
Mike Stroyan230e6252015-04-17 12:36:38 -06001895VK_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 -06001896{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001897 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1898 VkLayerDispatchTable *pTable = tableMap[pDisp];
1899 VkResult result = pTable->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001900 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001901 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1902 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001904 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001905 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 -06001906 }
1907 else {
1908 for (uint32_t i = 0; i < *pCount; i++) {
1909 char str[1024];
1910 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001911 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 -06001912 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001913 SET_NODE* pNewNode = new SET_NODE;
1914 if (NULL == pNewNode) {
1915 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001916 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001917 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 -06001918 }
1919 else {
1920 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001921 // Insert set at head of Set LL for this pool
1922 pNewNode->pNext = pPoolNode->pSets;
1923 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001924 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1925 if (NULL == pLayout) {
1926 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001927 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 -06001928 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 -06001929 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001930 pNewNode->pLayout = pLayout;
1931 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001932 pNewNode->set = pDescriptorSets[i];
1933 pNewNode->setUsage = setUsage;
1934 pNewNode->descriptorCount = pLayout->endIndex + 1;
1935 if (pNewNode->descriptorCount) {
1936 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1937 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1938 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1939 }
1940 setMap[pDescriptorSets[i]] = pNewNode;
1941 }
1942 }
1943 }
1944 }
1945 return result;
1946}
1947
Mike Stroyan230e6252015-04-17 12:36:38 -06001948VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001949{
1950 for (uint32_t i = 0; i < count; i++) {
1951 clearDescriptorSet(pDescriptorSets[i]);
1952 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001953 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1954 VkLayerDispatchTable *pTable = tableMap[pDisp];
1955 pTable->ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001956}
1957
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001958VK_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 -06001959{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001960 if (dsUpdate(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
Jon Ashburne0fa2282015-05-20 09:00:28 -06001961 dsUpdate(VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
1962 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1963 VkLayerDispatchTable *pTable = tableMap[pDisp];
1964 return pTable->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
1965 }
1966 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001967}
1968
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001969VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001970{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001971 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1972 VkLayerDispatchTable *pTable = tableMap[pDisp];
1973 VkResult result = pTable->CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001974 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975 return result;
1976}
1977
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001978VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001979{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001980 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1981 VkLayerDispatchTable *pTable = tableMap[pDisp];
1982 VkResult result = pTable->CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001983 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001984 return result;
1985}
1986
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001987VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001988{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001989 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1990 VkLayerDispatchTable *pTable = tableMap[pDisp];
1991 VkResult result = pTable->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001992 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001993 return result;
1994}
1995
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001996VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001997{
Jon Ashburne0fa2282015-05-20 09:00:28 -06001998 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
1999 VkLayerDispatchTable *pTable = tableMap[pDisp];
2000 VkResult result = pTable->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06002001 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002002 return result;
2003}
2004
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002005VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002006{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002007 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2008 VkLayerDispatchTable *pTable = tableMap[pDisp];
2009 VkResult result = pTable->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002010 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002011 loader_platform_thread_lock_mutex(&globalLock);
2012 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2013 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2014 pCB->cmdBuffer = *pCmdBuffer;
2015 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07002016 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002017 pCB->lastVtxBinding = MAX_BINDING;
2018 cmdBufferMap[*pCmdBuffer] = pCB;
2019 loader_platform_thread_unlock_mutex(&globalLock);
2020 updateCBTracking(*pCmdBuffer);
2021 }
2022 return result;
2023}
2024
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002025VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002026{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002027 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2028 VkLayerDispatchTable *pTable = tableMap[pDisp];
2029 VkResult result = pTable->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002030 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002031 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2032 if (pCB) {
2033 if (CB_NEW != pCB->state)
2034 resetCB(cmdBuffer);
2035 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002036 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002037 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002038 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002039 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002040 }
2041 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042 }
2043 else {
2044 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002045 sprintf(str, "In vkBeginCommandBuffer() 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 }
2050 return result;
2051}
2052
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002053VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002054{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002055 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2056 VkLayerDispatchTable *pTable = tableMap[pDisp];
2057 VkResult result = pTable->EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002058 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002059 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2060 if (pCB) {
2061 pCB->state = CB_UPDATE_COMPLETE;
Tobin Ehlis97866202015-06-10 12:57:07 -06002062 // Reset CB status flags
2063 pCB->status = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002064 printCB(cmdBuffer);
2065 }
2066 else {
2067 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002068 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002069 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 -06002070 }
2071 updateCBTracking(cmdBuffer);
2072 //cbDumpDotFile("cb_dump.dot");
2073 }
2074 return result;
2075}
2076
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002077VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002078{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002079 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2080 VkLayerDispatchTable *pTable = tableMap[pDisp];
2081 VkResult result = pTable->ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002082 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002083 resetCB(cmdBuffer);
2084 updateCBTracking(cmdBuffer);
2085 }
2086 return result;
2087}
2088
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002089VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002090{
2091 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2092 if (pCB) {
2093 updateCBTracking(cmdBuffer);
2094 addCmd(pCB, CMD_BINDPIPELINE);
2095 PIPELINE_NODE* pPN = getPipeline(pipeline);
2096 if (pPN) {
2097 pCB->lastBoundPipeline = pipeline;
2098 loader_platform_thread_lock_mutex(&globalLock);
2099 g_lastBoundPipeline = pPN;
2100 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002101 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002102 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2103 VkLayerDispatchTable *pTable = tableMap[pDisp];
2104 pTable->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002105 }
2106 else {
2107 char str[1024];
2108 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002109 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002110 }
2111 }
2112 else {
2113 char str[1024];
2114 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002115 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 -06002116 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002117}
2118
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002119VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002120{
2121 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
Jon Ashburne0fa2282015-05-20 09:00:28 -06002122 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2123 VkLayerDispatchTable *pTable = tableMap[pDisp];
2124 pTable->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002125}
2126
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002127VK_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 -06002128{
2129 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2130 if (pCB) {
2131 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002132 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002133 if (validateBoundPipeline(cmdBuffer)) {
2134 for (uint32_t i=0; i<setCount; i++) {
2135 if (getSetNode(pDescriptorSets[i])) {
2136 loader_platform_thread_lock_mutex(&globalLock);
2137 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2138 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2139 g_lastBoundDescriptorSet = pDescriptorSets[i];
2140 loader_platform_thread_unlock_mutex(&globalLock);
2141 char str[1024];
2142 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002143 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 -06002144 }
2145 else {
2146 char str[1024];
2147 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002148 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 -06002149 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002150 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002151 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2152 VkLayerDispatchTable *pTable = tableMap[pDisp];
2153 pTable->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002154 }
2155 }
2156 else {
2157 char str[1024];
2158 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002159 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 -06002160 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002161}
2162
Tony Barbour8205d902015-04-16 15:59:00 -06002163VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002164{
2165 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2166 if (pCB) {
2167 updateCBTracking(cmdBuffer);
2168 addCmd(pCB, CMD_BINDINDEXBUFFER);
2169 // TODO : Track idxBuffer binding
2170 }
2171 else {
2172 char str[1024];
2173 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002174 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 -06002175 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002176 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2177 VkLayerDispatchTable *pTable = tableMap[pDisp];
2178 pTable->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002179}
2180
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002181VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2182 VkCmdBuffer cmdBuffer,
2183 uint32_t startBinding,
2184 uint32_t bindingCount,
2185 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002186 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002187{
2188 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2189 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002190 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002191 updateCBTracking(cmdBuffer);
2192 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002193 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002194 if (validateBoundPipeline(cmdBuffer)) {
Jon Ashburne0fa2282015-05-20 09:00:28 -06002195 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2196 VkLayerDispatchTable *pTable = tableMap[pDisp];
2197 pTable->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002198 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002199 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002200 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 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002204}
2205
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002206VK_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 -06002207{
2208 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002209 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002210 if (pCB) {
2211 updateCBTracking(cmdBuffer);
2212 addCmd(pCB, CMD_DRAW);
2213 pCB->drawCount[DRAW]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002214 loader_platform_thread_lock_mutex(&globalLock);
2215 valid = validate_draw_state_flags(cmdBuffer);
2216 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002217 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002218 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002219 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002220 synchAndPrintDSConfig(cmdBuffer);
2221 }
2222 else {
2223 char str[1024];
2224 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002225 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 -06002226 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002227 if (valid) {
2228 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2229 VkLayerDispatchTable *pTable = tableMap[pDisp];
2230 pTable->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2231 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002232}
2233
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002234VK_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 -06002235{
2236 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002237 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002238 if (pCB) {
2239 updateCBTracking(cmdBuffer);
2240 addCmd(pCB, CMD_DRAWINDEXED);
2241 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002242 loader_platform_thread_lock_mutex(&globalLock);
2243 valid = validate_draw_state_flags(cmdBuffer);
2244 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002245 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002246 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002247 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002248 synchAndPrintDSConfig(cmdBuffer);
2249 }
2250 else {
2251 char str[1024];
2252 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002253 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 -06002254 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002255 if (valid) {
2256 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2257 VkLayerDispatchTable *pTable = tableMap[pDisp];
2258 pTable->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2259 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002260}
2261
Tony Barbour8205d902015-04-16 15:59:00 -06002262VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002263{
2264 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002265 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266 if (pCB) {
2267 updateCBTracking(cmdBuffer);
2268 addCmd(pCB, CMD_DRAWINDIRECT);
2269 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002270 loader_platform_thread_lock_mutex(&globalLock);
2271 valid = validate_draw_state_flags(cmdBuffer);
2272 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002273 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002274 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002275 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002276 synchAndPrintDSConfig(cmdBuffer);
2277 }
2278 else {
2279 char str[1024];
2280 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002281 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 -06002282 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002283 if (valid) {
2284 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2285 VkLayerDispatchTable *pTable = tableMap[pDisp];
2286 pTable->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2287 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002288}
2289
Tony Barbour8205d902015-04-16 15:59:00 -06002290VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002291{
2292 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis97866202015-06-10 12:57:07 -06002293 bool32_t valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002294 if (pCB) {
2295 updateCBTracking(cmdBuffer);
2296 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2297 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis97866202015-06-10 12:57:07 -06002298 loader_platform_thread_lock_mutex(&globalLock);
2299 valid = validate_draw_state_flags(cmdBuffer);
2300 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002301 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002302 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002303 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002304 synchAndPrintDSConfig(cmdBuffer);
2305 }
2306 else {
2307 char str[1024];
2308 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002309 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 -06002310 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002311 if (valid) {
2312 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2313 VkLayerDispatchTable *pTable = tableMap[pDisp];
2314 pTable->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2315 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002316}
2317
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002318VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002319{
2320 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2321 if (pCB) {
2322 updateCBTracking(cmdBuffer);
2323 addCmd(pCB, CMD_DISPATCH);
2324 }
2325 else {
2326 char str[1024];
2327 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002328 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 -06002329 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002330 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2331 VkLayerDispatchTable *pTable = tableMap[pDisp];
2332 pTable->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002333}
2334
Tony Barbour8205d902015-04-16 15:59:00 -06002335VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002336{
2337 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2338 if (pCB) {
2339 updateCBTracking(cmdBuffer);
2340 addCmd(pCB, CMD_DISPATCHINDIRECT);
2341 }
2342 else {
2343 char str[1024];
2344 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002345 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 -06002346 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002347 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2348 VkLayerDispatchTable *pTable = tableMap[pDisp];
2349 pTable->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002350}
2351
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002352VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002353{
2354 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2355 if (pCB) {
2356 updateCBTracking(cmdBuffer);
2357 addCmd(pCB, CMD_COPYBUFFER);
2358 }
2359 else {
2360 char str[1024];
2361 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002362 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 -06002363 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002364 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2365 VkLayerDispatchTable *pTable = tableMap[pDisp];
2366 pTable->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002367}
2368
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002369VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2370 VkImage srcImage,
2371 VkImageLayout srcImageLayout,
2372 VkImage destImage,
2373 VkImageLayout destImageLayout,
2374 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002375{
2376 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2377 if (pCB) {
2378 updateCBTracking(cmdBuffer);
2379 addCmd(pCB, CMD_COPYIMAGE);
2380 }
2381 else {
2382 char str[1024];
2383 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002384 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 -06002385 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002386 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2387 VkLayerDispatchTable *pTable = tableMap[pDisp];
2388 pTable->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002389}
2390
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002391VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2392 VkImage srcImage, VkImageLayout srcImageLayout,
2393 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002394 uint32_t regionCount, const VkImageBlit* pRegions,
2395 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002396{
2397 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2398 if (pCB) {
2399 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002400 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002401 }
2402 else {
2403 char str[1024];
2404 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002405 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 -06002406 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002407 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2408 VkLayerDispatchTable *pTable = tableMap[pDisp];
2409 pTable->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002410}
2411
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002412VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2413 VkBuffer srcBuffer,
2414 VkImage destImage, VkImageLayout destImageLayout,
2415 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002416{
2417 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2418 if (pCB) {
2419 updateCBTracking(cmdBuffer);
2420 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2421 }
2422 else {
2423 char str[1024];
2424 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002425 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 -06002426 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002427 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2428 VkLayerDispatchTable *pTable = tableMap[pDisp];
2429 pTable->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002430}
2431
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002432VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2433 VkImage srcImage, VkImageLayout srcImageLayout,
2434 VkBuffer destBuffer,
2435 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002436{
2437 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2438 if (pCB) {
2439 updateCBTracking(cmdBuffer);
2440 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2441 }
2442 else {
2443 char str[1024];
2444 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002445 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 -06002446 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002447 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2448 VkLayerDispatchTable *pTable = tableMap[pDisp];
2449 pTable->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002450}
2451
Tony Barbour8205d902015-04-16 15:59:00 -06002452VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453{
2454 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2455 if (pCB) {
2456 updateCBTracking(cmdBuffer);
2457 addCmd(pCB, CMD_UPDATEBUFFER);
2458 }
2459 else {
2460 char str[1024];
2461 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002462 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 -06002463 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002464 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2465 VkLayerDispatchTable *pTable = tableMap[pDisp];
2466 pTable->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467}
2468
Tony Barbour8205d902015-04-16 15:59:00 -06002469VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470{
2471 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2472 if (pCB) {
2473 updateCBTracking(cmdBuffer);
2474 addCmd(pCB, CMD_FILLBUFFER);
2475 }
2476 else {
2477 char str[1024];
2478 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002479 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 -06002480 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002481 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2482 VkLayerDispatchTable *pTable = tableMap[pDisp];
2483 pTable->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484}
2485
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002486VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2487 VkCmdBuffer cmdBuffer,
2488 VkImage image, VkImageLayout imageLayout,
2489 const VkClearColor *pColor,
2490 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002491{
2492 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2493 if (pCB) {
2494 updateCBTracking(cmdBuffer);
2495 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2496 }
2497 else {
2498 char str[1024];
2499 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002500 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 -06002501 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002502 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2503 VkLayerDispatchTable *pTable = tableMap[pDisp];
2504 pTable->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002505}
2506
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002507VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2508 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002509 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002510 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002511{
2512 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2513 if (pCB) {
2514 updateCBTracking(cmdBuffer);
2515 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2516 }
2517 else {
2518 char str[1024];
2519 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002520 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 -06002521 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002522 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2523 VkLayerDispatchTable *pTable = tableMap[pDisp];
2524 pTable->CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002525}
2526
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002527VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2528 VkImage srcImage, VkImageLayout srcImageLayout,
2529 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002530 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531{
2532 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2533 if (pCB) {
2534 updateCBTracking(cmdBuffer);
2535 addCmd(pCB, CMD_RESOLVEIMAGE);
2536 }
2537 else {
2538 char str[1024];
2539 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002540 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 -06002541 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002542 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2543 VkLayerDispatchTable *pTable = tableMap[pDisp];
2544 pTable->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002545}
2546
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002547VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002548{
2549 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2550 if (pCB) {
2551 updateCBTracking(cmdBuffer);
2552 addCmd(pCB, CMD_SETEVENT);
2553 }
2554 else {
2555 char str[1024];
2556 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002557 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 -06002558 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002559 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2560 VkLayerDispatchTable *pTable = tableMap[pDisp];
2561 pTable->CmdSetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002562}
2563
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002564VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002565{
2566 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2567 if (pCB) {
2568 updateCBTracking(cmdBuffer);
2569 addCmd(pCB, CMD_RESETEVENT);
2570 }
2571 else {
2572 char str[1024];
2573 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002574 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 -06002575 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002576 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2577 VkLayerDispatchTable *pTable = tableMap[pDisp];
2578 pTable->CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002579}
2580
Tony Barbour8205d902015-04-16 15:59:00 -06002581VK_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 -06002582{
2583 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2584 if (pCB) {
2585 updateCBTracking(cmdBuffer);
2586 addCmd(pCB, CMD_WAITEVENTS);
2587 }
2588 else {
2589 char str[1024];
2590 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002591 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 -06002592 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002593 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2594 VkLayerDispatchTable *pTable = tableMap[pDisp];
2595 pTable->CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002596}
2597
Tony Barbour8205d902015-04-16 15:59:00 -06002598VK_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 -06002599{
2600 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2601 if (pCB) {
2602 updateCBTracking(cmdBuffer);
2603 addCmd(pCB, CMD_PIPELINEBARRIER);
2604 }
2605 else {
2606 char str[1024];
2607 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002608 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 -06002609 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002610 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2611 VkLayerDispatchTable *pTable = tableMap[pDisp];
2612 pTable->CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002613}
2614
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002615VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002616{
2617 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2618 if (pCB) {
2619 updateCBTracking(cmdBuffer);
2620 addCmd(pCB, CMD_BEGINQUERY);
2621 }
2622 else {
2623 char str[1024];
2624 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002625 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 -06002626 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002627 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2628 VkLayerDispatchTable *pTable = tableMap[pDisp];
2629 pTable->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002630}
2631
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002632VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002633{
2634 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2635 if (pCB) {
2636 updateCBTracking(cmdBuffer);
2637 addCmd(pCB, CMD_ENDQUERY);
2638 }
2639 else {
2640 char str[1024];
2641 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002642 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 -06002643 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002644 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2645 VkLayerDispatchTable *pTable = tableMap[pDisp];
2646 pTable->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002647}
2648
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002649VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002650{
2651 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2652 if (pCB) {
2653 updateCBTracking(cmdBuffer);
2654 addCmd(pCB, CMD_RESETQUERYPOOL);
2655 }
2656 else {
2657 char str[1024];
2658 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002659 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 -06002660 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002661 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2662 VkLayerDispatchTable *pTable = tableMap[pDisp];
2663 pTable->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002664}
2665
Tony Barbour8205d902015-04-16 15:59:00 -06002666VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002667{
2668 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2669 if (pCB) {
2670 updateCBTracking(cmdBuffer);
2671 addCmd(pCB, CMD_WRITETIMESTAMP);
2672 }
2673 else {
2674 char str[1024];
2675 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002676 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 -06002677 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002678 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2679 VkLayerDispatchTable *pTable = tableMap[pDisp];
2680 pTable->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002681}
2682
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002683VK_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 -06002684{
2685 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2686 if (pCB) {
2687 updateCBTracking(cmdBuffer);
2688 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2689 }
2690 else {
2691 char str[1024];
2692 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002693 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 -06002694 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002695 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2696 VkLayerDispatchTable *pTable = tableMap[pDisp];
2697 pTable->CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002698}
2699
Tony Barbour8205d902015-04-16 15:59:00 -06002700VK_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 -06002701{
2702 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2703 if (pCB) {
2704 updateCBTracking(cmdBuffer);
2705 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2706 }
2707 else {
2708 char str[1024];
2709 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002710 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 -06002711 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002712 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2713 VkLayerDispatchTable *pTable = tableMap[pDisp];
2714 pTable->CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002715}
2716
Tony Barbour8205d902015-04-16 15:59:00 -06002717VK_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 -06002718{
2719 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2720 if (pCB) {
2721 updateCBTracking(cmdBuffer);
2722 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2723 }
2724 else {
2725 char str[1024];
2726 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002727 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 -06002728 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002729 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2730 VkLayerDispatchTable *pTable = tableMap[pDisp];
2731 pTable->CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002732}
2733
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002734VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002735{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002736 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2737 VkLayerDispatchTable *pTable = tableMap[pDisp];
2738 VkResult result = pTable->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002739 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002740 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002741 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002742 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002743 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2744 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002745 }
2746 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002747 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2748 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002749 }
2750 frameBufferMap[*pFramebuffer] = localFBCI;
2751 }
2752 return result;
2753}
2754
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002755VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002756{
Jon Ashburne0fa2282015-05-20 09:00:28 -06002757 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2758 VkLayerDispatchTable *pTable = tableMap[pDisp];
2759 VkResult result = pTable->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002760 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002761 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002762 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002763 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002764 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2765 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002766 }
2767 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002768 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2769 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002770 }
2771 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002772 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2773 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002774 }
2775 renderPassMap[*pRenderPass] = localRPCI;
2776 }
2777 return result;
2778}
2779
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002780VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002781{
2782 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2783 if (pCB) {
2784 updateCBTracking(cmdBuffer);
2785 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002786 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2787 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002788 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002789 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002790 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002791 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002792 char str[1024];
2793 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002794 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 -06002795 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002796 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2797 VkLayerDispatchTable *pTable = tableMap[pDisp];
2798 pTable->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002799}
2800
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002801VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002802{
2803 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2804 if (pCB) {
2805 updateCBTracking(cmdBuffer);
2806 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002807 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002808 }
2809 else {
2810 char str[1024];
2811 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002812 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 -06002813 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002814 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2815 VkLayerDispatchTable *pTable = tableMap[pDisp];
2816 pTable->CmdEndRenderPass(cmdBuffer, renderPass);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002817}
2818
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002819VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2820 VkInstance instance,
2821 VkFlags msgFlags,
2822 const PFN_vkDbgMsgCallback pfnMsgCallback,
2823 void* pUserData,
2824 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002825{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002826 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2827 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2828 return layer_create_msg_callback(instance, pTable, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002829}
2830
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002831VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2832 VkInstance instance,
2833 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002834{
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002835 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
2836 VkLayerInstanceDispatchTable *pTable = tableInstanceMap[pDisp];
2837 return layer_destroy_msg_callback(instance, pTable, msgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002838}
2839
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002840VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002841{
2842 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002843 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2844 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Jon Ashburnf0615e22015-05-25 14:11:37 -06002845 char str[1024];
2846 sprintf(str, "Attempt to use CmdDbgMarkerBegin but extension disabled!");
2847 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002848 return;
Jon Ashburnf0615e22015-05-25 14:11:37 -06002849 }
2850 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002851 updateCBTracking(cmdBuffer);
2852 addCmd(pCB, CMD_DBGMARKERBEGIN);
2853 }
2854 else {
2855 char str[1024];
2856 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002857 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 -06002858 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002859 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002860}
2861
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002862VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002863{
2864 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002865 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2866 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Jon Ashburnf0615e22015-05-25 14:11:37 -06002867 char str[1024];
2868 sprintf(str, "Attempt to use CmdDbgMarkerEnd but extension disabled!");
2869 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002870 return;
Jon Ashburnf0615e22015-05-25 14:11:37 -06002871 }
2872 else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002873 updateCBTracking(cmdBuffer);
2874 addCmd(pCB, CMD_DBGMARKEREND);
2875 }
2876 else {
2877 char str[1024];
2878 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002879 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 -06002880 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002881 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2882}
2883
2884VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2885{
2886 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2887 if (!deviceExtMap[pDisp].debug_marker_enabled) {
2888 char const str[] = "Attempt to use DbgSetObjectTag but extension disabled!";
2889 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2890 return VK_ERROR_UNAVAILABLE;
2891 }
2892 debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2893}
2894
2895VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2896{
2897 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2898 if (!deviceExtMap[pDisp].debug_marker_enabled) {
2899 char const str[] = "Attempt to use DbgSetObjectName but extension disabled!";
2900 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
2901 return VK_ERROR_UNAVAILABLE;
2902 }
2903 debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002904}
2905
2906// TODO : Want to pass in a cmdBuffer here based on which state to display
2907void drawStateDumpDotFile(char* outFileName)
2908{
2909 // TODO : Currently just setting cmdBuffer based on global var
2910 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2911 dumpGlobalDotFile(outFileName);
2912}
2913
2914void drawStateDumpCommandBufferDotFile(char* outFileName)
2915{
2916 cbDumpDotFile(outFileName);
2917}
2918
2919void drawStateDumpPngFile(char* outFileName)
2920{
2921#if defined(_WIN32)
2922// FIXME: NEED WINDOWS EQUIVALENT
2923 char str[1024];
2924 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002925 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002926#else // WIN32
2927 char dotExe[32] = "/usr/bin/dot";
2928 if( access(dotExe, X_OK) != -1) {
2929 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2930 char dotCmd[1024];
2931 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002932 int retval = system(dotCmd);
2933 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002934 remove("/tmp/tmp.dot");
2935 }
2936 else {
2937 char str[1024];
2938 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002939 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002940 }
2941#endif // WIN32
2942}
2943
Jon Ashburn1245cec2015-05-18 13:20:15 -06002944VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002945{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002946 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002947 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002948
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002949 loader_platform_thread_once(&g_initOnce, initDrawState);
2950
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002951 /* loader uses this to force layer initialization; device object is wrapped */
2952 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
2953 initDeviceTable((const VkBaseLayerObject *) dev);
Jon Ashburn1245cec2015-05-18 13:20:15 -06002954 return (void *) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002955 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002956 if (!strcmp(funcName, "vkDestroyDevice"))
2957 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002958 if (!strcmp(funcName, "vkQueueSubmit"))
2959 return (void*) vkQueueSubmit;
2960 if (!strcmp(funcName, "vkDestroyObject"))
2961 return (void*) vkDestroyObject;
2962 if (!strcmp(funcName, "vkCreateBufferView"))
2963 return (void*) vkCreateBufferView;
2964 if (!strcmp(funcName, "vkCreateImageView"))
2965 return (void*) vkCreateImageView;
2966 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2967 return (void*) vkCreateGraphicsPipeline;
2968 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2969 return (void*) vkCreateGraphicsPipelineDerivative;
2970 if (!strcmp(funcName, "vkCreateSampler"))
2971 return (void*) vkCreateSampler;
2972 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2973 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002974 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2975 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002976 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2977 return (void*) vkCreateDescriptorPool;
2978 if (!strcmp(funcName, "vkResetDescriptorPool"))
2979 return (void*) vkResetDescriptorPool;
2980 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2981 return (void*) vkAllocDescriptorSets;
2982 if (!strcmp(funcName, "vkClearDescriptorSets"))
2983 return (void*) vkClearDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08002984 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
2985 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002986 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2987 return (void*) vkCreateDynamicViewportState;
2988 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2989 return (void*) vkCreateDynamicRasterState;
2990 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2991 return (void*) vkCreateDynamicColorBlendState;
2992 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2993 return (void*) vkCreateDynamicDepthStencilState;
2994 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2995 return (void*) vkCreateCommandBuffer;
2996 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2997 return (void*) vkBeginCommandBuffer;
2998 if (!strcmp(funcName, "vkEndCommandBuffer"))
2999 return (void*) vkEndCommandBuffer;
3000 if (!strcmp(funcName, "vkResetCommandBuffer"))
3001 return (void*) vkResetCommandBuffer;
3002 if (!strcmp(funcName, "vkCmdBindPipeline"))
3003 return (void*) vkCmdBindPipeline;
3004 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
3005 return (void*) vkCmdBindDynamicStateObject;
3006 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
3007 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003008 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
3009 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003010 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
3011 return (void*) vkCmdBindIndexBuffer;
3012 if (!strcmp(funcName, "vkCmdDraw"))
3013 return (void*) vkCmdDraw;
3014 if (!strcmp(funcName, "vkCmdDrawIndexed"))
3015 return (void*) vkCmdDrawIndexed;
3016 if (!strcmp(funcName, "vkCmdDrawIndirect"))
3017 return (void*) vkCmdDrawIndirect;
3018 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
3019 return (void*) vkCmdDrawIndexedIndirect;
3020 if (!strcmp(funcName, "vkCmdDispatch"))
3021 return (void*) vkCmdDispatch;
3022 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
3023 return (void*) vkCmdDispatchIndirect;
3024 if (!strcmp(funcName, "vkCmdCopyBuffer"))
3025 return (void*) vkCmdCopyBuffer;
3026 if (!strcmp(funcName, "vkCmdCopyImage"))
3027 return (void*) vkCmdCopyImage;
3028 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
3029 return (void*) vkCmdCopyBufferToImage;
3030 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
3031 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003032 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
3033 return (void*) vkCmdUpdateBuffer;
3034 if (!strcmp(funcName, "vkCmdFillBuffer"))
3035 return (void*) vkCmdFillBuffer;
3036 if (!strcmp(funcName, "vkCmdClearColorImage"))
3037 return (void*) vkCmdClearColorImage;
3038 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
3039 return (void*) vkCmdClearDepthStencil;
3040 if (!strcmp(funcName, "vkCmdResolveImage"))
3041 return (void*) vkCmdResolveImage;
3042 if (!strcmp(funcName, "vkCmdSetEvent"))
3043 return (void*) vkCmdSetEvent;
3044 if (!strcmp(funcName, "vkCmdResetEvent"))
3045 return (void*) vkCmdResetEvent;
3046 if (!strcmp(funcName, "vkCmdWaitEvents"))
3047 return (void*) vkCmdWaitEvents;
3048 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
3049 return (void*) vkCmdPipelineBarrier;
3050 if (!strcmp(funcName, "vkCmdBeginQuery"))
3051 return (void*) vkCmdBeginQuery;
3052 if (!strcmp(funcName, "vkCmdEndQuery"))
3053 return (void*) vkCmdEndQuery;
3054 if (!strcmp(funcName, "vkCmdResetQueryPool"))
3055 return (void*) vkCmdResetQueryPool;
3056 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
3057 return (void*) vkCmdWriteTimestamp;
3058 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
3059 return (void*) vkCmdInitAtomicCounters;
3060 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
3061 return (void*) vkCmdLoadAtomicCounters;
3062 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
3063 return (void*) vkCmdSaveAtomicCounters;
3064 if (!strcmp(funcName, "vkCreateFramebuffer"))
3065 return (void*) vkCreateFramebuffer;
3066 if (!strcmp(funcName, "vkCreateRenderPass"))
3067 return (void*) vkCreateRenderPass;
3068 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
3069 return (void*) vkCmdBeginRenderPass;
3070 if (!strcmp(funcName, "vkCmdEndRenderPass"))
3071 return (void*) vkCmdEndRenderPass;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003072 if (!strcmp("drawStateDumpDotFile", funcName))
3073 return (void*) drawStateDumpDotFile;
3074 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
3075 return (void*) drawStateDumpCommandBufferDotFile;
3076 if (!strcmp("drawStateDumpPngFile", funcName))
3077 return (void*) drawStateDumpPngFile;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003078
3079 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) dev;
3080 if (!deviceExtMap[pDisp].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003081 {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003082 if (!strcmp(funcName, "CmdDbgMarkerBegin"))
3083 return (void*) vkCmdDbgMarkerBegin;
3084 if (!strcmp(funcName, "CmdDbgMarkerEnd"))
3085 return (void*) vkCmdDbgMarkerEnd;
3086 if (!strcmp(funcName, "DbgSetObjectTag"))
3087 return (void*) vkDbgSetObjectTag;
3088 if (!strcmp(funcName, "DbgSetObjectName"))
3089 return (void*) vkDbgSetObjectName;
3090 }
3091 {
3092 VkLayerDispatchTable* pTable = tableMap[pDisp];
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003093 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003094 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003095 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003096 }
3097}
3098
3099VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3100{
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003101 void *fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003102 if (instance == NULL)
3103 return NULL;
3104
Jon Ashburnd9564002015-05-07 10:27:37 -06003105 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003106
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003107 /* loader uses this to force layer initialization; instance object is wrapped */
3108 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
3109 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003110 return (void *) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003111 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003112 if (!strcmp(funcName, "vkCreateInstance"))
3113 return (void *) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003114 if (!strcmp(funcName, "vkDestroyInstance"))
3115 return (void *) vkDestroyInstance;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003116 if (!strcmp(funcName, "vkCreateDevice"))
3117 return (void*) vkCreateDevice;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003118
3119 fptr = msg_callback_get_proc_addr(funcName);
3120 if (fptr)
3121 return fptr;
3122
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003123 {
3124 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
3125 VkLayerInstanceDispatchTable* pTable = tableInstanceMap[*ppDisp];
3126 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003127 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003128 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003129 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003130}