blob: af1c478785cab31fcc4d72cc2a79de98ab1b40c6 [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) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600983 while (!(*ii).second->pCmds.empty()) {
984 delete (*ii).second->pCmds.back();
985 (*ii).second->pCmds.pop_back();
986 }
987 delete (*ii).second;
988 }
989}
990static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
991{
992 CMD_NODE* pCmd = new CMD_NODE;
993 if (pCmd) {
994 // init cmd node and append to end of cmd LL
995 memset(pCmd, 0, sizeof(CMD_NODE));
996 pCmd->cmdNumber = ++pCB->numCmds;
997 pCmd->type = cmd;
998 pCB->pCmds.push_back(pCmd);
999 }
1000 else {
1001 char str[1024];
1002 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001003 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 -06001004 }
1005}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001006static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001007{
1008 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1009 if (pCB) {
1010 while (!pCB->pCmds.empty()) {
1011 delete pCB->pCmds.back();
1012 pCB->pCmds.pop_back();
1013 }
1014 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001015 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001016 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1018 pCB->cmdBuffer = cb;
1019 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001020 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001021 pCB->lastVtxBinding = MAX_BINDING;
1022 }
1023}
1024// Set the last bound dynamic state of given type
1025// 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 -06001026static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001027{
1028 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1029 if (pCB) {
1030 updateCBTracking(cmdBuffer);
1031 loader_platform_thread_lock_mutex(&globalLock);
1032 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1033 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1034 char str[1024];
1035 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001036 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 -06001037 }
1038 else {
1039 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1040 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1041 }
1042 loader_platform_thread_unlock_mutex(&globalLock);
1043 }
1044 else {
1045 char str[1024];
1046 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001047 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001048 }
1049}
1050// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001051static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001052{
1053 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1054 if (pCB) {
1055 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1056 if (!pPipeTrav) {
1057 // nothing to print
1058 }
1059 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001060 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001061 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001062 }
1063 }
1064}
1065// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001066static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001067{
1068 SET_NODE* pSet = getSetNode(ds);
1069 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001070 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001071 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001072 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1073 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001074 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001075 fprintf(pOutFile, "%s", pGVstr);
1076 free(pGVstr);
1077 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1078 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001079 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001080 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001081 ++layout_index;
1082 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001083 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001084 fprintf(pOutFile, "%s", pGVstr);
1085 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001086 if (pSet->pUpdateStructs) {
1087 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1088 fprintf(pOutFile, "%s", pGVstr);
1089 free(pGVstr);
1090 }
1091 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001092 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1093 uint32_t i = 0;
1094 for (i=0; i < pSet->descriptorCount; i++) {
1095 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001096 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 -06001097 }
1098 }
1099#define NUM_COLORS 7
1100 vector<string> edgeColors;
1101 edgeColors.push_back("0000ff");
1102 edgeColors.push_back("ff00ff");
1103 edgeColors.push_back("ffff00");
1104 edgeColors.push_back("00ff00");
1105 edgeColors.push_back("000000");
1106 edgeColors.push_back("00ffff");
1107 edgeColors.push_back("ff0000");
1108 uint32_t colorIdx = 0;
1109 fprintf(pOutFile, "</TABLE>>\n];\n");
1110 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001111 VkUpdateSamplers* pUS = NULL;
1112 VkUpdateSamplerTextures* pUST = NULL;
1113 VkUpdateImages* pUI = NULL;
1114 VkUpdateBuffers* pUB = NULL;
1115 VkUpdateAsCopy* pUAC = NULL;
1116 VkSamplerCreateInfo* pSCI = NULL;
1117 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001118 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001119 void** ppNextPtr = NULL;
1120 void* pSaveNext = NULL;
1121 for (i=0; i < pSet->descriptorCount; i++) {
1122 if (pSet->ppDescriptors[i]) {
1123 switch (pSet->ppDescriptors[i]->sType)
1124 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001125 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001126 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001127 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001128 if (pSCI) {
1129 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001130 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001131 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1132 }
1133 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001134 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001135 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001136 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001137 if (pSCI) {
1138 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001139 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001140 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1141 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001142 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001143 if (pIVCI) {
1144 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001146 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1147 }
1148 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001149 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001150 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001151 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001152 if (pIVCI) {
1153 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001154 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001155 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1156 }
1157 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001158 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001159 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001160 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001161 if (pBVCI) {
1162 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001163 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001164 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1165 }
1166 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001167 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001168 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001169 // TODO : Need to validate this code
1170 // Save off pNext and set to NULL while printing this struct, then restore it
1171 ppNextPtr = (void**)&pUAC->pNext;
1172 pSaveNext = *ppNextPtr;
1173 *ppNextPtr = NULL;
1174 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001175 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001176 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1177 // Restore next ptr
1178 *ppNextPtr = pSaveNext;
1179 break;
1180 default:
1181 break;
1182 }
1183 colorIdx = (colorIdx+1) % NUM_COLORS;
1184 }
1185 }
1186 }
1187 fprintf(pOutFile, "}\n");
1188 fprintf(pOutFile, "}\n");
1189 }
1190}
1191// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001192static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001193{
1194 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1195 if (pCB && pCB->lastBoundDescriptorSet) {
1196 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1197 }
1198}
1199// Dump a GraphViz dot file showing the Cmd Buffers
1200static void cbDumpDotFile(string outFileName)
1201{
1202 // Print CB Chain for each CB
1203 FILE* pOutFile;
1204 pOutFile = fopen(outFileName.c_str(), "w");
1205 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1206 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1207 GLOBAL_CB_NODE* pCB = NULL;
1208 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1209 pCB = g_pLastTouchedCB[i];
1210 if (pCB) {
1211 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1212 uint32_t instNum = 0;
1213 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1214 if (instNum) {
1215 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1216 }
1217 if (pCB == g_lastGlobalCB) {
1218 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());
1219 }
1220 else {
1221 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());
1222 }
1223 ++instNum;
1224 }
1225 fprintf(pOutFile, "}\n");
1226 }
1227 }
1228 fprintf(pOutFile, "}\n");
1229 fprintf(pOutFile, "}\n"); // close main graph "g"
1230 fclose(pOutFile);
1231}
1232// Dump a GraphViz dot file showing the pipeline for last bound global state
1233static void dumpGlobalDotFile(char *outFileName)
1234{
1235 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1236 if (pPipeTrav) {
1237 FILE* pOutFile;
1238 pOutFile = fopen(outFileName, "w");
1239 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1240 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1241 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001242 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001243 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001244 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001245 fprintf(pOutFile, "%s", pGVstr);
1246 free(pGVstr);
1247 }
1248 }
1249 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1250 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001251 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001252 fprintf(pOutFile, "%s", pGVstr);
1253 free(pGVstr);
1254 fprintf(pOutFile, "}\n");
1255 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1256 fprintf(pOutFile, "}\n"); // close main graph "g"
1257 fclose(pOutFile);
1258 }
1259}
1260// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001261static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001262{
1263 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1264 if (pCB) {
1265 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1266 if (pPipeTrav) {
1267 FILE* pOutFile;
1268 pOutFile = fopen(outFileName.c_str(), "w");
1269 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1270 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1271 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001272 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001273 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001274 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001275 fprintf(pOutFile, "%s", pGVstr);
1276 free(pGVstr);
1277 }
1278 }
1279 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1280 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001281 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001282 fprintf(pOutFile, "%s", pGVstr);
1283 free(pGVstr);
1284 fprintf(pOutFile, "}\n");
1285 dsDumpDot(cb, pOutFile);
1286 fprintf(pOutFile, "}\n"); // close main graph "g"
1287 fclose(pOutFile);
1288 }
1289 }
1290}
1291// Verify VB Buffer binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001292static void validateVBBinding(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001293{
1294 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1295 if (pCB && pCB->lastBoundPipeline) {
1296 // First verify that we have a Node for bound pipeline
1297 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1298 char str[1024];
1299 if (!pPipeTrav) {
1300 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001301 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001302 }
1303 else {
1304 // Verify Vtx binding
1305 if (MAX_BINDING != pCB->lastVtxBinding) {
1306 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1307 if (0 == pPipeTrav->vtxBindingCount) {
1308 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 -06001309 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 -06001310 }
1311 else {
1312 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 -06001313 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 -06001314 }
1315 }
1316 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001317 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001318 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001319 }
1320 }
1321 }
1322 }
1323}
1324// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001325static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001326{
1327 char tmp_str[1024];
1328 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.
1329 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1330 if (pCB) {
1331 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001332 POOL_NODE* pPool = getPoolNode(pSet->pool);
1333 // Print out pool details
1334 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001335 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001336 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001337 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001338 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001339 // Print out set details
1340 char prefix[10];
1341 uint32_t index = 0;
1342 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001343 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001344 LAYOUT_NODE* pLayout = pSet->pLayout;
1345 // Print layout details
1346 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 -06001347 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001348 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001349 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001350 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001351 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001352 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001353 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1354 if (pUpdate) {
1355 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001356 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001357 sprintf(prefix, " [UC] ");
1358 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001359 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001360 // TODO : If there is a "view" associated with this update, print CI for that view
1361 }
1362 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001363 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1364 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001365 }
1366 }
1367}
1368
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001369static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001370{
1371 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1372 if (pCB) {
1373 char str[1024];
1374 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001375 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001376 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1377 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001378 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001379 }
1380 }
1381 else {
1382 // Nothing to print
1383 }
1384}
1385
1386
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001387static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001388{
1389 printDSConfig(cb);
1390 printPipeline(cb);
1391 printDynamicState(cb);
1392 static int autoDumpOnce = 0;
1393 if (autoDumpOnce) {
1394 autoDumpOnce = 0;
1395 dumpDotFile(cb, "pipeline_dump.dot");
1396 cbDumpDotFile("cb_dump.dot");
1397#if defined(_WIN32)
1398// FIXME: NEED WINDOWS EQUIVALENT
1399#else // WIN32
1400 // Convert dot to svg if dot available
1401 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001402 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1403 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001404 }
1405#endif // WIN32
1406 }
1407}
1408
1409static void initDrawState(void)
1410{
1411 const char *strOpt;
1412 // initialize DrawState options
1413 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1414 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1415
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001416 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001417 {
1418 strOpt = getLayerOption("DrawStateLogFilename");
1419 if (strOpt)
1420 {
1421 g_logFile = fopen(strOpt, "w");
1422 }
1423 if (g_logFile == NULL)
1424 g_logFile = stdout;
1425 }
1426 // initialize Layer dispatch table
1427 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001428 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001429 fpNextGPA = pCurObj->pGPA;
1430 assert(fpNextGPA);
1431
Tony Barbour8205d902015-04-16 15:59:00 -06001432 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001433
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001434 if (!globalLockInitialized)
1435 {
1436 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001437 // suggestion is to call this during vkCreateInstance(), and then we
1438 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001439 // that the layer have per-instance locks. We need to come back and
1440 // address this soon.
1441 loader_platform_thread_create_mutex(&globalLock);
1442 globalLockInitialized = 1;
1443 }
1444}
1445
Tony Barbour8205d902015-04-16 15:59:00 -06001446VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001447{
Jon Ashburn630e44f2015-04-08 21:33:34 -06001448 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001449 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001450 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001451 return result;
1452}
1453
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001454VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001455{
1456 // Free all the memory
1457 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001458 deletePipelines();
1459 deleteSamplers();
1460 deleteImages();
1461 deleteBuffers();
1462 deleteCmdBuffers();
1463 deleteDynamicState();
1464 deletePools();
1465 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001466 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001467 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001468 return result;
1469}
1470
Jon Ashburneb2728b2015-04-10 14:33:07 -06001471struct extProps {
1472 uint32_t version;
1473 const char * const name;
1474};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001475#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001476static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1477 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001478 0x10, "DrawState",
1479 0x10, "Validation",
1480 0x10, "drawStateDumpDotFile",
1481 0x10, "drawStateDumpCommandBufferDotFile",
1482 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001483};
1484
1485VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1486 VkExtensionInfoType infoType,
1487 uint32_t extensionIndex,
1488 size_t* pDataSize,
1489 void* pData)
1490{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001491 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1492 VkExtensionProperties *ext_props;
1493 uint32_t *count;
1494
1495 if (pDataSize == NULL)
1496 return VK_ERROR_INVALID_POINTER;
1497
1498 switch (infoType) {
1499 case VK_EXTENSION_INFO_TYPE_COUNT:
1500 *pDataSize = sizeof(uint32_t);
1501 if (pData == NULL)
1502 return VK_SUCCESS;
1503 count = (uint32_t *) pData;
1504 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1505 break;
1506 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1507 *pDataSize = sizeof(VkExtensionProperties);
1508 if (pData == NULL)
1509 return VK_SUCCESS;
1510 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1511 return VK_ERROR_INVALID_VALUE;
1512 ext_props = (VkExtensionProperties *) pData;
1513 ext_props->version = dsExts[extensionIndex].version;
1514 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1515 VK_MAX_EXTENSION_NAME);
1516 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1517 break;
1518 default:
1519 return VK_ERROR_INVALID_VALUE;
1520 };
1521
1522 return VK_SUCCESS;
1523}
1524
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001525VK_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 -06001526{
1527 if (gpu != NULL)
1528 {
Jon Ashburn630e44f2015-04-08 21:33:34 -06001529 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001530 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001531 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001532 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001533 } else {
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001534 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001535 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001536 // This layer compatible with all GPUs
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001537 *pLayerCount = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001538 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001539 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001540 }
1541}
1542
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001543VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001544{
1545 for (uint32_t i=0; i < cmdBufferCount; i++) {
1546 // Validate that cmd buffers have been updated
1547 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001548 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001549 return result;
1550}
1551
Mike Stroyan230e6252015-04-17 12:36:38 -06001552VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001553{
1554 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyan230e6252015-04-17 12:36:38 -06001555 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001556 return result;
1557}
1558
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001559VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001560{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001561 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001562 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001563 loader_platform_thread_lock_mutex(&globalLock);
1564 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1565 pNewNode->buffer = *pView;
1566 pNewNode->createInfo = *pCreateInfo;
1567 bufferMap[*pView] = pNewNode;
1568 loader_platform_thread_unlock_mutex(&globalLock);
1569 }
1570 return result;
1571}
1572
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001573VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001574{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001575 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001576 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001577 loader_platform_thread_lock_mutex(&globalLock);
1578 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1579 pNewNode->image = *pView;
1580 pNewNode->createInfo = *pCreateInfo;
1581 imageMap[*pView] = pNewNode;
1582 loader_platform_thread_unlock_mutex(&globalLock);
1583 }
1584 return result;
1585}
1586
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001587static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001588{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001589 // Create LL HEAD for this Pipeline
1590 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001591 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1592 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1593 pPipeNode->pipeline = *pPipeline;
1594 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001595 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001596}
1597
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001598VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001599{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001600 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001601 // Create LL HEAD for this Pipeline
1602 char str[1024];
1603 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001604 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001605
1606 track_pipeline(pCreateInfo, pPipeline);
1607
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001608 return result;
1609}
1610
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001611VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1612 VkDevice device,
1613 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1614 VkPipeline basePipeline,
1615 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001616{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001617 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001618 // Create LL HEAD for this Pipeline
1619 char str[1024];
1620 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001621 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001622
1623 track_pipeline(pCreateInfo, pPipeline);
1624
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001625 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001626
1627 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001628}
1629
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001630VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001631{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001632 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001633 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001634 loader_platform_thread_lock_mutex(&globalLock);
1635 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1636 pNewNode->sampler = *pSampler;
1637 pNewNode->createInfo = *pCreateInfo;
1638 sampleMap[*pSampler] = pNewNode;
1639 loader_platform_thread_unlock_mutex(&globalLock);
1640 }
1641 return result;
1642}
1643
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001644VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001645{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001646 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001647 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001648 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1649 if (NULL == pNewNode) {
1650 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001651 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1652 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001653 }
1654 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001655 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1656 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1657 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001658 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001659 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1660 totalCount += pCreateInfo->pBinding[i].count;
1661 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001662 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1663 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1664 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001665 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001666 }
1667 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001668 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001669 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001670 uint32_t j = 0;
1671 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1672 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1673 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001675 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001676 }
1677 }
1678 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001680 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1681 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001682 // Put new node at Head of global Layer list
1683 loader_platform_thread_lock_mutex(&globalLock);
1684 layoutMap[*pSetLayout] = pNewNode;
1685 loader_platform_thread_unlock_mutex(&globalLock);
1686 }
1687 return result;
1688}
1689
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001690VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001691{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001692 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001693 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001694 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001695 }
1696 return result;
1697}
1698
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001699VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001700{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001701 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001702 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001703 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001704 POOL_NODE* pPoolNode = poolMap.begin()->second;
1705 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001706 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001707 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001708 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001709 }
1710 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001711 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001712 }
1713 loader_platform_thread_unlock_mutex(&globalLock);
1714 }
1715 return result;
1716}
1717
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001718VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001719{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001720 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001721 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001722 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001723 POOL_NODE* pPoolNode = poolMap.begin()->second;
1724 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001725 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001726 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001727 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728 }
1729 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001730 if (!pPoolNode->updateActive) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001731 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001732 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1733 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 -06001734 }
1735 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001736 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001737 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001738 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001739 }
1740 loader_platform_thread_unlock_mutex(&globalLock);
1741 }
1742 return result;
1743}
1744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001745VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001746{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001747 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001748 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001749 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001750 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001751 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyan230e6252015-04-17 12:36:38 -06001752 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001753 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001754 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001755 if (NULL == pNewNode) {
1756 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001757 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyan230e6252015-04-17 12:36:38 -06001758 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 -06001759 }
1760 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001761 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001762 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1763 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001764 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001765 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1766 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001767 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1768 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001769 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001770 pNewNode->updateActive = 0;
1771 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001772 pNewNode->pool = *pDescriptorPool;
1773 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001774 }
1775 loader_platform_thread_unlock_mutex(&globalLock);
1776 }
1777 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001778 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001779 }
1780 return result;
1781}
1782
Mike Stroyan230e6252015-04-17 12:36:38 -06001783VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001784{
Mike Stroyan230e6252015-04-17 12:36:38 -06001785 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001786 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001787 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001788 }
1789 return result;
1790}
1791
Mike Stroyan230e6252015-04-17 12:36:38 -06001792VK_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 -06001793{
Mike Stroyan230e6252015-04-17 12:36:38 -06001794 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001795 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001796 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1797 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001798 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001799 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1800 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001801 }
1802 else {
1803 for (uint32_t i = 0; i < *pCount; i++) {
1804 char str[1024];
1805 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001806 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001807 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808 SET_NODE* pNewNode = new SET_NODE;
1809 if (NULL == pNewNode) {
1810 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001811 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1812 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 -06001813 }
1814 else {
1815 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001816 // Insert set at head of Set LL for this pool
1817 pNewNode->pNext = pPoolNode->pSets;
1818 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001819 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1820 if (NULL == pLayout) {
1821 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001822 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1823 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001824 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001825 pNewNode->pLayout = pLayout;
1826 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001827 pNewNode->set = pDescriptorSets[i];
1828 pNewNode->setUsage = setUsage;
1829 pNewNode->descriptorCount = pLayout->endIndex + 1;
1830 if (pNewNode->descriptorCount) {
1831 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1832 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1833 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1834 }
1835 setMap[pDescriptorSets[i]] = pNewNode;
1836 }
1837 }
1838 }
1839 }
1840 return result;
1841}
1842
Mike Stroyan230e6252015-04-17 12:36:38 -06001843VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844{
1845 for (uint32_t i = 0; i < count; i++) {
1846 clearDescriptorSet(pDescriptorSets[i]);
1847 }
Mike Stroyan230e6252015-04-17 12:36:38 -06001848 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849}
1850
Mike Stroyan230e6252015-04-17 12:36:38 -06001851VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001852{
1853 SET_NODE* pSet = getSetNode(descriptorSet);
1854 if (!dsUpdateActive(descriptorSet)) {
1855 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001856 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1857 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 -06001858 }
1859 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001860 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001861 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862 }
1863
Mike Stroyan230e6252015-04-17 12:36:38 -06001864 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865}
1866
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001867VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001869 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001870 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871 return result;
1872}
1873
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001874VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001875{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001876 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001877 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001878 return result;
1879}
1880
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001881VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001882{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001883 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001884 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001885 return result;
1886}
1887
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001888VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001889{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001890 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001891 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001892 return result;
1893}
1894
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001895VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001896{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001897 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001898 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001899 loader_platform_thread_lock_mutex(&globalLock);
1900 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1901 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1902 pCB->cmdBuffer = *pCmdBuffer;
1903 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001904 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001905 pCB->lastVtxBinding = MAX_BINDING;
1906 cmdBufferMap[*pCmdBuffer] = pCB;
1907 loader_platform_thread_unlock_mutex(&globalLock);
1908 updateCBTracking(*pCmdBuffer);
1909 }
1910 return result;
1911}
1912
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001913VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001914{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001915 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001916 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001917 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1918 if (pCB) {
1919 if (CB_NEW != pCB->state)
1920 resetCB(cmdBuffer);
1921 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001922 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001923 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001924 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001925 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001926 }
1927 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001928 }
1929 else {
1930 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001931 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1932 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001933 }
1934 updateCBTracking(cmdBuffer);
1935 }
1936 return result;
1937}
1938
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001939VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001940{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001941 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001942 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001943 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1944 if (pCB) {
1945 pCB->state = CB_UPDATE_COMPLETE;
1946 printCB(cmdBuffer);
1947 }
1948 else {
1949 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001950 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1951 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001952 }
1953 updateCBTracking(cmdBuffer);
1954 //cbDumpDotFile("cb_dump.dot");
1955 }
1956 return result;
1957}
1958
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001959VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001960{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001961 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001962 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001963 resetCB(cmdBuffer);
1964 updateCBTracking(cmdBuffer);
1965 }
1966 return result;
1967}
1968
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001969VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001970{
1971 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1972 if (pCB) {
1973 updateCBTracking(cmdBuffer);
1974 addCmd(pCB, CMD_BINDPIPELINE);
1975 PIPELINE_NODE* pPN = getPipeline(pipeline);
1976 if (pPN) {
1977 pCB->lastBoundPipeline = pipeline;
1978 loader_platform_thread_lock_mutex(&globalLock);
1979 g_lastBoundPipeline = pPN;
1980 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001981 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001982 }
1983 else {
1984 char str[1024];
1985 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001986 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001987 }
1988 }
1989 else {
1990 char str[1024];
1991 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001992 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001993 }
1994 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1995}
1996
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001997VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001998{
1999 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
2000 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2001}
2002
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002003VK_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 -06002004{
2005 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2006 if (pCB) {
2007 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002008 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002009 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002010 if (getSetNode(pDescriptorSets[i])) {
2011 if (dsUpdateActive(pDescriptorSets[i])) {
2012 // TODO : This check here needs to be made at QueueSubmit time
2013 /*
2014 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002015 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
2016 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 -06002017 */
2018 }
2019 loader_platform_thread_lock_mutex(&globalLock);
2020 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2021 g_lastBoundDescriptorSet = pDescriptorSets[i];
2022 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002023 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002024 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002025 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002026 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002027 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002028 else {
2029 char str[1024];
2030 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002031 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002032 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002033 }
2034 }
2035 else {
2036 char str[1024];
2037 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002038 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002039 }
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002040 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002041}
2042
Tony Barbour8205d902015-04-16 15:59:00 -06002043VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002044{
2045 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2046 if (pCB) {
2047 updateCBTracking(cmdBuffer);
2048 addCmd(pCB, CMD_BINDINDEXBUFFER);
2049 // TODO : Track idxBuffer binding
2050 }
2051 else {
2052 char str[1024];
2053 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002054 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002055 }
2056 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2057}
2058
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002059VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2060 VkCmdBuffer cmdBuffer,
2061 uint32_t startBinding,
2062 uint32_t bindingCount,
2063 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002064 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002065{
2066 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2067 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002068 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002069 updateCBTracking(cmdBuffer);
2070 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002071 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002072 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002073 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002074 char str[1024];
2075 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002076 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002077 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002078 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002079}
2080
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002081VK_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 -06002082{
2083 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2084 if (pCB) {
2085 updateCBTracking(cmdBuffer);
2086 addCmd(pCB, CMD_DRAW);
2087 pCB->drawCount[DRAW]++;
2088 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002089 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2090 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002091 synchAndPrintDSConfig(cmdBuffer);
2092 }
2093 else {
2094 char str[1024];
2095 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002096 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002097 }
2098 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2099}
2100
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002101VK_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 -06002102{
2103 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2104 if (pCB) {
2105 updateCBTracking(cmdBuffer);
2106 addCmd(pCB, CMD_DRAWINDEXED);
2107 pCB->drawCount[DRAW_INDEXED]++;
2108 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002109 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2110 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002111 synchAndPrintDSConfig(cmdBuffer);
2112 }
2113 else {
2114 char str[1024];
2115 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002116 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002117 }
2118 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2119}
2120
Tony Barbour8205d902015-04-16 15:59:00 -06002121VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002122{
2123 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2124 if (pCB) {
2125 updateCBTracking(cmdBuffer);
2126 addCmd(pCB, CMD_DRAWINDIRECT);
2127 pCB->drawCount[DRAW_INDIRECT]++;
2128 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002129 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2130 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002131 synchAndPrintDSConfig(cmdBuffer);
2132 }
2133 else {
2134 char str[1024];
2135 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002136 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002137 }
2138 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2139}
2140
Tony Barbour8205d902015-04-16 15:59:00 -06002141VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002142{
2143 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2144 if (pCB) {
2145 updateCBTracking(cmdBuffer);
2146 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2147 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2148 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002149 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2150 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002151 synchAndPrintDSConfig(cmdBuffer);
2152 }
2153 else {
2154 char str[1024];
2155 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002156 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002157 }
2158 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2159}
2160
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002161VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002162{
2163 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2164 if (pCB) {
2165 updateCBTracking(cmdBuffer);
2166 addCmd(pCB, CMD_DISPATCH);
2167 }
2168 else {
2169 char str[1024];
2170 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002171 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002172 }
2173 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2174}
2175
Tony Barbour8205d902015-04-16 15:59:00 -06002176VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002177{
2178 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2179 if (pCB) {
2180 updateCBTracking(cmdBuffer);
2181 addCmd(pCB, CMD_DISPATCHINDIRECT);
2182 }
2183 else {
2184 char str[1024];
2185 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002186 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002187 }
2188 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2189}
2190
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002191VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002192{
2193 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2194 if (pCB) {
2195 updateCBTracking(cmdBuffer);
2196 addCmd(pCB, CMD_COPYBUFFER);
2197 }
2198 else {
2199 char str[1024];
2200 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002201 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002202 }
2203 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2204}
2205
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002206VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2207 VkImage srcImage,
2208 VkImageLayout srcImageLayout,
2209 VkImage destImage,
2210 VkImageLayout destImageLayout,
2211 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002212{
2213 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2214 if (pCB) {
2215 updateCBTracking(cmdBuffer);
2216 addCmd(pCB, CMD_COPYIMAGE);
2217 }
2218 else {
2219 char str[1024];
2220 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002221 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002222 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002223 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002224}
2225
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002226VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2227 VkImage srcImage, VkImageLayout srcImageLayout,
2228 VkImage destImage, VkImageLayout destImageLayout,
2229 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002230{
2231 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2232 if (pCB) {
2233 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002234 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002235 }
2236 else {
2237 char str[1024];
2238 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002239 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002240 }
2241 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2242}
2243
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002244VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2245 VkBuffer srcBuffer,
2246 VkImage destImage, VkImageLayout destImageLayout,
2247 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002248{
2249 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2250 if (pCB) {
2251 updateCBTracking(cmdBuffer);
2252 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2253 }
2254 else {
2255 char str[1024];
2256 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002257 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002258 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002259 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002260}
2261
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002262VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2263 VkImage srcImage, VkImageLayout srcImageLayout,
2264 VkBuffer destBuffer,
2265 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266{
2267 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2268 if (pCB) {
2269 updateCBTracking(cmdBuffer);
2270 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2271 }
2272 else {
2273 char str[1024];
2274 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002275 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002276 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002277 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002278}
2279
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002280VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002281{
2282 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2283 if (pCB) {
2284 updateCBTracking(cmdBuffer);
2285 addCmd(pCB, CMD_CLONEIMAGEDATA);
2286 }
2287 else {
2288 char str[1024];
2289 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002290 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002291 }
2292 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2293}
2294
Tony Barbour8205d902015-04-16 15:59:00 -06002295VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002296{
2297 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2298 if (pCB) {
2299 updateCBTracking(cmdBuffer);
2300 addCmd(pCB, CMD_UPDATEBUFFER);
2301 }
2302 else {
2303 char str[1024];
2304 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002305 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002306 }
2307 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2308}
2309
Tony Barbour8205d902015-04-16 15:59:00 -06002310VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002311{
2312 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2313 if (pCB) {
2314 updateCBTracking(cmdBuffer);
2315 addCmd(pCB, CMD_FILLBUFFER);
2316 }
2317 else {
2318 char str[1024];
2319 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002320 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002321 }
2322 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2323}
2324
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002325VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
2326 VkImage image, VkImageLayout imageLayout,
2327 VkClearColor color,
2328 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002329{
2330 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2331 if (pCB) {
2332 updateCBTracking(cmdBuffer);
2333 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2334 }
2335 else {
2336 char str[1024];
2337 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002338 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002339 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002340 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002341}
2342
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002343VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2344 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002345 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002346 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002347{
2348 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2349 if (pCB) {
2350 updateCBTracking(cmdBuffer);
2351 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2352 }
2353 else {
2354 char str[1024];
2355 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002356 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002357 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002358 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359}
2360
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002361VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2362 VkImage srcImage, VkImageLayout srcImageLayout,
2363 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002364 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002365{
2366 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2367 if (pCB) {
2368 updateCBTracking(cmdBuffer);
2369 addCmd(pCB, CMD_RESOLVEIMAGE);
2370 }
2371 else {
2372 char str[1024];
2373 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002374 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002375 }
Tony Barbour11f74372015-04-13 15:02:52 -06002376 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002377}
2378
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002379VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002380{
2381 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2382 if (pCB) {
2383 updateCBTracking(cmdBuffer);
2384 addCmd(pCB, CMD_SETEVENT);
2385 }
2386 else {
2387 char str[1024];
2388 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002389 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002390 }
2391 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2392}
2393
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002394VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002395{
2396 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2397 if (pCB) {
2398 updateCBTracking(cmdBuffer);
2399 addCmd(pCB, CMD_RESETEVENT);
2400 }
2401 else {
2402 char str[1024];
2403 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002404 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002405 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002406 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002407}
2408
Tony Barbour8205d902015-04-16 15:59:00 -06002409VK_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 -06002410{
2411 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2412 if (pCB) {
2413 updateCBTracking(cmdBuffer);
2414 addCmd(pCB, CMD_WAITEVENTS);
2415 }
2416 else {
2417 char str[1024];
2418 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002419 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002420 }
Tony Barbour8205d902015-04-16 15:59:00 -06002421 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002422}
2423
Tony Barbour8205d902015-04-16 15:59:00 -06002424VK_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 -06002425{
2426 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2427 if (pCB) {
2428 updateCBTracking(cmdBuffer);
2429 addCmd(pCB, CMD_PIPELINEBARRIER);
2430 }
2431 else {
2432 char str[1024];
2433 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002434 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002435 }
Tony Barbour8205d902015-04-16 15:59:00 -06002436 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002437}
2438
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002439VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002440{
2441 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2442 if (pCB) {
2443 updateCBTracking(cmdBuffer);
2444 addCmd(pCB, CMD_BEGINQUERY);
2445 }
2446 else {
2447 char str[1024];
2448 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002449 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002450 }
2451 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2452}
2453
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002454VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002455{
2456 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2457 if (pCB) {
2458 updateCBTracking(cmdBuffer);
2459 addCmd(pCB, CMD_ENDQUERY);
2460 }
2461 else {
2462 char str[1024];
2463 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002464 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002465 }
2466 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2467}
2468
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002469VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470{
2471 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2472 if (pCB) {
2473 updateCBTracking(cmdBuffer);
2474 addCmd(pCB, CMD_RESETQUERYPOOL);
2475 }
2476 else {
2477 char str[1024];
2478 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002479 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002480 }
2481 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2482}
2483
Tony Barbour8205d902015-04-16 15:59:00 -06002484VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002485{
2486 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2487 if (pCB) {
2488 updateCBTracking(cmdBuffer);
2489 addCmd(pCB, CMD_WRITETIMESTAMP);
2490 }
2491 else {
2492 char str[1024];
2493 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002494 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002495 }
2496 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2497}
2498
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002499VK_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 -06002500{
2501 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2502 if (pCB) {
2503 updateCBTracking(cmdBuffer);
2504 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2505 }
2506 else {
2507 char str[1024];
2508 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002509 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002510 }
2511 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2512}
2513
Tony Barbour8205d902015-04-16 15:59:00 -06002514VK_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 -06002515{
2516 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2517 if (pCB) {
2518 updateCBTracking(cmdBuffer);
2519 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2520 }
2521 else {
2522 char str[1024];
2523 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002524 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002525 }
2526 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2527}
2528
Tony Barbour8205d902015-04-16 15:59:00 -06002529VK_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 -06002530{
2531 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2532 if (pCB) {
2533 updateCBTracking(cmdBuffer);
2534 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2535 }
2536 else {
2537 char str[1024];
2538 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002539 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002540 }
2541 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2542}
2543
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002544VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002545{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002546 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002547 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002548 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002549 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002550 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002551 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2552 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002553 }
2554 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002555 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2556 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002557 }
2558 frameBufferMap[*pFramebuffer] = localFBCI;
2559 }
2560 return result;
2561}
2562
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002563VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002564{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002565 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002566 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002567 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002568 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002569 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002570 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2571 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002572 }
2573 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002574 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2575 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002576 }
2577 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002578 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2579 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002580 }
2581 renderPassMap[*pRenderPass] = localRPCI;
2582 }
2583 return result;
2584}
2585
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002586VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002587{
2588 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2589 if (pCB) {
2590 updateCBTracking(cmdBuffer);
2591 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002592 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2593 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002594 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002595 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002596 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002597 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002598 char str[1024];
2599 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002600 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002601 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002602 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002603}
2604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002605VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002606{
2607 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2608 if (pCB) {
2609 updateCBTracking(cmdBuffer);
2610 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002611 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002612 }
2613 else {
2614 char str[1024];
2615 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002616 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002617 }
2618 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2619}
2620
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002621VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002622{
2623 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002624 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002626 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002627 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2628 pNewDbgFuncNode->pUserData = pUserData;
2629 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2630 g_pDbgFunctionHead = pNewDbgFuncNode;
2631 // force callbacks if DebugAction hasn't been set already other than initial value
2632 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002633 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002634 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002635 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002636 return result;
2637}
2638
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002639VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002640{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002641 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2642 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002643 while (pTrav) {
2644 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2645 pPrev->pNext = pTrav->pNext;
2646 if (g_pDbgFunctionHead == pTrav)
2647 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002648 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002649 break;
2650 }
2651 pPrev = pTrav;
2652 pTrav = pTrav->pNext;
2653 }
2654 if (g_pDbgFunctionHead == NULL)
2655 {
2656 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002657 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002658 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002659 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002660 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002661 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002662 return result;
2663}
2664
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002665VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002666{
2667 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2668 if (pCB) {
2669 updateCBTracking(cmdBuffer);
2670 addCmd(pCB, CMD_DBGMARKERBEGIN);
2671 }
2672 else {
2673 char str[1024];
2674 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002675 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002676 }
2677 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2678}
2679
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002680VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002681{
2682 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2683 if (pCB) {
2684 updateCBTracking(cmdBuffer);
2685 addCmd(pCB, CMD_DBGMARKEREND);
2686 }
2687 else {
2688 char str[1024];
2689 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002690 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002691 }
2692 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2693}
2694
2695// TODO : Want to pass in a cmdBuffer here based on which state to display
2696void drawStateDumpDotFile(char* outFileName)
2697{
2698 // TODO : Currently just setting cmdBuffer based on global var
2699 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2700 dumpGlobalDotFile(outFileName);
2701}
2702
2703void drawStateDumpCommandBufferDotFile(char* outFileName)
2704{
2705 cbDumpDotFile(outFileName);
2706}
2707
2708void drawStateDumpPngFile(char* outFileName)
2709{
2710#if defined(_WIN32)
2711// FIXME: NEED WINDOWS EQUIVALENT
2712 char str[1024];
2713 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002714 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002715#else // WIN32
2716 char dotExe[32] = "/usr/bin/dot";
2717 if( access(dotExe, X_OK) != -1) {
2718 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2719 char dotCmd[1024];
2720 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002721 int retval = system(dotCmd);
2722 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002723 remove("/tmp/tmp.dot");
2724 }
2725 else {
2726 char str[1024];
2727 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002728 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002729 }
2730#endif // WIN32
2731}
2732
Tony Barbour8205d902015-04-16 15:59:00 -06002733VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002734{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002735 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002736
2737 if (gpu == NULL)
2738 return NULL;
2739 pCurObj = gpuw;
2740 loader_platform_thread_once(&g_initOnce, initDrawState);
2741
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002742 if (!strcmp(funcName, "vkGetProcAddr"))
2743 return (void *) vkGetProcAddr;
2744 if (!strcmp(funcName, "vkCreateDevice"))
2745 return (void*) vkCreateDevice;
2746 if (!strcmp(funcName, "vkDestroyDevice"))
2747 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002748 if (!strcmp(funcName, "vkEnumerateLayers"))
2749 return (void*) vkEnumerateLayers;
2750 if (!strcmp(funcName, "vkQueueSubmit"))
2751 return (void*) vkQueueSubmit;
2752 if (!strcmp(funcName, "vkDestroyObject"))
2753 return (void*) vkDestroyObject;
2754 if (!strcmp(funcName, "vkCreateBufferView"))
2755 return (void*) vkCreateBufferView;
2756 if (!strcmp(funcName, "vkCreateImageView"))
2757 return (void*) vkCreateImageView;
2758 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2759 return (void*) vkCreateGraphicsPipeline;
2760 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2761 return (void*) vkCreateGraphicsPipelineDerivative;
2762 if (!strcmp(funcName, "vkCreateSampler"))
2763 return (void*) vkCreateSampler;
2764 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2765 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002766 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2767 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002768 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2769 return (void*) vkBeginDescriptorPoolUpdate;
2770 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2771 return (void*) vkEndDescriptorPoolUpdate;
2772 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2773 return (void*) vkCreateDescriptorPool;
2774 if (!strcmp(funcName, "vkResetDescriptorPool"))
2775 return (void*) vkResetDescriptorPool;
2776 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2777 return (void*) vkAllocDescriptorSets;
2778 if (!strcmp(funcName, "vkClearDescriptorSets"))
2779 return (void*) vkClearDescriptorSets;
2780 if (!strcmp(funcName, "vkUpdateDescriptors"))
2781 return (void*) vkUpdateDescriptors;
2782 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2783 return (void*) vkCreateDynamicViewportState;
2784 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2785 return (void*) vkCreateDynamicRasterState;
2786 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2787 return (void*) vkCreateDynamicColorBlendState;
2788 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2789 return (void*) vkCreateDynamicDepthStencilState;
2790 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2791 return (void*) vkCreateCommandBuffer;
2792 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2793 return (void*) vkBeginCommandBuffer;
2794 if (!strcmp(funcName, "vkEndCommandBuffer"))
2795 return (void*) vkEndCommandBuffer;
2796 if (!strcmp(funcName, "vkResetCommandBuffer"))
2797 return (void*) vkResetCommandBuffer;
2798 if (!strcmp(funcName, "vkCmdBindPipeline"))
2799 return (void*) vkCmdBindPipeline;
2800 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2801 return (void*) vkCmdBindDynamicStateObject;
2802 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2803 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002804 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2805 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002806 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2807 return (void*) vkCmdBindIndexBuffer;
2808 if (!strcmp(funcName, "vkCmdDraw"))
2809 return (void*) vkCmdDraw;
2810 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2811 return (void*) vkCmdDrawIndexed;
2812 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2813 return (void*) vkCmdDrawIndirect;
2814 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2815 return (void*) vkCmdDrawIndexedIndirect;
2816 if (!strcmp(funcName, "vkCmdDispatch"))
2817 return (void*) vkCmdDispatch;
2818 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2819 return (void*) vkCmdDispatchIndirect;
2820 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2821 return (void*) vkCmdCopyBuffer;
2822 if (!strcmp(funcName, "vkCmdCopyImage"))
2823 return (void*) vkCmdCopyImage;
2824 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2825 return (void*) vkCmdCopyBufferToImage;
2826 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2827 return (void*) vkCmdCopyImageToBuffer;
2828 if (!strcmp(funcName, "vkCmdCloneImageData"))
2829 return (void*) vkCmdCloneImageData;
2830 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2831 return (void*) vkCmdUpdateBuffer;
2832 if (!strcmp(funcName, "vkCmdFillBuffer"))
2833 return (void*) vkCmdFillBuffer;
2834 if (!strcmp(funcName, "vkCmdClearColorImage"))
2835 return (void*) vkCmdClearColorImage;
2836 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2837 return (void*) vkCmdClearDepthStencil;
2838 if (!strcmp(funcName, "vkCmdResolveImage"))
2839 return (void*) vkCmdResolveImage;
2840 if (!strcmp(funcName, "vkCmdSetEvent"))
2841 return (void*) vkCmdSetEvent;
2842 if (!strcmp(funcName, "vkCmdResetEvent"))
2843 return (void*) vkCmdResetEvent;
2844 if (!strcmp(funcName, "vkCmdWaitEvents"))
2845 return (void*) vkCmdWaitEvents;
2846 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2847 return (void*) vkCmdPipelineBarrier;
2848 if (!strcmp(funcName, "vkCmdBeginQuery"))
2849 return (void*) vkCmdBeginQuery;
2850 if (!strcmp(funcName, "vkCmdEndQuery"))
2851 return (void*) vkCmdEndQuery;
2852 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2853 return (void*) vkCmdResetQueryPool;
2854 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2855 return (void*) vkCmdWriteTimestamp;
2856 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2857 return (void*) vkCmdInitAtomicCounters;
2858 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2859 return (void*) vkCmdLoadAtomicCounters;
2860 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2861 return (void*) vkCmdSaveAtomicCounters;
2862 if (!strcmp(funcName, "vkCreateFramebuffer"))
2863 return (void*) vkCreateFramebuffer;
2864 if (!strcmp(funcName, "vkCreateRenderPass"))
2865 return (void*) vkCreateRenderPass;
2866 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2867 return (void*) vkCmdBeginRenderPass;
2868 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2869 return (void*) vkCmdEndRenderPass;
2870 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2871 return (void*) vkDbgRegisterMsgCallback;
2872 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2873 return (void*) vkDbgUnregisterMsgCallback;
2874 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2875 return (void*) vkCmdDbgMarkerBegin;
2876 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2877 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002878 if (!strcmp("drawStateDumpDotFile", funcName))
2879 return (void*) drawStateDumpDotFile;
2880 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2881 return (void*) drawStateDumpCommandBufferDotFile;
2882 if (!strcmp("drawStateDumpPngFile", funcName))
2883 return (void*) drawStateDumpPngFile;
2884 else {
2885 if (gpuw->pGPA == NULL)
2886 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002887 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002888 }
2889}