blob: 1b85873e6abf0524da9eec0723b1d030ae7fdafb [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
30#include "loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060036#include "vk_struct_graphviz_helper.h"
Tony Barboura938abb2015-04-22 11:36:22 -060037#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060038#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060039#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060040#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060041#include "draw_state.h"
42#include "layers_config.h"
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 Goeltzenleuchter382489d2015-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 Ehlisdd82f6b2015-04-03 12:01:11 -060056// Map for layout chains
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060057unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
58unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
59unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060060
Jon Ashburn301c5f02015-04-06 10:58:22 -060061static VkLayerDispatchTable nextTable;
62static VkBaseLayerObject *pCurObj;
Tobin Ehlis63bb9482015-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 Ehlis63bb9482015-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 Ehlisdd82f6b2015-04-03 12:01:11 -060095 case CMD_BINDDESCRIPTORSETS:
96 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-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 Ehlisdd82f6b2015-04-03 12:01:11 -0600117 case CMD_BLITIMAGE:
118 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600173#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-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 Goeltzenleuchter382489d2015-04-10 08:34:15 -0600183static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600190static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600191static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600192#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
193
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600194//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600195
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600196static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600197{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600198 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600205 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-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 Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600215 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600216 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600217 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600218 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600219 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600220 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600221 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600222 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis63bb9482015-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 Ehliseaf28662015-04-08 10:58:37 -0600233static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600234{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600235 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600236 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600237 delete[] (*ii).second->create_info.vpci.pScissors;
238 delete[] (*ii).second->create_info.vpci.pViewports;
239 }
240 delete (*ii).second;
241 }
242}
243// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600244static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600245{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600246 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600247 delete (*ii).second;
248 }
249}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600250static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251{
252 loader_platform_thread_lock_mutex(&globalLock);
253 if (imageMap.find(view) == imageMap.end()) {
254 loader_platform_thread_unlock_mutex(&globalLock);
255 return NULL;
256 }
257 else {
258 loader_platform_thread_unlock_mutex(&globalLock);
259 return &imageMap[view]->createInfo;
260 }
261}
262// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600263static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600264{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600265 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600266 delete (*ii).second;
267 }
268}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600269static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600270{
271 loader_platform_thread_lock_mutex(&globalLock);
272 if (bufferMap.find(view) == bufferMap.end()) {
273 loader_platform_thread_unlock_mutex(&globalLock);
274 return NULL;
275 }
276 else {
277 loader_platform_thread_unlock_mutex(&globalLock);
278 return &bufferMap[view]->createInfo;
279 }
280}
281// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600282static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600283{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600284 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600285 delete (*ii).second;
286 }
287}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600288static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600289
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600290static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600291{
292 g_lastCmdBuffer[getTIDIndex()] = cb;
293 GLOBAL_CB_NODE* pCB = getCBNode(cb);
294 loader_platform_thread_lock_mutex(&globalLock);
295 g_lastGlobalCB = pCB;
296 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
297 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
298 if (g_pLastTouchedCB[i] == pCB) {
299 loader_platform_thread_unlock_mutex(&globalLock);
300 return;
301 }
302 }
303 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
304 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
305 loader_platform_thread_unlock_mutex(&globalLock);
306}
307
308// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600310{
311 GLOBAL_CB_NODE* pCB = getCBNode(cb);
312 if (pCB) {
313 loader_platform_thread_lock_mutex(&globalLock);
314 char str[4*1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600315 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600316 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600317 sprintf(str, "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600318 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
319 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 Ehlis63bb9482015-03-17 16:24:32 -0600320 break;
321 }
322 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600323 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600324 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600325 }
326 }
327 loader_platform_thread_unlock_mutex(&globalLock);
328 }
329 else {
330 char str[1024];
331 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600332 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600333 }
334}
335// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600336static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600337{
338 loader_platform_thread_lock_mutex(&globalLock);
339 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
340 loader_platform_thread_unlock_mutex(&globalLock);
341 return NULL;
342 }
343 loader_platform_thread_unlock_mutex(&globalLock);
344 return pipelineMap[pipeline];
345}
346
347// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600348static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600349{
350 loader_platform_thread_lock_mutex(&globalLock);
351 if (sampleMap.find(sampler) == sampleMap.end()) {
352 loader_platform_thread_unlock_mutex(&globalLock);
353 return NULL;
354 }
355 loader_platform_thread_unlock_mutex(&globalLock);
356 return &sampleMap[sampler]->createInfo;
357}
358
359// Init the pipeline mapping info based on pipeline create info LL tree
360// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600361static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600362{
363 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600364 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600365 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600366 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600367 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600368 size_t bufferSize = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600369 VkPipelineVertexInputCreateInfo* pVICI = NULL;
370 VkPipelineCbStateCreateInfo* pCBCI = NULL;
371 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600372 while (pTrav) {
373 switch (pTrav->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600374 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600375 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600376 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 case VK_SHADER_STAGE_VERTEX:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600378 pPrev->pNext = &pPipeline->vsCI;
379 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600380 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600381 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600383 pPrev->pNext = &pPipeline->tcsCI;
384 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600385 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600386 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600387 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600388 pPrev->pNext = &pPipeline->tesCI;
389 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600390 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600391 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600392 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600393 pPrev->pNext = &pPipeline->gsCI;
394 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600395 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600396 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600397 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600398 pPrev->pNext = &pPipeline->fsCI;
399 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600400 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600401 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600402 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600403 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600404 break;
405 default:
406 // TODO : Flag error
407 break;
408 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600409 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600410 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600411 pPrev->pNext = &pPipeline->vertexInputCI;
412 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600413 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600414 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600415 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600416 pPipeline->vtxBindingCount = pVICI->bindingCount;
417 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600418 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
419 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
420 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600421 }
422 pPipeline->vtxAttributeCount = pVICI->attributeCount;
423 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600424 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
425 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
426 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600427 }
428 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600429 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600430 pPrev->pNext = &pPipeline->iaStateCI;
431 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600432 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600433 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600434 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600435 pPrev->pNext = &pPipeline->tessStateCI;
436 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600437 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600438 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600439 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600440 pPrev->pNext = &pPipeline->vpStateCI;
441 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600442 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600443 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600444 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600445 pPrev->pNext = &pPipeline->rsStateCI;
446 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600447 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600448 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600449 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600450 pPrev->pNext = &pPipeline->msStateCI;
451 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600452 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600453 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600454 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600455 pPrev->pNext = &pPipeline->cbStateCI;
456 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600457 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600458 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600459 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600460 pPipeline->attachmentCount = pCBCI->attachmentCount;
461 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600462 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
463 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
464 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600465 }
466 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600467 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600468 pPrev->pNext = &pPipeline->dsStateCI;
469 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600470 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600471 break;
472 default:
473 assert(0);
474 break;
475 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600476 pTrav = (GENERIC_HEADER*)pTrav->pNext;
477 }
478 pipelineMap[pPipeline->pipeline] = pPipeline;
479}
480// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600481static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600482{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600483 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600484 if ((*ii).second->pVertexBindingDescriptions) {
485 delete[] (*ii).second->pVertexBindingDescriptions;
486 }
487 if ((*ii).second->pVertexAttributeDescriptions) {
488 delete[] (*ii).second->pVertexAttributeDescriptions;
489 }
490 if ((*ii).second->pAttachments) {
491 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600492 }
493 delete (*ii).second;
494 }
495}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600496// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600497static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600498{
499 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600500 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600501 if (pPipe->msStateCI.multisampleEnable)
502 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600503 }
504 return 1;
505}
506// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600507static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600508{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600509 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600510 // Verify that any MSAA request in PSO matches sample# in bound FB
511 uint32_t psoNumSamples = getNumSamples(pipeline);
512 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600513 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
514 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis2464b882015-04-01 08:40:34 -0600515 if (psoNumSamples != pFBCI->sampleCount) {
516 char str[1024];
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600517 sprintf(str, "Num samples mismatche! Binding PSO (%p) with %u samples while current RenderPass (%p) uses FB (%p) with %u samples!", (void*)pipeline, psoNumSamples, (void*)pCB->activeRenderPass, (void*)pCB->framebuffer, pFBCI->sampleCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600518 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600519 }
520 } else {
521 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
522 // Verify and flag error as appropriate
523 }
524 // TODO : Add more checks here
525 } else {
526 // TODO : Validate non-gfx pipeline updates
527 }
528}
529
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600530// Block of code at start here specifically for managing/tracking DSs
531
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600532// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600533static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600534{
535 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600536 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600537 loader_platform_thread_unlock_mutex(&globalLock);
538 return NULL;
539 }
540 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600541 return poolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600542}
543// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600544static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600545{
546 loader_platform_thread_lock_mutex(&globalLock);
547 if (setMap.find(set) == setMap.end()) {
548 loader_platform_thread_unlock_mutex(&globalLock);
549 return NULL;
550 }
551 loader_platform_thread_unlock_mutex(&globalLock);
552 return setMap[set];
553}
554
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600555// Return VK_TRUE if DS Exists and is within an vkBeginDescriptorPoolUpdate() call sequence, otherwise VK_FALSE
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600556static bool32_t dsUpdateActive(VkDescriptorSet ds)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600557{
558 // Note, both "get" functions use global mutex so this guy does not
559 SET_NODE* pTrav = getSetNode(ds);
560 if (pTrav) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600561 POOL_NODE* pPool = getPoolNode(pTrav->pool);
562 if (pPool) {
563 return pPool->updateActive;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600564 }
565 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600566 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600567}
568
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600569static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600570 loader_platform_thread_lock_mutex(&globalLock);
571 if (layoutMap.find(layout) == layoutMap.end()) {
572 loader_platform_thread_unlock_mutex(&globalLock);
573 return NULL;
574 }
575 loader_platform_thread_unlock_mutex(&globalLock);
576 return layoutMap[layout];
577}
578
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600579// For given update struct, return binding
580static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600581{
582 switch (pUpdateStruct->sType)
583 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600585 return ((VkUpdateSamplers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600586 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600587 return ((VkUpdateSamplerTextures*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600588 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600589 return ((VkUpdateImages*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600590 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600591 return ((VkUpdateBuffers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600592 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600593 return ((VkUpdateAsCopy*)pUpdateStruct)->binding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600594 default:
595 // TODO : Flag specific error for this case
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600596 assert(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600597 return 0;
598 }
599}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600600// Return count for given update struct
601static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600602{
603 switch (pUpdateStruct->sType)
604 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600605 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600606 return (((VkUpdateSamplers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600607 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600608 return (((VkUpdateSamplerTextures*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600609 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600610 return (((VkUpdateImages*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600611 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600612 return (((VkUpdateBuffers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600613 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600614 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600615 return (((VkUpdateAsCopy*)pUpdateStruct)->arrayElement);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600616 default:
617 // TODO : Flag specific error for this case
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600618 assert(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600619 return 0;
620 }
621}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600622// Return count for given update struct
623static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
624{
625 switch (pUpdateStruct->sType)
626 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600627 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600628 return (((VkUpdateSamplers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600629 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600630 return (((VkUpdateSamplerTextures*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600631 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600632 return (((VkUpdateImages*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600633 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600634 return (((VkUpdateBuffers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600635 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600636 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600637 return (((VkUpdateAsCopy*)pUpdateStruct)->count);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600638 default:
639 // TODO : Flag specific error for this case
640 assert(0);
641 return 0;
642 }
643}
644// For given Layout Node and binding, return index where that binding begins
645static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
646{
647 uint32_t offsetIndex = 0;
648 for (uint32_t i = 0; i<binding; i++) {
649 offsetIndex += pLayout->createInfo.pBinding[i].count;
650 }
651 return offsetIndex;
652}
653// For given layout node and binding, return last index that is updated
654static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
655{
656 uint32_t offsetIndex = 0;
657 for (uint32_t i = 0; i<=binding; i++) {
658 offsetIndex += pLayout->createInfo.pBinding[i].count;
659 }
660 return offsetIndex-1;
661}
662// For given layout and update, return the first overall index of the layout that is update
663static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
664{
665 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
666}
667// For given layout and update, return the last overall index of the layout that is update
668static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
669{
670 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
671}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600672// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600673static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600674{
675 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600676 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600677 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600678 switch (pUpdateStruct->sType)
679 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600680 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
681 actualType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600682 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600683 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600684 actualType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600685 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600686 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600687 actualType = ((VkUpdateImages*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600688 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600689 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600690 actualType = ((VkUpdateBuffers*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600691 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600692 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600693 actualType = ((VkUpdateAsCopy*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600694 break;
695 default:
696 // TODO : Flag specific error for this case
697 return 0;
698 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600699 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600700 if (pLayout->pTypes[i] != actualType)
701 return 0;
702 }
703 return 1;
704}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600705// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
706// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
707// NOTE : Calls to this function should be wrapped in mutex
708static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
709{
710 GENERIC_HEADER* pNewNode = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600711 VkUpdateSamplers* pUS = NULL;
712 VkUpdateSamplerTextures* pUST = NULL;
713 VkUpdateBuffers* pUB = NULL;
714 VkUpdateImages* pUI = NULL;
715 VkUpdateAsCopy* pUAC = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600716 size_t array_size = 0;
717 size_t base_array_size = 0;
718 size_t total_array_size = 0;
719 size_t baseBuffAddr = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600720 VkImageViewAttachInfo** ppLocalImageViews = NULL;
721 VkBufferViewAttachInfo** ppLocalBufferViews = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600722 char str[1024];
723 switch (pUpdate->sType)
724 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600725 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600726 pUS = new VkUpdateSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600727 pNewNode = (GENERIC_HEADER*)pUS;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600728 memcpy(pUS, pUpdate, sizeof(VkUpdateSamplers));
729 pUS->pSamplers = new VkSampler[pUS->count];
730 array_size = sizeof(VkSampler) * pUS->count;
731 memcpy((void*)pUS->pSamplers, ((VkUpdateSamplers*)pUpdate)->pSamplers, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600732 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600733 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600734 pUST = new VkUpdateSamplerTextures;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600735 pNewNode = (GENERIC_HEADER*)pUST;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600736 memcpy(pUST, pUpdate, sizeof(VkUpdateSamplerTextures));
737 pUST->pSamplerImageViews = new VkSamplerImageViewInfo[pUST->count];
738 array_size = sizeof(VkSamplerImageViewInfo) * pUST->count;
739 memcpy((void*)pUST->pSamplerImageViews, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews, array_size);
Tobin Ehliseaf28662015-04-08 10:58:37 -0600740 for (uint32_t i = 0; i < pUST->count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600741 VkImageViewAttachInfo** ppIV = (VkImageViewAttachInfo**)&pUST->pSamplerImageViews[i].pImageView;
742 *ppIV = new VkImageViewAttachInfo;
743 memcpy((void*)*ppIV, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews[i].pImageView, sizeof(VkImageViewAttachInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600744 }
745 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600746 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600747 pUI = new VkUpdateImages;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600748 pNewNode = (GENERIC_HEADER*)pUI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600749 memcpy(pUI, pUpdate, sizeof(VkUpdateImages));
750 pUI->pImageViews = new VkImageViewAttachInfo[pUI->count];
751 array_size = (sizeof(VkImageViewAttachInfo) * pUI->count);
752 memcpy((void*)pUI->pImageViews, ((VkUpdateImages*)pUpdate)->pImageViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600753 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600754 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600755 pUB = new VkUpdateBuffers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600756 pNewNode = (GENERIC_HEADER*)pUB;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600757 memcpy(pUB, pUpdate, sizeof(VkUpdateBuffers));
758 pUB->pBufferViews = new VkBufferViewAttachInfo[pUB->count];
759 array_size = (sizeof(VkBufferViewAttachInfo) * pUB->count);
760 memcpy((void*)pUB->pBufferViews, ((VkUpdateBuffers*)pUpdate)->pBufferViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600761 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600762 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600763 pUAC = new VkUpdateAsCopy;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600764 pUpdate = (GENERIC_HEADER*)pUAC;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600765 memcpy(pUAC, pUpdate, sizeof(VkUpdateAsCopy));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600766 break;
767 default:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600768 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600769 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600770 return NULL;
771 }
772 // Make sure that pNext for the end of shadow copy is NULL
773 pNewNode->pNext = NULL;
774 return pNewNode;
775}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600776// For given ds, update its mapping based on ppUpdateArray
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600777static void dsUpdate(VkDescriptorSet ds, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600778{
779 SET_NODE* pSet = getSetNode(ds);
780 loader_platform_thread_lock_mutex(&globalLock);
781 g_lastBoundDescriptorSet = pSet->set;
782 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600783 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600784 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600785 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600786 for (uint32_t i = 0; i < updateCount; i++) {
787 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*)ppUpdateArray[i];
788 pLayout = pSet->pLayout;
789 // Make sure that binding is within bounds
790 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600791 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600792 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600793 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600794 }
795 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600796 // Next verify that update falls within size of given binding
797 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600798 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600799 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600800 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
801 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600802 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600803 }
804 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600805 // Layout bindings match w/ update ok, now verify that update is of the right type
806 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600807 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600808 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600809 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600810 }
811 else {
812 // Save the update info
813 // TODO : Info message that update successful
814 // Create new update struct for this set's shadow copy
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600815 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600816 if (NULL == pNewNode) {
817 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600818 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
819 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600820 }
821 else {
822 // Insert shadow node into LL of updates for this set
823 pNewNode->pNext = pSet->pUpdateStructs;
824 pSet->pUpdateStructs = pNewNode;
825 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600826 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
827 assert(j<pSet->descriptorCount);
828 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829 }
830 }
831 }
832 }
833 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600834 }
835 loader_platform_thread_unlock_mutex(&globalLock);
836}
837// Free the shadowed update node for this Set
838// NOTE : Calls to this function should be wrapped in mutex
839static void freeShadowUpdateTree(SET_NODE* pSet)
840{
841 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
842 pSet->pUpdateStructs = NULL;
843 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
844 // Clear the descriptor mappings as they will now be invalid
845 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
846 while(pShadowUpdate) {
847 pFreeUpdate = pShadowUpdate;
848 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
849 uint32_t index = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600850 VkUpdateSamplers* pUS = NULL;
851 VkUpdateSamplerTextures* pUST = NULL;
852 VkUpdateImages* pUI = NULL;
853 VkUpdateBuffers* pUB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600854 void** ppToFree = NULL;
855 switch (pFreeUpdate->sType)
856 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600857 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600858 pUS = (VkUpdateSamplers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600859 if (pUS->pSamplers)
860 delete[] pUS->pSamplers;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600861 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600862 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600863 pUST = (VkUpdateSamplerTextures*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600864 if (pUST->pSamplerImageViews) {
865 for (index = 0; index < pUST->count; index++) {
866 if (pUST->pSamplerImageViews[index].pImageView) {
867 delete pUST->pSamplerImageViews[index].pImageView;
868 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600869 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600870 delete[] pUST->pSamplerImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600871 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600872 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600873 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600874 pUI = (VkUpdateImages*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600875 if (pUI->pImageViews)
876 delete[] pUI->pImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600877 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600878 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600879 pUB = (VkUpdateBuffers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600880 if (pUB->pBufferViews)
881 delete[] pUB->pBufferViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600882 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600883 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600884 break;
885 default:
886 assert(0);
887 break;
888 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600889 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600890 }
891}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600892// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600893// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600894static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600895{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600896 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600897 SET_NODE* pSet = (*ii).second->pSets;
898 SET_NODE* pFreeSet = pSet;
899 while (pSet) {
900 pFreeSet = pSet;
901 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600902 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600903 // Free Update shadow struct tree
904 freeShadowUpdateTree(pFreeSet);
905 if (pFreeSet->ppDescriptors) {
906 delete pFreeSet->ppDescriptors;
907 }
908 delete pFreeSet;
909 }
910 if ((*ii).second->createInfo.pTypeCount) {
911 delete (*ii).second->createInfo.pTypeCount;
912 }
913 delete (*ii).second;
914 }
915}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600916// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600917// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600918static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600919{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600920 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600921 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600922 if (pLayout->createInfo.pBinding) {
923 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
924 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
925 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
926 }
927 delete[] pLayout->createInfo.pBinding;
928 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600929 if (pLayout->pTypes) {
930 delete pLayout->pTypes;
931 }
932 delete pLayout;
933 }
934}
935// Currently clearing a set is removing all previous updates to that set
936// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600937static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600938{
939 SET_NODE* pSet = getSetNode(set);
940 if (!pSet) {
941 // TODO : Return error
942 }
943 else {
944 loader_platform_thread_lock_mutex(&globalLock);
945 freeShadowUpdateTree(pSet);
946 loader_platform_thread_unlock_mutex(&globalLock);
947 }
948}
949
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600950static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600951{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600952 POOL_NODE* pPool = getPoolNode(pool);
953 if (!pPool) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600954 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600955 sprintf(str, "Unable to find pool node for pool %p specified in vkClearDescriptorPool() call", (void*)pool);
956 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600957 }
958 else
959 {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600960 // For every set off of this pool, clear it
961 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600962 while (pSet) {
963 clearDescriptorSet(pSet->set);
964 }
965 }
966}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600967// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600968static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600969{
970 loader_platform_thread_lock_mutex(&globalLock);
971 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
972 loader_platform_thread_unlock_mutex(&globalLock);
973 return NULL;
974 }
975 loader_platform_thread_unlock_mutex(&globalLock);
976 return cmdBufferMap[cb];
977}
978// Free all CB Nodes
979// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600980static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600981{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600982 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -0600983 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
984 while (!cmd_node_list.empty()) {
985 CMD_NODE* cmd_node = cmd_node_list.back();
986 delete cmd_node;
987 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600988 }
989 delete (*ii).second;
990 }
991}
992static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
993{
994 CMD_NODE* pCmd = new CMD_NODE;
995 if (pCmd) {
996 // init cmd node and append to end of cmd LL
997 memset(pCmd, 0, sizeof(CMD_NODE));
998 pCmd->cmdNumber = ++pCB->numCmds;
999 pCmd->type = cmd;
1000 pCB->pCmds.push_back(pCmd);
1001 }
1002 else {
1003 char str[1024];
1004 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001005 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001006 }
1007}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001008static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001009{
1010 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1011 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001012 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1013 while (!cmd_list.empty()) {
1014 delete cmd_list.back();
1015 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001016 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001017 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001018 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001019 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001020 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001021 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1022 pCB->cmdBuffer = cb;
1023 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001024 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001025 pCB->lastVtxBinding = MAX_BINDING;
1026 }
1027}
1028// Set the last bound dynamic state of given type
1029// TODO : Need to track this per cmdBuffer and correlate cmdBuffer for Draw w/ last bound for that cmdBuffer?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001030static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001031{
1032 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1033 if (pCB) {
1034 updateCBTracking(cmdBuffer);
1035 loader_platform_thread_lock_mutex(&globalLock);
1036 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1037 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1038 char str[1024];
1039 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001040 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001041 }
1042 else {
1043 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1044 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1045 }
1046 loader_platform_thread_unlock_mutex(&globalLock);
1047 }
1048 else {
1049 char str[1024];
1050 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001051 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001052 }
1053}
1054// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001055static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001056{
1057 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1058 if (pCB) {
1059 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1060 if (!pPipeTrav) {
1061 // nothing to print
1062 }
1063 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001064 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001065 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001066 }
1067 }
1068}
1069// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001070static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001071{
1072 SET_NODE* pSet = getSetNode(ds);
1073 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001074 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001075 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001076 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1077 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001078 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001079 fprintf(pOutFile, "%s", pGVstr);
1080 free(pGVstr);
1081 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1082 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001083 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001084 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001085 ++layout_index;
1086 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001087 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001088 fprintf(pOutFile, "%s", pGVstr);
1089 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001090 if (pSet->pUpdateStructs) {
1091 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1092 fprintf(pOutFile, "%s", pGVstr);
1093 free(pGVstr);
1094 }
1095 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001096 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1097 uint32_t i = 0;
1098 for (i=0; i < pSet->descriptorCount; i++) {
1099 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001100 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_VkStructureType(pSet->ppDescriptors[i]->sType));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001101 }
1102 }
1103#define NUM_COLORS 7
1104 vector<string> edgeColors;
1105 edgeColors.push_back("0000ff");
1106 edgeColors.push_back("ff00ff");
1107 edgeColors.push_back("ffff00");
1108 edgeColors.push_back("00ff00");
1109 edgeColors.push_back("000000");
1110 edgeColors.push_back("00ffff");
1111 edgeColors.push_back("ff0000");
1112 uint32_t colorIdx = 0;
1113 fprintf(pOutFile, "</TABLE>>\n];\n");
1114 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001115 VkUpdateSamplers* pUS = NULL;
1116 VkUpdateSamplerTextures* pUST = NULL;
1117 VkUpdateImages* pUI = NULL;
1118 VkUpdateBuffers* pUB = NULL;
1119 VkUpdateAsCopy* pUAC = NULL;
1120 VkSamplerCreateInfo* pSCI = NULL;
1121 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001122 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001123 void** ppNextPtr = NULL;
1124 void* pSaveNext = NULL;
1125 for (i=0; i < pSet->descriptorCount; i++) {
1126 if (pSet->ppDescriptors[i]) {
1127 switch (pSet->ppDescriptors[i]->sType)
1128 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001129 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001130 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001131 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001132 if (pSCI) {
1133 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001134 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001135 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1136 }
1137 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001138 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001139 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001140 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001141 if (pSCI) {
1142 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001143 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001144 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1145 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001146 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001147 if (pIVCI) {
1148 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001149 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001150 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1151 }
1152 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001153 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001154 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001155 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001156 if (pIVCI) {
1157 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001158 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001159 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1160 }
1161 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001162 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001163 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001164 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001165 if (pBVCI) {
1166 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001167 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001168 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1169 }
1170 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001171 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001172 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001173 // TODO : Need to validate this code
1174 // Save off pNext and set to NULL while printing this struct, then restore it
1175 ppNextPtr = (void**)&pUAC->pNext;
1176 pSaveNext = *ppNextPtr;
1177 *ppNextPtr = NULL;
1178 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001179 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001180 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1181 // Restore next ptr
1182 *ppNextPtr = pSaveNext;
1183 break;
1184 default:
1185 break;
1186 }
1187 colorIdx = (colorIdx+1) % NUM_COLORS;
1188 }
1189 }
1190 }
1191 fprintf(pOutFile, "}\n");
1192 fprintf(pOutFile, "}\n");
1193 }
1194}
1195// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001196static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001197{
1198 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1199 if (pCB && pCB->lastBoundDescriptorSet) {
1200 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1201 }
1202}
1203// Dump a GraphViz dot file showing the Cmd Buffers
1204static void cbDumpDotFile(string outFileName)
1205{
1206 // Print CB Chain for each CB
1207 FILE* pOutFile;
1208 pOutFile = fopen(outFileName.c_str(), "w");
1209 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1210 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1211 GLOBAL_CB_NODE* pCB = NULL;
1212 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1213 pCB = g_pLastTouchedCB[i];
1214 if (pCB) {
1215 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1216 uint32_t instNum = 0;
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001217 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1218 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001219 if (instNum) {
1220 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1221 }
1222 if (pCB == g_lastGlobalCB) {
1223 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());
1224 }
1225 else {
1226 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());
1227 }
1228 ++instNum;
1229 }
1230 fprintf(pOutFile, "}\n");
1231 }
1232 }
1233 fprintf(pOutFile, "}\n");
1234 fprintf(pOutFile, "}\n"); // close main graph "g"
1235 fclose(pOutFile);
1236}
1237// Dump a GraphViz dot file showing the pipeline for last bound global state
1238static void dumpGlobalDotFile(char *outFileName)
1239{
1240 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1241 if (pPipeTrav) {
1242 FILE* pOutFile;
1243 pOutFile = fopen(outFileName, "w");
1244 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1245 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1246 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001247 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001248 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001249 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001250 fprintf(pOutFile, "%s", pGVstr);
1251 free(pGVstr);
1252 }
1253 }
1254 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1255 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001256 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001257 fprintf(pOutFile, "%s", pGVstr);
1258 free(pGVstr);
1259 fprintf(pOutFile, "}\n");
1260 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1261 fprintf(pOutFile, "}\n"); // close main graph "g"
1262 fclose(pOutFile);
1263 }
1264}
1265// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001266static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001267{
1268 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1269 if (pCB) {
1270 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1271 if (pPipeTrav) {
1272 FILE* pOutFile;
1273 pOutFile = fopen(outFileName.c_str(), "w");
1274 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1275 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1276 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001277 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001278 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001279 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001280 fprintf(pOutFile, "%s", pGVstr);
1281 free(pGVstr);
1282 }
1283 }
1284 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1285 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001286 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001287 fprintf(pOutFile, "%s", pGVstr);
1288 free(pGVstr);
1289 fprintf(pOutFile, "}\n");
1290 dsDumpDot(cb, pOutFile);
1291 fprintf(pOutFile, "}\n"); // close main graph "g"
1292 fclose(pOutFile);
1293 }
1294 }
1295}
1296// Verify VB Buffer binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001297static void validateVBBinding(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001298{
1299 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1300 if (pCB && pCB->lastBoundPipeline) {
1301 // First verify that we have a Node for bound pipeline
1302 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1303 char str[1024];
1304 if (!pPipeTrav) {
1305 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001306 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001307 }
1308 else {
1309 // Verify Vtx binding
1310 if (MAX_BINDING != pCB->lastVtxBinding) {
1311 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1312 if (0 == pPipeTrav->vtxBindingCount) {
1313 sprintf(str, "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001315 }
1316 else {
1317 sprintf(str, "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001318 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001319 }
1320 }
1321 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001322 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001323 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001324 }
1325 }
1326 }
1327 }
1328}
1329// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001330static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001331{
1332 char tmp_str[1024];
1333 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.
1334 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1335 if (pCB) {
1336 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001337 POOL_NODE* pPool = getPoolNode(pSet->pool);
1338 // Print out pool details
1339 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001340 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001341 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001342 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001343 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001344 // Print out set details
1345 char prefix[10];
1346 uint32_t index = 0;
1347 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001348 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001349 LAYOUT_NODE* pLayout = pSet->pLayout;
1350 // Print layout details
1351 sprintf(tmp_str, "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001352 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001353 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001354 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001355 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001356 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001357 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001358 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1359 if (pUpdate) {
1360 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001361 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001362 sprintf(prefix, " [UC] ");
1363 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001364 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001365 // TODO : If there is a "view" associated with this update, print CI for that view
1366 }
1367 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001368 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1369 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001370 }
1371 }
1372}
1373
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001374static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001375{
1376 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1377 if (pCB) {
1378 char str[1024];
1379 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001380 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001381 vector<CMD_NODE*> pCmds = pCB->pCmds;
1382 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001383 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001384 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001385 }
1386 }
1387 else {
1388 // Nothing to print
1389 }
1390}
1391
1392
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001393static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001394{
1395 printDSConfig(cb);
1396 printPipeline(cb);
1397 printDynamicState(cb);
1398 static int autoDumpOnce = 0;
1399 if (autoDumpOnce) {
1400 autoDumpOnce = 0;
1401 dumpDotFile(cb, "pipeline_dump.dot");
1402 cbDumpDotFile("cb_dump.dot");
1403#if defined(_WIN32)
1404// FIXME: NEED WINDOWS EQUIVALENT
1405#else // WIN32
1406 // Convert dot to svg if dot available
1407 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001408 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1409 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001410 }
1411#endif // WIN32
1412 }
1413}
1414
1415static void initDrawState(void)
1416{
1417 const char *strOpt;
1418 // initialize DrawState options
1419 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1420 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1421
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001422 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001423 {
1424 strOpt = getLayerOption("DrawStateLogFilename");
1425 if (strOpt)
1426 {
1427 g_logFile = fopen(strOpt, "w");
1428 }
1429 if (g_logFile == NULL)
1430 g_logFile = stdout;
1431 }
1432 // initialize Layer dispatch table
1433 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001434 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001435 fpNextGPA = pCurObj->pGPA;
1436 assert(fpNextGPA);
1437
Tony Barbour8205d902015-04-16 15:59:00 -06001438 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001439
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001440 if (!globalLockInitialized)
1441 {
1442 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001443 // suggestion is to call this during vkCreateInstance(), and then we
1444 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001445 // that the layer have per-instance locks. We need to come back and
1446 // address this soon.
1447 loader_platform_thread_create_mutex(&globalLock);
1448 globalLockInitialized = 1;
1449 }
1450}
1451
Tony Barbour8205d902015-04-16 15:59:00 -06001452VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001453{
Jon Ashburn630e44f2015-04-08 21:33:34 -06001454 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001455 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001456 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001457 return result;
1458}
1459
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001460VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001461{
1462 // Free all the memory
1463 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001464 deletePipelines();
1465 deleteSamplers();
1466 deleteImages();
1467 deleteBuffers();
1468 deleteCmdBuffers();
1469 deleteDynamicState();
1470 deletePools();
1471 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001472 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001473 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001474 return result;
1475}
1476
Jon Ashburneb2728b2015-04-10 14:33:07 -06001477struct extProps {
1478 uint32_t version;
1479 const char * const name;
1480};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001481#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001482static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1483 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001484 0x10, "DrawState",
1485 0x10, "Validation",
1486 0x10, "drawStateDumpDotFile",
1487 0x10, "drawStateDumpCommandBufferDotFile",
1488 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001489};
1490
1491VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1492 VkExtensionInfoType infoType,
1493 uint32_t extensionIndex,
1494 size_t* pDataSize,
1495 void* pData)
1496{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001497 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1498 VkExtensionProperties *ext_props;
1499 uint32_t *count;
1500
1501 if (pDataSize == NULL)
1502 return VK_ERROR_INVALID_POINTER;
1503
1504 switch (infoType) {
1505 case VK_EXTENSION_INFO_TYPE_COUNT:
1506 *pDataSize = sizeof(uint32_t);
1507 if (pData == NULL)
1508 return VK_SUCCESS;
1509 count = (uint32_t *) pData;
1510 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1511 break;
1512 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1513 *pDataSize = sizeof(VkExtensionProperties);
1514 if (pData == NULL)
1515 return VK_SUCCESS;
1516 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1517 return VK_ERROR_INVALID_VALUE;
1518 ext_props = (VkExtensionProperties *) pData;
1519 ext_props->version = dsExts[extensionIndex].version;
1520 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1521 VK_MAX_EXTENSION_NAME);
1522 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1523 break;
1524 default:
1525 return VK_ERROR_INVALID_VALUE;
1526 };
1527
1528 return VK_SUCCESS;
1529}
1530
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001531VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001532{
1533 if (gpu != NULL)
1534 {
Jon Ashburn630e44f2015-04-08 21:33:34 -06001535 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001536 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001537 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001538 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001539 } else {
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001540 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001541 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001542 // This layer compatible with all GPUs
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001543 *pLayerCount = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001544 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001545 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001546 }
1547}
1548
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001549VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001550{
1551 for (uint32_t i=0; i < cmdBufferCount; i++) {
1552 // Validate that cmd buffers have been updated
1553 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001554 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001555 return result;
1556}
1557
Mike Stroyan230e6252015-04-17 12:36:38 -06001558VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001559{
1560 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyan230e6252015-04-17 12:36:38 -06001561 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001562 return result;
1563}
1564
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001565VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001566{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001567 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001568 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001569 loader_platform_thread_lock_mutex(&globalLock);
1570 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1571 pNewNode->buffer = *pView;
1572 pNewNode->createInfo = *pCreateInfo;
1573 bufferMap[*pView] = pNewNode;
1574 loader_platform_thread_unlock_mutex(&globalLock);
1575 }
1576 return result;
1577}
1578
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001579VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001580{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001581 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001582 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001583 loader_platform_thread_lock_mutex(&globalLock);
1584 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1585 pNewNode->image = *pView;
1586 pNewNode->createInfo = *pCreateInfo;
1587 imageMap[*pView] = pNewNode;
1588 loader_platform_thread_unlock_mutex(&globalLock);
1589 }
1590 return result;
1591}
1592
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001593static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001594{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001595 // Create LL HEAD for this Pipeline
1596 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001597 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1598 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1599 pPipeNode->pipeline = *pPipeline;
1600 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001601 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001602}
1603
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001604VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001605{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001606 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001607 // Create LL HEAD for this Pipeline
1608 char str[1024];
1609 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001610 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001611
1612 track_pipeline(pCreateInfo, pPipeline);
1613
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001614 return result;
1615}
1616
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001617VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1618 VkDevice device,
1619 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1620 VkPipeline basePipeline,
1621 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001622{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001623 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001624 // Create LL HEAD for this Pipeline
1625 char str[1024];
1626 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001627 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001628
1629 track_pipeline(pCreateInfo, pPipeline);
1630
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001631 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001632
1633 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001634}
1635
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001636VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001637{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001638 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001639 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001640 loader_platform_thread_lock_mutex(&globalLock);
1641 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1642 pNewNode->sampler = *pSampler;
1643 pNewNode->createInfo = *pCreateInfo;
1644 sampleMap[*pSampler] = pNewNode;
1645 loader_platform_thread_unlock_mutex(&globalLock);
1646 }
1647 return result;
1648}
1649
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001650VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001651{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001652 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001653 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001654 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1655 if (NULL == pNewNode) {
1656 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001657 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1658 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001659 }
1660 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001661 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1662 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1663 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001664 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001665 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1666 totalCount += pCreateInfo->pBinding[i].count;
1667 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001668 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1669 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1670 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001671 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001672 }
1673 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001674 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001675 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001676 uint32_t j = 0;
1677 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1678 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1679 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001680 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001681 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001682 }
1683 }
1684 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001685 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001686 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1687 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001688 // Put new node at Head of global Layer list
1689 loader_platform_thread_lock_mutex(&globalLock);
1690 layoutMap[*pSetLayout] = pNewNode;
1691 loader_platform_thread_unlock_mutex(&globalLock);
1692 }
1693 return result;
1694}
1695
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001696VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001697{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001698 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001699 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001700 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001701 }
1702 return result;
1703}
1704
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001705VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001706{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001707 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001708 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001709 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001710 POOL_NODE* pPoolNode = poolMap.begin()->second;
1711 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001712 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001713 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001714 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001715 }
1716 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001717 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001718 }
1719 loader_platform_thread_unlock_mutex(&globalLock);
1720 }
1721 return result;
1722}
1723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001724VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001725{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001726 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001727 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001729 POOL_NODE* pPoolNode = poolMap.begin()->second;
1730 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001731 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001732 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001733 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001734 }
1735 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001736 if (!pPoolNode->updateActive) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001737 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001738 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1739 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_DS_END_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001740 }
1741 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001742 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001743 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001744 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001745 }
1746 loader_platform_thread_unlock_mutex(&globalLock);
1747 }
1748 return result;
1749}
1750
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001751VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001752{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001753 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001754 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001755 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001756 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001757 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyan230e6252015-04-17 12:36:38 -06001758 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001759 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001760 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761 if (NULL == pNewNode) {
1762 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001763 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyan230e6252015-04-17 12:36:38 -06001764 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001765 }
1766 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001767 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001768 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1769 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001770 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001771 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1772 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001773 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1774 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001775 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001776 pNewNode->updateActive = 0;
1777 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001778 pNewNode->pool = *pDescriptorPool;
1779 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001780 }
1781 loader_platform_thread_unlock_mutex(&globalLock);
1782 }
1783 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001784 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785 }
1786 return result;
1787}
1788
Mike Stroyan230e6252015-04-17 12:36:38 -06001789VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001790{
Mike Stroyan230e6252015-04-17 12:36:38 -06001791 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001792 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001793 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001794 }
1795 return result;
1796}
1797
Mike Stroyan230e6252015-04-17 12:36:38 -06001798VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799{
Mike Stroyan230e6252015-04-17 12:36:38 -06001800 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001801 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001802 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1803 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001805 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1806 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001807 }
1808 else {
1809 for (uint32_t i = 0; i < *pCount; i++) {
1810 char str[1024];
1811 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001812 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001813 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 SET_NODE* pNewNode = new SET_NODE;
1815 if (NULL == pNewNode) {
1816 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001817 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1818 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001819 }
1820 else {
1821 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001822 // Insert set at head of Set LL for this pool
1823 pNewNode->pNext = pPoolNode->pSets;
1824 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1826 if (NULL == pLayout) {
1827 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001828 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1829 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001830 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001831 pNewNode->pLayout = pLayout;
1832 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001833 pNewNode->set = pDescriptorSets[i];
1834 pNewNode->setUsage = setUsage;
1835 pNewNode->descriptorCount = pLayout->endIndex + 1;
1836 if (pNewNode->descriptorCount) {
1837 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1838 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1839 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1840 }
1841 setMap[pDescriptorSets[i]] = pNewNode;
1842 }
1843 }
1844 }
1845 }
1846 return result;
1847}
1848
Mike Stroyan230e6252015-04-17 12:36:38 -06001849VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001850{
1851 for (uint32_t i = 0; i < count; i++) {
1852 clearDescriptorSet(pDescriptorSets[i]);
1853 }
Mike Stroyan230e6252015-04-17 12:36:38 -06001854 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001855}
1856
Mike Stroyan230e6252015-04-17 12:36:38 -06001857VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001858{
1859 SET_NODE* pSet = getSetNode(descriptorSet);
1860 if (!dsUpdateActive(descriptorSet)) {
1861 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001862 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1863 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSet->pool, 0, DRAWSTATE_UPDATE_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001864 }
1865 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001866 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001867 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868 }
1869
Mike Stroyan230e6252015-04-17 12:36:38 -06001870 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871}
1872
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001873VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001874{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001875 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001876 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001877 return result;
1878}
1879
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001880VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001882 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001883 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001884 return result;
1885}
1886
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001887VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001888{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001889 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001890 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001891 return result;
1892}
1893
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001894VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001895{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001896 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001897 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001898 return result;
1899}
1900
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001901VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001902{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001903 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001904 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001905 loader_platform_thread_lock_mutex(&globalLock);
1906 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1907 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1908 pCB->cmdBuffer = *pCmdBuffer;
1909 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001910 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001911 pCB->lastVtxBinding = MAX_BINDING;
1912 cmdBufferMap[*pCmdBuffer] = pCB;
1913 loader_platform_thread_unlock_mutex(&globalLock);
1914 updateCBTracking(*pCmdBuffer);
1915 }
1916 return result;
1917}
1918
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001919VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001920{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001921 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001922 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001923 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1924 if (pCB) {
1925 if (CB_NEW != pCB->state)
1926 resetCB(cmdBuffer);
1927 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001928 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001929 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001930 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001931 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001932 }
1933 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001934 }
1935 else {
1936 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001937 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1938 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001939 }
1940 updateCBTracking(cmdBuffer);
1941 }
1942 return result;
1943}
1944
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001945VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001946{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001947 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001948 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001949 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1950 if (pCB) {
1951 pCB->state = CB_UPDATE_COMPLETE;
1952 printCB(cmdBuffer);
1953 }
1954 else {
1955 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001956 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1957 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001958 }
1959 updateCBTracking(cmdBuffer);
1960 //cbDumpDotFile("cb_dump.dot");
1961 }
1962 return result;
1963}
1964
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001965VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001966{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001967 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001968 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001969 resetCB(cmdBuffer);
1970 updateCBTracking(cmdBuffer);
1971 }
1972 return result;
1973}
1974
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001975VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001976{
1977 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1978 if (pCB) {
1979 updateCBTracking(cmdBuffer);
1980 addCmd(pCB, CMD_BINDPIPELINE);
1981 PIPELINE_NODE* pPN = getPipeline(pipeline);
1982 if (pPN) {
1983 pCB->lastBoundPipeline = pipeline;
1984 loader_platform_thread_lock_mutex(&globalLock);
1985 g_lastBoundPipeline = pPN;
1986 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001987 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001988 }
1989 else {
1990 char str[1024];
1991 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001992 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001993 }
1994 }
1995 else {
1996 char str[1024];
1997 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001998 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001999 }
2000 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2001}
2002
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002003VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002004{
2005 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
2006 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2007}
2008
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002009VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002010{
2011 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2012 if (pCB) {
2013 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002014 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002015 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002016 if (getSetNode(pDescriptorSets[i])) {
2017 if (dsUpdateActive(pDescriptorSets[i])) {
2018 // TODO : This check here needs to be made at QueueSubmit time
2019 /*
2020 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002021 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
2022 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_BINDING_DS_NO_END_UPDATE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002023 */
2024 }
2025 loader_platform_thread_lock_mutex(&globalLock);
2026 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2027 g_lastBoundDescriptorSet = pDescriptorSets[i];
2028 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002029 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002030 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002031 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002032 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002033 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002034 else {
2035 char str[1024];
2036 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002037 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002038 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002039 }
2040 }
2041 else {
2042 char str[1024];
2043 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002044 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002045 }
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002046 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002047}
2048
Tony Barbour8205d902015-04-16 15:59:00 -06002049VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002050{
2051 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2052 if (pCB) {
2053 updateCBTracking(cmdBuffer);
2054 addCmd(pCB, CMD_BINDINDEXBUFFER);
2055 // TODO : Track idxBuffer binding
2056 }
2057 else {
2058 char str[1024];
2059 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002060 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002061 }
2062 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2063}
2064
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002065VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2066 VkCmdBuffer cmdBuffer,
2067 uint32_t startBinding,
2068 uint32_t bindingCount,
2069 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002070 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002071{
2072 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2073 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002074 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002075 updateCBTracking(cmdBuffer);
2076 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002077 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002078 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002079 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002080 char str[1024];
2081 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002082 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002083 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002084 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002085}
2086
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002087VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002088{
2089 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2090 if (pCB) {
2091 updateCBTracking(cmdBuffer);
2092 addCmd(pCB, CMD_DRAW);
2093 pCB->drawCount[DRAW]++;
2094 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002095 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2096 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002097 synchAndPrintDSConfig(cmdBuffer);
2098 }
2099 else {
2100 char str[1024];
2101 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002102 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002103 }
2104 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2105}
2106
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002107VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002108{
2109 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2110 if (pCB) {
2111 updateCBTracking(cmdBuffer);
2112 addCmd(pCB, CMD_DRAWINDEXED);
2113 pCB->drawCount[DRAW_INDEXED]++;
2114 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002115 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2116 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002117 synchAndPrintDSConfig(cmdBuffer);
2118 }
2119 else {
2120 char str[1024];
2121 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002122 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002123 }
2124 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2125}
2126
Tony Barbour8205d902015-04-16 15:59:00 -06002127VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002128{
2129 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2130 if (pCB) {
2131 updateCBTracking(cmdBuffer);
2132 addCmd(pCB, CMD_DRAWINDIRECT);
2133 pCB->drawCount[DRAW_INDIRECT]++;
2134 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002135 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2136 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002137 synchAndPrintDSConfig(cmdBuffer);
2138 }
2139 else {
2140 char str[1024];
2141 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002142 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002143 }
2144 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2145}
2146
Tony Barbour8205d902015-04-16 15:59:00 -06002147VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002148{
2149 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2150 if (pCB) {
2151 updateCBTracking(cmdBuffer);
2152 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2153 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2154 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002155 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2156 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002157 synchAndPrintDSConfig(cmdBuffer);
2158 }
2159 else {
2160 char str[1024];
2161 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002162 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002163 }
2164 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2165}
2166
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002167VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002168{
2169 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2170 if (pCB) {
2171 updateCBTracking(cmdBuffer);
2172 addCmd(pCB, CMD_DISPATCH);
2173 }
2174 else {
2175 char str[1024];
2176 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002177 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002178 }
2179 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2180}
2181
Tony Barbour8205d902015-04-16 15:59:00 -06002182VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002183{
2184 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2185 if (pCB) {
2186 updateCBTracking(cmdBuffer);
2187 addCmd(pCB, CMD_DISPATCHINDIRECT);
2188 }
2189 else {
2190 char str[1024];
2191 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002192 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002193 }
2194 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2195}
2196
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002197VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002198{
2199 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2200 if (pCB) {
2201 updateCBTracking(cmdBuffer);
2202 addCmd(pCB, CMD_COPYBUFFER);
2203 }
2204 else {
2205 char str[1024];
2206 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002207 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002208 }
2209 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2210}
2211
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002212VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2213 VkImage srcImage,
2214 VkImageLayout srcImageLayout,
2215 VkImage destImage,
2216 VkImageLayout destImageLayout,
2217 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002218{
2219 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2220 if (pCB) {
2221 updateCBTracking(cmdBuffer);
2222 addCmd(pCB, CMD_COPYIMAGE);
2223 }
2224 else {
2225 char str[1024];
2226 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002227 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002228 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002229 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002230}
2231
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002232VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2233 VkImage srcImage, VkImageLayout srcImageLayout,
2234 VkImage destImage, VkImageLayout destImageLayout,
2235 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002236{
2237 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2238 if (pCB) {
2239 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002240 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002241 }
2242 else {
2243 char str[1024];
2244 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002245 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002246 }
2247 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2248}
2249
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002250VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2251 VkBuffer srcBuffer,
2252 VkImage destImage, VkImageLayout destImageLayout,
2253 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002254{
2255 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2256 if (pCB) {
2257 updateCBTracking(cmdBuffer);
2258 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2259 }
2260 else {
2261 char str[1024];
2262 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002263 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002264 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002265 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266}
2267
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002268VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2269 VkImage srcImage, VkImageLayout srcImageLayout,
2270 VkBuffer destBuffer,
2271 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002272{
2273 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2274 if (pCB) {
2275 updateCBTracking(cmdBuffer);
2276 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2277 }
2278 else {
2279 char str[1024];
2280 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002281 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002282 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002283 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002284}
2285
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002286VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002287{
2288 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2289 if (pCB) {
2290 updateCBTracking(cmdBuffer);
2291 addCmd(pCB, CMD_CLONEIMAGEDATA);
2292 }
2293 else {
2294 char str[1024];
2295 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002296 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002297 }
2298 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2299}
2300
Tony Barbour8205d902015-04-16 15:59:00 -06002301VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002302{
2303 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2304 if (pCB) {
2305 updateCBTracking(cmdBuffer);
2306 addCmd(pCB, CMD_UPDATEBUFFER);
2307 }
2308 else {
2309 char str[1024];
2310 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002311 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002312 }
2313 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2314}
2315
Tony Barbour8205d902015-04-16 15:59:00 -06002316VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002317{
2318 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2319 if (pCB) {
2320 updateCBTracking(cmdBuffer);
2321 addCmd(pCB, CMD_FILLBUFFER);
2322 }
2323 else {
2324 char str[1024];
2325 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002326 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002327 }
2328 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2329}
2330
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002331VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
2332 VkImage image, VkImageLayout imageLayout,
2333 VkClearColor color,
2334 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002335{
2336 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2337 if (pCB) {
2338 updateCBTracking(cmdBuffer);
2339 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2340 }
2341 else {
2342 char str[1024];
2343 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002344 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002345 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002346 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002347}
2348
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002349VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2350 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002351 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002352 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002353{
2354 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2355 if (pCB) {
2356 updateCBTracking(cmdBuffer);
2357 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2358 }
2359 else {
2360 char str[1024];
2361 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002362 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002363 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002364 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002365}
2366
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002367VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2368 VkImage srcImage, VkImageLayout srcImageLayout,
2369 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002370 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002371{
2372 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2373 if (pCB) {
2374 updateCBTracking(cmdBuffer);
2375 addCmd(pCB, CMD_RESOLVEIMAGE);
2376 }
2377 else {
2378 char str[1024];
2379 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002380 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002381 }
Tony Barbour11f74372015-04-13 15:02:52 -06002382 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002383}
2384
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002385VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002386{
2387 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2388 if (pCB) {
2389 updateCBTracking(cmdBuffer);
2390 addCmd(pCB, CMD_SETEVENT);
2391 }
2392 else {
2393 char str[1024];
2394 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002395 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002396 }
2397 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2398}
2399
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002400VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002401{
2402 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2403 if (pCB) {
2404 updateCBTracking(cmdBuffer);
2405 addCmd(pCB, CMD_RESETEVENT);
2406 }
2407 else {
2408 char str[1024];
2409 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002410 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002411 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002412 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002413}
2414
Tony Barbour8205d902015-04-16 15:59:00 -06002415VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t eventCount, const VkEvent* pEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002416{
2417 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2418 if (pCB) {
2419 updateCBTracking(cmdBuffer);
2420 addCmd(pCB, CMD_WAITEVENTS);
2421 }
2422 else {
2423 char str[1024];
2424 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002425 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002426 }
Tony Barbour8205d902015-04-16 15:59:00 -06002427 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002428}
2429
Tony Barbour8205d902015-04-16 15:59:00 -06002430VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002431{
2432 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2433 if (pCB) {
2434 updateCBTracking(cmdBuffer);
2435 addCmd(pCB, CMD_PIPELINEBARRIER);
2436 }
2437 else {
2438 char str[1024];
2439 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002440 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002441 }
Tony Barbour8205d902015-04-16 15:59:00 -06002442 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443}
2444
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002445VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002446{
2447 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2448 if (pCB) {
2449 updateCBTracking(cmdBuffer);
2450 addCmd(pCB, CMD_BEGINQUERY);
2451 }
2452 else {
2453 char str[1024];
2454 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002455 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002456 }
2457 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2458}
2459
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002460VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002461{
2462 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2463 if (pCB) {
2464 updateCBTracking(cmdBuffer);
2465 addCmd(pCB, CMD_ENDQUERY);
2466 }
2467 else {
2468 char str[1024];
2469 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002470 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002471 }
2472 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2473}
2474
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002475VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002476{
2477 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2478 if (pCB) {
2479 updateCBTracking(cmdBuffer);
2480 addCmd(pCB, CMD_RESETQUERYPOOL);
2481 }
2482 else {
2483 char str[1024];
2484 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002485 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002486 }
2487 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2488}
2489
Tony Barbour8205d902015-04-16 15:59:00 -06002490VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002491{
2492 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2493 if (pCB) {
2494 updateCBTracking(cmdBuffer);
2495 addCmd(pCB, CMD_WRITETIMESTAMP);
2496 }
2497 else {
2498 char str[1024];
2499 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002500 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002501 }
2502 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2503}
2504
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002505VK_LAYER_EXPORT void VKAPI vkCmdInitAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002506{
2507 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2508 if (pCB) {
2509 updateCBTracking(cmdBuffer);
2510 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2511 }
2512 else {
2513 char str[1024];
2514 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002515 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002516 }
2517 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2518}
2519
Tony Barbour8205d902015-04-16 15:59:00 -06002520VK_LAYER_EXPORT void VKAPI vkCmdLoadAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer srcBuffer, VkDeviceSize srcOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002521{
2522 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2523 if (pCB) {
2524 updateCBTracking(cmdBuffer);
2525 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2526 }
2527 else {
2528 char str[1024];
2529 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002530 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531 }
2532 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2533}
2534
Tony Barbour8205d902015-04-16 15:59:00 -06002535VK_LAYER_EXPORT void VKAPI vkCmdSaveAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002536{
2537 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2538 if (pCB) {
2539 updateCBTracking(cmdBuffer);
2540 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2541 }
2542 else {
2543 char str[1024];
2544 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002545 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002546 }
2547 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2548}
2549
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002550VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002551{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002552 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002553 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002554 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002555 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002556 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002557 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2558 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002559 }
2560 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002561 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2562 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002563 }
2564 frameBufferMap[*pFramebuffer] = localFBCI;
2565 }
2566 return result;
2567}
2568
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002569VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002570{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002571 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002572 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002573 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002574 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002575 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002576 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2577 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002578 }
2579 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002580 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2581 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002582 }
2583 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002584 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2585 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002586 }
2587 renderPassMap[*pRenderPass] = localRPCI;
2588 }
2589 return result;
2590}
2591
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002592VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002593{
2594 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2595 if (pCB) {
2596 updateCBTracking(cmdBuffer);
2597 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002598 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2599 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002600 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002601 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002602 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002603 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604 char str[1024];
2605 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002606 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002607 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002608 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002609}
2610
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002611VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002612{
2613 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2614 if (pCB) {
2615 updateCBTracking(cmdBuffer);
2616 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002617 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002618 }
2619 else {
2620 char str[1024];
2621 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002622 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002623 }
2624 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2625}
2626
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002627VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002628{
2629 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002630 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002631 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002632 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002633 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2634 pNewDbgFuncNode->pUserData = pUserData;
2635 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2636 g_pDbgFunctionHead = pNewDbgFuncNode;
2637 // force callbacks if DebugAction hasn't been set already other than initial value
2638 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002639 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002640 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002641 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002642 return result;
2643}
2644
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002645VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002647 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2648 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002649 while (pTrav) {
2650 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2651 pPrev->pNext = pTrav->pNext;
2652 if (g_pDbgFunctionHead == pTrav)
2653 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002654 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002655 break;
2656 }
2657 pPrev = pTrav;
2658 pTrav = pTrav->pNext;
2659 }
2660 if (g_pDbgFunctionHead == NULL)
2661 {
2662 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002663 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002664 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002665 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002666 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002667 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002668 return result;
2669}
2670
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002671VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002672{
2673 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2674 if (pCB) {
2675 updateCBTracking(cmdBuffer);
2676 addCmd(pCB, CMD_DBGMARKERBEGIN);
2677 }
2678 else {
2679 char str[1024];
2680 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002681 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002682 }
2683 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2684}
2685
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002686VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002687{
2688 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2689 if (pCB) {
2690 updateCBTracking(cmdBuffer);
2691 addCmd(pCB, CMD_DBGMARKEREND);
2692 }
2693 else {
2694 char str[1024];
2695 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002696 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002697 }
2698 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2699}
2700
2701// TODO : Want to pass in a cmdBuffer here based on which state to display
2702void drawStateDumpDotFile(char* outFileName)
2703{
2704 // TODO : Currently just setting cmdBuffer based on global var
2705 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2706 dumpGlobalDotFile(outFileName);
2707}
2708
2709void drawStateDumpCommandBufferDotFile(char* outFileName)
2710{
2711 cbDumpDotFile(outFileName);
2712}
2713
2714void drawStateDumpPngFile(char* outFileName)
2715{
2716#if defined(_WIN32)
2717// FIXME: NEED WINDOWS EQUIVALENT
2718 char str[1024];
2719 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002720 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002721#else // WIN32
2722 char dotExe[32] = "/usr/bin/dot";
2723 if( access(dotExe, X_OK) != -1) {
2724 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2725 char dotCmd[1024];
2726 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002727 int retval = system(dotCmd);
2728 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002729 remove("/tmp/tmp.dot");
2730 }
2731 else {
2732 char str[1024];
2733 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002734 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002735 }
2736#endif // WIN32
2737}
2738
Tony Barbour8205d902015-04-16 15:59:00 -06002739VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002740{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002741 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002742
2743 if (gpu == NULL)
2744 return NULL;
2745 pCurObj = gpuw;
2746 loader_platform_thread_once(&g_initOnce, initDrawState);
2747
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002748 if (!strcmp(funcName, "vkGetProcAddr"))
2749 return (void *) vkGetProcAddr;
2750 if (!strcmp(funcName, "vkCreateDevice"))
2751 return (void*) vkCreateDevice;
2752 if (!strcmp(funcName, "vkDestroyDevice"))
2753 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002754 if (!strcmp(funcName, "vkEnumerateLayers"))
2755 return (void*) vkEnumerateLayers;
2756 if (!strcmp(funcName, "vkQueueSubmit"))
2757 return (void*) vkQueueSubmit;
2758 if (!strcmp(funcName, "vkDestroyObject"))
2759 return (void*) vkDestroyObject;
2760 if (!strcmp(funcName, "vkCreateBufferView"))
2761 return (void*) vkCreateBufferView;
2762 if (!strcmp(funcName, "vkCreateImageView"))
2763 return (void*) vkCreateImageView;
2764 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2765 return (void*) vkCreateGraphicsPipeline;
2766 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2767 return (void*) vkCreateGraphicsPipelineDerivative;
2768 if (!strcmp(funcName, "vkCreateSampler"))
2769 return (void*) vkCreateSampler;
2770 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2771 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002772 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2773 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002774 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2775 return (void*) vkBeginDescriptorPoolUpdate;
2776 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2777 return (void*) vkEndDescriptorPoolUpdate;
2778 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2779 return (void*) vkCreateDescriptorPool;
2780 if (!strcmp(funcName, "vkResetDescriptorPool"))
2781 return (void*) vkResetDescriptorPool;
2782 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2783 return (void*) vkAllocDescriptorSets;
2784 if (!strcmp(funcName, "vkClearDescriptorSets"))
2785 return (void*) vkClearDescriptorSets;
2786 if (!strcmp(funcName, "vkUpdateDescriptors"))
2787 return (void*) vkUpdateDescriptors;
2788 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2789 return (void*) vkCreateDynamicViewportState;
2790 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2791 return (void*) vkCreateDynamicRasterState;
2792 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2793 return (void*) vkCreateDynamicColorBlendState;
2794 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2795 return (void*) vkCreateDynamicDepthStencilState;
2796 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2797 return (void*) vkCreateCommandBuffer;
2798 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2799 return (void*) vkBeginCommandBuffer;
2800 if (!strcmp(funcName, "vkEndCommandBuffer"))
2801 return (void*) vkEndCommandBuffer;
2802 if (!strcmp(funcName, "vkResetCommandBuffer"))
2803 return (void*) vkResetCommandBuffer;
2804 if (!strcmp(funcName, "vkCmdBindPipeline"))
2805 return (void*) vkCmdBindPipeline;
2806 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2807 return (void*) vkCmdBindDynamicStateObject;
2808 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2809 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002810 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2811 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002812 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2813 return (void*) vkCmdBindIndexBuffer;
2814 if (!strcmp(funcName, "vkCmdDraw"))
2815 return (void*) vkCmdDraw;
2816 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2817 return (void*) vkCmdDrawIndexed;
2818 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2819 return (void*) vkCmdDrawIndirect;
2820 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2821 return (void*) vkCmdDrawIndexedIndirect;
2822 if (!strcmp(funcName, "vkCmdDispatch"))
2823 return (void*) vkCmdDispatch;
2824 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2825 return (void*) vkCmdDispatchIndirect;
2826 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2827 return (void*) vkCmdCopyBuffer;
2828 if (!strcmp(funcName, "vkCmdCopyImage"))
2829 return (void*) vkCmdCopyImage;
2830 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2831 return (void*) vkCmdCopyBufferToImage;
2832 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2833 return (void*) vkCmdCopyImageToBuffer;
2834 if (!strcmp(funcName, "vkCmdCloneImageData"))
2835 return (void*) vkCmdCloneImageData;
2836 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2837 return (void*) vkCmdUpdateBuffer;
2838 if (!strcmp(funcName, "vkCmdFillBuffer"))
2839 return (void*) vkCmdFillBuffer;
2840 if (!strcmp(funcName, "vkCmdClearColorImage"))
2841 return (void*) vkCmdClearColorImage;
2842 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2843 return (void*) vkCmdClearDepthStencil;
2844 if (!strcmp(funcName, "vkCmdResolveImage"))
2845 return (void*) vkCmdResolveImage;
2846 if (!strcmp(funcName, "vkCmdSetEvent"))
2847 return (void*) vkCmdSetEvent;
2848 if (!strcmp(funcName, "vkCmdResetEvent"))
2849 return (void*) vkCmdResetEvent;
2850 if (!strcmp(funcName, "vkCmdWaitEvents"))
2851 return (void*) vkCmdWaitEvents;
2852 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2853 return (void*) vkCmdPipelineBarrier;
2854 if (!strcmp(funcName, "vkCmdBeginQuery"))
2855 return (void*) vkCmdBeginQuery;
2856 if (!strcmp(funcName, "vkCmdEndQuery"))
2857 return (void*) vkCmdEndQuery;
2858 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2859 return (void*) vkCmdResetQueryPool;
2860 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2861 return (void*) vkCmdWriteTimestamp;
2862 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2863 return (void*) vkCmdInitAtomicCounters;
2864 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2865 return (void*) vkCmdLoadAtomicCounters;
2866 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2867 return (void*) vkCmdSaveAtomicCounters;
2868 if (!strcmp(funcName, "vkCreateFramebuffer"))
2869 return (void*) vkCreateFramebuffer;
2870 if (!strcmp(funcName, "vkCreateRenderPass"))
2871 return (void*) vkCreateRenderPass;
2872 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2873 return (void*) vkCmdBeginRenderPass;
2874 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2875 return (void*) vkCmdEndRenderPass;
2876 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2877 return (void*) vkDbgRegisterMsgCallback;
2878 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2879 return (void*) vkDbgUnregisterMsgCallback;
2880 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2881 return (void*) vkCmdDbgMarkerBegin;
2882 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2883 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002884 if (!strcmp("drawStateDumpDotFile", funcName))
2885 return (void*) drawStateDumpDotFile;
2886 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2887 return (void*) drawStateDumpCommandBufferDotFile;
2888 if (!strcmp("drawStateDumpPngFile", funcName))
2889 return (void*) drawStateDumpPngFile;
2890 else {
2891 if (gpuw->pGPA == NULL)
2892 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002893 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002894 }
2895}