blob: 5bfe41d4eef97c5b4560336126dee20a3ea07675 [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);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001376 vector<CMD_NODE*> pCmds = pCB->pCmds;
1377 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001378 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001379 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001380 }
1381 }
1382 else {
1383 // Nothing to print
1384 }
1385}
1386
1387
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001388static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001389{
1390 printDSConfig(cb);
1391 printPipeline(cb);
1392 printDynamicState(cb);
1393 static int autoDumpOnce = 0;
1394 if (autoDumpOnce) {
1395 autoDumpOnce = 0;
1396 dumpDotFile(cb, "pipeline_dump.dot");
1397 cbDumpDotFile("cb_dump.dot");
1398#if defined(_WIN32)
1399// FIXME: NEED WINDOWS EQUIVALENT
1400#else // WIN32
1401 // Convert dot to svg if dot available
1402 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001403 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1404 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001405 }
1406#endif // WIN32
1407 }
1408}
1409
1410static void initDrawState(void)
1411{
1412 const char *strOpt;
1413 // initialize DrawState options
1414 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1415 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1416
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001417 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001418 {
1419 strOpt = getLayerOption("DrawStateLogFilename");
1420 if (strOpt)
1421 {
1422 g_logFile = fopen(strOpt, "w");
1423 }
1424 if (g_logFile == NULL)
1425 g_logFile = stdout;
1426 }
1427 // initialize Layer dispatch table
1428 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001429 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001430 fpNextGPA = pCurObj->pGPA;
1431 assert(fpNextGPA);
1432
Tony Barbour8205d902015-04-16 15:59:00 -06001433 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001434
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001435 if (!globalLockInitialized)
1436 {
1437 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001438 // suggestion is to call this during vkCreateInstance(), and then we
1439 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001440 // that the layer have per-instance locks. We need to come back and
1441 // address this soon.
1442 loader_platform_thread_create_mutex(&globalLock);
1443 globalLockInitialized = 1;
1444 }
1445}
1446
Tony Barbour8205d902015-04-16 15:59:00 -06001447VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001448{
Jon Ashburn630e44f2015-04-08 21:33:34 -06001449 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001450 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001451 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001452 return result;
1453}
1454
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001455VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001456{
1457 // Free all the memory
1458 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001459 deletePipelines();
1460 deleteSamplers();
1461 deleteImages();
1462 deleteBuffers();
1463 deleteCmdBuffers();
1464 deleteDynamicState();
1465 deletePools();
1466 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001467 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001468 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001469 return result;
1470}
1471
Jon Ashburneb2728b2015-04-10 14:33:07 -06001472struct extProps {
1473 uint32_t version;
1474 const char * const name;
1475};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001476#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001477static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1478 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001479 0x10, "DrawState",
1480 0x10, "Validation",
1481 0x10, "drawStateDumpDotFile",
1482 0x10, "drawStateDumpCommandBufferDotFile",
1483 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001484};
1485
1486VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1487 VkExtensionInfoType infoType,
1488 uint32_t extensionIndex,
1489 size_t* pDataSize,
1490 void* pData)
1491{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001492 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1493 VkExtensionProperties *ext_props;
1494 uint32_t *count;
1495
1496 if (pDataSize == NULL)
1497 return VK_ERROR_INVALID_POINTER;
1498
1499 switch (infoType) {
1500 case VK_EXTENSION_INFO_TYPE_COUNT:
1501 *pDataSize = sizeof(uint32_t);
1502 if (pData == NULL)
1503 return VK_SUCCESS;
1504 count = (uint32_t *) pData;
1505 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1506 break;
1507 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1508 *pDataSize = sizeof(VkExtensionProperties);
1509 if (pData == NULL)
1510 return VK_SUCCESS;
1511 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1512 return VK_ERROR_INVALID_VALUE;
1513 ext_props = (VkExtensionProperties *) pData;
1514 ext_props->version = dsExts[extensionIndex].version;
1515 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1516 VK_MAX_EXTENSION_NAME);
1517 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1518 break;
1519 default:
1520 return VK_ERROR_INVALID_VALUE;
1521 };
1522
1523 return VK_SUCCESS;
1524}
1525
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001526VK_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 -06001527{
1528 if (gpu != NULL)
1529 {
Jon Ashburn630e44f2015-04-08 21:33:34 -06001530 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001531 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001532 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001533 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001534 } else {
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001535 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001536 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001537 // This layer compatible with all GPUs
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001538 *pLayerCount = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001539 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001540 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001541 }
1542}
1543
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001544VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001545{
1546 for (uint32_t i=0; i < cmdBufferCount; i++) {
1547 // Validate that cmd buffers have been updated
1548 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001549 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001550 return result;
1551}
1552
Mike Stroyan230e6252015-04-17 12:36:38 -06001553VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001554{
1555 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyan230e6252015-04-17 12:36:38 -06001556 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001557 return result;
1558}
1559
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001560VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001561{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001562 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001563 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001564 loader_platform_thread_lock_mutex(&globalLock);
1565 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1566 pNewNode->buffer = *pView;
1567 pNewNode->createInfo = *pCreateInfo;
1568 bufferMap[*pView] = pNewNode;
1569 loader_platform_thread_unlock_mutex(&globalLock);
1570 }
1571 return result;
1572}
1573
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001574VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001575{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001576 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001577 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001578 loader_platform_thread_lock_mutex(&globalLock);
1579 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1580 pNewNode->image = *pView;
1581 pNewNode->createInfo = *pCreateInfo;
1582 imageMap[*pView] = pNewNode;
1583 loader_platform_thread_unlock_mutex(&globalLock);
1584 }
1585 return result;
1586}
1587
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001588static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001589{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001590 // Create LL HEAD for this Pipeline
1591 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001592 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1593 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1594 pPipeNode->pipeline = *pPipeline;
1595 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001596 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001597}
1598
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001599VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001600{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001601 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001602 // Create LL HEAD for this Pipeline
1603 char str[1024];
1604 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001605 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001606
1607 track_pipeline(pCreateInfo, pPipeline);
1608
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001609 return result;
1610}
1611
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001612VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1613 VkDevice device,
1614 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1615 VkPipeline basePipeline,
1616 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001617{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001618 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001619 // Create LL HEAD for this Pipeline
1620 char str[1024];
1621 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001622 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001623
1624 track_pipeline(pCreateInfo, pPipeline);
1625
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001626 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001627
1628 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001629}
1630
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001631VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001632{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001633 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001634 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001635 loader_platform_thread_lock_mutex(&globalLock);
1636 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1637 pNewNode->sampler = *pSampler;
1638 pNewNode->createInfo = *pCreateInfo;
1639 sampleMap[*pSampler] = pNewNode;
1640 loader_platform_thread_unlock_mutex(&globalLock);
1641 }
1642 return result;
1643}
1644
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001645VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001646{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001647 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001648 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001649 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1650 if (NULL == pNewNode) {
1651 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001652 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1653 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001654 }
1655 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001656 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1657 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1658 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001659 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001660 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1661 totalCount += pCreateInfo->pBinding[i].count;
1662 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001663 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1664 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1665 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001666 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001667 }
1668 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001669 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001670 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001671 uint32_t j = 0;
1672 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1673 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1674 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001675 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001676 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001677 }
1678 }
1679 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001680 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001681 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1682 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683 // Put new node at Head of global Layer list
1684 loader_platform_thread_lock_mutex(&globalLock);
1685 layoutMap[*pSetLayout] = pNewNode;
1686 loader_platform_thread_unlock_mutex(&globalLock);
1687 }
1688 return result;
1689}
1690
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001691VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001692{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001693 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001694 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001695 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001696 }
1697 return result;
1698}
1699
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001700VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001701{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001702 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001703 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001704 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001705 POOL_NODE* pPoolNode = poolMap.begin()->second;
1706 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001707 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001708 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001709 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001710 }
1711 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001712 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001713 }
1714 loader_platform_thread_unlock_mutex(&globalLock);
1715 }
1716 return result;
1717}
1718
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001719VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001720{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001721 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001722 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001723 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001724 POOL_NODE* pPoolNode = poolMap.begin()->second;
1725 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001726 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001727 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001728 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001729 }
1730 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001731 if (!pPoolNode->updateActive) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001732 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001733 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1734 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 -06001735 }
1736 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001737 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001738 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001739 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001740 }
1741 loader_platform_thread_unlock_mutex(&globalLock);
1742 }
1743 return result;
1744}
1745
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001746VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001747{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001748 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001749 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001750 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001751 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001752 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyan230e6252015-04-17 12:36:38 -06001753 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001754 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001755 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001756 if (NULL == pNewNode) {
1757 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001758 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyan230e6252015-04-17 12:36:38 -06001759 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 -06001760 }
1761 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001762 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001763 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1764 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001765 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001766 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1767 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001768 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1769 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001770 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771 pNewNode->updateActive = 0;
1772 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001773 pNewNode->pool = *pDescriptorPool;
1774 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001775 }
1776 loader_platform_thread_unlock_mutex(&globalLock);
1777 }
1778 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001779 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001780 }
1781 return result;
1782}
1783
Mike Stroyan230e6252015-04-17 12:36:38 -06001784VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785{
Mike Stroyan230e6252015-04-17 12:36:38 -06001786 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001787 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001788 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001789 }
1790 return result;
1791}
1792
Mike Stroyan230e6252015-04-17 12:36:38 -06001793VK_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 -06001794{
Mike Stroyan230e6252015-04-17 12:36:38 -06001795 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001796 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001797 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1798 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001800 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1801 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001802 }
1803 else {
1804 for (uint32_t i = 0; i < *pCount; i++) {
1805 char str[1024];
1806 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001807 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001808 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001809 SET_NODE* pNewNode = new SET_NODE;
1810 if (NULL == pNewNode) {
1811 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001812 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1813 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 -06001814 }
1815 else {
1816 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001817 // Insert set at head of Set LL for this pool
1818 pNewNode->pNext = pPoolNode->pSets;
1819 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1821 if (NULL == pLayout) {
1822 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001823 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1824 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001826 pNewNode->pLayout = pLayout;
1827 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001828 pNewNode->set = pDescriptorSets[i];
1829 pNewNode->setUsage = setUsage;
1830 pNewNode->descriptorCount = pLayout->endIndex + 1;
1831 if (pNewNode->descriptorCount) {
1832 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1833 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1834 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1835 }
1836 setMap[pDescriptorSets[i]] = pNewNode;
1837 }
1838 }
1839 }
1840 }
1841 return result;
1842}
1843
Mike Stroyan230e6252015-04-17 12:36:38 -06001844VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001845{
1846 for (uint32_t i = 0; i < count; i++) {
1847 clearDescriptorSet(pDescriptorSets[i]);
1848 }
Mike Stroyan230e6252015-04-17 12:36:38 -06001849 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001850}
1851
Mike Stroyan230e6252015-04-17 12:36:38 -06001852VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853{
1854 SET_NODE* pSet = getSetNode(descriptorSet);
1855 if (!dsUpdateActive(descriptorSet)) {
1856 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001857 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1858 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 -06001859 }
1860 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001861 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001862 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001863 }
1864
Mike Stroyan230e6252015-04-17 12:36:38 -06001865 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001866}
1867
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001868VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001869{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001870 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001871 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001872 return result;
1873}
1874
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001875VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001876{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001877 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001878 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001879 return result;
1880}
1881
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001882VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001883{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001884 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001885 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001886 return result;
1887}
1888
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001889VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001890{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001891 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001892 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001893 return result;
1894}
1895
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001896VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001897{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001898 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001899 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001900 loader_platform_thread_lock_mutex(&globalLock);
1901 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1902 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1903 pCB->cmdBuffer = *pCmdBuffer;
1904 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001905 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001906 pCB->lastVtxBinding = MAX_BINDING;
1907 cmdBufferMap[*pCmdBuffer] = pCB;
1908 loader_platform_thread_unlock_mutex(&globalLock);
1909 updateCBTracking(*pCmdBuffer);
1910 }
1911 return result;
1912}
1913
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001914VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001915{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001916 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001917 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001918 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1919 if (pCB) {
1920 if (CB_NEW != pCB->state)
1921 resetCB(cmdBuffer);
1922 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001923 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001924 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001925 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001926 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001927 }
1928 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001929 }
1930 else {
1931 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001932 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1933 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001934 }
1935 updateCBTracking(cmdBuffer);
1936 }
1937 return result;
1938}
1939
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001940VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001941{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001942 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001943 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001944 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1945 if (pCB) {
1946 pCB->state = CB_UPDATE_COMPLETE;
1947 printCB(cmdBuffer);
1948 }
1949 else {
1950 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1952 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001953 }
1954 updateCBTracking(cmdBuffer);
1955 //cbDumpDotFile("cb_dump.dot");
1956 }
1957 return result;
1958}
1959
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001960VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001961{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001962 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001963 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001964 resetCB(cmdBuffer);
1965 updateCBTracking(cmdBuffer);
1966 }
1967 return result;
1968}
1969
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001970VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001971{
1972 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1973 if (pCB) {
1974 updateCBTracking(cmdBuffer);
1975 addCmd(pCB, CMD_BINDPIPELINE);
1976 PIPELINE_NODE* pPN = getPipeline(pipeline);
1977 if (pPN) {
1978 pCB->lastBoundPipeline = pipeline;
1979 loader_platform_thread_lock_mutex(&globalLock);
1980 g_lastBoundPipeline = pPN;
1981 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001982 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001983 }
1984 else {
1985 char str[1024];
1986 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001987 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001988 }
1989 }
1990 else {
1991 char str[1024];
1992 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001993 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001994 }
1995 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1996}
1997
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001998VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001999{
2000 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
2001 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2002}
2003
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002004VK_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 -06002005{
2006 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2007 if (pCB) {
2008 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002009 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002010 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002011 if (getSetNode(pDescriptorSets[i])) {
2012 if (dsUpdateActive(pDescriptorSets[i])) {
2013 // TODO : This check here needs to be made at QueueSubmit time
2014 /*
2015 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002016 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
2017 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 -06002018 */
2019 }
2020 loader_platform_thread_lock_mutex(&globalLock);
2021 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2022 g_lastBoundDescriptorSet = pDescriptorSets[i];
2023 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002024 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002025 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002026 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002027 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002028 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002029 else {
2030 char str[1024];
2031 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002032 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002033 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002034 }
2035 }
2036 else {
2037 char str[1024];
2038 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002039 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002040 }
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002041 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042}
2043
Tony Barbour8205d902015-04-16 15:59:00 -06002044VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002045{
2046 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2047 if (pCB) {
2048 updateCBTracking(cmdBuffer);
2049 addCmd(pCB, CMD_BINDINDEXBUFFER);
2050 // TODO : Track idxBuffer binding
2051 }
2052 else {
2053 char str[1024];
2054 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002055 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002056 }
2057 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2058}
2059
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002060VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2061 VkCmdBuffer cmdBuffer,
2062 uint32_t startBinding,
2063 uint32_t bindingCount,
2064 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002065 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002066{
2067 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2068 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002069 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002070 updateCBTracking(cmdBuffer);
2071 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002072 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002073 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002074 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002075 char str[1024];
2076 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002077 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002078 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002079 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002080}
2081
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002082VK_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 -06002083{
2084 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2085 if (pCB) {
2086 updateCBTracking(cmdBuffer);
2087 addCmd(pCB, CMD_DRAW);
2088 pCB->drawCount[DRAW]++;
2089 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002090 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2091 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002092 synchAndPrintDSConfig(cmdBuffer);
2093 }
2094 else {
2095 char str[1024];
2096 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002097 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002098 }
2099 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2100}
2101
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002102VK_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 -06002103{
2104 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2105 if (pCB) {
2106 updateCBTracking(cmdBuffer);
2107 addCmd(pCB, CMD_DRAWINDEXED);
2108 pCB->drawCount[DRAW_INDEXED]++;
2109 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002110 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2111 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002112 synchAndPrintDSConfig(cmdBuffer);
2113 }
2114 else {
2115 char str[1024];
2116 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002117 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002118 }
2119 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2120}
2121
Tony Barbour8205d902015-04-16 15:59:00 -06002122VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002123{
2124 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2125 if (pCB) {
2126 updateCBTracking(cmdBuffer);
2127 addCmd(pCB, CMD_DRAWINDIRECT);
2128 pCB->drawCount[DRAW_INDIRECT]++;
2129 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002130 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2131 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002132 synchAndPrintDSConfig(cmdBuffer);
2133 }
2134 else {
2135 char str[1024];
2136 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002137 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002138 }
2139 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2140}
2141
Tony Barbour8205d902015-04-16 15:59:00 -06002142VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002143{
2144 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2145 if (pCB) {
2146 updateCBTracking(cmdBuffer);
2147 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2148 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2149 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002150 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2151 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002152 synchAndPrintDSConfig(cmdBuffer);
2153 }
2154 else {
2155 char str[1024];
2156 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002157 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002158 }
2159 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2160}
2161
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002162VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002163{
2164 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2165 if (pCB) {
2166 updateCBTracking(cmdBuffer);
2167 addCmd(pCB, CMD_DISPATCH);
2168 }
2169 else {
2170 char str[1024];
2171 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002172 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002173 }
2174 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2175}
2176
Tony Barbour8205d902015-04-16 15:59:00 -06002177VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002178{
2179 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2180 if (pCB) {
2181 updateCBTracking(cmdBuffer);
2182 addCmd(pCB, CMD_DISPATCHINDIRECT);
2183 }
2184 else {
2185 char str[1024];
2186 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002187 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002188 }
2189 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2190}
2191
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002192VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002193{
2194 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2195 if (pCB) {
2196 updateCBTracking(cmdBuffer);
2197 addCmd(pCB, CMD_COPYBUFFER);
2198 }
2199 else {
2200 char str[1024];
2201 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002202 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002203 }
2204 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2205}
2206
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002207VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2208 VkImage srcImage,
2209 VkImageLayout srcImageLayout,
2210 VkImage destImage,
2211 VkImageLayout destImageLayout,
2212 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002213{
2214 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2215 if (pCB) {
2216 updateCBTracking(cmdBuffer);
2217 addCmd(pCB, CMD_COPYIMAGE);
2218 }
2219 else {
2220 char str[1024];
2221 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002222 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002223 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002224 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002225}
2226
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002227VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2228 VkImage srcImage, VkImageLayout srcImageLayout,
2229 VkImage destImage, VkImageLayout destImageLayout,
2230 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002231{
2232 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2233 if (pCB) {
2234 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002235 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002236 }
2237 else {
2238 char str[1024];
2239 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002240 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002241 }
2242 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2243}
2244
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002245VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2246 VkBuffer srcBuffer,
2247 VkImage destImage, VkImageLayout destImageLayout,
2248 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002249{
2250 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2251 if (pCB) {
2252 updateCBTracking(cmdBuffer);
2253 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2254 }
2255 else {
2256 char str[1024];
2257 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002258 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002259 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002260 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002261}
2262
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002263VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2264 VkImage srcImage, VkImageLayout srcImageLayout,
2265 VkBuffer destBuffer,
2266 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002267{
2268 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2269 if (pCB) {
2270 updateCBTracking(cmdBuffer);
2271 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2272 }
2273 else {
2274 char str[1024];
2275 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002276 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002277 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002278 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002279}
2280
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002281VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002282{
2283 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2284 if (pCB) {
2285 updateCBTracking(cmdBuffer);
2286 addCmd(pCB, CMD_CLONEIMAGEDATA);
2287 }
2288 else {
2289 char str[1024];
2290 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002291 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002292 }
2293 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2294}
2295
Tony Barbour8205d902015-04-16 15:59:00 -06002296VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002297{
2298 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2299 if (pCB) {
2300 updateCBTracking(cmdBuffer);
2301 addCmd(pCB, CMD_UPDATEBUFFER);
2302 }
2303 else {
2304 char str[1024];
2305 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002306 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002307 }
2308 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2309}
2310
Tony Barbour8205d902015-04-16 15:59:00 -06002311VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002312{
2313 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2314 if (pCB) {
2315 updateCBTracking(cmdBuffer);
2316 addCmd(pCB, CMD_FILLBUFFER);
2317 }
2318 else {
2319 char str[1024];
2320 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002321 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002322 }
2323 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2324}
2325
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002326VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
2327 VkImage image, VkImageLayout imageLayout,
2328 VkClearColor color,
2329 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002330{
2331 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2332 if (pCB) {
2333 updateCBTracking(cmdBuffer);
2334 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2335 }
2336 else {
2337 char str[1024];
2338 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002339 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002340 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002341 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002342}
2343
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002344VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2345 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002346 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002347 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002348{
2349 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2350 if (pCB) {
2351 updateCBTracking(cmdBuffer);
2352 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2353 }
2354 else {
2355 char str[1024];
2356 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002357 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002358 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002359 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002360}
2361
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002362VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2363 VkImage srcImage, VkImageLayout srcImageLayout,
2364 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002365 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002366{
2367 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2368 if (pCB) {
2369 updateCBTracking(cmdBuffer);
2370 addCmd(pCB, CMD_RESOLVEIMAGE);
2371 }
2372 else {
2373 char str[1024];
2374 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002375 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002376 }
Tony Barbour11f74372015-04-13 15:02:52 -06002377 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002378}
2379
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002380VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002381{
2382 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2383 if (pCB) {
2384 updateCBTracking(cmdBuffer);
2385 addCmd(pCB, CMD_SETEVENT);
2386 }
2387 else {
2388 char str[1024];
2389 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002390 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002391 }
2392 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2393}
2394
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002395VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002396{
2397 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2398 if (pCB) {
2399 updateCBTracking(cmdBuffer);
2400 addCmd(pCB, CMD_RESETEVENT);
2401 }
2402 else {
2403 char str[1024];
2404 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002405 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002406 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002407 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002408}
2409
Tony Barbour8205d902015-04-16 15:59:00 -06002410VK_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 -06002411{
2412 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2413 if (pCB) {
2414 updateCBTracking(cmdBuffer);
2415 addCmd(pCB, CMD_WAITEVENTS);
2416 }
2417 else {
2418 char str[1024];
2419 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002420 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002421 }
Tony Barbour8205d902015-04-16 15:59:00 -06002422 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002423}
2424
Tony Barbour8205d902015-04-16 15:59:00 -06002425VK_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 -06002426{
2427 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2428 if (pCB) {
2429 updateCBTracking(cmdBuffer);
2430 addCmd(pCB, CMD_PIPELINEBARRIER);
2431 }
2432 else {
2433 char str[1024];
2434 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002435 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002436 }
Tony Barbour8205d902015-04-16 15:59:00 -06002437 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002438}
2439
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002440VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002441{
2442 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2443 if (pCB) {
2444 updateCBTracking(cmdBuffer);
2445 addCmd(pCB, CMD_BEGINQUERY);
2446 }
2447 else {
2448 char str[1024];
2449 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002450 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002451 }
2452 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2453}
2454
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002455VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002456{
2457 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2458 if (pCB) {
2459 updateCBTracking(cmdBuffer);
2460 addCmd(pCB, CMD_ENDQUERY);
2461 }
2462 else {
2463 char str[1024];
2464 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002465 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002466 }
2467 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2468}
2469
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002470VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002471{
2472 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2473 if (pCB) {
2474 updateCBTracking(cmdBuffer);
2475 addCmd(pCB, CMD_RESETQUERYPOOL);
2476 }
2477 else {
2478 char str[1024];
2479 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002480 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002481 }
2482 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2483}
2484
Tony Barbour8205d902015-04-16 15:59:00 -06002485VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002486{
2487 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2488 if (pCB) {
2489 updateCBTracking(cmdBuffer);
2490 addCmd(pCB, CMD_WRITETIMESTAMP);
2491 }
2492 else {
2493 char str[1024];
2494 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002495 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002496 }
2497 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2498}
2499
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002500VK_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 -06002501{
2502 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2503 if (pCB) {
2504 updateCBTracking(cmdBuffer);
2505 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2506 }
2507 else {
2508 char str[1024];
2509 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002510 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002511 }
2512 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2513}
2514
Tony Barbour8205d902015-04-16 15:59:00 -06002515VK_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 -06002516{
2517 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2518 if (pCB) {
2519 updateCBTracking(cmdBuffer);
2520 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2521 }
2522 else {
2523 char str[1024];
2524 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002525 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002526 }
2527 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2528}
2529
Tony Barbour8205d902015-04-16 15:59:00 -06002530VK_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 -06002531{
2532 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2533 if (pCB) {
2534 updateCBTracking(cmdBuffer);
2535 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2536 }
2537 else {
2538 char str[1024];
2539 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002540 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002541 }
2542 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2543}
2544
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002545VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002546{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002547 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002548 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002549 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002550 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002551 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002552 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2553 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002554 }
2555 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002556 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2557 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002558 }
2559 frameBufferMap[*pFramebuffer] = localFBCI;
2560 }
2561 return result;
2562}
2563
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002564VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002565{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002566 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002567 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002568 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002569 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002570 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002571 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2572 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002573 }
2574 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002575 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2576 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002577 }
2578 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002579 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2580 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002581 }
2582 renderPassMap[*pRenderPass] = localRPCI;
2583 }
2584 return result;
2585}
2586
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002587VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002588{
2589 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2590 if (pCB) {
2591 updateCBTracking(cmdBuffer);
2592 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002593 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2594 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002595 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002596 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002597 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002598 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002599 char str[1024];
2600 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002601 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002602 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002603 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604}
2605
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002606VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002607{
2608 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2609 if (pCB) {
2610 updateCBTracking(cmdBuffer);
2611 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002612 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002613 }
2614 else {
2615 char str[1024];
2616 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002617 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002618 }
2619 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2620}
2621
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002622VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002623{
2624 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002625 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002626 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002627 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002628 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2629 pNewDbgFuncNode->pUserData = pUserData;
2630 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2631 g_pDbgFunctionHead = pNewDbgFuncNode;
2632 // force callbacks if DebugAction hasn't been set already other than initial value
2633 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002634 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002635 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002636 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002637 return result;
2638}
2639
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002640VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002641{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002642 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2643 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002644 while (pTrav) {
2645 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2646 pPrev->pNext = pTrav->pNext;
2647 if (g_pDbgFunctionHead == pTrav)
2648 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002649 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002650 break;
2651 }
2652 pPrev = pTrav;
2653 pTrav = pTrav->pNext;
2654 }
2655 if (g_pDbgFunctionHead == NULL)
2656 {
2657 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002658 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002659 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002660 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002661 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002662 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663 return result;
2664}
2665
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002666VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002667{
2668 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2669 if (pCB) {
2670 updateCBTracking(cmdBuffer);
2671 addCmd(pCB, CMD_DBGMARKERBEGIN);
2672 }
2673 else {
2674 char str[1024];
2675 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002676 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002677 }
2678 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2679}
2680
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002681VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002682{
2683 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2684 if (pCB) {
2685 updateCBTracking(cmdBuffer);
2686 addCmd(pCB, CMD_DBGMARKEREND);
2687 }
2688 else {
2689 char str[1024];
2690 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002691 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002692 }
2693 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2694}
2695
2696// TODO : Want to pass in a cmdBuffer here based on which state to display
2697void drawStateDumpDotFile(char* outFileName)
2698{
2699 // TODO : Currently just setting cmdBuffer based on global var
2700 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2701 dumpGlobalDotFile(outFileName);
2702}
2703
2704void drawStateDumpCommandBufferDotFile(char* outFileName)
2705{
2706 cbDumpDotFile(outFileName);
2707}
2708
2709void drawStateDumpPngFile(char* outFileName)
2710{
2711#if defined(_WIN32)
2712// FIXME: NEED WINDOWS EQUIVALENT
2713 char str[1024];
2714 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002715 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002716#else // WIN32
2717 char dotExe[32] = "/usr/bin/dot";
2718 if( access(dotExe, X_OK) != -1) {
2719 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2720 char dotCmd[1024];
2721 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002722 int retval = system(dotCmd);
2723 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002724 remove("/tmp/tmp.dot");
2725 }
2726 else {
2727 char str[1024];
2728 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002729 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002730 }
2731#endif // WIN32
2732}
2733
Tony Barbour8205d902015-04-16 15:59:00 -06002734VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002735{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002736 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002737
2738 if (gpu == NULL)
2739 return NULL;
2740 pCurObj = gpuw;
2741 loader_platform_thread_once(&g_initOnce, initDrawState);
2742
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002743 if (!strcmp(funcName, "vkGetProcAddr"))
2744 return (void *) vkGetProcAddr;
2745 if (!strcmp(funcName, "vkCreateDevice"))
2746 return (void*) vkCreateDevice;
2747 if (!strcmp(funcName, "vkDestroyDevice"))
2748 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002749 if (!strcmp(funcName, "vkEnumerateLayers"))
2750 return (void*) vkEnumerateLayers;
2751 if (!strcmp(funcName, "vkQueueSubmit"))
2752 return (void*) vkQueueSubmit;
2753 if (!strcmp(funcName, "vkDestroyObject"))
2754 return (void*) vkDestroyObject;
2755 if (!strcmp(funcName, "vkCreateBufferView"))
2756 return (void*) vkCreateBufferView;
2757 if (!strcmp(funcName, "vkCreateImageView"))
2758 return (void*) vkCreateImageView;
2759 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2760 return (void*) vkCreateGraphicsPipeline;
2761 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2762 return (void*) vkCreateGraphicsPipelineDerivative;
2763 if (!strcmp(funcName, "vkCreateSampler"))
2764 return (void*) vkCreateSampler;
2765 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2766 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002767 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2768 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002769 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2770 return (void*) vkBeginDescriptorPoolUpdate;
2771 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2772 return (void*) vkEndDescriptorPoolUpdate;
2773 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2774 return (void*) vkCreateDescriptorPool;
2775 if (!strcmp(funcName, "vkResetDescriptorPool"))
2776 return (void*) vkResetDescriptorPool;
2777 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2778 return (void*) vkAllocDescriptorSets;
2779 if (!strcmp(funcName, "vkClearDescriptorSets"))
2780 return (void*) vkClearDescriptorSets;
2781 if (!strcmp(funcName, "vkUpdateDescriptors"))
2782 return (void*) vkUpdateDescriptors;
2783 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2784 return (void*) vkCreateDynamicViewportState;
2785 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2786 return (void*) vkCreateDynamicRasterState;
2787 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2788 return (void*) vkCreateDynamicColorBlendState;
2789 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2790 return (void*) vkCreateDynamicDepthStencilState;
2791 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2792 return (void*) vkCreateCommandBuffer;
2793 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2794 return (void*) vkBeginCommandBuffer;
2795 if (!strcmp(funcName, "vkEndCommandBuffer"))
2796 return (void*) vkEndCommandBuffer;
2797 if (!strcmp(funcName, "vkResetCommandBuffer"))
2798 return (void*) vkResetCommandBuffer;
2799 if (!strcmp(funcName, "vkCmdBindPipeline"))
2800 return (void*) vkCmdBindPipeline;
2801 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2802 return (void*) vkCmdBindDynamicStateObject;
2803 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2804 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002805 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2806 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002807 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2808 return (void*) vkCmdBindIndexBuffer;
2809 if (!strcmp(funcName, "vkCmdDraw"))
2810 return (void*) vkCmdDraw;
2811 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2812 return (void*) vkCmdDrawIndexed;
2813 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2814 return (void*) vkCmdDrawIndirect;
2815 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2816 return (void*) vkCmdDrawIndexedIndirect;
2817 if (!strcmp(funcName, "vkCmdDispatch"))
2818 return (void*) vkCmdDispatch;
2819 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2820 return (void*) vkCmdDispatchIndirect;
2821 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2822 return (void*) vkCmdCopyBuffer;
2823 if (!strcmp(funcName, "vkCmdCopyImage"))
2824 return (void*) vkCmdCopyImage;
2825 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2826 return (void*) vkCmdCopyBufferToImage;
2827 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2828 return (void*) vkCmdCopyImageToBuffer;
2829 if (!strcmp(funcName, "vkCmdCloneImageData"))
2830 return (void*) vkCmdCloneImageData;
2831 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2832 return (void*) vkCmdUpdateBuffer;
2833 if (!strcmp(funcName, "vkCmdFillBuffer"))
2834 return (void*) vkCmdFillBuffer;
2835 if (!strcmp(funcName, "vkCmdClearColorImage"))
2836 return (void*) vkCmdClearColorImage;
2837 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2838 return (void*) vkCmdClearDepthStencil;
2839 if (!strcmp(funcName, "vkCmdResolveImage"))
2840 return (void*) vkCmdResolveImage;
2841 if (!strcmp(funcName, "vkCmdSetEvent"))
2842 return (void*) vkCmdSetEvent;
2843 if (!strcmp(funcName, "vkCmdResetEvent"))
2844 return (void*) vkCmdResetEvent;
2845 if (!strcmp(funcName, "vkCmdWaitEvents"))
2846 return (void*) vkCmdWaitEvents;
2847 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2848 return (void*) vkCmdPipelineBarrier;
2849 if (!strcmp(funcName, "vkCmdBeginQuery"))
2850 return (void*) vkCmdBeginQuery;
2851 if (!strcmp(funcName, "vkCmdEndQuery"))
2852 return (void*) vkCmdEndQuery;
2853 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2854 return (void*) vkCmdResetQueryPool;
2855 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2856 return (void*) vkCmdWriteTimestamp;
2857 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2858 return (void*) vkCmdInitAtomicCounters;
2859 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2860 return (void*) vkCmdLoadAtomicCounters;
2861 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2862 return (void*) vkCmdSaveAtomicCounters;
2863 if (!strcmp(funcName, "vkCreateFramebuffer"))
2864 return (void*) vkCreateFramebuffer;
2865 if (!strcmp(funcName, "vkCreateRenderPass"))
2866 return (void*) vkCreateRenderPass;
2867 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2868 return (void*) vkCmdBeginRenderPass;
2869 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2870 return (void*) vkCmdEndRenderPass;
2871 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2872 return (void*) vkDbgRegisterMsgCallback;
2873 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2874 return (void*) vkDbgUnregisterMsgCallback;
2875 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2876 return (void*) vkCmdDbgMarkerBegin;
2877 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2878 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002879 if (!strcmp("drawStateDumpDotFile", funcName))
2880 return (void*) drawStateDumpDotFile;
2881 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2882 return (void*) drawStateDumpCommandBufferDotFile;
2883 if (!strcmp("drawStateDumpPngFile", funcName))
2884 return (void*) drawStateDumpPngFile;
2885 else {
2886 if (gpuw->pGPA == NULL)
2887 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002888 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002889 }
2890}