blob: 39b12b17a855cb92387c5c8d7feb68917799b906 [file] [log] [blame]
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis10ae8c12015-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060035#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036#include "vk_struct_graphviz_helper.h"
Tony Barbour18f71552015-04-22 11:36:22 -060037#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060038#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060039#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060040#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060041#include "draw_state.h"
42#include "layers_config.h"
43// The following is #included again to catch certain OS-specific functions
44// being used:
45#include "loader_platform.h"
46#include "layers_msg.h"
47
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060048unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
49unordered_map<VkImageView, IMAGE_NODE*> imageMap;
50unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
51unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
52unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
53unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
54unordered_map<VkDescriptorSet, SET_NODE*> setMap;
55unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlis793ad302015-04-03 12:01:11 -060056// Map for layout chains
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060057unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
58unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
59unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060060
Jon Ashburnbacb0f52015-04-06 10:58:22 -060061static VkLayerDispatchTable nextTable;
62static VkBaseLayerObject *pCurObj;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060063static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
64// TODO : This can be much smarter, using separate locks for separate global data
65static int globalLockInitialized = 0;
66static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060067#define MAX_TID 513
68static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
69static uint32_t g_maxTID = 0;
70// Map actual TID to an index value and return that index
71// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
72static uint32_t getTIDIndex() {
73 loader_platform_thread_id tid = loader_platform_get_thread_id();
74 for (uint32_t i = 0; i < g_maxTID; i++) {
75 if (tid == g_tidMapping[i])
76 return i;
77 }
78 // Don't yet have mapping, set it and return newly set index
79 uint32_t retVal = (uint32_t) g_maxTID;
80 g_tidMapping[g_maxTID++] = tid;
81 assert(g_maxTID < MAX_TID);
82 return retVal;
83}
84// Return a string representation of CMD_TYPE enum
85static string cmdTypeToString(CMD_TYPE cmd)
86{
87 switch (cmd)
88 {
89 case CMD_BINDPIPELINE:
90 return "CMD_BINDPIPELINE";
91 case CMD_BINDPIPELINEDELTA:
92 return "CMD_BINDPIPELINEDELTA";
93 case CMD_BINDDYNAMICSTATEOBJECT:
94 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlis793ad302015-04-03 12:01:11 -060095 case CMD_BINDDESCRIPTORSETS:
96 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060097 case CMD_BINDINDEXBUFFER:
98 return "CMD_BINDINDEXBUFFER";
99 case CMD_BINDVERTEXBUFFER:
100 return "CMD_BINDVERTEXBUFFER";
101 case CMD_DRAW:
102 return "CMD_DRAW";
103 case CMD_DRAWINDEXED:
104 return "CMD_DRAWINDEXED";
105 case CMD_DRAWINDIRECT:
106 return "CMD_DRAWINDIRECT";
107 case CMD_DRAWINDEXEDINDIRECT:
108 return "CMD_DRAWINDEXEDINDIRECT";
109 case CMD_DISPATCH:
110 return "CMD_DISPATCH";
111 case CMD_DISPATCHINDIRECT:
112 return "CMD_DISPATCHINDIRECT";
113 case CMD_COPYBUFFER:
114 return "CMD_COPYBUFFER";
115 case CMD_COPYIMAGE:
116 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600117 case CMD_BLITIMAGE:
118 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600119 case CMD_COPYBUFFERTOIMAGE:
120 return "CMD_COPYBUFFERTOIMAGE";
121 case CMD_COPYIMAGETOBUFFER:
122 return "CMD_COPYIMAGETOBUFFER";
123 case CMD_CLONEIMAGEDATA:
124 return "CMD_CLONEIMAGEDATA";
125 case CMD_UPDATEBUFFER:
126 return "CMD_UPDATEBUFFER";
127 case CMD_FILLBUFFER:
128 return "CMD_FILLBUFFER";
129 case CMD_CLEARCOLORIMAGE:
130 return "CMD_CLEARCOLORIMAGE";
131 case CMD_CLEARCOLORIMAGERAW:
132 return "CMD_CLEARCOLORIMAGERAW";
133 case CMD_CLEARDEPTHSTENCIL:
134 return "CMD_CLEARDEPTHSTENCIL";
135 case CMD_RESOLVEIMAGE:
136 return "CMD_RESOLVEIMAGE";
137 case CMD_SETEVENT:
138 return "CMD_SETEVENT";
139 case CMD_RESETEVENT:
140 return "CMD_RESETEVENT";
141 case CMD_WAITEVENTS:
142 return "CMD_WAITEVENTS";
143 case CMD_PIPELINEBARRIER:
144 return "CMD_PIPELINEBARRIER";
145 case CMD_BEGINQUERY:
146 return "CMD_BEGINQUERY";
147 case CMD_ENDQUERY:
148 return "CMD_ENDQUERY";
149 case CMD_RESETQUERYPOOL:
150 return "CMD_RESETQUERYPOOL";
151 case CMD_WRITETIMESTAMP:
152 return "CMD_WRITETIMESTAMP";
153 case CMD_INITATOMICCOUNTERS:
154 return "CMD_INITATOMICCOUNTERS";
155 case CMD_LOADATOMICCOUNTERS:
156 return "CMD_LOADATOMICCOUNTERS";
157 case CMD_SAVEATOMICCOUNTERS:
158 return "CMD_SAVEATOMICCOUNTERS";
159 case CMD_BEGINRENDERPASS:
160 return "CMD_BEGINRENDERPASS";
161 case CMD_ENDRENDERPASS:
162 return "CMD_ENDRENDERPASS";
163 case CMD_DBGMARKERBEGIN:
164 return "CMD_DBGMARKERBEGIN";
165 case CMD_DBGMARKEREND:
166 return "CMD_DBGMARKEREND";
167 default:
168 return "UNKNOWN";
169 }
170}
171// Block of code at start here for managing/tracking Pipeline state that this layer cares about
172// Just track 2 shaders for now
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600173#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600174#define MAX_SLOTS 2048
175#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
176
177static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
178
179// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
180// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
181// to that same cmd buffer by separate thread are not changing state from underneath us
182// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600183static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600184// Track the last group of CBs touched for displaying to dot file
185static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
186static uint32_t g_lastTouchedCBIndex = 0;
187// Track the last global DrawState of interest touched by any thread
188static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
189static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600190static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600191static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600192#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
193
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600194//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600195
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600196static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600197{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600198 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600199 size_t scSize = 0;
200 size_t vpSize = 0;
201 loader_platform_thread_lock_mutex(&globalLock);
202 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
203 pStateNode->stateObj = state;
204 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600205 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600206 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
207 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
208 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
209 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
210 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
211 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600212 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
213 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
214 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600215 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600216 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600217 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600218 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600219 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600220 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600221 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600222 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600223 break;
224 default:
225 assert(0);
226 break;
227 }
228 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
229 dynamicStateMap[state] = pStateNode;
230 loader_platform_thread_unlock_mutex(&globalLock);
231}
232// Free all allocated nodes for Dynamic State objs
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600233static void deleteDynamicState()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600234{
David Pinedod8f83d82015-04-27 16:36:17 -0600235 if (dynamicStateMap.size() <= 0)
236 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600237 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600238 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600239 delete[] (*ii).second->create_info.vpci.pScissors;
240 delete[] (*ii).second->create_info.vpci.pViewports;
241 }
242 delete (*ii).second;
243 }
244}
245// Free all sampler nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600246static void deleteSamplers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600247{
David Pinedod8f83d82015-04-27 16:36:17 -0600248 if (sampleMap.size() <= 0)
249 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600250 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600251 delete (*ii).second;
252 }
253}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600254static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600255{
256 loader_platform_thread_lock_mutex(&globalLock);
257 if (imageMap.find(view) == imageMap.end()) {
258 loader_platform_thread_unlock_mutex(&globalLock);
259 return NULL;
260 }
261 else {
262 loader_platform_thread_unlock_mutex(&globalLock);
263 return &imageMap[view]->createInfo;
264 }
265}
266// Free all image nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600267static void deleteImages()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600268{
David Pinedod8f83d82015-04-27 16:36:17 -0600269 if (imageMap.size() <= 0)
270 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600271 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600272 delete (*ii).second;
273 }
274}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600275static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600276{
277 loader_platform_thread_lock_mutex(&globalLock);
278 if (bufferMap.find(view) == bufferMap.end()) {
279 loader_platform_thread_unlock_mutex(&globalLock);
280 return NULL;
281 }
282 else {
283 loader_platform_thread_unlock_mutex(&globalLock);
284 return &bufferMap[view]->createInfo;
285 }
286}
287// Free all buffer nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600288static void deleteBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600289{
David Pinedod8f83d82015-04-27 16:36:17 -0600290 if (bufferMap.size() <= 0)
291 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600292 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600293 delete (*ii).second;
294 }
295}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600296static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600297
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600298static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600299{
300 g_lastCmdBuffer[getTIDIndex()] = cb;
301 GLOBAL_CB_NODE* pCB = getCBNode(cb);
302 loader_platform_thread_lock_mutex(&globalLock);
303 g_lastGlobalCB = pCB;
304 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
305 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
306 if (g_pLastTouchedCB[i] == pCB) {
307 loader_platform_thread_unlock_mutex(&globalLock);
308 return;
309 }
310 }
311 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
312 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
313 loader_platform_thread_unlock_mutex(&globalLock);
314}
315
316// Print the last bound dynamic state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600317static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600318{
319 GLOBAL_CB_NODE* pCB = getCBNode(cb);
320 if (pCB) {
321 loader_platform_thread_lock_mutex(&globalLock);
322 char str[4*1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600323 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600324 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600325 sprintf(str, "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600326 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
327 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", dynamic_display(pCB->lastBoundDynamicState[i]->pCreateInfo, " ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600328 break;
329 }
330 else {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600331 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600332 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600333 }
334 }
335 loader_platform_thread_unlock_mutex(&globalLock);
336 }
337 else {
338 char str[1024];
339 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600340 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600341 }
342}
343// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600345{
346 loader_platform_thread_lock_mutex(&globalLock);
347 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
348 loader_platform_thread_unlock_mutex(&globalLock);
349 return NULL;
350 }
351 loader_platform_thread_unlock_mutex(&globalLock);
352 return pipelineMap[pipeline];
353}
354
355// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600356static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600357{
358 loader_platform_thread_lock_mutex(&globalLock);
359 if (sampleMap.find(sampler) == sampleMap.end()) {
360 loader_platform_thread_unlock_mutex(&globalLock);
361 return NULL;
362 }
363 loader_platform_thread_unlock_mutex(&globalLock);
364 return &sampleMap[sampler]->createInfo;
365}
366
367// Init the pipeline mapping info based on pipeline create info LL tree
368// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600370{
371 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehliseba312c2015-04-01 08:40:34 -0600372 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600373 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600374 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600375 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600376 size_t bufferSize = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600377 VkPipelineVertexInputCreateInfo* pVICI = NULL;
378 VkPipelineCbStateCreateInfo* pCBCI = NULL;
379 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600380 while (pTrav) {
381 switch (pTrav->sType) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600382 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600383 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600384 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600385 case VK_SHADER_STAGE_VERTEX:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600386 pPrev->pNext = &pPipeline->vsCI;
387 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600388 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600389 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600390 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600391 pPrev->pNext = &pPipeline->tcsCI;
392 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600393 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600394 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600395 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600396 pPrev->pNext = &pPipeline->tesCI;
397 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600398 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600399 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600400 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600401 pPrev->pNext = &pPipeline->gsCI;
402 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600404 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600405 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600406 pPrev->pNext = &pPipeline->fsCI;
407 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600408 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600409 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600410 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600411 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600412 break;
413 default:
414 // TODO : Flag error
415 break;
416 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600417 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600418 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600419 pPrev->pNext = &pPipeline->vertexInputCI;
420 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600421 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600422 // Copy embedded ptrs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600423 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600424 pPipeline->vtxBindingCount = pVICI->bindingCount;
425 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600426 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
427 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
428 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600429 }
430 pPipeline->vtxAttributeCount = pVICI->attributeCount;
431 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600432 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
433 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
434 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600435 }
436 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600437 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600438 pPrev->pNext = &pPipeline->iaStateCI;
439 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600440 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600441 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600442 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600443 pPrev->pNext = &pPipeline->tessStateCI;
444 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600445 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600446 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600447 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600448 pPrev->pNext = &pPipeline->vpStateCI;
449 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600450 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600451 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600452 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600453 pPrev->pNext = &pPipeline->rsStateCI;
454 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600455 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600456 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600457 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600458 pPrev->pNext = &pPipeline->msStateCI;
459 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600460 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600461 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600462 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600463 pPrev->pNext = &pPipeline->cbStateCI;
464 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600465 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600466 // Copy embedded ptrs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600467 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600468 pPipeline->attachmentCount = pCBCI->attachmentCount;
469 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600470 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
471 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
472 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600473 }
474 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600475 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600476 pPrev->pNext = &pPipeline->dsStateCI;
477 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600478 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600479 break;
480 default:
481 assert(0);
482 break;
483 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600484 pTrav = (GENERIC_HEADER*)pTrav->pNext;
485 }
486 pipelineMap[pPipeline->pipeline] = pPipeline;
487}
488// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600489static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600490{
David Pinedod8f83d82015-04-27 16:36:17 -0600491 if (pipelineMap.size() <= 0)
492 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600493 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600494 if ((*ii).second->pVertexBindingDescriptions) {
495 delete[] (*ii).second->pVertexBindingDescriptions;
496 }
497 if ((*ii).second->pVertexAttributeDescriptions) {
498 delete[] (*ii).second->pVertexAttributeDescriptions;
499 }
500 if ((*ii).second->pAttachments) {
501 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600502 }
503 delete (*ii).second;
504 }
505}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600506// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600507static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600508{
509 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600510 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600511 if (pPipe->msStateCI.multisampleEnable)
512 return pPipe->msStateCI.samples;
Tobin Ehliseba312c2015-04-01 08:40:34 -0600513 }
514 return 1;
515}
516// Validate state related to the PSO
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600517static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600518{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600519 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600520 // Verify that any MSAA request in PSO matches sample# in bound FB
521 uint32_t psoNumSamples = getNumSamples(pipeline);
522 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600523 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
524 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis7c3ec602015-05-21 09:06:56 -0600525 if ((psoNumSamples != pFBCI->sampleCount) || (psoNumSamples != pRPCI->sampleCount)) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600526 char str[1024];
Tobin Ehlis7c3ec602015-05-21 09:06:56 -0600527 sprintf(str, "Num samples mismatche! 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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600528 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
Tobin Ehliseba312c2015-04-01 08:40:34 -0600529 }
530 } else {
531 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
532 // Verify and flag error as appropriate
533 }
534 // TODO : Add more checks here
535 } else {
536 // TODO : Validate non-gfx pipeline updates
537 }
538}
539
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600540// Block of code at start here specifically for managing/tracking DSs
541
Tobin Ehlis793ad302015-04-03 12:01:11 -0600542// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600543static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600544{
545 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600546 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600547 loader_platform_thread_unlock_mutex(&globalLock);
548 return NULL;
549 }
550 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600551 return poolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600552}
553// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600554static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600555{
556 loader_platform_thread_lock_mutex(&globalLock);
557 if (setMap.find(set) == setMap.end()) {
558 loader_platform_thread_unlock_mutex(&globalLock);
559 return NULL;
560 }
561 loader_platform_thread_unlock_mutex(&globalLock);
562 return setMap[set];
563}
564
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600565// Return VK_TRUE if DS Exists and is within an vkBeginDescriptorPoolUpdate() call sequence, otherwise VK_FALSE
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600566static bool32_t dsUpdateActive(VkDescriptorSet ds)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600567{
568 // Note, both "get" functions use global mutex so this guy does not
569 SET_NODE* pTrav = getSetNode(ds);
570 if (pTrav) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600571 POOL_NODE* pPool = getPoolNode(pTrav->pool);
572 if (pPool) {
573 return pPool->updateActive;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600574 }
575 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600576 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600577}
578
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600579static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600580 loader_platform_thread_lock_mutex(&globalLock);
581 if (layoutMap.find(layout) == layoutMap.end()) {
582 loader_platform_thread_unlock_mutex(&globalLock);
583 return NULL;
584 }
585 loader_platform_thread_unlock_mutex(&globalLock);
586 return layoutMap[layout];
587}
588
Tobin Ehlis793ad302015-04-03 12:01:11 -0600589// For given update struct, return binding
590static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600591{
592 switch (pUpdateStruct->sType)
593 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600594 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600595 return ((VkUpdateSamplers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600596 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600597 return ((VkUpdateSamplerTextures*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600598 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600599 return ((VkUpdateImages*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600600 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600601 return ((VkUpdateBuffers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600602 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600603 return ((VkUpdateAsCopy*)pUpdateStruct)->binding;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600604 default:
605 // TODO : Flag specific error for this case
Tobin Ehlis793ad302015-04-03 12:01:11 -0600606 assert(0);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600607 return 0;
608 }
609}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600610// Return count for given update struct
611static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600612{
613 switch (pUpdateStruct->sType)
614 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600615 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600616 return (((VkUpdateSamplers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600617 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600618 return (((VkUpdateSamplerTextures*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600620 return (((VkUpdateImages*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600621 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600622 return (((VkUpdateBuffers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600623 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600624 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600625 return (((VkUpdateAsCopy*)pUpdateStruct)->arrayElement);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600626 default:
627 // TODO : Flag specific error for this case
Tobin Ehlis793ad302015-04-03 12:01:11 -0600628 assert(0);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600629 return 0;
630 }
631}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600632// Return count for given update struct
633static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
634{
635 switch (pUpdateStruct->sType)
636 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600637 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600638 return (((VkUpdateSamplers*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600639 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600640 return (((VkUpdateSamplerTextures*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600641 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600642 return (((VkUpdateImages*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600643 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600644 return (((VkUpdateBuffers*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600645 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600646 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600647 return (((VkUpdateAsCopy*)pUpdateStruct)->count);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600648 default:
649 // TODO : Flag specific error for this case
650 assert(0);
651 return 0;
652 }
653}
654// For given Layout Node and binding, return index where that binding begins
655static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
656{
657 uint32_t offsetIndex = 0;
658 for (uint32_t i = 0; i<binding; i++) {
659 offsetIndex += pLayout->createInfo.pBinding[i].count;
660 }
661 return offsetIndex;
662}
663// For given layout node and binding, return last index that is updated
664static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
665{
666 uint32_t offsetIndex = 0;
667 for (uint32_t i = 0; i<=binding; i++) {
668 offsetIndex += pLayout->createInfo.pBinding[i].count;
669 }
670 return offsetIndex-1;
671}
672// For given layout and update, return the first overall index of the layout that is update
673static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
674{
675 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
676}
677// For given layout and update, return the last overall index of the layout that is update
678static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
679{
680 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
681}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600682// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis793ad302015-04-03 12:01:11 -0600683static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600684{
685 // First get actual type of update
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600686 VkDescriptorType actualType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600687 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600688 switch (pUpdateStruct->sType)
689 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600690 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
691 actualType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600692 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600693 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600694 actualType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600695 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600696 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600697 actualType = ((VkUpdateImages*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600698 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600699 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600700 actualType = ((VkUpdateBuffers*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600701 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600702 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600703 actualType = ((VkUpdateAsCopy*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600704 break;
705 default:
706 // TODO : Flag specific error for this case
707 return 0;
708 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600709 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600710 if (pLayout->pTypes[i] != actualType)
711 return 0;
712 }
713 return 1;
714}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600715// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
716// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
717// NOTE : Calls to this function should be wrapped in mutex
718static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
719{
720 GENERIC_HEADER* pNewNode = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600721 VkUpdateSamplers* pUS = NULL;
722 VkUpdateSamplerTextures* pUST = NULL;
723 VkUpdateBuffers* pUB = NULL;
724 VkUpdateImages* pUI = NULL;
725 VkUpdateAsCopy* pUAC = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600726 size_t array_size = 0;
727 size_t base_array_size = 0;
728 size_t total_array_size = 0;
729 size_t baseBuffAddr = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600730 VkImageViewAttachInfo** ppLocalImageViews = NULL;
731 VkBufferViewAttachInfo** ppLocalBufferViews = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600732 char str[1024];
733 switch (pUpdate->sType)
734 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600735 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600736 pUS = new VkUpdateSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600737 pNewNode = (GENERIC_HEADER*)pUS;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600738 memcpy(pUS, pUpdate, sizeof(VkUpdateSamplers));
739 pUS->pSamplers = new VkSampler[pUS->count];
740 array_size = sizeof(VkSampler) * pUS->count;
741 memcpy((void*)pUS->pSamplers, ((VkUpdateSamplers*)pUpdate)->pSamplers, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600742 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600743 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600744 pUST = new VkUpdateSamplerTextures;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600745 pNewNode = (GENERIC_HEADER*)pUST;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600746 memcpy(pUST, pUpdate, sizeof(VkUpdateSamplerTextures));
747 pUST->pSamplerImageViews = new VkSamplerImageViewInfo[pUST->count];
748 array_size = sizeof(VkSamplerImageViewInfo) * pUST->count;
749 memcpy((void*)pUST->pSamplerImageViews, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews, array_size);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600750 for (uint32_t i = 0; i < pUST->count; i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600751 VkImageViewAttachInfo** ppIV = (VkImageViewAttachInfo**)&pUST->pSamplerImageViews[i].pImageView;
752 *ppIV = new VkImageViewAttachInfo;
753 memcpy((void*)*ppIV, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews[i].pImageView, sizeof(VkImageViewAttachInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600754 }
755 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600756 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600757 pUI = new VkUpdateImages;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600758 pNewNode = (GENERIC_HEADER*)pUI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600759 memcpy(pUI, pUpdate, sizeof(VkUpdateImages));
760 pUI->pImageViews = new VkImageViewAttachInfo[pUI->count];
761 array_size = (sizeof(VkImageViewAttachInfo) * pUI->count);
762 memcpy((void*)pUI->pImageViews, ((VkUpdateImages*)pUpdate)->pImageViews, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600763 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600764 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600765 pUB = new VkUpdateBuffers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600766 pNewNode = (GENERIC_HEADER*)pUB;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600767 memcpy(pUB, pUpdate, sizeof(VkUpdateBuffers));
768 pUB->pBufferViews = new VkBufferViewAttachInfo[pUB->count];
769 array_size = (sizeof(VkBufferViewAttachInfo) * pUB->count);
770 memcpy((void*)pUB->pBufferViews, ((VkUpdateBuffers*)pUpdate)->pBufferViews, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600771 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600772 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600773 pUAC = new VkUpdateAsCopy;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600774 pUpdate = (GENERIC_HEADER*)pUAC;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600775 memcpy(pUAC, pUpdate, sizeof(VkUpdateAsCopy));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600776 break;
777 default:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600778 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600779 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600780 return NULL;
781 }
782 // Make sure that pNext for the end of shadow copy is NULL
783 pNewNode->pNext = NULL;
784 return pNewNode;
785}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600786// For given ds, update its mapping based on ppUpdateArray
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600787static void dsUpdate(VkDescriptorSet ds, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600788{
789 SET_NODE* pSet = getSetNode(ds);
790 loader_platform_thread_lock_mutex(&globalLock);
791 g_lastBoundDescriptorSet = pSet->set;
792 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600793 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600794 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600795 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600796 for (uint32_t i = 0; i < updateCount; i++) {
797 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*)ppUpdateArray[i];
798 pLayout = pSet->pLayout;
799 // Make sure that binding is within bounds
800 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600801 char str[1024];
Courtney Goeltzenleuchterfb4efc62015-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600803 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600804 }
805 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600806 // Next verify that update falls within size of given binding
807 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600808 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlis793ad302015-04-03 12:01:11 -0600809 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600810 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
811 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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600812 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600813 }
814 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600815 // Layout bindings match w/ update ok, now verify that update is of the right type
816 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600817 char str[1024];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600818 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600819 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600820 }
821 else {
822 // Save the update info
823 // TODO : Info message that update successful
824 // Create new update struct for this set's shadow copy
Tobin Ehlis793ad302015-04-03 12:01:11 -0600825 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600826 if (NULL == pNewNode) {
827 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600828 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
829 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600830 }
831 else {
832 // Insert shadow node into LL of updates for this set
833 pNewNode->pNext = pSet->pUpdateStructs;
834 pSet->pUpdateStructs = pNewNode;
835 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis793ad302015-04-03 12:01:11 -0600836 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
837 assert(j<pSet->descriptorCount);
838 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600839 }
840 }
841 }
842 }
843 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600844 }
845 loader_platform_thread_unlock_mutex(&globalLock);
846}
847// Free the shadowed update node for this Set
848// NOTE : Calls to this function should be wrapped in mutex
849static void freeShadowUpdateTree(SET_NODE* pSet)
850{
851 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
852 pSet->pUpdateStructs = NULL;
853 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
854 // Clear the descriptor mappings as they will now be invalid
855 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
856 while(pShadowUpdate) {
857 pFreeUpdate = pShadowUpdate;
858 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
859 uint32_t index = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600860 VkUpdateSamplers* pUS = NULL;
861 VkUpdateSamplerTextures* pUST = NULL;
862 VkUpdateImages* pUI = NULL;
863 VkUpdateBuffers* pUB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600864 void** ppToFree = NULL;
865 switch (pFreeUpdate->sType)
866 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600867 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600868 pUS = (VkUpdateSamplers*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600869 if (pUS->pSamplers)
870 delete[] pUS->pSamplers;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600871 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600872 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600873 pUST = (VkUpdateSamplerTextures*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600874 if (pUST->pSamplerImageViews) {
875 for (index = 0; index < pUST->count; index++) {
876 if (pUST->pSamplerImageViews[index].pImageView) {
877 delete pUST->pSamplerImageViews[index].pImageView;
878 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600879 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600880 delete[] pUST->pSamplerImageViews;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600881 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600882 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600883 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600884 pUI = (VkUpdateImages*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600885 if (pUI->pImageViews)
886 delete[] pUI->pImageViews;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600887 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600888 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600889 pUB = (VkUpdateBuffers*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600890 if (pUB->pBufferViews)
891 delete[] pUB->pBufferViews;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600892 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600893 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600894 break;
895 default:
896 assert(0);
897 break;
898 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600899 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600900 }
901}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600902// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600903// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600904static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600905{
David Pinedod8f83d82015-04-27 16:36:17 -0600906 if (poolMap.size() <= 0)
907 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600908 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600909 SET_NODE* pSet = (*ii).second->pSets;
910 SET_NODE* pFreeSet = pSet;
911 while (pSet) {
912 pFreeSet = pSet;
913 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600914 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600915 // Free Update shadow struct tree
916 freeShadowUpdateTree(pFreeSet);
917 if (pFreeSet->ppDescriptors) {
918 delete pFreeSet->ppDescriptors;
919 }
920 delete pFreeSet;
921 }
922 if ((*ii).second->createInfo.pTypeCount) {
923 delete (*ii).second->createInfo.pTypeCount;
924 }
925 delete (*ii).second;
926 }
927}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600928// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600929// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600930static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600931{
David Pinedod8f83d82015-04-27 16:36:17 -0600932 if (layoutMap.size() <= 0)
933 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600934 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600935 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600936 if (pLayout->createInfo.pBinding) {
937 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
938 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
939 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
940 }
941 delete[] pLayout->createInfo.pBinding;
942 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600943 if (pLayout->pTypes) {
944 delete pLayout->pTypes;
945 }
946 delete pLayout;
947 }
948}
949// Currently clearing a set is removing all previous updates to that set
950// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600951static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600952{
953 SET_NODE* pSet = getSetNode(set);
954 if (!pSet) {
955 // TODO : Return error
956 }
957 else {
958 loader_platform_thread_lock_mutex(&globalLock);
959 freeShadowUpdateTree(pSet);
960 loader_platform_thread_unlock_mutex(&globalLock);
961 }
962}
963
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600964static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600965{
Tobin Ehlis793ad302015-04-03 12:01:11 -0600966 POOL_NODE* pPool = getPoolNode(pool);
967 if (!pPool) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600968 char str[1024];
Tobin Ehlisa9f3d762015-05-22 12:38:16 -0600969 sprintf(str, "Unable to find pool node for pool %p specified in vkResetDescriptorPool() call", (void*)pool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600970 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600971 }
972 else
973 {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600974 // For every set off of this pool, clear it
975 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600976 while (pSet) {
977 clearDescriptorSet(pSet->set);
978 }
979 }
980}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600981// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600982static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600983{
984 loader_platform_thread_lock_mutex(&globalLock);
985 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
986 loader_platform_thread_unlock_mutex(&globalLock);
987 return NULL;
988 }
989 loader_platform_thread_unlock_mutex(&globalLock);
990 return cmdBufferMap[cb];
991}
992// Free all CB Nodes
993// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600994static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600995{
David Pinedod8f83d82015-04-27 16:36:17 -0600996 if (cmdBufferMap.size() <= 0)
997 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600998 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -0600999 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1000 while (!cmd_node_list.empty()) {
1001 CMD_NODE* cmd_node = cmd_node_list.back();
1002 delete cmd_node;
1003 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001004 }
1005 delete (*ii).second;
1006 }
1007}
1008static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1009{
1010 CMD_NODE* pCmd = new CMD_NODE;
1011 if (pCmd) {
1012 // init cmd node and append to end of cmd LL
1013 memset(pCmd, 0, sizeof(CMD_NODE));
1014 pCmd->cmdNumber = ++pCB->numCmds;
1015 pCmd->type = cmd;
1016 pCB->pCmds.push_back(pCmd);
1017 }
1018 else {
1019 char str[1024];
1020 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001021 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001022 }
1023}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001024static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001025{
1026 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1027 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001028 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1029 while (!cmd_list.empty()) {
1030 delete cmd_list.back();
1031 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001032 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001033 pCB->pCmds.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001034 // Reset CB state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001035 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001036 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001037 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1038 pCB->cmdBuffer = cb;
1039 pCB->flags = saveFlags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001040 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001041 pCB->lastVtxBinding = MAX_BINDING;
1042 }
1043}
1044// Set the last bound dynamic state of given type
1045// TODO : Need to track this per cmdBuffer and correlate cmdBuffer for Draw w/ last bound for that cmdBuffer?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001046static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001047{
1048 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1049 if (pCB) {
1050 updateCBTracking(cmdBuffer);
1051 loader_platform_thread_lock_mutex(&globalLock);
1052 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1053 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1054 char str[1024];
1055 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001056 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001057 }
1058 else {
1059 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1060 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1061 }
1062 loader_platform_thread_unlock_mutex(&globalLock);
1063 }
1064 else {
1065 char str[1024];
1066 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001067 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001068 }
1069}
1070// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001071static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001072{
1073 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1074 if (pCB) {
1075 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1076 if (!pPipeTrav) {
1077 // nothing to print
1078 }
1079 else {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001080 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001081 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001082 }
1083 }
1084}
1085// Common Dot dumping code
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001086static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001087{
1088 SET_NODE* pSet = getSetNode(ds);
1089 if (pSet) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001090 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001091 char tmp_str[4*1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001092 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1093 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001094 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001095 fprintf(pOutFile, "%s", pGVstr);
1096 free(pGVstr);
1097 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1098 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001099 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001100 uint32_t layout_index = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001101 ++layout_index;
1102 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001103 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001104 fprintf(pOutFile, "%s", pGVstr);
1105 free(pGVstr);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001106 if (pSet->pUpdateStructs) {
1107 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1108 fprintf(pOutFile, "%s", pGVstr);
1109 free(pGVstr);
1110 }
1111 if (pSet->ppDescriptors) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001112 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1113 uint32_t i = 0;
1114 for (i=0; i < pSet->descriptorCount; i++) {
1115 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001116 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_VkStructureType(pSet->ppDescriptors[i]->sType));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001117 }
1118 }
1119#define NUM_COLORS 7
1120 vector<string> edgeColors;
1121 edgeColors.push_back("0000ff");
1122 edgeColors.push_back("ff00ff");
1123 edgeColors.push_back("ffff00");
1124 edgeColors.push_back("00ff00");
1125 edgeColors.push_back("000000");
1126 edgeColors.push_back("00ffff");
1127 edgeColors.push_back("ff0000");
1128 uint32_t colorIdx = 0;
1129 fprintf(pOutFile, "</TABLE>>\n];\n");
1130 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001131 VkUpdateSamplers* pUS = NULL;
1132 VkUpdateSamplerTextures* pUST = NULL;
1133 VkUpdateImages* pUI = NULL;
1134 VkUpdateBuffers* pUB = NULL;
1135 VkUpdateAsCopy* pUAC = NULL;
1136 VkSamplerCreateInfo* pSCI = NULL;
1137 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001138 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001139 void** ppNextPtr = NULL;
1140 void* pSaveNext = NULL;
1141 for (i=0; i < pSet->descriptorCount; i++) {
1142 if (pSet->ppDescriptors[i]) {
1143 switch (pSet->ppDescriptors[i]->sType)
1144 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001145 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001146 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001147 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001148 if (pSCI) {
1149 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001150 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001151 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1152 }
1153 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001154 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001155 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterf39b3ec2015-04-09 11:43:10 -06001156 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001157 if (pSCI) {
1158 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001159 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001160 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1161 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001162 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001163 if (pIVCI) {
1164 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001165 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001166 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1167 }
1168 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001169 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001170 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001171 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001172 if (pIVCI) {
1173 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001174 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001175 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1176 }
1177 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001178 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001179 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001180 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001181 if (pBVCI) {
1182 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001183 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001184 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1185 }
1186 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001187 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001188 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001189 // TODO : Need to validate this code
1190 // Save off pNext and set to NULL while printing this struct, then restore it
1191 ppNextPtr = (void**)&pUAC->pNext;
1192 pSaveNext = *ppNextPtr;
1193 *ppNextPtr = NULL;
1194 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001195 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001196 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1197 // Restore next ptr
1198 *ppNextPtr = pSaveNext;
1199 break;
1200 default:
1201 break;
1202 }
1203 colorIdx = (colorIdx+1) % NUM_COLORS;
1204 }
1205 }
1206 }
1207 fprintf(pOutFile, "}\n");
1208 fprintf(pOutFile, "}\n");
1209 }
1210}
1211// Dump subgraph w/ DS info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001212static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001213{
1214 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1215 if (pCB && pCB->lastBoundDescriptorSet) {
1216 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1217 }
1218}
1219// Dump a GraphViz dot file showing the Cmd Buffers
1220static void cbDumpDotFile(string outFileName)
1221{
1222 // Print CB Chain for each CB
1223 FILE* pOutFile;
1224 pOutFile = fopen(outFileName.c_str(), "w");
1225 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1226 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1227 GLOBAL_CB_NODE* pCB = NULL;
1228 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1229 pCB = g_pLastTouchedCB[i];
David Pinedod8f83d82015-04-27 16:36:17 -06001230 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001231 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1232 uint32_t instNum = 0;
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001233 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1234 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001235 if (instNum) {
1236 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1237 }
1238 if (pCB == g_lastGlobalCB) {
1239 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());
1240 }
1241 else {
1242 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());
1243 }
1244 ++instNum;
1245 }
1246 fprintf(pOutFile, "}\n");
1247 }
1248 }
1249 fprintf(pOutFile, "}\n");
1250 fprintf(pOutFile, "}\n"); // close main graph "g"
1251 fclose(pOutFile);
1252}
1253// Dump a GraphViz dot file showing the pipeline for last bound global state
1254static void dumpGlobalDotFile(char *outFileName)
1255{
1256 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1257 if (pPipeTrav) {
1258 FILE* pOutFile;
1259 pOutFile = fopen(outFileName, "w");
1260 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1261 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1262 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001263 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001264 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001265 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001266 fprintf(pOutFile, "%s", pGVstr);
1267 free(pGVstr);
1268 }
1269 }
1270 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1271 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001272 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001273 fprintf(pOutFile, "%s", pGVstr);
1274 free(pGVstr);
1275 fprintf(pOutFile, "}\n");
1276 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1277 fprintf(pOutFile, "}\n"); // close main graph "g"
1278 fclose(pOutFile);
1279 }
1280}
1281// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001282static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001283{
1284 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1285 if (pCB) {
1286 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1287 if (pPipeTrav) {
1288 FILE* pOutFile;
1289 pOutFile = fopen(outFileName.c_str(), "w");
1290 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1291 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1292 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001293 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001294 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001295 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001296 fprintf(pOutFile, "%s", pGVstr);
1297 free(pGVstr);
1298 }
1299 }
1300 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1301 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001302 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001303 fprintf(pOutFile, "%s", pGVstr);
1304 free(pGVstr);
1305 fprintf(pOutFile, "}\n");
1306 dsDumpDot(cb, pOutFile);
1307 fprintf(pOutFile, "}\n"); // close main graph "g"
1308 fclose(pOutFile);
1309 }
1310 }
1311}
1312// Verify VB Buffer binding
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001313static void validateVBBinding(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001314{
1315 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1316 if (pCB && pCB->lastBoundPipeline) {
1317 // First verify that we have a Node for bound pipeline
1318 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1319 char str[1024];
1320 if (!pPipeTrav) {
1321 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001322 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001323 }
1324 else {
1325 // Verify Vtx binding
1326 if (MAX_BINDING != pCB->lastVtxBinding) {
1327 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1328 if (0 == pPipeTrav->vtxBindingCount) {
1329 sprintf(str, "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001330 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001331 }
1332 else {
1333 sprintf(str, "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001334 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001335 }
1336 }
1337 else {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001338 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001339 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001340 }
1341 }
1342 }
1343 }
1344}
1345// Print details of DS config to stdout
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001346static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001347{
1348 char tmp_str[1024];
1349 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.
1350 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1351 if (pCB) {
1352 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001353 POOL_NODE* pPool = getPoolNode(pSet->pool);
1354 // Print out pool details
1355 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001356 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001357 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis793ad302015-04-03 12:01:11 -06001358 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001359 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001360 // Print out set details
1361 char prefix[10];
1362 uint32_t index = 0;
1363 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001364 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001365 LAYOUT_NODE* pLayout = pSet->pLayout;
1366 // Print layout details
1367 sprintf(tmp_str, "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001368 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001369 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001370 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis793ad302015-04-03 12:01:11 -06001371 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001372 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001373 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001374 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1375 if (pUpdate) {
1376 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001377 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001378 sprintf(prefix, " [UC] ");
1379 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001380 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001381 // TODO : If there is a "view" associated with this update, print CI for that view
1382 }
1383 else {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001384 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1385 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001386 }
1387 }
1388}
1389
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001390static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001391{
1392 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001393 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001394 char str[1024];
1395 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001396 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001397 vector<CMD_NODE*> pCmds = pCB->pCmds;
1398 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001399 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001400 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001401 }
1402 }
1403 else {
1404 // Nothing to print
1405 }
1406}
1407
1408
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001409static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001410{
1411 printDSConfig(cb);
1412 printPipeline(cb);
1413 printDynamicState(cb);
1414 static int autoDumpOnce = 0;
1415 if (autoDumpOnce) {
1416 autoDumpOnce = 0;
1417 dumpDotFile(cb, "pipeline_dump.dot");
1418 cbDumpDotFile("cb_dump.dot");
1419#if defined(_WIN32)
1420// FIXME: NEED WINDOWS EQUIVALENT
1421#else // WIN32
1422 // Convert dot to svg if dot available
1423 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbourf20f87b2015-04-22 09:02:32 -06001424 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1425 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001426 }
1427#endif // WIN32
1428 }
1429}
1430
1431static void initDrawState(void)
1432{
1433 const char *strOpt;
1434 // initialize DrawState options
1435 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1436 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1437
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001438 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001439 {
1440 strOpt = getLayerOption("DrawStateLogFilename");
1441 if (strOpt)
1442 {
1443 g_logFile = fopen(strOpt, "w");
1444 }
1445 if (g_logFile == NULL)
1446 g_logFile = stdout;
1447 }
1448 // initialize Layer dispatch table
1449 // TODO handle multiple GPUs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001450 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001451 fpNextGPA = pCurObj->pGPA;
1452 assert(fpNextGPA);
1453
Tony Barbourd1c35722015-04-16 15:59:00 -06001454 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001455
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001456 if (!globalLockInitialized)
1457 {
1458 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001459 // suggestion is to call this during vkCreateInstance(), and then we
1460 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001461 // that the layer have per-instance locks. We need to come back and
1462 // address this soon.
1463 loader_platform_thread_create_mutex(&globalLock);
1464 globalLockInitialized = 1;
1465 }
1466}
1467
Tony Barbourd1c35722015-04-16 15:59:00 -06001468VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001469{
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001470 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001471 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001472 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001473 return result;
1474}
1475
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001476VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001477{
1478 // Free all the memory
1479 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001480 deletePipelines();
1481 deleteSamplers();
1482 deleteImages();
1483 deleteBuffers();
1484 deleteCmdBuffers();
1485 deleteDynamicState();
1486 deletePools();
1487 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001488 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001489 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001490 return result;
1491}
1492
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001493struct extProps {
1494 uint32_t version;
1495 const char * const name;
1496};
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001497#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001498static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1499 // TODO what is the version?
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001500 0x10, "DrawState",
1501 0x10, "Validation",
1502 0x10, "drawStateDumpDotFile",
1503 0x10, "drawStateDumpCommandBufferDotFile",
1504 0x10, "drawStateDumpPngFile"
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001505};
1506
1507VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1508 VkExtensionInfoType infoType,
1509 uint32_t extensionIndex,
1510 size_t* pDataSize,
1511 void* pData)
1512{
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001513 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1514 VkExtensionProperties *ext_props;
1515 uint32_t *count;
1516
1517 if (pDataSize == NULL)
1518 return VK_ERROR_INVALID_POINTER;
1519
1520 switch (infoType) {
1521 case VK_EXTENSION_INFO_TYPE_COUNT:
1522 *pDataSize = sizeof(uint32_t);
1523 if (pData == NULL)
1524 return VK_SUCCESS;
1525 count = (uint32_t *) pData;
1526 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1527 break;
1528 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1529 *pDataSize = sizeof(VkExtensionProperties);
1530 if (pData == NULL)
1531 return VK_SUCCESS;
1532 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1533 return VK_ERROR_INVALID_VALUE;
1534 ext_props = (VkExtensionProperties *) pData;
1535 ext_props->version = dsExts[extensionIndex].version;
1536 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1537 VK_MAX_EXTENSION_NAME);
1538 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1539 break;
1540 default:
1541 return VK_ERROR_INVALID_VALUE;
1542 };
1543
1544 return VK_SUCCESS;
1545}
1546
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001547VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001548{
1549 if (gpu != NULL)
1550 {
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001551 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001552 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001553 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001554 return result;
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001555 } else {
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001556 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001557 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001558 // This layer compatible with all GPUs
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001559 *pLayerCount = 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001560 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001561 return VK_SUCCESS;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001562 }
1563}
1564
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001565VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001566{
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001567 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001568 for (uint32_t i=0; i < cmdBufferCount; i++) {
1569 // Validate that cmd buffers have been updated
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001570 pCB = getCBNode(pCmdBuffers[i]);
1571 loader_platform_thread_lock_mutex(&globalLock);
1572 if (CB_UPDATE_COMPLETE != pCB->state) {
1573 // Flag error for using CB w/o vkEndCommandBuffer() called
1574 char str[1024];
1575 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
1576 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS", str);
1577 }
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06001578 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001579 for (auto ii=pCB->boundDescriptorSets.begin(); ii != pCB->boundDescriptorSets.end(); ++ii) {
1580 if (dsUpdateActive(*ii)) {
1581 char str[1024];
1582 sprintf(str, "You must call vkEndDescriptorPoolUpdate() before this call to vkQueueSubmit()!");
1583 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *ii, 0, DRAWSTATE_BINDING_DS_NO_END_UPDATE, "DS", str);
1584 }
1585 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001586 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001587 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001588 return result;
1589}
1590
Mike Stroyanb050c682015-04-17 12:36:38 -06001591VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001592{
1593 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyanb050c682015-04-17 12:36:38 -06001594 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001595 return result;
1596}
1597
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001598VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001599{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001600 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001601 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001602 loader_platform_thread_lock_mutex(&globalLock);
1603 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1604 pNewNode->buffer = *pView;
1605 pNewNode->createInfo = *pCreateInfo;
1606 bufferMap[*pView] = pNewNode;
1607 loader_platform_thread_unlock_mutex(&globalLock);
1608 }
1609 return result;
1610}
1611
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001612VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001613{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001614 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001615 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001616 loader_platform_thread_lock_mutex(&globalLock);
1617 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1618 pNewNode->image = *pView;
1619 pNewNode->createInfo = *pCreateInfo;
1620 imageMap[*pView] = pNewNode;
1621 loader_platform_thread_unlock_mutex(&globalLock);
1622 }
1623 return result;
1624}
1625
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001626static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001627{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001628 // Create LL HEAD for this Pipeline
1629 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001630 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1631 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1632 pPipeNode->pipeline = *pPipeline;
1633 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001634 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001635}
1636
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001637VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001638{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001639 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001640 // Create LL HEAD for this Pipeline
1641 char str[1024];
1642 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001643 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001644
1645 track_pipeline(pCreateInfo, pPipeline);
1646
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001647 return result;
1648}
1649
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001650VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1651 VkDevice device,
1652 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1653 VkPipeline basePipeline,
1654 VkPipeline* pPipeline)
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001655{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001656 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001657 // Create LL HEAD for this Pipeline
1658 char str[1024];
1659 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001660 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001661
1662 track_pipeline(pCreateInfo, pPipeline);
1663
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001664 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001665
1666 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001667}
1668
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001669VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001670{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001671 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001672 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001673 loader_platform_thread_lock_mutex(&globalLock);
1674 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1675 pNewNode->sampler = *pSampler;
1676 pNewNode->createInfo = *pCreateInfo;
1677 sampleMap[*pSampler] = pNewNode;
1678 loader_platform_thread_unlock_mutex(&globalLock);
1679 }
1680 return result;
1681}
1682
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001683VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001684{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001685 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001686 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001687 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1688 if (NULL == pNewNode) {
1689 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001690 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1691 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001692 }
1693 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001694 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1695 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1696 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001697 uint32_t totalCount = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001698 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1699 totalCount += pCreateInfo->pBinding[i].count;
1700 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001701 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1702 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1703 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001704 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001705 }
1706 if (totalCount > 0) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001707 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001708 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001709 uint32_t j = 0;
1710 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1711 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1712 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001713 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001714 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001715 }
1716 }
1717 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001718 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001719 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1720 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001721 // Put new node at Head of global Layer list
1722 loader_platform_thread_lock_mutex(&globalLock);
1723 layoutMap[*pSetLayout] = pNewNode;
1724 loader_platform_thread_unlock_mutex(&globalLock);
1725 }
1726 return result;
1727}
1728
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001729VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001730{
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001731 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001732 if (VK_SUCCESS == result) {
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001733 // TODO : Need to capture the pipeline layout
Tobin Ehlis793ad302015-04-03 12:01:11 -06001734 }
1735 return result;
1736}
1737
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001738VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001739{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001740 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001741 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001742 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001743 POOL_NODE* pPoolNode = poolMap.begin()->second;
1744 if (!pPoolNode) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001745 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001746 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001747 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001748 }
1749 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001750 pPoolNode->updateActive = 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001751 }
1752 loader_platform_thread_unlock_mutex(&globalLock);
1753 }
1754 return result;
1755}
1756
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001757VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001758{
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001759 // Perform some initial validation checks
1760 POOL_NODE* pPoolNode = NULL;
1761 loader_platform_thread_lock_mutex(&globalLock);
1762 auto poolEntry = poolMap.begin();
1763 if (poolEntry == poolMap.end()) {
1764 char str[1024];
1765 sprintf(str, "Unable to find pool node");
1766 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
1767 }
1768 else {
1769 pPoolNode = poolEntry->second;
1770 if (!pPoolNode->updateActive) {
1771 char str[1024];
1772 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1773 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_DS_END_WITHOUT_BEGIN, "DS", str);
1774 }
1775 }
1776 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001777 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001778 if (VK_SUCCESS == result) {
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001779 pPoolNode->updateActive = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001780 }
1781 return result;
1782}
1783
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001784VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001785{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001786 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001787 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001788 // Insert this pool into Global Pool LL at head
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001789 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001790 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyanb050c682015-04-17 12:36:38 -06001791 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001792 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001793 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001794 if (NULL == pNewNode) {
1795 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001796 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyanb050c682015-04-17 12:36:38 -06001797 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001798 }
1799 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001800 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001801 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1802 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001803 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001804 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1805 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001806 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1807 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001808 pNewNode->poolUsage = poolUsage;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001809 pNewNode->updateActive = 0;
1810 pNewNode->maxSets = maxSets;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001811 pNewNode->pool = *pDescriptorPool;
1812 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001813 }
1814 loader_platform_thread_unlock_mutex(&globalLock);
1815 }
1816 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001817 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001818 }
1819 return result;
1820}
1821
Mike Stroyanb050c682015-04-17 12:36:38 -06001822VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001823{
Mike Stroyanb050c682015-04-17 12:36:38 -06001824 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001825 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001826 clearDescriptorPool(descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001827 }
1828 return result;
1829}
1830
Mike Stroyanb050c682015-04-17 12:36:38 -06001831VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001832{
Mike Stroyanb050c682015-04-17 12:36:38 -06001833 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001834 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001835 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1836 if (!pPoolNode) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001837 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001838 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1839 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001840 }
1841 else {
1842 for (uint32_t i = 0; i < *pCount; i++) {
1843 char str[1024];
1844 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001845 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001846 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001847 SET_NODE* pNewNode = new SET_NODE;
1848 if (NULL == pNewNode) {
1849 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001850 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1851 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001852 }
1853 else {
1854 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001855 // Insert set at head of Set LL for this pool
1856 pNewNode->pNext = pPoolNode->pSets;
1857 pPoolNode->pSets = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001858 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1859 if (NULL == pLayout) {
1860 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001861 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1862 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001863 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001864 pNewNode->pLayout = pLayout;
1865 pNewNode->pool = descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001866 pNewNode->set = pDescriptorSets[i];
1867 pNewNode->setUsage = setUsage;
1868 pNewNode->descriptorCount = pLayout->endIndex + 1;
1869 if (pNewNode->descriptorCount) {
1870 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1871 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1872 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1873 }
1874 setMap[pDescriptorSets[i]] = pNewNode;
1875 }
1876 }
1877 }
1878 }
1879 return result;
1880}
1881
Mike Stroyanb050c682015-04-17 12:36:38 -06001882VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001883{
1884 for (uint32_t i = 0; i < count; i++) {
1885 clearDescriptorSet(pDescriptorSets[i]);
1886 }
Mike Stroyanb050c682015-04-17 12:36:38 -06001887 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001888}
1889
Mike Stroyanb050c682015-04-17 12:36:38 -06001890VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001891{
1892 SET_NODE* pSet = getSetNode(descriptorSet);
1893 if (!dsUpdateActive(descriptorSet)) {
1894 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001895 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1896 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSet->pool, 0, DRAWSTATE_UPDATE_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001897 }
1898 else {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001899 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlis793ad302015-04-03 12:01:11 -06001900 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001901 }
1902
Mike Stroyanb050c682015-04-17 12:36:38 -06001903 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001904}
1905
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001906VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001907{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001908 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001909 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001910 return result;
1911}
1912
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001913VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001914{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001915 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001916 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001917 return result;
1918}
1919
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001920VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001921{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001922 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001923 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001924 return result;
1925}
1926
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001927VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001928{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001929 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001930 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001931 return result;
1932}
1933
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001934VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001935{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001936 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001937 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001938 loader_platform_thread_lock_mutex(&globalLock);
1939 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1940 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1941 pCB->cmdBuffer = *pCmdBuffer;
1942 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001943 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001944 pCB->lastVtxBinding = MAX_BINDING;
1945 cmdBufferMap[*pCmdBuffer] = pCB;
1946 loader_platform_thread_unlock_mutex(&globalLock);
1947 updateCBTracking(*pCmdBuffer);
1948 }
1949 return result;
1950}
1951
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001952VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001953{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001954 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001955 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001956 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1957 if (pCB) {
1958 if (CB_NEW != pCB->state)
1959 resetCB(cmdBuffer);
1960 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001961 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001962 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001963 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001964 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001965 }
1966 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001967 }
1968 else {
1969 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001970 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1971 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001972 }
1973 updateCBTracking(cmdBuffer);
1974 }
1975 return result;
1976}
1977
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001978VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001979{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001980 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001981 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001982 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1983 if (pCB) {
1984 pCB->state = CB_UPDATE_COMPLETE;
1985 printCB(cmdBuffer);
1986 }
1987 else {
1988 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001989 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1990 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001991 }
1992 updateCBTracking(cmdBuffer);
1993 //cbDumpDotFile("cb_dump.dot");
1994 }
1995 return result;
1996}
1997
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001998VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001999{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002000 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002001 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002002 resetCB(cmdBuffer);
2003 updateCBTracking(cmdBuffer);
2004 }
2005 return result;
2006}
2007
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002008VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002009{
2010 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2011 if (pCB) {
2012 updateCBTracking(cmdBuffer);
2013 addCmd(pCB, CMD_BINDPIPELINE);
2014 PIPELINE_NODE* pPN = getPipeline(pipeline);
2015 if (pPN) {
2016 pCB->lastBoundPipeline = pipeline;
2017 loader_platform_thread_lock_mutex(&globalLock);
2018 g_lastBoundPipeline = pPN;
2019 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002020 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06002021 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002022 }
2023 else {
2024 char str[1024];
2025 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002026 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002027 }
2028 }
2029 else {
2030 char str[1024];
2031 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002032 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002033 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002034}
2035
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002036VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002037{
2038 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
2039 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2040}
2041
Cody Northropd4c1a502015-04-16 13:41:56 -06002042VK_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 Ehlis10ae8c12015-03-17 16:24:32 -06002043{
2044 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2045 if (pCB) {
2046 updateCBTracking(cmdBuffer);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002047 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Cody Northropd4c1a502015-04-16 13:41:56 -06002048 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002049 if (getSetNode(pDescriptorSets[i])) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002050 loader_platform_thread_lock_mutex(&globalLock);
2051 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06002052 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002053 g_lastBoundDescriptorSet = pDescriptorSets[i];
2054 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002055 char str[1024];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002056 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002057 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002058 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002059 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06002060 else {
2061 char str[1024];
2062 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002063 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002064 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002065 }
2066 }
2067 else {
2068 char str[1024];
2069 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002070 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002071 }
Cody Northropd4c1a502015-04-16 13:41:56 -06002072 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002073}
2074
Tony Barbourd1c35722015-04-16 15:59:00 -06002075VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002076{
2077 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2078 if (pCB) {
2079 updateCBTracking(cmdBuffer);
2080 addCmd(pCB, CMD_BINDINDEXBUFFER);
2081 // TODO : Track idxBuffer binding
2082 }
2083 else {
2084 char str[1024];
2085 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002086 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002087 }
2088 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2089}
2090
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002091VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2092 VkCmdBuffer cmdBuffer,
2093 uint32_t startBinding,
2094 uint32_t bindingCount,
2095 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002096 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002097{
2098 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2099 if (pCB) {
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002100 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002101 updateCBTracking(cmdBuffer);
2102 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002103 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002104 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002105 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002106 char str[1024];
2107 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002108 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002109 }
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002110 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002111}
2112
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002113VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002114{
2115 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2116 if (pCB) {
2117 updateCBTracking(cmdBuffer);
2118 addCmd(pCB, CMD_DRAW);
2119 pCB->drawCount[DRAW]++;
2120 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002121 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2122 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002123 synchAndPrintDSConfig(cmdBuffer);
2124 }
2125 else {
2126 char str[1024];
2127 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002128 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002129 }
2130 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2131}
2132
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002133VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002134{
2135 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2136 if (pCB) {
2137 updateCBTracking(cmdBuffer);
2138 addCmd(pCB, CMD_DRAWINDEXED);
2139 pCB->drawCount[DRAW_INDEXED]++;
2140 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002141 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2142 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002143 synchAndPrintDSConfig(cmdBuffer);
2144 }
2145 else {
2146 char str[1024];
2147 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002148 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002149 }
2150 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2151}
2152
Tony Barbourd1c35722015-04-16 15:59:00 -06002153VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002154{
2155 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2156 if (pCB) {
2157 updateCBTracking(cmdBuffer);
2158 addCmd(pCB, CMD_DRAWINDIRECT);
2159 pCB->drawCount[DRAW_INDIRECT]++;
2160 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002161 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2162 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002163 synchAndPrintDSConfig(cmdBuffer);
2164 }
2165 else {
2166 char str[1024];
2167 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002168 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002169 }
2170 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2171}
2172
Tony Barbourd1c35722015-04-16 15:59:00 -06002173VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002174{
2175 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2176 if (pCB) {
2177 updateCBTracking(cmdBuffer);
2178 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2179 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2180 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002181 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2182 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002183 synchAndPrintDSConfig(cmdBuffer);
2184 }
2185 else {
2186 char str[1024];
2187 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002188 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002189 }
2190 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2191}
2192
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002193VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002194{
2195 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2196 if (pCB) {
2197 updateCBTracking(cmdBuffer);
2198 addCmd(pCB, CMD_DISPATCH);
2199 }
2200 else {
2201 char str[1024];
2202 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002203 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002204 }
2205 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2206}
2207
Tony Barbourd1c35722015-04-16 15:59:00 -06002208VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002209{
2210 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2211 if (pCB) {
2212 updateCBTracking(cmdBuffer);
2213 addCmd(pCB, CMD_DISPATCHINDIRECT);
2214 }
2215 else {
2216 char str[1024];
2217 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002218 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002219 }
2220 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2221}
2222
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002223VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002224{
2225 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2226 if (pCB) {
2227 updateCBTracking(cmdBuffer);
2228 addCmd(pCB, CMD_COPYBUFFER);
2229 }
2230 else {
2231 char str[1024];
2232 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002233 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002234 }
2235 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2236}
2237
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002238VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2239 VkImage srcImage,
2240 VkImageLayout srcImageLayout,
2241 VkImage destImage,
2242 VkImageLayout destImageLayout,
2243 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002244{
2245 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2246 if (pCB) {
2247 updateCBTracking(cmdBuffer);
2248 addCmd(pCB, CMD_COPYIMAGE);
2249 }
2250 else {
2251 char str[1024];
2252 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002253 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002254 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002255 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002256}
2257
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002258VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2259 VkImage srcImage, VkImageLayout srcImageLayout,
2260 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002261 uint32_t regionCount, const VkImageBlit* pRegions,
2262 VkTexFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002263{
2264 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2265 if (pCB) {
2266 updateCBTracking(cmdBuffer);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002267 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002268 }
2269 else {
2270 char str[1024];
2271 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002272 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002273 }
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002274 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002275}
2276
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002277VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2278 VkBuffer srcBuffer,
2279 VkImage destImage, VkImageLayout destImageLayout,
2280 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002281{
2282 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2283 if (pCB) {
2284 updateCBTracking(cmdBuffer);
2285 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2286 }
2287 else {
2288 char str[1024];
2289 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002290 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002291 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002292 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002293}
2294
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002295VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2296 VkImage srcImage, VkImageLayout srcImageLayout,
2297 VkBuffer destBuffer,
2298 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002299{
2300 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2301 if (pCB) {
2302 updateCBTracking(cmdBuffer);
2303 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2304 }
2305 else {
2306 char str[1024];
2307 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002308 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002309 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002310 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002311}
2312
Tony Barbourd1c35722015-04-16 15:59:00 -06002313VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002314{
2315 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2316 if (pCB) {
2317 updateCBTracking(cmdBuffer);
2318 addCmd(pCB, CMD_UPDATEBUFFER);
2319 }
2320 else {
2321 char str[1024];
2322 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002323 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002324 }
2325 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2326}
2327
Tony Barbourd1c35722015-04-16 15:59:00 -06002328VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002329{
2330 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2331 if (pCB) {
2332 updateCBTracking(cmdBuffer);
2333 addCmd(pCB, CMD_FILLBUFFER);
2334 }
2335 else {
2336 char str[1024];
2337 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002338 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002339 }
2340 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2341}
2342
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002343VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2344 VkCmdBuffer cmdBuffer,
2345 VkImage image, VkImageLayout imageLayout,
2346 const VkClearColor *pColor,
2347 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002348{
2349 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2350 if (pCB) {
2351 updateCBTracking(cmdBuffer);
2352 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2353 }
2354 else {
2355 char str[1024];
2356 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002357 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002358 }
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002359 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002360}
2361
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002362VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2363 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002364 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002365 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002366{
2367 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2368 if (pCB) {
2369 updateCBTracking(cmdBuffer);
2370 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2371 }
2372 else {
2373 char str[1024];
2374 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002375 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002376 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002377 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002378}
2379
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002380VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2381 VkImage srcImage, VkImageLayout srcImageLayout,
2382 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002383 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002384{
2385 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2386 if (pCB) {
2387 updateCBTracking(cmdBuffer);
2388 addCmd(pCB, CMD_RESOLVEIMAGE);
2389 }
2390 else {
2391 char str[1024];
2392 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002393 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002394 }
Tony Barbour6865d4a2015-04-13 15:02:52 -06002395 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002396}
2397
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002398VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002399{
2400 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2401 if (pCB) {
2402 updateCBTracking(cmdBuffer);
2403 addCmd(pCB, CMD_SETEVENT);
2404 }
2405 else {
2406 char str[1024];
2407 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002408 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002409 }
2410 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2411}
2412
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002413VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002414{
2415 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2416 if (pCB) {
2417 updateCBTracking(cmdBuffer);
2418 addCmd(pCB, CMD_RESETEVENT);
2419 }
2420 else {
2421 char str[1024];
2422 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002423 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002424 }
Courtney Goeltzenleuchter1e8f3be2015-03-24 18:02:34 -06002425 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002426}
2427
Tony Barbourd1c35722015-04-16 15:59:00 -06002428VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t eventCount, const VkEvent* pEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002429{
2430 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2431 if (pCB) {
2432 updateCBTracking(cmdBuffer);
2433 addCmd(pCB, CMD_WAITEVENTS);
2434 }
2435 else {
2436 char str[1024];
2437 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002438 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002439 }
Tony Barbourd1c35722015-04-16 15:59:00 -06002440 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002441}
2442
Tony Barbourd1c35722015-04-16 15:59:00 -06002443VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002444{
2445 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2446 if (pCB) {
2447 updateCBTracking(cmdBuffer);
2448 addCmd(pCB, CMD_PIPELINEBARRIER);
2449 }
2450 else {
2451 char str[1024];
2452 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002453 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002454 }
Tony Barbourd1c35722015-04-16 15:59:00 -06002455 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002456}
2457
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002458VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002459{
2460 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2461 if (pCB) {
2462 updateCBTracking(cmdBuffer);
2463 addCmd(pCB, CMD_BEGINQUERY);
2464 }
2465 else {
2466 char str[1024];
2467 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002468 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002469 }
2470 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2471}
2472
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002473VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002474{
2475 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2476 if (pCB) {
2477 updateCBTracking(cmdBuffer);
2478 addCmd(pCB, CMD_ENDQUERY);
2479 }
2480 else {
2481 char str[1024];
2482 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002483 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002484 }
2485 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2486}
2487
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002488VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002489{
2490 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2491 if (pCB) {
2492 updateCBTracking(cmdBuffer);
2493 addCmd(pCB, CMD_RESETQUERYPOOL);
2494 }
2495 else {
2496 char str[1024];
2497 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002498 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002499 }
2500 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2501}
2502
Tony Barbourd1c35722015-04-16 15:59:00 -06002503VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002504{
2505 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2506 if (pCB) {
2507 updateCBTracking(cmdBuffer);
2508 addCmd(pCB, CMD_WRITETIMESTAMP);
2509 }
2510 else {
2511 char str[1024];
2512 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002513 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002514 }
2515 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2516}
2517
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002518VK_LAYER_EXPORT void VKAPI vkCmdInitAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002519{
2520 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2521 if (pCB) {
2522 updateCBTracking(cmdBuffer);
2523 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2524 }
2525 else {
2526 char str[1024];
2527 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002528 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002529 }
2530 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2531}
2532
Tony Barbourd1c35722015-04-16 15:59:00 -06002533VK_LAYER_EXPORT void VKAPI vkCmdLoadAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer srcBuffer, VkDeviceSize srcOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002534{
2535 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2536 if (pCB) {
2537 updateCBTracking(cmdBuffer);
2538 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2539 }
2540 else {
2541 char str[1024];
2542 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002543 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002544 }
2545 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2546}
2547
Tony Barbourd1c35722015-04-16 15:59:00 -06002548VK_LAYER_EXPORT void VKAPI vkCmdSaveAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002549{
2550 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2551 if (pCB) {
2552 updateCBTracking(cmdBuffer);
2553 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2554 }
2555 else {
2556 char str[1024];
2557 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002558 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002559 }
2560 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2561}
2562
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002563VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002564{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002565 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002566 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002567 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002568 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002569 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002570 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2571 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002572 }
2573 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002574 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2575 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002576 }
2577 frameBufferMap[*pFramebuffer] = localFBCI;
2578 }
2579 return result;
2580}
2581
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002582VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002583{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002584 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002585 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002586 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002587 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002588 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002589 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2590 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002591 }
2592 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002593 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2594 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002595 }
2596 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002597 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2598 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002599 }
2600 renderPassMap[*pRenderPass] = localRPCI;
2601 }
2602 return result;
2603}
2604
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002605VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002606{
2607 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2608 if (pCB) {
2609 updateCBTracking(cmdBuffer);
2610 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002611 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2612 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourbadda992015-04-06 11:09:26 -06002613 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002614 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourbadda992015-04-06 11:09:26 -06002615 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002616 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002617 char str[1024];
2618 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002619 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002620 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002621 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002622}
2623
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002624VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002625{
2626 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2627 if (pCB) {
2628 updateCBTracking(cmdBuffer);
2629 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002630 pCB->activeRenderPass = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002631 }
2632 else {
2633 char str[1024];
2634 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002635 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002636 }
2637 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2638}
2639
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002640VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002641{
2642 // This layer intercepts callbacks
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002643 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002644 if (!pNewDbgFuncNode)
Tony Barbourd1c35722015-04-16 15:59:00 -06002645 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002646 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2647 pNewDbgFuncNode->pUserData = pUserData;
2648 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2649 g_pDbgFunctionHead = pNewDbgFuncNode;
2650 // force callbacks if DebugAction hasn't been set already other than initial value
2651 if (g_actionIsDefault) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002652 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002653 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002654 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002655 return result;
2656}
2657
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002658VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002659{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002660 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2661 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002662 while (pTrav) {
2663 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2664 pPrev->pNext = pTrav->pNext;
2665 if (g_pDbgFunctionHead == pTrav)
2666 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002667 delete pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002668 break;
2669 }
2670 pPrev = pTrav;
2671 pTrav = pTrav->pNext;
2672 }
2673 if (g_pDbgFunctionHead == NULL)
2674 {
2675 if (g_actionIsDefault)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002676 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002677 else
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002678 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002679 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002680 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002681 return result;
2682}
2683
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002684VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002685{
2686 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2687 if (pCB) {
2688 updateCBTracking(cmdBuffer);
2689 addCmd(pCB, CMD_DBGMARKERBEGIN);
2690 }
2691 else {
2692 char str[1024];
2693 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002694 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002695 }
2696 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2697}
2698
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002699VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002700{
2701 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2702 if (pCB) {
2703 updateCBTracking(cmdBuffer);
2704 addCmd(pCB, CMD_DBGMARKEREND);
2705 }
2706 else {
2707 char str[1024];
2708 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002709 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002710 }
2711 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2712}
2713
2714// TODO : Want to pass in a cmdBuffer here based on which state to display
2715void drawStateDumpDotFile(char* outFileName)
2716{
2717 // TODO : Currently just setting cmdBuffer based on global var
2718 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2719 dumpGlobalDotFile(outFileName);
2720}
2721
2722void drawStateDumpCommandBufferDotFile(char* outFileName)
2723{
2724 cbDumpDotFile(outFileName);
2725}
2726
2727void drawStateDumpPngFile(char* outFileName)
2728{
2729#if defined(_WIN32)
2730// FIXME: NEED WINDOWS EQUIVALENT
2731 char str[1024];
2732 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002733 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002734#else // WIN32
2735 char dotExe[32] = "/usr/bin/dot";
2736 if( access(dotExe, X_OK) != -1) {
2737 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2738 char dotCmd[1024];
2739 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbourf20f87b2015-04-22 09:02:32 -06002740 int retval = system(dotCmd);
2741 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002742 remove("/tmp/tmp.dot");
2743 }
2744 else {
2745 char str[1024];
2746 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002747 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002748 }
2749#endif // WIN32
2750}
2751
Tony Barbourd1c35722015-04-16 15:59:00 -06002752VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002753{
Jon Ashburnbacb0f52015-04-06 10:58:22 -06002754 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002755
2756 if (gpu == NULL)
2757 return NULL;
2758 pCurObj = gpuw;
2759 loader_platform_thread_once(&g_initOnce, initDrawState);
2760
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002761 if (!strcmp(funcName, "vkGetProcAddr"))
2762 return (void *) vkGetProcAddr;
2763 if (!strcmp(funcName, "vkCreateDevice"))
2764 return (void*) vkCreateDevice;
2765 if (!strcmp(funcName, "vkDestroyDevice"))
2766 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002767 if (!strcmp(funcName, "vkEnumerateLayers"))
2768 return (void*) vkEnumerateLayers;
2769 if (!strcmp(funcName, "vkQueueSubmit"))
2770 return (void*) vkQueueSubmit;
2771 if (!strcmp(funcName, "vkDestroyObject"))
2772 return (void*) vkDestroyObject;
2773 if (!strcmp(funcName, "vkCreateBufferView"))
2774 return (void*) vkCreateBufferView;
2775 if (!strcmp(funcName, "vkCreateImageView"))
2776 return (void*) vkCreateImageView;
2777 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2778 return (void*) vkCreateGraphicsPipeline;
2779 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2780 return (void*) vkCreateGraphicsPipelineDerivative;
2781 if (!strcmp(funcName, "vkCreateSampler"))
2782 return (void*) vkCreateSampler;
2783 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2784 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05002785 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2786 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002787 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2788 return (void*) vkBeginDescriptorPoolUpdate;
2789 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2790 return (void*) vkEndDescriptorPoolUpdate;
2791 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2792 return (void*) vkCreateDescriptorPool;
2793 if (!strcmp(funcName, "vkResetDescriptorPool"))
2794 return (void*) vkResetDescriptorPool;
2795 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2796 return (void*) vkAllocDescriptorSets;
2797 if (!strcmp(funcName, "vkClearDescriptorSets"))
2798 return (void*) vkClearDescriptorSets;
2799 if (!strcmp(funcName, "vkUpdateDescriptors"))
2800 return (void*) vkUpdateDescriptors;
2801 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2802 return (void*) vkCreateDynamicViewportState;
2803 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2804 return (void*) vkCreateDynamicRasterState;
2805 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2806 return (void*) vkCreateDynamicColorBlendState;
2807 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2808 return (void*) vkCreateDynamicDepthStencilState;
2809 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2810 return (void*) vkCreateCommandBuffer;
2811 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2812 return (void*) vkBeginCommandBuffer;
2813 if (!strcmp(funcName, "vkEndCommandBuffer"))
2814 return (void*) vkEndCommandBuffer;
2815 if (!strcmp(funcName, "vkResetCommandBuffer"))
2816 return (void*) vkResetCommandBuffer;
2817 if (!strcmp(funcName, "vkCmdBindPipeline"))
2818 return (void*) vkCmdBindPipeline;
2819 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2820 return (void*) vkCmdBindDynamicStateObject;
2821 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2822 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002823 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2824 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002825 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2826 return (void*) vkCmdBindIndexBuffer;
2827 if (!strcmp(funcName, "vkCmdDraw"))
2828 return (void*) vkCmdDraw;
2829 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2830 return (void*) vkCmdDrawIndexed;
2831 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2832 return (void*) vkCmdDrawIndirect;
2833 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2834 return (void*) vkCmdDrawIndexedIndirect;
2835 if (!strcmp(funcName, "vkCmdDispatch"))
2836 return (void*) vkCmdDispatch;
2837 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2838 return (void*) vkCmdDispatchIndirect;
2839 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2840 return (void*) vkCmdCopyBuffer;
2841 if (!strcmp(funcName, "vkCmdCopyImage"))
2842 return (void*) vkCmdCopyImage;
2843 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2844 return (void*) vkCmdCopyBufferToImage;
2845 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2846 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002847 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2848 return (void*) vkCmdUpdateBuffer;
2849 if (!strcmp(funcName, "vkCmdFillBuffer"))
2850 return (void*) vkCmdFillBuffer;
2851 if (!strcmp(funcName, "vkCmdClearColorImage"))
2852 return (void*) vkCmdClearColorImage;
2853 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2854 return (void*) vkCmdClearDepthStencil;
2855 if (!strcmp(funcName, "vkCmdResolveImage"))
2856 return (void*) vkCmdResolveImage;
2857 if (!strcmp(funcName, "vkCmdSetEvent"))
2858 return (void*) vkCmdSetEvent;
2859 if (!strcmp(funcName, "vkCmdResetEvent"))
2860 return (void*) vkCmdResetEvent;
2861 if (!strcmp(funcName, "vkCmdWaitEvents"))
2862 return (void*) vkCmdWaitEvents;
2863 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2864 return (void*) vkCmdPipelineBarrier;
2865 if (!strcmp(funcName, "vkCmdBeginQuery"))
2866 return (void*) vkCmdBeginQuery;
2867 if (!strcmp(funcName, "vkCmdEndQuery"))
2868 return (void*) vkCmdEndQuery;
2869 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2870 return (void*) vkCmdResetQueryPool;
2871 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2872 return (void*) vkCmdWriteTimestamp;
2873 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2874 return (void*) vkCmdInitAtomicCounters;
2875 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2876 return (void*) vkCmdLoadAtomicCounters;
2877 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2878 return (void*) vkCmdSaveAtomicCounters;
2879 if (!strcmp(funcName, "vkCreateFramebuffer"))
2880 return (void*) vkCreateFramebuffer;
2881 if (!strcmp(funcName, "vkCreateRenderPass"))
2882 return (void*) vkCreateRenderPass;
2883 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2884 return (void*) vkCmdBeginRenderPass;
2885 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2886 return (void*) vkCmdEndRenderPass;
2887 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2888 return (void*) vkDbgRegisterMsgCallback;
2889 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2890 return (void*) vkDbgUnregisterMsgCallback;
2891 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2892 return (void*) vkCmdDbgMarkerBegin;
2893 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2894 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002895 if (!strcmp("drawStateDumpDotFile", funcName))
2896 return (void*) drawStateDumpDotFile;
2897 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2898 return (void*) drawStateDumpCommandBufferDotFile;
2899 if (!strcmp("drawStateDumpPngFile", funcName))
2900 return (void*) drawStateDumpPngFile;
2901 else {
2902 if (gpuw->pGPA == NULL)
2903 return NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -06002904 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002905 }
2906}