blob: 2f5e561428cf69d44a2eb6779b6ec90abe2be05c [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"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060033#pragma GCC diagnostic ignored "-Wwrite-strings"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060034#include "vk_struct_graphviz_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060035#pragma GCC diagnostic warning "-Wwrite-strings"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060036#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060037#include "draw_state.h"
38#include "layers_config.h"
39// The following is #included again to catch certain OS-specific functions
40// being used:
41#include "loader_platform.h"
42#include "layers_msg.h"
43
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060044unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
45unordered_map<VkImageView, IMAGE_NODE*> imageMap;
46unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
47unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
48unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
49unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
50unordered_map<VkDescriptorSet, SET_NODE*> setMap;
51unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060052// Map for layout chains
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060053unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
54unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
55unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060056
Jon Ashburn301c5f02015-04-06 10:58:22 -060057static VkLayerDispatchTable nextTable;
58static VkBaseLayerObject *pCurObj;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060059static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
60// TODO : This can be much smarter, using separate locks for separate global data
61static int globalLockInitialized = 0;
62static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060063#define MAX_TID 513
64static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
65static uint32_t g_maxTID = 0;
66// Map actual TID to an index value and return that index
67// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
68static uint32_t getTIDIndex() {
69 loader_platform_thread_id tid = loader_platform_get_thread_id();
70 for (uint32_t i = 0; i < g_maxTID; i++) {
71 if (tid == g_tidMapping[i])
72 return i;
73 }
74 // Don't yet have mapping, set it and return newly set index
75 uint32_t retVal = (uint32_t) g_maxTID;
76 g_tidMapping[g_maxTID++] = tid;
77 assert(g_maxTID < MAX_TID);
78 return retVal;
79}
80// Return a string representation of CMD_TYPE enum
81static string cmdTypeToString(CMD_TYPE cmd)
82{
83 switch (cmd)
84 {
85 case CMD_BINDPIPELINE:
86 return "CMD_BINDPIPELINE";
87 case CMD_BINDPIPELINEDELTA:
88 return "CMD_BINDPIPELINEDELTA";
89 case CMD_BINDDYNAMICSTATEOBJECT:
90 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060091 case CMD_BINDDESCRIPTORSETS:
92 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -060093 case CMD_BINDINDEXBUFFER:
94 return "CMD_BINDINDEXBUFFER";
95 case CMD_BINDVERTEXBUFFER:
96 return "CMD_BINDVERTEXBUFFER";
97 case CMD_DRAW:
98 return "CMD_DRAW";
99 case CMD_DRAWINDEXED:
100 return "CMD_DRAWINDEXED";
101 case CMD_DRAWINDIRECT:
102 return "CMD_DRAWINDIRECT";
103 case CMD_DRAWINDEXEDINDIRECT:
104 return "CMD_DRAWINDEXEDINDIRECT";
105 case CMD_DISPATCH:
106 return "CMD_DISPATCH";
107 case CMD_DISPATCHINDIRECT:
108 return "CMD_DISPATCHINDIRECT";
109 case CMD_COPYBUFFER:
110 return "CMD_COPYBUFFER";
111 case CMD_COPYIMAGE:
112 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600113 case CMD_BLITIMAGE:
114 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600115 case CMD_COPYBUFFERTOIMAGE:
116 return "CMD_COPYBUFFERTOIMAGE";
117 case CMD_COPYIMAGETOBUFFER:
118 return "CMD_COPYIMAGETOBUFFER";
119 case CMD_CLONEIMAGEDATA:
120 return "CMD_CLONEIMAGEDATA";
121 case CMD_UPDATEBUFFER:
122 return "CMD_UPDATEBUFFER";
123 case CMD_FILLBUFFER:
124 return "CMD_FILLBUFFER";
125 case CMD_CLEARCOLORIMAGE:
126 return "CMD_CLEARCOLORIMAGE";
127 case CMD_CLEARCOLORIMAGERAW:
128 return "CMD_CLEARCOLORIMAGERAW";
129 case CMD_CLEARDEPTHSTENCIL:
130 return "CMD_CLEARDEPTHSTENCIL";
131 case CMD_RESOLVEIMAGE:
132 return "CMD_RESOLVEIMAGE";
133 case CMD_SETEVENT:
134 return "CMD_SETEVENT";
135 case CMD_RESETEVENT:
136 return "CMD_RESETEVENT";
137 case CMD_WAITEVENTS:
138 return "CMD_WAITEVENTS";
139 case CMD_PIPELINEBARRIER:
140 return "CMD_PIPELINEBARRIER";
141 case CMD_BEGINQUERY:
142 return "CMD_BEGINQUERY";
143 case CMD_ENDQUERY:
144 return "CMD_ENDQUERY";
145 case CMD_RESETQUERYPOOL:
146 return "CMD_RESETQUERYPOOL";
147 case CMD_WRITETIMESTAMP:
148 return "CMD_WRITETIMESTAMP";
149 case CMD_INITATOMICCOUNTERS:
150 return "CMD_INITATOMICCOUNTERS";
151 case CMD_LOADATOMICCOUNTERS:
152 return "CMD_LOADATOMICCOUNTERS";
153 case CMD_SAVEATOMICCOUNTERS:
154 return "CMD_SAVEATOMICCOUNTERS";
155 case CMD_BEGINRENDERPASS:
156 return "CMD_BEGINRENDERPASS";
157 case CMD_ENDRENDERPASS:
158 return "CMD_ENDRENDERPASS";
159 case CMD_DBGMARKERBEGIN:
160 return "CMD_DBGMARKERBEGIN";
161 case CMD_DBGMARKEREND:
162 return "CMD_DBGMARKEREND";
163 default:
164 return "UNKNOWN";
165 }
166}
167// Block of code at start here for managing/tracking Pipeline state that this layer cares about
168// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600169#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600170#define MAX_SLOTS 2048
171#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
172
173static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
174
175// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
176// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
177// to that same cmd buffer by separate thread are not changing state from underneath us
178// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600179static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600180// Track the last group of CBs touched for displaying to dot file
181static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
182static uint32_t g_lastTouchedCBIndex = 0;
183// Track the last global DrawState of interest touched by any thread
184static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
185static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600186static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600188#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
189
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600190//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600191
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600193{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600194 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600195 size_t scSize = 0;
196 size_t vpSize = 0;
197 loader_platform_thread_lock_mutex(&globalLock);
198 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
199 pStateNode->stateObj = state;
200 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600201 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600202 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
203 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
204 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
205 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
206 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
207 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600208 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
209 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
210 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600212 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600213 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600214 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600215 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600216 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600217 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600218 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600219 break;
220 default:
221 assert(0);
222 break;
223 }
224 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
225 dynamicStateMap[state] = pStateNode;
226 loader_platform_thread_unlock_mutex(&globalLock);
227}
228// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600229static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600230{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600231 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600232 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600233 delete[] (*ii).second->create_info.vpci.pScissors;
234 delete[] (*ii).second->create_info.vpci.pViewports;
235 }
236 delete (*ii).second;
237 }
238}
239// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600240static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600241{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243 delete (*ii).second;
244 }
245}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600246static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600247{
248 loader_platform_thread_lock_mutex(&globalLock);
249 if (imageMap.find(view) == imageMap.end()) {
250 loader_platform_thread_unlock_mutex(&globalLock);
251 return NULL;
252 }
253 else {
254 loader_platform_thread_unlock_mutex(&globalLock);
255 return &imageMap[view]->createInfo;
256 }
257}
258// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600259static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600260{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600261 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600262 delete (*ii).second;
263 }
264}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600265static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600266{
267 loader_platform_thread_lock_mutex(&globalLock);
268 if (bufferMap.find(view) == bufferMap.end()) {
269 loader_platform_thread_unlock_mutex(&globalLock);
270 return NULL;
271 }
272 else {
273 loader_platform_thread_unlock_mutex(&globalLock);
274 return &bufferMap[view]->createInfo;
275 }
276}
277// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600278static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600279{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600280 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281 delete (*ii).second;
282 }
283}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600284static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600285
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600286static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600287{
288 g_lastCmdBuffer[getTIDIndex()] = cb;
289 GLOBAL_CB_NODE* pCB = getCBNode(cb);
290 loader_platform_thread_lock_mutex(&globalLock);
291 g_lastGlobalCB = pCB;
292 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
293 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
294 if (g_pLastTouchedCB[i] == pCB) {
295 loader_platform_thread_unlock_mutex(&globalLock);
296 return;
297 }
298 }
299 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
300 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
301 loader_platform_thread_unlock_mutex(&globalLock);
302}
303
304// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600305static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600306{
307 GLOBAL_CB_NODE* pCB = getCBNode(cb);
308 if (pCB) {
309 loader_platform_thread_lock_mutex(&globalLock);
310 char str[4*1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600311 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600312 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313 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 -0600314 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
315 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 -0600316 break;
317 }
318 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600319 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600320 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600321 }
322 }
323 loader_platform_thread_unlock_mutex(&globalLock);
324 }
325 else {
326 char str[1024];
327 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600328 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600329 }
330}
331// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600332static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600333{
334 loader_platform_thread_lock_mutex(&globalLock);
335 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
336 loader_platform_thread_unlock_mutex(&globalLock);
337 return NULL;
338 }
339 loader_platform_thread_unlock_mutex(&globalLock);
340 return pipelineMap[pipeline];
341}
342
343// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600344static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600345{
346 loader_platform_thread_lock_mutex(&globalLock);
347 if (sampleMap.find(sampler) == sampleMap.end()) {
348 loader_platform_thread_unlock_mutex(&globalLock);
349 return NULL;
350 }
351 loader_platform_thread_unlock_mutex(&globalLock);
352 return &sampleMap[sampler]->createInfo;
353}
354
355// Init the pipeline mapping info based on pipeline create info LL tree
356// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600357static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600358{
359 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600360 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600361 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600362 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600363 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600364 size_t bufferSize = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600365 VkPipelineVertexInputCreateInfo* pVICI = NULL;
366 VkPipelineCbStateCreateInfo* pCBCI = NULL;
367 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600368 while (pTrav) {
369 switch (pTrav->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600370 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600371 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600372 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600373 case VK_SHADER_STAGE_VERTEX:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600374 pPrev->pNext = &pPipeline->vsCI;
375 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600376 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600377 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600379 pPrev->pNext = &pPipeline->tcsCI;
380 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600381 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600382 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600383 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600384 pPrev->pNext = &pPipeline->tesCI;
385 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600386 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600387 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600389 pPrev->pNext = &pPipeline->gsCI;
390 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600391 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600392 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600393 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600394 pPrev->pNext = &pPipeline->fsCI;
395 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600396 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600397 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600399 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600400 break;
401 default:
402 // TODO : Flag error
403 break;
404 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600405 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600407 pPrev->pNext = &pPipeline->vertexInputCI;
408 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600410 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600412 pPipeline->vtxBindingCount = pVICI->bindingCount;
413 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600414 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
415 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
416 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600417 }
418 pPipeline->vtxAttributeCount = pVICI->attributeCount;
419 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600420 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
421 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
422 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600423 }
424 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600426 pPrev->pNext = &pPipeline->iaStateCI;
427 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600428 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600429 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600431 pPrev->pNext = &pPipeline->tessStateCI;
432 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600433 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600434 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600435 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600436 pPrev->pNext = &pPipeline->vpStateCI;
437 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600438 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600439 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600440 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600441 pPrev->pNext = &pPipeline->rsStateCI;
442 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600443 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600444 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600445 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600446 pPrev->pNext = &pPipeline->msStateCI;
447 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600448 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600449 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600450 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600451 pPrev->pNext = &pPipeline->cbStateCI;
452 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600453 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600454 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600455 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600456 pPipeline->attachmentCount = pCBCI->attachmentCount;
457 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600458 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
459 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
460 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600461 }
462 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600463 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600464 pPrev->pNext = &pPipeline->dsStateCI;
465 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600467 break;
468 default:
469 assert(0);
470 break;
471 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600472 pTrav = (GENERIC_HEADER*)pTrav->pNext;
473 }
474 pipelineMap[pPipeline->pipeline] = pPipeline;
475}
476// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600477static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600478{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600479 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600480 if ((*ii).second->pVertexBindingDescriptions) {
481 delete[] (*ii).second->pVertexBindingDescriptions;
482 }
483 if ((*ii).second->pVertexAttributeDescriptions) {
484 delete[] (*ii).second->pVertexAttributeDescriptions;
485 }
486 if ((*ii).second->pAttachments) {
487 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600488 }
489 delete (*ii).second;
490 }
491}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600492// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600493static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600494{
495 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600497 if (pPipe->msStateCI.multisampleEnable)
498 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600499 }
500 return 1;
501}
502// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600503static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600504{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600506 // Verify that any MSAA request in PSO matches sample# in bound FB
507 uint32_t psoNumSamples = getNumSamples(pipeline);
508 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600509 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
510 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis2464b882015-04-01 08:40:34 -0600511 if (psoNumSamples != pFBCI->sampleCount) {
512 char str[1024];
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600513 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 -0600514 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600515 }
516 } else {
517 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
518 // Verify and flag error as appropriate
519 }
520 // TODO : Add more checks here
521 } else {
522 // TODO : Validate non-gfx pipeline updates
523 }
524}
525
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600526// Block of code at start here specifically for managing/tracking DSs
527
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600528// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600529static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600530{
531 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600532 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600533 loader_platform_thread_unlock_mutex(&globalLock);
534 return NULL;
535 }
536 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600537 return poolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600538}
539// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600540static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600541{
542 loader_platform_thread_lock_mutex(&globalLock);
543 if (setMap.find(set) == setMap.end()) {
544 loader_platform_thread_unlock_mutex(&globalLock);
545 return NULL;
546 }
547 loader_platform_thread_unlock_mutex(&globalLock);
548 return setMap[set];
549}
550
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600551// Return VK_TRUE if DS Exists and is within an vkBeginDescriptorPoolUpdate() call sequence, otherwise VK_FALSE
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600552static bool32_t dsUpdateActive(VkDescriptorSet ds)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600553{
554 // Note, both "get" functions use global mutex so this guy does not
555 SET_NODE* pTrav = getSetNode(ds);
556 if (pTrav) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600557 POOL_NODE* pPool = getPoolNode(pTrav->pool);
558 if (pPool) {
559 return pPool->updateActive;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600560 }
561 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600562 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600563}
564
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600565static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600566 loader_platform_thread_lock_mutex(&globalLock);
567 if (layoutMap.find(layout) == layoutMap.end()) {
568 loader_platform_thread_unlock_mutex(&globalLock);
569 return NULL;
570 }
571 loader_platform_thread_unlock_mutex(&globalLock);
572 return layoutMap[layout];
573}
574
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600575// For given update struct, return binding
576static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600577{
578 switch (pUpdateStruct->sType)
579 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600580 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600581 return ((VkUpdateSamplers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600583 return ((VkUpdateSamplerTextures*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600585 return ((VkUpdateImages*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600586 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600587 return ((VkUpdateBuffers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600588 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600589 return ((VkUpdateAsCopy*)pUpdateStruct)->binding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600590 default:
591 // TODO : Flag specific error for this case
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600592 assert(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600593 return 0;
594 }
595}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600596// Return count for given update struct
597static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600598{
599 switch (pUpdateStruct->sType)
600 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600601 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600602 return (((VkUpdateSamplers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600603 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600604 return (((VkUpdateSamplerTextures*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600605 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600606 return (((VkUpdateImages*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600607 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600608 return (((VkUpdateBuffers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600609 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600610 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600611 return (((VkUpdateAsCopy*)pUpdateStruct)->arrayElement);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600612 default:
613 // TODO : Flag specific error for this case
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600614 assert(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600615 return 0;
616 }
617}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600618// Return count for given update struct
619static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
620{
621 switch (pUpdateStruct->sType)
622 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600623 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624 return (((VkUpdateSamplers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600626 return (((VkUpdateSamplerTextures*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600627 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600628 return (((VkUpdateImages*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600629 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600630 return (((VkUpdateBuffers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600631 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600632 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600633 return (((VkUpdateAsCopy*)pUpdateStruct)->count);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600634 default:
635 // TODO : Flag specific error for this case
636 assert(0);
637 return 0;
638 }
639}
640// For given Layout Node and binding, return index where that binding begins
641static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
642{
643 uint32_t offsetIndex = 0;
644 for (uint32_t i = 0; i<binding; i++) {
645 offsetIndex += pLayout->createInfo.pBinding[i].count;
646 }
647 return offsetIndex;
648}
649// For given layout node and binding, return last index that is updated
650static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
651{
652 uint32_t offsetIndex = 0;
653 for (uint32_t i = 0; i<=binding; i++) {
654 offsetIndex += pLayout->createInfo.pBinding[i].count;
655 }
656 return offsetIndex-1;
657}
658// For given layout and update, return the first overall index of the layout that is update
659static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
660{
661 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
662}
663// For given layout and update, return the last overall index of the layout that is update
664static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
665{
666 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
667}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600668// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600669static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600670{
671 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600672 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600673 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600674 switch (pUpdateStruct->sType)
675 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600676 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
677 actualType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600678 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600679 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600680 actualType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600681 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600682 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600683 actualType = ((VkUpdateImages*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600684 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600686 actualType = ((VkUpdateBuffers*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600687 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600688 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600689 actualType = ((VkUpdateAsCopy*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600690 break;
691 default:
692 // TODO : Flag specific error for this case
693 return 0;
694 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600695 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600696 if (pLayout->pTypes[i] != actualType)
697 return 0;
698 }
699 return 1;
700}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600701// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
702// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
703// NOTE : Calls to this function should be wrapped in mutex
704static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
705{
706 GENERIC_HEADER* pNewNode = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600707 VkUpdateSamplers* pUS = NULL;
708 VkUpdateSamplerTextures* pUST = NULL;
709 VkUpdateBuffers* pUB = NULL;
710 VkUpdateImages* pUI = NULL;
711 VkUpdateAsCopy* pUAC = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600712 size_t array_size = 0;
713 size_t base_array_size = 0;
714 size_t total_array_size = 0;
715 size_t baseBuffAddr = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600716 VkImageViewAttachInfo** ppLocalImageViews = NULL;
717 VkBufferViewAttachInfo** ppLocalBufferViews = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600718 char str[1024];
719 switch (pUpdate->sType)
720 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600721 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600722 pUS = new VkUpdateSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600723 pNewNode = (GENERIC_HEADER*)pUS;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724 memcpy(pUS, pUpdate, sizeof(VkUpdateSamplers));
725 pUS->pSamplers = new VkSampler[pUS->count];
726 array_size = sizeof(VkSampler) * pUS->count;
727 memcpy((void*)pUS->pSamplers, ((VkUpdateSamplers*)pUpdate)->pSamplers, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600728 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600729 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600730 pUST = new VkUpdateSamplerTextures;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600731 pNewNode = (GENERIC_HEADER*)pUST;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732 memcpy(pUST, pUpdate, sizeof(VkUpdateSamplerTextures));
733 pUST->pSamplerImageViews = new VkSamplerImageViewInfo[pUST->count];
734 array_size = sizeof(VkSamplerImageViewInfo) * pUST->count;
735 memcpy((void*)pUST->pSamplerImageViews, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews, array_size);
Tobin Ehliseaf28662015-04-08 10:58:37 -0600736 for (uint32_t i = 0; i < pUST->count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600737 VkImageViewAttachInfo** ppIV = (VkImageViewAttachInfo**)&pUST->pSamplerImageViews[i].pImageView;
738 *ppIV = new VkImageViewAttachInfo;
739 memcpy((void*)*ppIV, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews[i].pImageView, sizeof(VkImageViewAttachInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600740 }
741 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600742 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600743 pUI = new VkUpdateImages;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600744 pNewNode = (GENERIC_HEADER*)pUI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600745 memcpy(pUI, pUpdate, sizeof(VkUpdateImages));
746 pUI->pImageViews = new VkImageViewAttachInfo[pUI->count];
747 array_size = (sizeof(VkImageViewAttachInfo) * pUI->count);
748 memcpy((void*)pUI->pImageViews, ((VkUpdateImages*)pUpdate)->pImageViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600749 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600751 pUB = new VkUpdateBuffers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600752 pNewNode = (GENERIC_HEADER*)pUB;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600753 memcpy(pUB, pUpdate, sizeof(VkUpdateBuffers));
754 pUB->pBufferViews = new VkBufferViewAttachInfo[pUB->count];
755 array_size = (sizeof(VkBufferViewAttachInfo) * pUB->count);
756 memcpy((void*)pUB->pBufferViews, ((VkUpdateBuffers*)pUpdate)->pBufferViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600757 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600759 pUAC = new VkUpdateAsCopy;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600760 pUpdate = (GENERIC_HEADER*)pUAC;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600761 memcpy(pUAC, pUpdate, sizeof(VkUpdateAsCopy));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600762 break;
763 default:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764 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 -0600765 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600766 return NULL;
767 }
768 // Make sure that pNext for the end of shadow copy is NULL
769 pNewNode->pNext = NULL;
770 return pNewNode;
771}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600772// For given ds, update its mapping based on ppUpdateArray
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600773static void dsUpdate(VkDescriptorSet ds, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600774{
775 SET_NODE* pSet = getSetNode(ds);
776 loader_platform_thread_lock_mutex(&globalLock);
777 g_lastBoundDescriptorSet = pSet->set;
778 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600779 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600780 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600781 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600782 for (uint32_t i = 0; i < updateCount; i++) {
783 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*)ppUpdateArray[i];
784 pLayout = pSet->pLayout;
785 // Make sure that binding is within bounds
786 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600787 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600788 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 -0600789 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600790 }
791 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600792 // Next verify that update falls within size of given binding
793 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600794 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 -0600795 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600796 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
797 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 -0600798 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 -0600799 }
800 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600801 // Layout bindings match w/ update ok, now verify that update is of the right type
802 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600803 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600804 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600805 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600806 }
807 else {
808 // Save the update info
809 // TODO : Info message that update successful
810 // Create new update struct for this set's shadow copy
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600811 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600812 if (NULL == pNewNode) {
813 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600814 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
815 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600816 }
817 else {
818 // Insert shadow node into LL of updates for this set
819 pNewNode->pNext = pSet->pUpdateStructs;
820 pSet->pUpdateStructs = pNewNode;
821 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600822 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
823 assert(j<pSet->descriptorCount);
824 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600825 }
826 }
827 }
828 }
829 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600830 }
831 loader_platform_thread_unlock_mutex(&globalLock);
832}
833// Free the shadowed update node for this Set
834// NOTE : Calls to this function should be wrapped in mutex
835static void freeShadowUpdateTree(SET_NODE* pSet)
836{
837 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
838 pSet->pUpdateStructs = NULL;
839 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
840 // Clear the descriptor mappings as they will now be invalid
841 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
842 while(pShadowUpdate) {
843 pFreeUpdate = pShadowUpdate;
844 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
845 uint32_t index = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600846 VkUpdateSamplers* pUS = NULL;
847 VkUpdateSamplerTextures* pUST = NULL;
848 VkUpdateImages* pUI = NULL;
849 VkUpdateBuffers* pUB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600850 void** ppToFree = NULL;
851 switch (pFreeUpdate->sType)
852 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600853 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600854 pUS = (VkUpdateSamplers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600855 if (pUS->pSamplers)
856 delete[] pUS->pSamplers;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600857 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600858 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600859 pUST = (VkUpdateSamplerTextures*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600860 if (pUST->pSamplerImageViews) {
861 for (index = 0; index < pUST->count; index++) {
862 if (pUST->pSamplerImageViews[index].pImageView) {
863 delete pUST->pSamplerImageViews[index].pImageView;
864 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600865 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600866 delete[] pUST->pSamplerImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600867 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600868 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600870 pUI = (VkUpdateImages*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600871 if (pUI->pImageViews)
872 delete[] pUI->pImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600873 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600874 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600875 pUB = (VkUpdateBuffers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600876 if (pUB->pBufferViews)
877 delete[] pUB->pBufferViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600878 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600879 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880 break;
881 default:
882 assert(0);
883 break;
884 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600885 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600886 }
887}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600888// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600889// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600890static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600891{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600892 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600893 SET_NODE* pSet = (*ii).second->pSets;
894 SET_NODE* pFreeSet = pSet;
895 while (pSet) {
896 pFreeSet = pSet;
897 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600898 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600899 // Free Update shadow struct tree
900 freeShadowUpdateTree(pFreeSet);
901 if (pFreeSet->ppDescriptors) {
902 delete pFreeSet->ppDescriptors;
903 }
904 delete pFreeSet;
905 }
906 if ((*ii).second->createInfo.pTypeCount) {
907 delete (*ii).second->createInfo.pTypeCount;
908 }
909 delete (*ii).second;
910 }
911}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600912// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600913// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600914static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600915{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600916 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600917 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600918 if (pLayout->createInfo.pBinding) {
919 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
920 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
921 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
922 }
923 delete[] pLayout->createInfo.pBinding;
924 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600925 if (pLayout->pTypes) {
926 delete pLayout->pTypes;
927 }
928 delete pLayout;
929 }
930}
931// Currently clearing a set is removing all previous updates to that set
932// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600933static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600934{
935 SET_NODE* pSet = getSetNode(set);
936 if (!pSet) {
937 // TODO : Return error
938 }
939 else {
940 loader_platform_thread_lock_mutex(&globalLock);
941 freeShadowUpdateTree(pSet);
942 loader_platform_thread_unlock_mutex(&globalLock);
943 }
944}
945
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600946static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600947{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600948 POOL_NODE* pPool = getPoolNode(pool);
949 if (!pPool) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600950 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600951 sprintf(str, "Unable to find pool node for pool %p specified in vkClearDescriptorPool() call", (void*)pool);
952 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600953 }
954 else
955 {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600956 // For every set off of this pool, clear it
957 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600958 while (pSet) {
959 clearDescriptorSet(pSet->set);
960 }
961 }
962}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600963// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600964static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600965{
966 loader_platform_thread_lock_mutex(&globalLock);
967 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
968 loader_platform_thread_unlock_mutex(&globalLock);
969 return NULL;
970 }
971 loader_platform_thread_unlock_mutex(&globalLock);
972 return cmdBufferMap[cb];
973}
974// Free all CB Nodes
975// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600976static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600977{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600978 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600979 while (!(*ii).second->pCmds.empty()) {
980 delete (*ii).second->pCmds.back();
981 (*ii).second->pCmds.pop_back();
982 }
983 delete (*ii).second;
984 }
985}
986static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
987{
988 CMD_NODE* pCmd = new CMD_NODE;
989 if (pCmd) {
990 // init cmd node and append to end of cmd LL
991 memset(pCmd, 0, sizeof(CMD_NODE));
992 pCmd->cmdNumber = ++pCB->numCmds;
993 pCmd->type = cmd;
994 pCB->pCmds.push_back(pCmd);
995 }
996 else {
997 char str[1024];
998 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 -0600999 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 -06001000 }
1001}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001002static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001003{
1004 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1005 if (pCB) {
1006 while (!pCB->pCmds.empty()) {
1007 delete pCB->pCmds.back();
1008 pCB->pCmds.pop_back();
1009 }
1010 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001011 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001012 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001013 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1014 pCB->cmdBuffer = cb;
1015 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001016 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017 pCB->lastVtxBinding = MAX_BINDING;
1018 }
1019}
1020// Set the last bound dynamic state of given type
1021// 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 -06001022static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023{
1024 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1025 if (pCB) {
1026 updateCBTracking(cmdBuffer);
1027 loader_platform_thread_lock_mutex(&globalLock);
1028 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1029 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1030 char str[1024];
1031 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001032 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 -06001033 }
1034 else {
1035 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1036 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1037 }
1038 loader_platform_thread_unlock_mutex(&globalLock);
1039 }
1040 else {
1041 char str[1024];
1042 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001043 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001044 }
1045}
1046// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001047static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001048{
1049 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1050 if (pCB) {
1051 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1052 if (!pPipeTrav) {
1053 // nothing to print
1054 }
1055 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001056 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001057 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001058 }
1059 }
1060}
1061// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001062static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001063{
1064 SET_NODE* pSet = getSetNode(ds);
1065 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001066 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001067 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001068 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1069 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001070 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001071 fprintf(pOutFile, "%s", pGVstr);
1072 free(pGVstr);
1073 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1074 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001075 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001076 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001077 ++layout_index;
1078 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001079 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001080 fprintf(pOutFile, "%s", pGVstr);
1081 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001082 if (pSet->pUpdateStructs) {
1083 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1084 fprintf(pOutFile, "%s", pGVstr);
1085 free(pGVstr);
1086 }
1087 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001088 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1089 uint32_t i = 0;
1090 for (i=0; i < pSet->descriptorCount; i++) {
1091 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001092 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 -06001093 }
1094 }
1095#define NUM_COLORS 7
1096 vector<string> edgeColors;
1097 edgeColors.push_back("0000ff");
1098 edgeColors.push_back("ff00ff");
1099 edgeColors.push_back("ffff00");
1100 edgeColors.push_back("00ff00");
1101 edgeColors.push_back("000000");
1102 edgeColors.push_back("00ffff");
1103 edgeColors.push_back("ff0000");
1104 uint32_t colorIdx = 0;
1105 fprintf(pOutFile, "</TABLE>>\n];\n");
1106 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001107 VkUpdateSamplers* pUS = NULL;
1108 VkUpdateSamplerTextures* pUST = NULL;
1109 VkUpdateImages* pUI = NULL;
1110 VkUpdateBuffers* pUB = NULL;
1111 VkUpdateAsCopy* pUAC = NULL;
1112 VkSamplerCreateInfo* pSCI = NULL;
1113 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001114 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001115 void** ppNextPtr = NULL;
1116 void* pSaveNext = NULL;
1117 for (i=0; i < pSet->descriptorCount; i++) {
1118 if (pSet->ppDescriptors[i]) {
1119 switch (pSet->ppDescriptors[i]->sType)
1120 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001121 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001122 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001123 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001124 if (pSCI) {
1125 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001126 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001127 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1128 }
1129 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001130 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001131 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001132 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001133 if (pSCI) {
1134 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001135 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001136 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1137 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001138 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001139 if (pIVCI) {
1140 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001141 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001142 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1143 }
1144 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001145 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001146 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001147 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001148 if (pIVCI) {
1149 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001150 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001151 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1152 }
1153 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001154 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001155 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001156 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001157 if (pBVCI) {
1158 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001159 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001160 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1161 }
1162 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001163 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001164 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001165 // TODO : Need to validate this code
1166 // Save off pNext and set to NULL while printing this struct, then restore it
1167 ppNextPtr = (void**)&pUAC->pNext;
1168 pSaveNext = *ppNextPtr;
1169 *ppNextPtr = NULL;
1170 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001171 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001172 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1173 // Restore next ptr
1174 *ppNextPtr = pSaveNext;
1175 break;
1176 default:
1177 break;
1178 }
1179 colorIdx = (colorIdx+1) % NUM_COLORS;
1180 }
1181 }
1182 }
1183 fprintf(pOutFile, "}\n");
1184 fprintf(pOutFile, "}\n");
1185 }
1186}
1187// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001188static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001189{
1190 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1191 if (pCB && pCB->lastBoundDescriptorSet) {
1192 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1193 }
1194}
1195// Dump a GraphViz dot file showing the Cmd Buffers
1196static void cbDumpDotFile(string outFileName)
1197{
1198 // Print CB Chain for each CB
1199 FILE* pOutFile;
1200 pOutFile = fopen(outFileName.c_str(), "w");
1201 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1202 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1203 GLOBAL_CB_NODE* pCB = NULL;
1204 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1205 pCB = g_pLastTouchedCB[i];
1206 if (pCB) {
1207 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1208 uint32_t instNum = 0;
1209 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1210 if (instNum) {
1211 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1212 }
1213 if (pCB == g_lastGlobalCB) {
1214 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());
1215 }
1216 else {
1217 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());
1218 }
1219 ++instNum;
1220 }
1221 fprintf(pOutFile, "}\n");
1222 }
1223 }
1224 fprintf(pOutFile, "}\n");
1225 fprintf(pOutFile, "}\n"); // close main graph "g"
1226 fclose(pOutFile);
1227}
1228// Dump a GraphViz dot file showing the pipeline for last bound global state
1229static void dumpGlobalDotFile(char *outFileName)
1230{
1231 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1232 if (pPipeTrav) {
1233 FILE* pOutFile;
1234 pOutFile = fopen(outFileName, "w");
1235 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1236 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1237 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001238 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001239 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001240 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001241 fprintf(pOutFile, "%s", pGVstr);
1242 free(pGVstr);
1243 }
1244 }
1245 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1246 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001247 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001248 fprintf(pOutFile, "%s", pGVstr);
1249 free(pGVstr);
1250 fprintf(pOutFile, "}\n");
1251 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1252 fprintf(pOutFile, "}\n"); // close main graph "g"
1253 fclose(pOutFile);
1254 }
1255}
1256// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001257static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001258{
1259 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1260 if (pCB) {
1261 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1262 if (pPipeTrav) {
1263 FILE* pOutFile;
1264 pOutFile = fopen(outFileName.c_str(), "w");
1265 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1266 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1267 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001268 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001269 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001270 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001271 fprintf(pOutFile, "%s", pGVstr);
1272 free(pGVstr);
1273 }
1274 }
1275 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1276 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001277 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001278 fprintf(pOutFile, "%s", pGVstr);
1279 free(pGVstr);
1280 fprintf(pOutFile, "}\n");
1281 dsDumpDot(cb, pOutFile);
1282 fprintf(pOutFile, "}\n"); // close main graph "g"
1283 fclose(pOutFile);
1284 }
1285 }
1286}
1287// Verify VB Buffer binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001288static void validateVBBinding(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001289{
1290 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1291 if (pCB && pCB->lastBoundPipeline) {
1292 // First verify that we have a Node for bound pipeline
1293 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1294 char str[1024];
1295 if (!pPipeTrav) {
1296 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001297 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001298 }
1299 else {
1300 // Verify Vtx binding
1301 if (MAX_BINDING != pCB->lastVtxBinding) {
1302 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1303 if (0 == pPipeTrav->vtxBindingCount) {
1304 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 -06001305 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 -06001306 }
1307 else {
1308 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 -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 }
1312 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001313 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001315 }
1316 }
1317 }
1318 }
1319}
1320// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001321static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001322{
1323 char tmp_str[1024];
1324 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.
1325 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1326 if (pCB) {
1327 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001328 POOL_NODE* pPool = getPoolNode(pSet->pool);
1329 // Print out pool details
1330 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001331 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001332 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001333 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001334 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001335 // Print out set details
1336 char prefix[10];
1337 uint32_t index = 0;
1338 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001339 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001340 LAYOUT_NODE* pLayout = pSet->pLayout;
1341 // Print layout details
1342 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 -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 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001345 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001346 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001347 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001348 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001349 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1350 if (pUpdate) {
1351 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001352 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001353 sprintf(prefix, " [UC] ");
1354 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001355 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001356 // TODO : If there is a "view" associated with this update, print CI for that view
1357 }
1358 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001359 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1360 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001361 }
1362 }
1363}
1364
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001365static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001366{
1367 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1368 if (pCB) {
1369 char str[1024];
1370 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001371 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001372 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1373 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001374 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001375 }
1376 }
1377 else {
1378 // Nothing to print
1379 }
1380}
1381
1382
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001383static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001384{
1385 printDSConfig(cb);
1386 printPipeline(cb);
1387 printDynamicState(cb);
1388 static int autoDumpOnce = 0;
1389 if (autoDumpOnce) {
1390 autoDumpOnce = 0;
1391 dumpDotFile(cb, "pipeline_dump.dot");
1392 cbDumpDotFile("cb_dump.dot");
1393#if defined(_WIN32)
1394// FIXME: NEED WINDOWS EQUIVALENT
1395#else // WIN32
1396 // Convert dot to svg if dot available
1397 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001398 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1399 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001400 }
1401#endif // WIN32
1402 }
1403}
1404
1405static void initDrawState(void)
1406{
1407 const char *strOpt;
1408 // initialize DrawState options
1409 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1410 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1411
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001412 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001413 {
1414 strOpt = getLayerOption("DrawStateLogFilename");
1415 if (strOpt)
1416 {
1417 g_logFile = fopen(strOpt, "w");
1418 }
1419 if (g_logFile == NULL)
1420 g_logFile = stdout;
1421 }
1422 // initialize Layer dispatch table
1423 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001424 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001425 fpNextGPA = pCurObj->pGPA;
1426 assert(fpNextGPA);
1427
Tony Barbour8205d902015-04-16 15:59:00 -06001428 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001429
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001430 if (!globalLockInitialized)
1431 {
1432 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001433 // suggestion is to call this during vkCreateInstance(), and then we
1434 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001435 // that the layer have per-instance locks. We need to come back and
1436 // address this soon.
1437 loader_platform_thread_create_mutex(&globalLock);
1438 globalLockInitialized = 1;
1439 }
1440}
1441
Tony Barbour8205d902015-04-16 15:59:00 -06001442VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001443{
Jon Ashburn630e44f2015-04-08 21:33:34 -06001444 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001445 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001446 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001447 return result;
1448}
1449
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001450VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001451{
1452 // Free all the memory
1453 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001454 deletePipelines();
1455 deleteSamplers();
1456 deleteImages();
1457 deleteBuffers();
1458 deleteCmdBuffers();
1459 deleteDynamicState();
1460 deletePools();
1461 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001462 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001463 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001464 return result;
1465}
1466
Jon Ashburneb2728b2015-04-10 14:33:07 -06001467struct extProps {
1468 uint32_t version;
1469 const char * const name;
1470};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001471#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001472static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1473 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001474 0x10, "DrawState",
1475 0x10, "Validation",
1476 0x10, "drawStateDumpDotFile",
1477 0x10, "drawStateDumpCommandBufferDotFile",
1478 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001479};
1480
1481VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1482 VkExtensionInfoType infoType,
1483 uint32_t extensionIndex,
1484 size_t* pDataSize,
1485 void* pData)
1486{
1487 VkResult result;
1488
1489 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1490 VkExtensionProperties *ext_props;
1491 uint32_t *count;
1492
1493 if (pDataSize == NULL)
1494 return VK_ERROR_INVALID_POINTER;
1495
1496 switch (infoType) {
1497 case VK_EXTENSION_INFO_TYPE_COUNT:
1498 *pDataSize = sizeof(uint32_t);
1499 if (pData == NULL)
1500 return VK_SUCCESS;
1501 count = (uint32_t *) pData;
1502 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1503 break;
1504 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1505 *pDataSize = sizeof(VkExtensionProperties);
1506 if (pData == NULL)
1507 return VK_SUCCESS;
1508 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1509 return VK_ERROR_INVALID_VALUE;
1510 ext_props = (VkExtensionProperties *) pData;
1511 ext_props->version = dsExts[extensionIndex].version;
1512 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1513 VK_MAX_EXTENSION_NAME);
1514 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1515 break;
1516 default:
1517 return VK_ERROR_INVALID_VALUE;
1518 };
1519
1520 return VK_SUCCESS;
1521}
1522
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001523VK_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 -06001524{
1525 if (gpu != NULL)
1526 {
Jon Ashburn630e44f2015-04-08 21:33:34 -06001527 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001528 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001529 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001530 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001531 } else {
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001532 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001533 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001534 // This layer compatible with all GPUs
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001535 *pLayerCount = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001536 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001537 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001538 }
1539}
1540
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001541VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001542{
1543 for (uint32_t i=0; i < cmdBufferCount; i++) {
1544 // Validate that cmd buffers have been updated
1545 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001546 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001547 return result;
1548}
1549
Mike Stroyan230e6252015-04-17 12:36:38 -06001550VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001551{
1552 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyan230e6252015-04-17 12:36:38 -06001553 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001554 return result;
1555}
1556
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001557VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001558{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001559 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001560 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001561 loader_platform_thread_lock_mutex(&globalLock);
1562 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1563 pNewNode->buffer = *pView;
1564 pNewNode->createInfo = *pCreateInfo;
1565 bufferMap[*pView] = pNewNode;
1566 loader_platform_thread_unlock_mutex(&globalLock);
1567 }
1568 return result;
1569}
1570
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001571VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001572{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001573 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001574 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001575 loader_platform_thread_lock_mutex(&globalLock);
1576 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1577 pNewNode->image = *pView;
1578 pNewNode->createInfo = *pCreateInfo;
1579 imageMap[*pView] = pNewNode;
1580 loader_platform_thread_unlock_mutex(&globalLock);
1581 }
1582 return result;
1583}
1584
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001585static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001586{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001587 // Create LL HEAD for this Pipeline
1588 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001589 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1590 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1591 pPipeNode->pipeline = *pPipeline;
1592 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001593 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001594}
1595
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001596VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001597{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001598 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001599 // Create LL HEAD for this Pipeline
1600 char str[1024];
1601 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001602 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001603
1604 track_pipeline(pCreateInfo, pPipeline);
1605
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001606 return result;
1607}
1608
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001609VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1610 VkDevice device,
1611 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1612 VkPipeline basePipeline,
1613 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001614{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001615 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001616 // Create LL HEAD for this Pipeline
1617 char str[1024];
1618 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001619 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001620
1621 track_pipeline(pCreateInfo, pPipeline);
1622
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001623 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001624
1625 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001626}
1627
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001628VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001629{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001630 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001631 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001632 loader_platform_thread_lock_mutex(&globalLock);
1633 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1634 pNewNode->sampler = *pSampler;
1635 pNewNode->createInfo = *pCreateInfo;
1636 sampleMap[*pSampler] = pNewNode;
1637 loader_platform_thread_unlock_mutex(&globalLock);
1638 }
1639 return result;
1640}
1641
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001642VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001643{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001644 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001645 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001646 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1647 if (NULL == pNewNode) {
1648 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001649 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1650 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001651 }
1652 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001653 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1654 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1655 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001656 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001657 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1658 totalCount += pCreateInfo->pBinding[i].count;
1659 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001660 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1661 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1662 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001663 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001664 }
1665 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001666 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001667 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001668 uint32_t j = 0;
1669 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1670 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1671 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001672 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001673 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674 }
1675 }
1676 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001677 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001678 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1679 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001680 // Put new node at Head of global Layer list
1681 loader_platform_thread_lock_mutex(&globalLock);
1682 layoutMap[*pSetLayout] = pNewNode;
1683 loader_platform_thread_unlock_mutex(&globalLock);
1684 }
1685 return result;
1686}
1687
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001688VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001689{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001690 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001691 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001692 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001693 }
1694 return result;
1695}
1696
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001697VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001698{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001699 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001700 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001701 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001702 POOL_NODE* pPoolNode = poolMap.begin()->second;
1703 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001704 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001705 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001706 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001707 }
1708 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001709 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001710 }
1711 loader_platform_thread_unlock_mutex(&globalLock);
1712 }
1713 return result;
1714}
1715
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001716VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001717{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001718 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001719 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001720 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001721 POOL_NODE* pPoolNode = poolMap.begin()->second;
1722 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001723 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001724 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001725 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001726 }
1727 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001728 if (!pPoolNode->updateActive) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001729 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001730 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1731 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 -06001732 }
1733 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001734 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001735 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001736 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001737 }
1738 loader_platform_thread_unlock_mutex(&globalLock);
1739 }
1740 return result;
1741}
1742
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001743VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001744{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001745 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001746 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001747 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001748 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001749 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyan230e6252015-04-17 12:36:38 -06001750 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001751 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001752 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001753 if (NULL == pNewNode) {
1754 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001755 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyan230e6252015-04-17 12:36:38 -06001756 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 -06001757 }
1758 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001759 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001760 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1761 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001762 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001763 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1764 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001765 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1766 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001767 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001768 pNewNode->updateActive = 0;
1769 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001770 pNewNode->pool = *pDescriptorPool;
1771 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001772 }
1773 loader_platform_thread_unlock_mutex(&globalLock);
1774 }
1775 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001776 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001777 }
1778 return result;
1779}
1780
Mike Stroyan230e6252015-04-17 12:36:38 -06001781VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001782{
Mike Stroyan230e6252015-04-17 12:36:38 -06001783 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001784 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001785 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001786 }
1787 return result;
1788}
1789
Mike Stroyan230e6252015-04-17 12:36:38 -06001790VK_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 -06001791{
Mike Stroyan230e6252015-04-17 12:36:38 -06001792 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001793 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001794 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1795 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001796 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001797 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1798 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799 }
1800 else {
1801 for (uint32_t i = 0; i < *pCount; i++) {
1802 char str[1024];
1803 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001804 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001805 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001806 SET_NODE* pNewNode = new SET_NODE;
1807 if (NULL == pNewNode) {
1808 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001809 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1810 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 -06001811 }
1812 else {
1813 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001814 // Insert set at head of Set LL for this pool
1815 pNewNode->pNext = pPoolNode->pSets;
1816 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001817 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1818 if (NULL == pLayout) {
1819 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001820 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1821 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001822 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001823 pNewNode->pLayout = pLayout;
1824 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825 pNewNode->set = pDescriptorSets[i];
1826 pNewNode->setUsage = setUsage;
1827 pNewNode->descriptorCount = pLayout->endIndex + 1;
1828 if (pNewNode->descriptorCount) {
1829 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1830 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1831 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1832 }
1833 setMap[pDescriptorSets[i]] = pNewNode;
1834 }
1835 }
1836 }
1837 }
1838 return result;
1839}
1840
Mike Stroyan230e6252015-04-17 12:36:38 -06001841VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001842{
1843 for (uint32_t i = 0; i < count; i++) {
1844 clearDescriptorSet(pDescriptorSets[i]);
1845 }
Mike Stroyan230e6252015-04-17 12:36:38 -06001846 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847}
1848
Mike Stroyan230e6252015-04-17 12:36:38 -06001849VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001850{
1851 SET_NODE* pSet = getSetNode(descriptorSet);
1852 if (!dsUpdateActive(descriptorSet)) {
1853 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001854 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1855 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 -06001856 }
1857 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001858 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001859 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001860 }
1861
Mike Stroyan230e6252015-04-17 12:36:38 -06001862 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001863}
1864
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001865VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001866{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001867 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001868 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001869 return result;
1870}
1871
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001872VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001873{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001874 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001875 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001876 return result;
1877}
1878
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001879VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001880{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001881 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001882 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001883 return result;
1884}
1885
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001886VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001887{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001888 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001889 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001890 return result;
1891}
1892
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001893VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001894{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001895 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001896 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001897 loader_platform_thread_lock_mutex(&globalLock);
1898 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1899 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1900 pCB->cmdBuffer = *pCmdBuffer;
1901 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001902 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 pCB->lastVtxBinding = MAX_BINDING;
1904 cmdBufferMap[*pCmdBuffer] = pCB;
1905 loader_platform_thread_unlock_mutex(&globalLock);
1906 updateCBTracking(*pCmdBuffer);
1907 }
1908 return result;
1909}
1910
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001911VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001912{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001913 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001914 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001915 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1916 if (pCB) {
1917 if (CB_NEW != pCB->state)
1918 resetCB(cmdBuffer);
1919 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001920 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001921 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001922 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001923 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001924 }
1925 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001926 }
1927 else {
1928 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001929 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1930 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001931 }
1932 updateCBTracking(cmdBuffer);
1933 }
1934 return result;
1935}
1936
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001937VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001938{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001939 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001940 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001941 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1942 if (pCB) {
1943 pCB->state = CB_UPDATE_COMPLETE;
1944 printCB(cmdBuffer);
1945 }
1946 else {
1947 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001948 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1949 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001950 }
1951 updateCBTracking(cmdBuffer);
1952 //cbDumpDotFile("cb_dump.dot");
1953 }
1954 return result;
1955}
1956
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001957VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001958{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001959 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001960 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001961 resetCB(cmdBuffer);
1962 updateCBTracking(cmdBuffer);
1963 }
1964 return result;
1965}
1966
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001967VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001968{
1969 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1970 if (pCB) {
1971 updateCBTracking(cmdBuffer);
1972 addCmd(pCB, CMD_BINDPIPELINE);
1973 PIPELINE_NODE* pPN = getPipeline(pipeline);
1974 if (pPN) {
1975 pCB->lastBoundPipeline = pipeline;
1976 loader_platform_thread_lock_mutex(&globalLock);
1977 g_lastBoundPipeline = pPN;
1978 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001979 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001980 }
1981 else {
1982 char str[1024];
1983 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001984 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001985 }
1986 }
1987 else {
1988 char str[1024];
1989 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001990 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001991 }
1992 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1993}
1994
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001995VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001996{
1997 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
1998 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
1999}
2000
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002001VK_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 -06002002{
2003 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2004 if (pCB) {
2005 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002006 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002007 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002008 if (getSetNode(pDescriptorSets[i])) {
2009 if (dsUpdateActive(pDescriptorSets[i])) {
2010 // TODO : This check here needs to be made at QueueSubmit time
2011 /*
2012 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002013 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
2014 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 -06002015 */
2016 }
2017 loader_platform_thread_lock_mutex(&globalLock);
2018 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2019 g_lastBoundDescriptorSet = pDescriptorSets[i];
2020 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002021 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002022 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002023 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002024 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002025 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002026 else {
2027 char str[1024];
2028 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002029 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002030 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002031 }
2032 }
2033 else {
2034 char str[1024];
2035 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002036 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002037 }
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002038 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002039}
2040
Tony Barbour8205d902015-04-16 15:59:00 -06002041VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042{
2043 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2044 if (pCB) {
2045 updateCBTracking(cmdBuffer);
2046 addCmd(pCB, CMD_BINDINDEXBUFFER);
2047 // TODO : Track idxBuffer binding
2048 }
2049 else {
2050 char str[1024];
2051 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002052 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002053 }
2054 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2055}
2056
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002057VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2058 VkCmdBuffer cmdBuffer,
2059 uint32_t startBinding,
2060 uint32_t bindingCount,
2061 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002062 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002063{
2064 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2065 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002066 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002067 updateCBTracking(cmdBuffer);
2068 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002069 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002070 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002071 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002072 char str[1024];
2073 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002074 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002075 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002076 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002077}
2078
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002079VK_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 -06002080{
2081 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2082 if (pCB) {
2083 updateCBTracking(cmdBuffer);
2084 addCmd(pCB, CMD_DRAW);
2085 pCB->drawCount[DRAW]++;
2086 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002087 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2088 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002089 synchAndPrintDSConfig(cmdBuffer);
2090 }
2091 else {
2092 char str[1024];
2093 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002094 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002095 }
2096 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2097}
2098
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002099VK_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 -06002100{
2101 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2102 if (pCB) {
2103 updateCBTracking(cmdBuffer);
2104 addCmd(pCB, CMD_DRAWINDEXED);
2105 pCB->drawCount[DRAW_INDEXED]++;
2106 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002107 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2108 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002109 synchAndPrintDSConfig(cmdBuffer);
2110 }
2111 else {
2112 char str[1024];
2113 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002114 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002115 }
2116 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2117}
2118
Tony Barbour8205d902015-04-16 15:59:00 -06002119VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002120{
2121 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2122 if (pCB) {
2123 updateCBTracking(cmdBuffer);
2124 addCmd(pCB, CMD_DRAWINDIRECT);
2125 pCB->drawCount[DRAW_INDIRECT]++;
2126 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002127 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2128 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002129 synchAndPrintDSConfig(cmdBuffer);
2130 }
2131 else {
2132 char str[1024];
2133 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002134 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002135 }
2136 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2137}
2138
Tony Barbour8205d902015-04-16 15:59:00 -06002139VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002140{
2141 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2142 if (pCB) {
2143 updateCBTracking(cmdBuffer);
2144 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2145 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2146 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002147 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2148 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002149 synchAndPrintDSConfig(cmdBuffer);
2150 }
2151 else {
2152 char str[1024];
2153 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002154 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002155 }
2156 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2157}
2158
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002159VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002160{
2161 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2162 if (pCB) {
2163 updateCBTracking(cmdBuffer);
2164 addCmd(pCB, CMD_DISPATCH);
2165 }
2166 else {
2167 char str[1024];
2168 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002169 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002170 }
2171 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2172}
2173
Tony Barbour8205d902015-04-16 15:59:00 -06002174VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002175{
2176 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2177 if (pCB) {
2178 updateCBTracking(cmdBuffer);
2179 addCmd(pCB, CMD_DISPATCHINDIRECT);
2180 }
2181 else {
2182 char str[1024];
2183 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002184 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002185 }
2186 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2187}
2188
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002189VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002190{
2191 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2192 if (pCB) {
2193 updateCBTracking(cmdBuffer);
2194 addCmd(pCB, CMD_COPYBUFFER);
2195 }
2196 else {
2197 char str[1024];
2198 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002199 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002200 }
2201 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2202}
2203
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002204VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2205 VkImage srcImage,
2206 VkImageLayout srcImageLayout,
2207 VkImage destImage,
2208 VkImageLayout destImageLayout,
2209 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002210{
2211 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2212 if (pCB) {
2213 updateCBTracking(cmdBuffer);
2214 addCmd(pCB, CMD_COPYIMAGE);
2215 }
2216 else {
2217 char str[1024];
2218 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002219 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002220 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002221 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002222}
2223
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002224VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2225 VkImage srcImage, VkImageLayout srcImageLayout,
2226 VkImage destImage, VkImageLayout destImageLayout,
2227 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002228{
2229 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2230 if (pCB) {
2231 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002232 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002233 }
2234 else {
2235 char str[1024];
2236 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002237 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002238 }
2239 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2240}
2241
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002242VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2243 VkBuffer srcBuffer,
2244 VkImage destImage, VkImageLayout destImageLayout,
2245 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002246{
2247 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2248 if (pCB) {
2249 updateCBTracking(cmdBuffer);
2250 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2251 }
2252 else {
2253 char str[1024];
2254 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002255 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002256 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002257 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002258}
2259
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002260VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2261 VkImage srcImage, VkImageLayout srcImageLayout,
2262 VkBuffer destBuffer,
2263 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002264{
2265 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2266 if (pCB) {
2267 updateCBTracking(cmdBuffer);
2268 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2269 }
2270 else {
2271 char str[1024];
2272 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002273 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002274 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002275 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002276}
2277
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002278VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002279{
2280 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2281 if (pCB) {
2282 updateCBTracking(cmdBuffer);
2283 addCmd(pCB, CMD_CLONEIMAGEDATA);
2284 }
2285 else {
2286 char str[1024];
2287 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002288 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002289 }
2290 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2291}
2292
Tony Barbour8205d902015-04-16 15:59:00 -06002293VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002294{
2295 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2296 if (pCB) {
2297 updateCBTracking(cmdBuffer);
2298 addCmd(pCB, CMD_UPDATEBUFFER);
2299 }
2300 else {
2301 char str[1024];
2302 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002303 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002304 }
2305 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2306}
2307
Tony Barbour8205d902015-04-16 15:59:00 -06002308VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002309{
2310 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2311 if (pCB) {
2312 updateCBTracking(cmdBuffer);
2313 addCmd(pCB, CMD_FILLBUFFER);
2314 }
2315 else {
2316 char str[1024];
2317 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002318 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002319 }
2320 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2321}
2322
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002323VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
2324 VkImage image, VkImageLayout imageLayout,
2325 VkClearColor color,
2326 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002327{
2328 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2329 if (pCB) {
2330 updateCBTracking(cmdBuffer);
2331 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2332 }
2333 else {
2334 char str[1024];
2335 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002336 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002337 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002338 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002339}
2340
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002341VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2342 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002343 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002344 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002345{
2346 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2347 if (pCB) {
2348 updateCBTracking(cmdBuffer);
2349 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2350 }
2351 else {
2352 char str[1024];
2353 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002354 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002355 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002356 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002357}
2358
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002359VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2360 VkImage srcImage, VkImageLayout srcImageLayout,
2361 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002362 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002363{
2364 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2365 if (pCB) {
2366 updateCBTracking(cmdBuffer);
2367 addCmd(pCB, CMD_RESOLVEIMAGE);
2368 }
2369 else {
2370 char str[1024];
2371 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002372 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002373 }
Tony Barbour11f74372015-04-13 15:02:52 -06002374 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002375}
2376
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002377VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002378{
2379 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2380 if (pCB) {
2381 updateCBTracking(cmdBuffer);
2382 addCmd(pCB, CMD_SETEVENT);
2383 }
2384 else {
2385 char str[1024];
2386 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002387 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002388 }
2389 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2390}
2391
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002392VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002393{
2394 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2395 if (pCB) {
2396 updateCBTracking(cmdBuffer);
2397 addCmd(pCB, CMD_RESETEVENT);
2398 }
2399 else {
2400 char str[1024];
2401 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002402 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002403 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002404 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002405}
2406
Tony Barbour8205d902015-04-16 15:59:00 -06002407VK_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 -06002408{
2409 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2410 if (pCB) {
2411 updateCBTracking(cmdBuffer);
2412 addCmd(pCB, CMD_WAITEVENTS);
2413 }
2414 else {
2415 char str[1024];
2416 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002417 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002418 }
Tony Barbour8205d902015-04-16 15:59:00 -06002419 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002420}
2421
Tony Barbour8205d902015-04-16 15:59:00 -06002422VK_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 -06002423{
2424 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2425 if (pCB) {
2426 updateCBTracking(cmdBuffer);
2427 addCmd(pCB, CMD_PIPELINEBARRIER);
2428 }
2429 else {
2430 char str[1024];
2431 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002432 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002433 }
Tony Barbour8205d902015-04-16 15:59:00 -06002434 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002435}
2436
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002437VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002438{
2439 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2440 if (pCB) {
2441 updateCBTracking(cmdBuffer);
2442 addCmd(pCB, CMD_BEGINQUERY);
2443 }
2444 else {
2445 char str[1024];
2446 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002447 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002448 }
2449 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2450}
2451
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002452VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453{
2454 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2455 if (pCB) {
2456 updateCBTracking(cmdBuffer);
2457 addCmd(pCB, CMD_ENDQUERY);
2458 }
2459 else {
2460 char str[1024];
2461 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002462 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463 }
2464 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2465}
2466
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002467VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002468{
2469 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2470 if (pCB) {
2471 updateCBTracking(cmdBuffer);
2472 addCmd(pCB, CMD_RESETQUERYPOOL);
2473 }
2474 else {
2475 char str[1024];
2476 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002477 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002478 }
2479 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2480}
2481
Tony Barbour8205d902015-04-16 15:59:00 -06002482VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002483{
2484 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2485 if (pCB) {
2486 updateCBTracking(cmdBuffer);
2487 addCmd(pCB, CMD_WRITETIMESTAMP);
2488 }
2489 else {
2490 char str[1024];
2491 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002492 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002493 }
2494 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2495}
2496
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002497VK_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 -06002498{
2499 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2500 if (pCB) {
2501 updateCBTracking(cmdBuffer);
2502 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2503 }
2504 else {
2505 char str[1024];
2506 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002507 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002508 }
2509 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2510}
2511
Tony Barbour8205d902015-04-16 15:59:00 -06002512VK_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 -06002513{
2514 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2515 if (pCB) {
2516 updateCBTracking(cmdBuffer);
2517 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2518 }
2519 else {
2520 char str[1024];
2521 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002522 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002523 }
2524 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2525}
2526
Tony Barbour8205d902015-04-16 15:59:00 -06002527VK_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 -06002528{
2529 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2530 if (pCB) {
2531 updateCBTracking(cmdBuffer);
2532 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2533 }
2534 else {
2535 char str[1024];
2536 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002537 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002538 }
2539 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2540}
2541
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002542VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002543{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002544 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002545 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002546 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002547 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002548 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002549 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2550 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002551 }
2552 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002553 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2554 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002555 }
2556 frameBufferMap[*pFramebuffer] = localFBCI;
2557 }
2558 return result;
2559}
2560
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002561VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002562{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002563 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002564 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002565 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002566 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002567 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002568 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2569 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002570 }
2571 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002572 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2573 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002574 }
2575 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002576 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2577 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002578 }
2579 renderPassMap[*pRenderPass] = localRPCI;
2580 }
2581 return result;
2582}
2583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002584VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002585{
2586 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2587 if (pCB) {
2588 updateCBTracking(cmdBuffer);
2589 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002590 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2591 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002592 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002593 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002594 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002595 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002596 char str[1024];
2597 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002598 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002599 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002600 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002601}
2602
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002603VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604{
2605 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2606 if (pCB) {
2607 updateCBTracking(cmdBuffer);
2608 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002609 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002610 }
2611 else {
2612 char str[1024];
2613 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002614 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002615 }
2616 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2617}
2618
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002619VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002620{
2621 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002622 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002623 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002624 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2626 pNewDbgFuncNode->pUserData = pUserData;
2627 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2628 g_pDbgFunctionHead = pNewDbgFuncNode;
2629 // force callbacks if DebugAction hasn't been set already other than initial value
2630 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002631 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002632 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002633 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002634 return result;
2635}
2636
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002637VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002638{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002639 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2640 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002641 while (pTrav) {
2642 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2643 pPrev->pNext = pTrav->pNext;
2644 if (g_pDbgFunctionHead == pTrav)
2645 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002646 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002647 break;
2648 }
2649 pPrev = pTrav;
2650 pTrav = pTrav->pNext;
2651 }
2652 if (g_pDbgFunctionHead == NULL)
2653 {
2654 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002655 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002656 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002657 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002658 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002659 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002660 return result;
2661}
2662
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002663VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002664{
2665 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2666 if (pCB) {
2667 updateCBTracking(cmdBuffer);
2668 addCmd(pCB, CMD_DBGMARKERBEGIN);
2669 }
2670 else {
2671 char str[1024];
2672 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002673 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002674 }
2675 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2676}
2677
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002678VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002679{
2680 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2681 if (pCB) {
2682 updateCBTracking(cmdBuffer);
2683 addCmd(pCB, CMD_DBGMARKEREND);
2684 }
2685 else {
2686 char str[1024];
2687 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002688 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002689 }
2690 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2691}
2692
2693// TODO : Want to pass in a cmdBuffer here based on which state to display
2694void drawStateDumpDotFile(char* outFileName)
2695{
2696 // TODO : Currently just setting cmdBuffer based on global var
2697 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2698 dumpGlobalDotFile(outFileName);
2699}
2700
2701void drawStateDumpCommandBufferDotFile(char* outFileName)
2702{
2703 cbDumpDotFile(outFileName);
2704}
2705
2706void drawStateDumpPngFile(char* outFileName)
2707{
2708#if defined(_WIN32)
2709// FIXME: NEED WINDOWS EQUIVALENT
2710 char str[1024];
2711 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002712 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002713#else // WIN32
2714 char dotExe[32] = "/usr/bin/dot";
2715 if( access(dotExe, X_OK) != -1) {
2716 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2717 char dotCmd[1024];
2718 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002719 int retval = system(dotCmd);
2720 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002721 remove("/tmp/tmp.dot");
2722 }
2723 else {
2724 char str[1024];
2725 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002726 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002727 }
2728#endif // WIN32
2729}
2730
Tony Barbour8205d902015-04-16 15:59:00 -06002731VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002732{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002733 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002734
2735 if (gpu == NULL)
2736 return NULL;
2737 pCurObj = gpuw;
2738 loader_platform_thread_once(&g_initOnce, initDrawState);
2739
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002740 if (!strcmp(funcName, "vkGetProcAddr"))
2741 return (void *) vkGetProcAddr;
2742 if (!strcmp(funcName, "vkCreateDevice"))
2743 return (void*) vkCreateDevice;
2744 if (!strcmp(funcName, "vkDestroyDevice"))
2745 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002746 if (!strcmp(funcName, "vkEnumerateLayers"))
2747 return (void*) vkEnumerateLayers;
2748 if (!strcmp(funcName, "vkQueueSubmit"))
2749 return (void*) vkQueueSubmit;
2750 if (!strcmp(funcName, "vkDestroyObject"))
2751 return (void*) vkDestroyObject;
2752 if (!strcmp(funcName, "vkCreateBufferView"))
2753 return (void*) vkCreateBufferView;
2754 if (!strcmp(funcName, "vkCreateImageView"))
2755 return (void*) vkCreateImageView;
2756 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2757 return (void*) vkCreateGraphicsPipeline;
2758 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2759 return (void*) vkCreateGraphicsPipelineDerivative;
2760 if (!strcmp(funcName, "vkCreateSampler"))
2761 return (void*) vkCreateSampler;
2762 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2763 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002764 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2765 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002766 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2767 return (void*) vkBeginDescriptorPoolUpdate;
2768 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2769 return (void*) vkEndDescriptorPoolUpdate;
2770 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2771 return (void*) vkCreateDescriptorPool;
2772 if (!strcmp(funcName, "vkResetDescriptorPool"))
2773 return (void*) vkResetDescriptorPool;
2774 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2775 return (void*) vkAllocDescriptorSets;
2776 if (!strcmp(funcName, "vkClearDescriptorSets"))
2777 return (void*) vkClearDescriptorSets;
2778 if (!strcmp(funcName, "vkUpdateDescriptors"))
2779 return (void*) vkUpdateDescriptors;
2780 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2781 return (void*) vkCreateDynamicViewportState;
2782 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2783 return (void*) vkCreateDynamicRasterState;
2784 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2785 return (void*) vkCreateDynamicColorBlendState;
2786 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2787 return (void*) vkCreateDynamicDepthStencilState;
2788 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2789 return (void*) vkCreateCommandBuffer;
2790 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2791 return (void*) vkBeginCommandBuffer;
2792 if (!strcmp(funcName, "vkEndCommandBuffer"))
2793 return (void*) vkEndCommandBuffer;
2794 if (!strcmp(funcName, "vkResetCommandBuffer"))
2795 return (void*) vkResetCommandBuffer;
2796 if (!strcmp(funcName, "vkCmdBindPipeline"))
2797 return (void*) vkCmdBindPipeline;
2798 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2799 return (void*) vkCmdBindDynamicStateObject;
2800 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2801 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002802 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2803 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002804 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2805 return (void*) vkCmdBindIndexBuffer;
2806 if (!strcmp(funcName, "vkCmdDraw"))
2807 return (void*) vkCmdDraw;
2808 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2809 return (void*) vkCmdDrawIndexed;
2810 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2811 return (void*) vkCmdDrawIndirect;
2812 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2813 return (void*) vkCmdDrawIndexedIndirect;
2814 if (!strcmp(funcName, "vkCmdDispatch"))
2815 return (void*) vkCmdDispatch;
2816 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2817 return (void*) vkCmdDispatchIndirect;
2818 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2819 return (void*) vkCmdCopyBuffer;
2820 if (!strcmp(funcName, "vkCmdCopyImage"))
2821 return (void*) vkCmdCopyImage;
2822 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2823 return (void*) vkCmdCopyBufferToImage;
2824 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2825 return (void*) vkCmdCopyImageToBuffer;
2826 if (!strcmp(funcName, "vkCmdCloneImageData"))
2827 return (void*) vkCmdCloneImageData;
2828 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2829 return (void*) vkCmdUpdateBuffer;
2830 if (!strcmp(funcName, "vkCmdFillBuffer"))
2831 return (void*) vkCmdFillBuffer;
2832 if (!strcmp(funcName, "vkCmdClearColorImage"))
2833 return (void*) vkCmdClearColorImage;
2834 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2835 return (void*) vkCmdClearDepthStencil;
2836 if (!strcmp(funcName, "vkCmdResolveImage"))
2837 return (void*) vkCmdResolveImage;
2838 if (!strcmp(funcName, "vkCmdSetEvent"))
2839 return (void*) vkCmdSetEvent;
2840 if (!strcmp(funcName, "vkCmdResetEvent"))
2841 return (void*) vkCmdResetEvent;
2842 if (!strcmp(funcName, "vkCmdWaitEvents"))
2843 return (void*) vkCmdWaitEvents;
2844 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2845 return (void*) vkCmdPipelineBarrier;
2846 if (!strcmp(funcName, "vkCmdBeginQuery"))
2847 return (void*) vkCmdBeginQuery;
2848 if (!strcmp(funcName, "vkCmdEndQuery"))
2849 return (void*) vkCmdEndQuery;
2850 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2851 return (void*) vkCmdResetQueryPool;
2852 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2853 return (void*) vkCmdWriteTimestamp;
2854 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2855 return (void*) vkCmdInitAtomicCounters;
2856 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2857 return (void*) vkCmdLoadAtomicCounters;
2858 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2859 return (void*) vkCmdSaveAtomicCounters;
2860 if (!strcmp(funcName, "vkCreateFramebuffer"))
2861 return (void*) vkCreateFramebuffer;
2862 if (!strcmp(funcName, "vkCreateRenderPass"))
2863 return (void*) vkCreateRenderPass;
2864 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2865 return (void*) vkCmdBeginRenderPass;
2866 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2867 return (void*) vkCmdEndRenderPass;
2868 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2869 return (void*) vkDbgRegisterMsgCallback;
2870 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2871 return (void*) vkDbgUnregisterMsgCallback;
2872 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2873 return (void*) vkCmdDbgMarkerBegin;
2874 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2875 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002876 if (!strcmp("drawStateDumpDotFile", funcName))
2877 return (void*) drawStateDumpDotFile;
2878 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2879 return (void*) drawStateDumpCommandBufferDotFile;
2880 if (!strcmp("drawStateDumpPngFile", funcName))
2881 return (void*) drawStateDumpPngFile;
2882 else {
2883 if (gpuw->pGPA == NULL)
2884 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002885 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002886 }
2887}