blob: 8ab366fe44dc100d3bcfe6acf19d552a20d3dcbc [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) {
1012 while (!pCB->pCmds.empty()) {
1013 delete pCB->pCmds.back();
1014 pCB->pCmds.pop_back();
1015 }
1016 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001017 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001018 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1020 pCB->cmdBuffer = cb;
1021 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001022 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023 pCB->lastVtxBinding = MAX_BINDING;
1024 }
1025}
1026// Set the last bound dynamic state of given type
1027// 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 -06001028static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001029{
1030 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1031 if (pCB) {
1032 updateCBTracking(cmdBuffer);
1033 loader_platform_thread_lock_mutex(&globalLock);
1034 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1035 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1036 char str[1024];
1037 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001038 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 -06001039 }
1040 else {
1041 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1042 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1043 }
1044 loader_platform_thread_unlock_mutex(&globalLock);
1045 }
1046 else {
1047 char str[1024];
1048 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001049 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001050 }
1051}
1052// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001053static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001054{
1055 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1056 if (pCB) {
1057 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1058 if (!pPipeTrav) {
1059 // nothing to print
1060 }
1061 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001062 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001063 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001064 }
1065 }
1066}
1067// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001068static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001069{
1070 SET_NODE* pSet = getSetNode(ds);
1071 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001072 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001073 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001074 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1075 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001076 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001077 fprintf(pOutFile, "%s", pGVstr);
1078 free(pGVstr);
1079 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1080 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001081 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001082 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001083 ++layout_index;
1084 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001085 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001086 fprintf(pOutFile, "%s", pGVstr);
1087 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001088 if (pSet->pUpdateStructs) {
1089 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1090 fprintf(pOutFile, "%s", pGVstr);
1091 free(pGVstr);
1092 }
1093 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001094 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1095 uint32_t i = 0;
1096 for (i=0; i < pSet->descriptorCount; i++) {
1097 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001098 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 -06001099 }
1100 }
1101#define NUM_COLORS 7
1102 vector<string> edgeColors;
1103 edgeColors.push_back("0000ff");
1104 edgeColors.push_back("ff00ff");
1105 edgeColors.push_back("ffff00");
1106 edgeColors.push_back("00ff00");
1107 edgeColors.push_back("000000");
1108 edgeColors.push_back("00ffff");
1109 edgeColors.push_back("ff0000");
1110 uint32_t colorIdx = 0;
1111 fprintf(pOutFile, "</TABLE>>\n];\n");
1112 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001113 VkUpdateSamplers* pUS = NULL;
1114 VkUpdateSamplerTextures* pUST = NULL;
1115 VkUpdateImages* pUI = NULL;
1116 VkUpdateBuffers* pUB = NULL;
1117 VkUpdateAsCopy* pUAC = NULL;
1118 VkSamplerCreateInfo* pSCI = NULL;
1119 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001120 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001121 void** ppNextPtr = NULL;
1122 void* pSaveNext = NULL;
1123 for (i=0; i < pSet->descriptorCount; i++) {
1124 if (pSet->ppDescriptors[i]) {
1125 switch (pSet->ppDescriptors[i]->sType)
1126 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001127 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001128 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001129 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001130 if (pSCI) {
1131 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001132 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001133 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1134 }
1135 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001136 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001137 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001138 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001139 if (pSCI) {
1140 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001141 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001142 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1143 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001144 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001145 if (pIVCI) {
1146 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001147 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001148 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1149 }
1150 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001151 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001152 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001153 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001154 if (pIVCI) {
1155 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001156 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001157 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1158 }
1159 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001160 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001161 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001162 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001163 if (pBVCI) {
1164 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001165 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001166 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1167 }
1168 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001169 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001170 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001171 // TODO : Need to validate this code
1172 // Save off pNext and set to NULL while printing this struct, then restore it
1173 ppNextPtr = (void**)&pUAC->pNext;
1174 pSaveNext = *ppNextPtr;
1175 *ppNextPtr = NULL;
1176 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001177 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001178 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1179 // Restore next ptr
1180 *ppNextPtr = pSaveNext;
1181 break;
1182 default:
1183 break;
1184 }
1185 colorIdx = (colorIdx+1) % NUM_COLORS;
1186 }
1187 }
1188 }
1189 fprintf(pOutFile, "}\n");
1190 fprintf(pOutFile, "}\n");
1191 }
1192}
1193// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001194static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001195{
1196 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1197 if (pCB && pCB->lastBoundDescriptorSet) {
1198 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1199 }
1200}
1201// Dump a GraphViz dot file showing the Cmd Buffers
1202static void cbDumpDotFile(string outFileName)
1203{
1204 // Print CB Chain for each CB
1205 FILE* pOutFile;
1206 pOutFile = fopen(outFileName.c_str(), "w");
1207 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1208 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1209 GLOBAL_CB_NODE* pCB = NULL;
1210 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1211 pCB = g_pLastTouchedCB[i];
1212 if (pCB) {
1213 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1214 uint32_t instNum = 0;
1215 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1216 if (instNum) {
1217 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1218 }
1219 if (pCB == g_lastGlobalCB) {
1220 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());
1221 }
1222 else {
1223 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());
1224 }
1225 ++instNum;
1226 }
1227 fprintf(pOutFile, "}\n");
1228 }
1229 }
1230 fprintf(pOutFile, "}\n");
1231 fprintf(pOutFile, "}\n"); // close main graph "g"
1232 fclose(pOutFile);
1233}
1234// Dump a GraphViz dot file showing the pipeline for last bound global state
1235static void dumpGlobalDotFile(char *outFileName)
1236{
1237 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1238 if (pPipeTrav) {
1239 FILE* pOutFile;
1240 pOutFile = fopen(outFileName, "w");
1241 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1242 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1243 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001244 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001245 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001246 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001247 fprintf(pOutFile, "%s", pGVstr);
1248 free(pGVstr);
1249 }
1250 }
1251 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1252 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001253 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001254 fprintf(pOutFile, "%s", pGVstr);
1255 free(pGVstr);
1256 fprintf(pOutFile, "}\n");
1257 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1258 fprintf(pOutFile, "}\n"); // close main graph "g"
1259 fclose(pOutFile);
1260 }
1261}
1262// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001263static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001264{
1265 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1266 if (pCB) {
1267 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1268 if (pPipeTrav) {
1269 FILE* pOutFile;
1270 pOutFile = fopen(outFileName.c_str(), "w");
1271 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1272 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1273 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001274 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001275 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001276 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001277 fprintf(pOutFile, "%s", pGVstr);
1278 free(pGVstr);
1279 }
1280 }
1281 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1282 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001283 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001284 fprintf(pOutFile, "%s", pGVstr);
1285 free(pGVstr);
1286 fprintf(pOutFile, "}\n");
1287 dsDumpDot(cb, pOutFile);
1288 fprintf(pOutFile, "}\n"); // close main graph "g"
1289 fclose(pOutFile);
1290 }
1291 }
1292}
1293// Verify VB Buffer binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001294static void validateVBBinding(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001295{
1296 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1297 if (pCB && pCB->lastBoundPipeline) {
1298 // First verify that we have a Node for bound pipeline
1299 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1300 char str[1024];
1301 if (!pPipeTrav) {
1302 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001303 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001304 }
1305 else {
1306 // Verify Vtx binding
1307 if (MAX_BINDING != pCB->lastVtxBinding) {
1308 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1309 if (0 == pPipeTrav->vtxBindingCount) {
1310 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 -06001311 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 -06001312 }
1313 else {
1314 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 -06001315 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 -06001316 }
1317 }
1318 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001319 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001320 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001321 }
1322 }
1323 }
1324 }
1325}
1326// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001327static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001328{
1329 char tmp_str[1024];
1330 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.
1331 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1332 if (pCB) {
1333 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001334 POOL_NODE* pPool = getPoolNode(pSet->pool);
1335 // Print out pool details
1336 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001337 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001338 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001339 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001340 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001341 // Print out set details
1342 char prefix[10];
1343 uint32_t index = 0;
1344 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001345 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001346 LAYOUT_NODE* pLayout = pSet->pLayout;
1347 // Print layout details
1348 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 -06001349 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001350 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001351 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001352 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001353 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001354 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001355 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1356 if (pUpdate) {
1357 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001358 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001359 sprintf(prefix, " [UC] ");
1360 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001361 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001362 // TODO : If there is a "view" associated with this update, print CI for that view
1363 }
1364 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001365 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1366 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001367 }
1368 }
1369}
1370
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001371static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001372{
1373 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1374 if (pCB) {
1375 char str[1024];
1376 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001377 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001378 vector<CMD_NODE*> pCmds = pCB->pCmds;
1379 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001380 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001381 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001382 }
1383 }
1384 else {
1385 // Nothing to print
1386 }
1387}
1388
1389
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001390static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001391{
1392 printDSConfig(cb);
1393 printPipeline(cb);
1394 printDynamicState(cb);
1395 static int autoDumpOnce = 0;
1396 if (autoDumpOnce) {
1397 autoDumpOnce = 0;
1398 dumpDotFile(cb, "pipeline_dump.dot");
1399 cbDumpDotFile("cb_dump.dot");
1400#if defined(_WIN32)
1401// FIXME: NEED WINDOWS EQUIVALENT
1402#else // WIN32
1403 // Convert dot to svg if dot available
1404 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001405 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1406 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001407 }
1408#endif // WIN32
1409 }
1410}
1411
1412static void initDrawState(void)
1413{
1414 const char *strOpt;
1415 // initialize DrawState options
1416 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1417 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1418
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001419 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001420 {
1421 strOpt = getLayerOption("DrawStateLogFilename");
1422 if (strOpt)
1423 {
1424 g_logFile = fopen(strOpt, "w");
1425 }
1426 if (g_logFile == NULL)
1427 g_logFile = stdout;
1428 }
1429 // initialize Layer dispatch table
1430 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001431 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001432 fpNextGPA = pCurObj->pGPA;
1433 assert(fpNextGPA);
1434
Tony Barbour8205d902015-04-16 15:59:00 -06001435 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001436
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001437 if (!globalLockInitialized)
1438 {
1439 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001440 // suggestion is to call this during vkCreateInstance(), and then we
1441 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001442 // that the layer have per-instance locks. We need to come back and
1443 // address this soon.
1444 loader_platform_thread_create_mutex(&globalLock);
1445 globalLockInitialized = 1;
1446 }
1447}
1448
Tony Barbour8205d902015-04-16 15:59:00 -06001449VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001450{
Jon Ashburn630e44f2015-04-08 21:33:34 -06001451 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001452 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001453 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001454 return result;
1455}
1456
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001457VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001458{
1459 // Free all the memory
1460 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001461 deletePipelines();
1462 deleteSamplers();
1463 deleteImages();
1464 deleteBuffers();
1465 deleteCmdBuffers();
1466 deleteDynamicState();
1467 deletePools();
1468 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001469 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001470 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001471 return result;
1472}
1473
Jon Ashburneb2728b2015-04-10 14:33:07 -06001474struct extProps {
1475 uint32_t version;
1476 const char * const name;
1477};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001478#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001479static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1480 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001481 0x10, "DrawState",
1482 0x10, "Validation",
1483 0x10, "drawStateDumpDotFile",
1484 0x10, "drawStateDumpCommandBufferDotFile",
1485 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001486};
1487
1488VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1489 VkExtensionInfoType infoType,
1490 uint32_t extensionIndex,
1491 size_t* pDataSize,
1492 void* pData)
1493{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001494 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1495 VkExtensionProperties *ext_props;
1496 uint32_t *count;
1497
1498 if (pDataSize == NULL)
1499 return VK_ERROR_INVALID_POINTER;
1500
1501 switch (infoType) {
1502 case VK_EXTENSION_INFO_TYPE_COUNT:
1503 *pDataSize = sizeof(uint32_t);
1504 if (pData == NULL)
1505 return VK_SUCCESS;
1506 count = (uint32_t *) pData;
1507 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1508 break;
1509 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1510 *pDataSize = sizeof(VkExtensionProperties);
1511 if (pData == NULL)
1512 return VK_SUCCESS;
1513 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1514 return VK_ERROR_INVALID_VALUE;
1515 ext_props = (VkExtensionProperties *) pData;
1516 ext_props->version = dsExts[extensionIndex].version;
1517 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1518 VK_MAX_EXTENSION_NAME);
1519 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1520 break;
1521 default:
1522 return VK_ERROR_INVALID_VALUE;
1523 };
1524
1525 return VK_SUCCESS;
1526}
1527
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001528VK_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 -06001529{
1530 if (gpu != NULL)
1531 {
Jon Ashburn630e44f2015-04-08 21:33:34 -06001532 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001533 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001534 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001535 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001536 } else {
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001537 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001538 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001539 // This layer compatible with all GPUs
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001540 *pLayerCount = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001541 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001542 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001543 }
1544}
1545
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001546VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001547{
1548 for (uint32_t i=0; i < cmdBufferCount; i++) {
1549 // Validate that cmd buffers have been updated
1550 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001551 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001552 return result;
1553}
1554
Mike Stroyan230e6252015-04-17 12:36:38 -06001555VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001556{
1557 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyan230e6252015-04-17 12:36:38 -06001558 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001559 return result;
1560}
1561
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001562VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001563{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001564 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001565 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001566 loader_platform_thread_lock_mutex(&globalLock);
1567 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1568 pNewNode->buffer = *pView;
1569 pNewNode->createInfo = *pCreateInfo;
1570 bufferMap[*pView] = pNewNode;
1571 loader_platform_thread_unlock_mutex(&globalLock);
1572 }
1573 return result;
1574}
1575
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001576VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001577{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001578 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001579 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001580 loader_platform_thread_lock_mutex(&globalLock);
1581 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1582 pNewNode->image = *pView;
1583 pNewNode->createInfo = *pCreateInfo;
1584 imageMap[*pView] = pNewNode;
1585 loader_platform_thread_unlock_mutex(&globalLock);
1586 }
1587 return result;
1588}
1589
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001590static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001591{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001592 // Create LL HEAD for this Pipeline
1593 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001594 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1595 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1596 pPipeNode->pipeline = *pPipeline;
1597 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001598 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001599}
1600
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001601VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001602{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001603 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001604 // Create LL HEAD for this Pipeline
1605 char str[1024];
1606 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001607 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001608
1609 track_pipeline(pCreateInfo, pPipeline);
1610
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001611 return result;
1612}
1613
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001614VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1615 VkDevice device,
1616 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1617 VkPipeline basePipeline,
1618 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001619{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001620 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001621 // Create LL HEAD for this Pipeline
1622 char str[1024];
1623 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001624 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001625
1626 track_pipeline(pCreateInfo, pPipeline);
1627
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001628 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001629
1630 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001631}
1632
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001633VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001634{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001635 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001636 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001637 loader_platform_thread_lock_mutex(&globalLock);
1638 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1639 pNewNode->sampler = *pSampler;
1640 pNewNode->createInfo = *pCreateInfo;
1641 sampleMap[*pSampler] = pNewNode;
1642 loader_platform_thread_unlock_mutex(&globalLock);
1643 }
1644 return result;
1645}
1646
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001647VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001648{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001649 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001650 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001651 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1652 if (NULL == pNewNode) {
1653 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001654 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1655 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001656 }
1657 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001658 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1659 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1660 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001661 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001662 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1663 totalCount += pCreateInfo->pBinding[i].count;
1664 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001665 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1666 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1667 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001668 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001669 }
1670 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001671 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001672 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001673 uint32_t j = 0;
1674 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1675 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1676 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001677 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001678 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679 }
1680 }
1681 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001682 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1684 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001685 // Put new node at Head of global Layer list
1686 loader_platform_thread_lock_mutex(&globalLock);
1687 layoutMap[*pSetLayout] = pNewNode;
1688 loader_platform_thread_unlock_mutex(&globalLock);
1689 }
1690 return result;
1691}
1692
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001693VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001694{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001695 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001696 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001697 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001698 }
1699 return result;
1700}
1701
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001702VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001703{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001704 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001705 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001706 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001707 POOL_NODE* pPoolNode = poolMap.begin()->second;
1708 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001709 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001710 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001711 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001712 }
1713 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001714 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001715 }
1716 loader_platform_thread_unlock_mutex(&globalLock);
1717 }
1718 return result;
1719}
1720
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001721VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001722{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001723 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001724 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001725 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001726 POOL_NODE* pPoolNode = poolMap.begin()->second;
1727 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001729 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001730 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001731 }
1732 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001733 if (!pPoolNode->updateActive) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001734 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001735 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1736 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 -06001737 }
1738 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001739 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001740 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001741 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001742 }
1743 loader_platform_thread_unlock_mutex(&globalLock);
1744 }
1745 return result;
1746}
1747
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001748VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001749{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001750 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001751 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001752 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001753 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001754 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyan230e6252015-04-17 12:36:38 -06001755 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001756 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001757 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001758 if (NULL == pNewNode) {
1759 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001760 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyan230e6252015-04-17 12:36:38 -06001761 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 -06001762 }
1763 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001764 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001765 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1766 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001767 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001768 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1769 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001770 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1771 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001772 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001773 pNewNode->updateActive = 0;
1774 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001775 pNewNode->pool = *pDescriptorPool;
1776 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001777 }
1778 loader_platform_thread_unlock_mutex(&globalLock);
1779 }
1780 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001781 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001782 }
1783 return result;
1784}
1785
Mike Stroyan230e6252015-04-17 12:36:38 -06001786VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001787{
Mike Stroyan230e6252015-04-17 12:36:38 -06001788 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001789 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001790 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001791 }
1792 return result;
1793}
1794
Mike Stroyan230e6252015-04-17 12:36:38 -06001795VK_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 -06001796{
Mike Stroyan230e6252015-04-17 12:36:38 -06001797 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001798 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001799 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1800 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001801 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001802 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1803 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804 }
1805 else {
1806 for (uint32_t i = 0; i < *pCount; i++) {
1807 char str[1024];
1808 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001809 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001810 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001811 SET_NODE* pNewNode = new SET_NODE;
1812 if (NULL == pNewNode) {
1813 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001814 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1815 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 -06001816 }
1817 else {
1818 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001819 // Insert set at head of Set LL for this pool
1820 pNewNode->pNext = pPoolNode->pSets;
1821 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001822 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1823 if (NULL == pLayout) {
1824 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001825 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1826 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001827 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001828 pNewNode->pLayout = pLayout;
1829 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001830 pNewNode->set = pDescriptorSets[i];
1831 pNewNode->setUsage = setUsage;
1832 pNewNode->descriptorCount = pLayout->endIndex + 1;
1833 if (pNewNode->descriptorCount) {
1834 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1835 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1836 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1837 }
1838 setMap[pDescriptorSets[i]] = pNewNode;
1839 }
1840 }
1841 }
1842 }
1843 return result;
1844}
1845
Mike Stroyan230e6252015-04-17 12:36:38 -06001846VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847{
1848 for (uint32_t i = 0; i < count; i++) {
1849 clearDescriptorSet(pDescriptorSets[i]);
1850 }
Mike Stroyan230e6252015-04-17 12:36:38 -06001851 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001852}
1853
Mike Stroyan230e6252015-04-17 12:36:38 -06001854VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001855{
1856 SET_NODE* pSet = getSetNode(descriptorSet);
1857 if (!dsUpdateActive(descriptorSet)) {
1858 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001859 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1860 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 -06001861 }
1862 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001863 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001864 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865 }
1866
Mike Stroyan230e6252015-04-17 12:36:38 -06001867 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868}
1869
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001870VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001872 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001873 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001874 return result;
1875}
1876
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001877VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001878{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001879 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001880 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881 return result;
1882}
1883
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001884VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001885{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001886 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001887 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001888 return result;
1889}
1890
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001891VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001892{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001893 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001894 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001895 return result;
1896}
1897
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001898VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001899{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001900 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001901 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001902 loader_platform_thread_lock_mutex(&globalLock);
1903 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1904 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1905 pCB->cmdBuffer = *pCmdBuffer;
1906 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001907 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001908 pCB->lastVtxBinding = MAX_BINDING;
1909 cmdBufferMap[*pCmdBuffer] = pCB;
1910 loader_platform_thread_unlock_mutex(&globalLock);
1911 updateCBTracking(*pCmdBuffer);
1912 }
1913 return result;
1914}
1915
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001916VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001917{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001918 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001919 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001920 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1921 if (pCB) {
1922 if (CB_NEW != pCB->state)
1923 resetCB(cmdBuffer);
1924 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001925 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001926 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001927 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001928 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001929 }
1930 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001931 }
1932 else {
1933 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001934 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1935 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001936 }
1937 updateCBTracking(cmdBuffer);
1938 }
1939 return result;
1940}
1941
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001942VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001943{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001944 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001945 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001946 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1947 if (pCB) {
1948 pCB->state = CB_UPDATE_COMPLETE;
1949 printCB(cmdBuffer);
1950 }
1951 else {
1952 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001953 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1954 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001955 }
1956 updateCBTracking(cmdBuffer);
1957 //cbDumpDotFile("cb_dump.dot");
1958 }
1959 return result;
1960}
1961
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001962VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001963{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001964 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001965 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001966 resetCB(cmdBuffer);
1967 updateCBTracking(cmdBuffer);
1968 }
1969 return result;
1970}
1971
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001972VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001973{
1974 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1975 if (pCB) {
1976 updateCBTracking(cmdBuffer);
1977 addCmd(pCB, CMD_BINDPIPELINE);
1978 PIPELINE_NODE* pPN = getPipeline(pipeline);
1979 if (pPN) {
1980 pCB->lastBoundPipeline = pipeline;
1981 loader_platform_thread_lock_mutex(&globalLock);
1982 g_lastBoundPipeline = pPN;
1983 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001984 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001985 }
1986 else {
1987 char str[1024];
1988 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001989 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001990 }
1991 }
1992 else {
1993 char str[1024];
1994 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001995 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001996 }
1997 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1998}
1999
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002000VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002001{
2002 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
2003 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2004}
2005
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002006VK_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 -06002007{
2008 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2009 if (pCB) {
2010 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002011 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002012 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002013 if (getSetNode(pDescriptorSets[i])) {
2014 if (dsUpdateActive(pDescriptorSets[i])) {
2015 // TODO : This check here needs to be made at QueueSubmit time
2016 /*
2017 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002018 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
2019 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 -06002020 */
2021 }
2022 loader_platform_thread_lock_mutex(&globalLock);
2023 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2024 g_lastBoundDescriptorSet = pDescriptorSets[i];
2025 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002026 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002027 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002028 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002029 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002030 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002031 else {
2032 char str[1024];
2033 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002034 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002035 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002036 }
2037 }
2038 else {
2039 char str[1024];
2040 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002041 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042 }
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002043 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002044}
2045
Tony Barbour8205d902015-04-16 15:59:00 -06002046VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002047{
2048 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2049 if (pCB) {
2050 updateCBTracking(cmdBuffer);
2051 addCmd(pCB, CMD_BINDINDEXBUFFER);
2052 // TODO : Track idxBuffer binding
2053 }
2054 else {
2055 char str[1024];
2056 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002057 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002058 }
2059 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2060}
2061
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002062VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2063 VkCmdBuffer cmdBuffer,
2064 uint32_t startBinding,
2065 uint32_t bindingCount,
2066 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002067 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002068{
2069 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2070 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002071 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002072 updateCBTracking(cmdBuffer);
2073 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002074 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002075 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002076 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002077 char str[1024];
2078 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002079 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002080 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002081 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002082}
2083
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002084VK_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 -06002085{
2086 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2087 if (pCB) {
2088 updateCBTracking(cmdBuffer);
2089 addCmd(pCB, CMD_DRAW);
2090 pCB->drawCount[DRAW]++;
2091 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002092 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2093 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002094 synchAndPrintDSConfig(cmdBuffer);
2095 }
2096 else {
2097 char str[1024];
2098 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002099 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002100 }
2101 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2102}
2103
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002104VK_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 -06002105{
2106 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2107 if (pCB) {
2108 updateCBTracking(cmdBuffer);
2109 addCmd(pCB, CMD_DRAWINDEXED);
2110 pCB->drawCount[DRAW_INDEXED]++;
2111 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002112 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2113 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002114 synchAndPrintDSConfig(cmdBuffer);
2115 }
2116 else {
2117 char str[1024];
2118 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002119 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002120 }
2121 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2122}
2123
Tony Barbour8205d902015-04-16 15:59:00 -06002124VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002125{
2126 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2127 if (pCB) {
2128 updateCBTracking(cmdBuffer);
2129 addCmd(pCB, CMD_DRAWINDIRECT);
2130 pCB->drawCount[DRAW_INDIRECT]++;
2131 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002132 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2133 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002134 synchAndPrintDSConfig(cmdBuffer);
2135 }
2136 else {
2137 char str[1024];
2138 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002139 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002140 }
2141 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2142}
2143
Tony Barbour8205d902015-04-16 15:59:00 -06002144VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002145{
2146 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2147 if (pCB) {
2148 updateCBTracking(cmdBuffer);
2149 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2150 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2151 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002152 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2153 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002154 synchAndPrintDSConfig(cmdBuffer);
2155 }
2156 else {
2157 char str[1024];
2158 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002159 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002160 }
2161 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2162}
2163
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002164VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002165{
2166 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2167 if (pCB) {
2168 updateCBTracking(cmdBuffer);
2169 addCmd(pCB, CMD_DISPATCH);
2170 }
2171 else {
2172 char str[1024];
2173 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002174 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002175 }
2176 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2177}
2178
Tony Barbour8205d902015-04-16 15:59:00 -06002179VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002180{
2181 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2182 if (pCB) {
2183 updateCBTracking(cmdBuffer);
2184 addCmd(pCB, CMD_DISPATCHINDIRECT);
2185 }
2186 else {
2187 char str[1024];
2188 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002189 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002190 }
2191 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2192}
2193
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002194VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002195{
2196 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2197 if (pCB) {
2198 updateCBTracking(cmdBuffer);
2199 addCmd(pCB, CMD_COPYBUFFER);
2200 }
2201 else {
2202 char str[1024];
2203 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002204 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002205 }
2206 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2207}
2208
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002209VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2210 VkImage srcImage,
2211 VkImageLayout srcImageLayout,
2212 VkImage destImage,
2213 VkImageLayout destImageLayout,
2214 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002215{
2216 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2217 if (pCB) {
2218 updateCBTracking(cmdBuffer);
2219 addCmd(pCB, CMD_COPYIMAGE);
2220 }
2221 else {
2222 char str[1024];
2223 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002224 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002225 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002226 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002227}
2228
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002229VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2230 VkImage srcImage, VkImageLayout srcImageLayout,
2231 VkImage destImage, VkImageLayout destImageLayout,
2232 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002233{
2234 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2235 if (pCB) {
2236 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002237 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002238 }
2239 else {
2240 char str[1024];
2241 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002242 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002243 }
2244 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2245}
2246
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002247VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2248 VkBuffer srcBuffer,
2249 VkImage destImage, VkImageLayout destImageLayout,
2250 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002251{
2252 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2253 if (pCB) {
2254 updateCBTracking(cmdBuffer);
2255 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2256 }
2257 else {
2258 char str[1024];
2259 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002260 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002261 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002262 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002263}
2264
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002265VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2266 VkImage srcImage, VkImageLayout srcImageLayout,
2267 VkBuffer destBuffer,
2268 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002269{
2270 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2271 if (pCB) {
2272 updateCBTracking(cmdBuffer);
2273 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2274 }
2275 else {
2276 char str[1024];
2277 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002278 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002279 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002280 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002281}
2282
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002283VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002284{
2285 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2286 if (pCB) {
2287 updateCBTracking(cmdBuffer);
2288 addCmd(pCB, CMD_CLONEIMAGEDATA);
2289 }
2290 else {
2291 char str[1024];
2292 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002293 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002294 }
2295 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2296}
2297
Tony Barbour8205d902015-04-16 15:59:00 -06002298VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002299{
2300 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2301 if (pCB) {
2302 updateCBTracking(cmdBuffer);
2303 addCmd(pCB, CMD_UPDATEBUFFER);
2304 }
2305 else {
2306 char str[1024];
2307 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002308 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002309 }
2310 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2311}
2312
Tony Barbour8205d902015-04-16 15:59:00 -06002313VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002314{
2315 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2316 if (pCB) {
2317 updateCBTracking(cmdBuffer);
2318 addCmd(pCB, CMD_FILLBUFFER);
2319 }
2320 else {
2321 char str[1024];
2322 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002323 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002324 }
2325 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2326}
2327
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002328VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
2329 VkImage image, VkImageLayout imageLayout,
2330 VkClearColor color,
2331 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002332{
2333 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2334 if (pCB) {
2335 updateCBTracking(cmdBuffer);
2336 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2337 }
2338 else {
2339 char str[1024];
2340 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002341 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002342 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002343 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344}
2345
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002346VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2347 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002348 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002349 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002350{
2351 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2352 if (pCB) {
2353 updateCBTracking(cmdBuffer);
2354 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2355 }
2356 else {
2357 char str[1024];
2358 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002359 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002360 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002361 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362}
2363
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002364VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2365 VkImage srcImage, VkImageLayout srcImageLayout,
2366 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002367 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002368{
2369 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2370 if (pCB) {
2371 updateCBTracking(cmdBuffer);
2372 addCmd(pCB, CMD_RESOLVEIMAGE);
2373 }
2374 else {
2375 char str[1024];
2376 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002377 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002378 }
Tony Barbour11f74372015-04-13 15:02:52 -06002379 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002380}
2381
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002382VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002383{
2384 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2385 if (pCB) {
2386 updateCBTracking(cmdBuffer);
2387 addCmd(pCB, CMD_SETEVENT);
2388 }
2389 else {
2390 char str[1024];
2391 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002392 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002393 }
2394 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2395}
2396
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002397VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002398{
2399 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2400 if (pCB) {
2401 updateCBTracking(cmdBuffer);
2402 addCmd(pCB, CMD_RESETEVENT);
2403 }
2404 else {
2405 char str[1024];
2406 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002407 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002408 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002409 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002410}
2411
Tony Barbour8205d902015-04-16 15:59:00 -06002412VK_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 -06002413{
2414 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2415 if (pCB) {
2416 updateCBTracking(cmdBuffer);
2417 addCmd(pCB, CMD_WAITEVENTS);
2418 }
2419 else {
2420 char str[1024];
2421 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002422 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002423 }
Tony Barbour8205d902015-04-16 15:59:00 -06002424 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002425}
2426
Tony Barbour8205d902015-04-16 15:59:00 -06002427VK_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 -06002428{
2429 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2430 if (pCB) {
2431 updateCBTracking(cmdBuffer);
2432 addCmd(pCB, CMD_PIPELINEBARRIER);
2433 }
2434 else {
2435 char str[1024];
2436 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002437 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002438 }
Tony Barbour8205d902015-04-16 15:59:00 -06002439 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002440}
2441
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002442VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443{
2444 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2445 if (pCB) {
2446 updateCBTracking(cmdBuffer);
2447 addCmd(pCB, CMD_BEGINQUERY);
2448 }
2449 else {
2450 char str[1024];
2451 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002452 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453 }
2454 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2455}
2456
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002457VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002458{
2459 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2460 if (pCB) {
2461 updateCBTracking(cmdBuffer);
2462 addCmd(pCB, CMD_ENDQUERY);
2463 }
2464 else {
2465 char str[1024];
2466 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002467 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002468 }
2469 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2470}
2471
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002472VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002473{
2474 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2475 if (pCB) {
2476 updateCBTracking(cmdBuffer);
2477 addCmd(pCB, CMD_RESETQUERYPOOL);
2478 }
2479 else {
2480 char str[1024];
2481 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002482 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002483 }
2484 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2485}
2486
Tony Barbour8205d902015-04-16 15:59:00 -06002487VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002488{
2489 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2490 if (pCB) {
2491 updateCBTracking(cmdBuffer);
2492 addCmd(pCB, CMD_WRITETIMESTAMP);
2493 }
2494 else {
2495 char str[1024];
2496 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002497 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002498 }
2499 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2500}
2501
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002502VK_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 -06002503{
2504 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2505 if (pCB) {
2506 updateCBTracking(cmdBuffer);
2507 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2508 }
2509 else {
2510 char str[1024];
2511 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002512 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513 }
2514 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2515}
2516
Tony Barbour8205d902015-04-16 15:59:00 -06002517VK_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 -06002518{
2519 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2520 if (pCB) {
2521 updateCBTracking(cmdBuffer);
2522 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2523 }
2524 else {
2525 char str[1024];
2526 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002527 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002528 }
2529 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2530}
2531
Tony Barbour8205d902015-04-16 15:59:00 -06002532VK_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 -06002533{
2534 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2535 if (pCB) {
2536 updateCBTracking(cmdBuffer);
2537 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2538 }
2539 else {
2540 char str[1024];
2541 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002542 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002543 }
2544 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2545}
2546
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002547VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002548{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002549 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002550 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002551 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002552 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002553 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002554 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2555 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002556 }
2557 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002558 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2559 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002560 }
2561 frameBufferMap[*pFramebuffer] = localFBCI;
2562 }
2563 return result;
2564}
2565
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002566VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002567{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002568 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002569 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002570 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002571 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002572 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002573 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2574 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002575 }
2576 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002577 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2578 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002579 }
2580 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002581 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2582 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002583 }
2584 renderPassMap[*pRenderPass] = localRPCI;
2585 }
2586 return result;
2587}
2588
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002589VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002590{
2591 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2592 if (pCB) {
2593 updateCBTracking(cmdBuffer);
2594 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002595 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2596 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002597 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002598 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002599 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002600 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002601 char str[1024];
2602 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002603 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002605 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002606}
2607
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002608VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002609{
2610 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2611 if (pCB) {
2612 updateCBTracking(cmdBuffer);
2613 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002614 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002615 }
2616 else {
2617 char str[1024];
2618 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002619 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002620 }
2621 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2622}
2623
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002624VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625{
2626 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002627 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002628 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002629 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002630 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2631 pNewDbgFuncNode->pUserData = pUserData;
2632 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2633 g_pDbgFunctionHead = pNewDbgFuncNode;
2634 // force callbacks if DebugAction hasn't been set already other than initial value
2635 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002636 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002637 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002638 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002639 return result;
2640}
2641
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002642VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002643{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002644 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2645 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646 while (pTrav) {
2647 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2648 pPrev->pNext = pTrav->pNext;
2649 if (g_pDbgFunctionHead == pTrav)
2650 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002651 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002652 break;
2653 }
2654 pPrev = pTrav;
2655 pTrav = pTrav->pNext;
2656 }
2657 if (g_pDbgFunctionHead == NULL)
2658 {
2659 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002660 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002661 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002662 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002664 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002665 return result;
2666}
2667
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002668VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002669{
2670 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2671 if (pCB) {
2672 updateCBTracking(cmdBuffer);
2673 addCmd(pCB, CMD_DBGMARKERBEGIN);
2674 }
2675 else {
2676 char str[1024];
2677 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002678 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002679 }
2680 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2681}
2682
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002683VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002684{
2685 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2686 if (pCB) {
2687 updateCBTracking(cmdBuffer);
2688 addCmd(pCB, CMD_DBGMARKEREND);
2689 }
2690 else {
2691 char str[1024];
2692 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002693 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002694 }
2695 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2696}
2697
2698// TODO : Want to pass in a cmdBuffer here based on which state to display
2699void drawStateDumpDotFile(char* outFileName)
2700{
2701 // TODO : Currently just setting cmdBuffer based on global var
2702 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2703 dumpGlobalDotFile(outFileName);
2704}
2705
2706void drawStateDumpCommandBufferDotFile(char* outFileName)
2707{
2708 cbDumpDotFile(outFileName);
2709}
2710
2711void drawStateDumpPngFile(char* outFileName)
2712{
2713#if defined(_WIN32)
2714// FIXME: NEED WINDOWS EQUIVALENT
2715 char str[1024];
2716 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002717 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002718#else // WIN32
2719 char dotExe[32] = "/usr/bin/dot";
2720 if( access(dotExe, X_OK) != -1) {
2721 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2722 char dotCmd[1024];
2723 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002724 int retval = system(dotCmd);
2725 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002726 remove("/tmp/tmp.dot");
2727 }
2728 else {
2729 char str[1024];
2730 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002731 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002732 }
2733#endif // WIN32
2734}
2735
Tony Barbour8205d902015-04-16 15:59:00 -06002736VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002737{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002738 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002739
2740 if (gpu == NULL)
2741 return NULL;
2742 pCurObj = gpuw;
2743 loader_platform_thread_once(&g_initOnce, initDrawState);
2744
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002745 if (!strcmp(funcName, "vkGetProcAddr"))
2746 return (void *) vkGetProcAddr;
2747 if (!strcmp(funcName, "vkCreateDevice"))
2748 return (void*) vkCreateDevice;
2749 if (!strcmp(funcName, "vkDestroyDevice"))
2750 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002751 if (!strcmp(funcName, "vkEnumerateLayers"))
2752 return (void*) vkEnumerateLayers;
2753 if (!strcmp(funcName, "vkQueueSubmit"))
2754 return (void*) vkQueueSubmit;
2755 if (!strcmp(funcName, "vkDestroyObject"))
2756 return (void*) vkDestroyObject;
2757 if (!strcmp(funcName, "vkCreateBufferView"))
2758 return (void*) vkCreateBufferView;
2759 if (!strcmp(funcName, "vkCreateImageView"))
2760 return (void*) vkCreateImageView;
2761 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2762 return (void*) vkCreateGraphicsPipeline;
2763 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2764 return (void*) vkCreateGraphicsPipelineDerivative;
2765 if (!strcmp(funcName, "vkCreateSampler"))
2766 return (void*) vkCreateSampler;
2767 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2768 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002769 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2770 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002771 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2772 return (void*) vkBeginDescriptorPoolUpdate;
2773 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2774 return (void*) vkEndDescriptorPoolUpdate;
2775 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2776 return (void*) vkCreateDescriptorPool;
2777 if (!strcmp(funcName, "vkResetDescriptorPool"))
2778 return (void*) vkResetDescriptorPool;
2779 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2780 return (void*) vkAllocDescriptorSets;
2781 if (!strcmp(funcName, "vkClearDescriptorSets"))
2782 return (void*) vkClearDescriptorSets;
2783 if (!strcmp(funcName, "vkUpdateDescriptors"))
2784 return (void*) vkUpdateDescriptors;
2785 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2786 return (void*) vkCreateDynamicViewportState;
2787 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2788 return (void*) vkCreateDynamicRasterState;
2789 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2790 return (void*) vkCreateDynamicColorBlendState;
2791 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2792 return (void*) vkCreateDynamicDepthStencilState;
2793 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2794 return (void*) vkCreateCommandBuffer;
2795 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2796 return (void*) vkBeginCommandBuffer;
2797 if (!strcmp(funcName, "vkEndCommandBuffer"))
2798 return (void*) vkEndCommandBuffer;
2799 if (!strcmp(funcName, "vkResetCommandBuffer"))
2800 return (void*) vkResetCommandBuffer;
2801 if (!strcmp(funcName, "vkCmdBindPipeline"))
2802 return (void*) vkCmdBindPipeline;
2803 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2804 return (void*) vkCmdBindDynamicStateObject;
2805 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2806 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002807 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2808 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002809 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2810 return (void*) vkCmdBindIndexBuffer;
2811 if (!strcmp(funcName, "vkCmdDraw"))
2812 return (void*) vkCmdDraw;
2813 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2814 return (void*) vkCmdDrawIndexed;
2815 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2816 return (void*) vkCmdDrawIndirect;
2817 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2818 return (void*) vkCmdDrawIndexedIndirect;
2819 if (!strcmp(funcName, "vkCmdDispatch"))
2820 return (void*) vkCmdDispatch;
2821 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2822 return (void*) vkCmdDispatchIndirect;
2823 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2824 return (void*) vkCmdCopyBuffer;
2825 if (!strcmp(funcName, "vkCmdCopyImage"))
2826 return (void*) vkCmdCopyImage;
2827 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2828 return (void*) vkCmdCopyBufferToImage;
2829 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2830 return (void*) vkCmdCopyImageToBuffer;
2831 if (!strcmp(funcName, "vkCmdCloneImageData"))
2832 return (void*) vkCmdCloneImageData;
2833 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2834 return (void*) vkCmdUpdateBuffer;
2835 if (!strcmp(funcName, "vkCmdFillBuffer"))
2836 return (void*) vkCmdFillBuffer;
2837 if (!strcmp(funcName, "vkCmdClearColorImage"))
2838 return (void*) vkCmdClearColorImage;
2839 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2840 return (void*) vkCmdClearDepthStencil;
2841 if (!strcmp(funcName, "vkCmdResolveImage"))
2842 return (void*) vkCmdResolveImage;
2843 if (!strcmp(funcName, "vkCmdSetEvent"))
2844 return (void*) vkCmdSetEvent;
2845 if (!strcmp(funcName, "vkCmdResetEvent"))
2846 return (void*) vkCmdResetEvent;
2847 if (!strcmp(funcName, "vkCmdWaitEvents"))
2848 return (void*) vkCmdWaitEvents;
2849 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2850 return (void*) vkCmdPipelineBarrier;
2851 if (!strcmp(funcName, "vkCmdBeginQuery"))
2852 return (void*) vkCmdBeginQuery;
2853 if (!strcmp(funcName, "vkCmdEndQuery"))
2854 return (void*) vkCmdEndQuery;
2855 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2856 return (void*) vkCmdResetQueryPool;
2857 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2858 return (void*) vkCmdWriteTimestamp;
2859 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2860 return (void*) vkCmdInitAtomicCounters;
2861 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2862 return (void*) vkCmdLoadAtomicCounters;
2863 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2864 return (void*) vkCmdSaveAtomicCounters;
2865 if (!strcmp(funcName, "vkCreateFramebuffer"))
2866 return (void*) vkCreateFramebuffer;
2867 if (!strcmp(funcName, "vkCreateRenderPass"))
2868 return (void*) vkCreateRenderPass;
2869 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2870 return (void*) vkCmdBeginRenderPass;
2871 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2872 return (void*) vkCmdEndRenderPass;
2873 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2874 return (void*) vkDbgRegisterMsgCallback;
2875 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2876 return (void*) vkDbgUnregisterMsgCallback;
2877 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2878 return (void*) vkCmdDbgMarkerBegin;
2879 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2880 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002881 if (!strcmp("drawStateDumpDotFile", funcName))
2882 return (void*) drawStateDumpDotFile;
2883 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2884 return (void*) drawStateDumpCommandBufferDotFile;
2885 if (!strcmp("drawStateDumpPngFile", funcName))
2886 return (void*) drawStateDumpPngFile;
2887 else {
2888 if (gpuw->pGPA == NULL)
2889 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002890 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002891 }
2892}