blob: 3510370f944890c176de6aa2f69f2fa4a4e755c6 [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) {
1398 system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1399 }
1400#endif // WIN32
1401 }
1402}
1403
1404static void initDrawState(void)
1405{
1406 const char *strOpt;
1407 // initialize DrawState options
1408 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1409 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1410
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001411 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001412 {
1413 strOpt = getLayerOption("DrawStateLogFilename");
1414 if (strOpt)
1415 {
1416 g_logFile = fopen(strOpt, "w");
1417 }
1418 if (g_logFile == NULL)
1419 g_logFile = stdout;
1420 }
1421 // initialize Layer dispatch table
1422 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001423 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001424 fpNextGPA = pCurObj->pGPA;
1425 assert(fpNextGPA);
1426
Tony Barbour8205d902015-04-16 15:59:00 -06001427 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001428
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001429 if (!globalLockInitialized)
1430 {
1431 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001432 // suggestion is to call this during vkCreateInstance(), and then we
1433 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001434 // that the layer have per-instance locks. We need to come back and
1435 // address this soon.
1436 loader_platform_thread_create_mutex(&globalLock);
1437 globalLockInitialized = 1;
1438 }
1439}
1440
Tony Barbour8205d902015-04-16 15:59:00 -06001441VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001442{
Jon Ashburn630e44f2015-04-08 21:33:34 -06001443 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001444 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001445 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001446 return result;
1447}
1448
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001449VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001450{
1451 // Free all the memory
1452 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001453 deletePipelines();
1454 deleteSamplers();
1455 deleteImages();
1456 deleteBuffers();
1457 deleteCmdBuffers();
1458 deleteDynamicState();
1459 deletePools();
1460 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001461 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001462 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001463 return result;
1464}
1465
Jon Ashburneb2728b2015-04-10 14:33:07 -06001466struct extProps {
1467 uint32_t version;
1468 const char * const name;
1469};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001470#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001471static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1472 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001473 0x10, "DrawState",
1474 0x10, "Validation",
1475 0x10, "drawStateDumpDotFile",
1476 0x10, "drawStateDumpCommandBufferDotFile",
1477 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001478};
1479
1480VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1481 VkExtensionInfoType infoType,
1482 uint32_t extensionIndex,
1483 size_t* pDataSize,
1484 void* pData)
1485{
1486 VkResult result;
1487
1488 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1489 VkExtensionProperties *ext_props;
1490 uint32_t *count;
1491
1492 if (pDataSize == NULL)
1493 return VK_ERROR_INVALID_POINTER;
1494
1495 switch (infoType) {
1496 case VK_EXTENSION_INFO_TYPE_COUNT:
1497 *pDataSize = sizeof(uint32_t);
1498 if (pData == NULL)
1499 return VK_SUCCESS;
1500 count = (uint32_t *) pData;
1501 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1502 break;
1503 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1504 *pDataSize = sizeof(VkExtensionProperties);
1505 if (pData == NULL)
1506 return VK_SUCCESS;
1507 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1508 return VK_ERROR_INVALID_VALUE;
1509 ext_props = (VkExtensionProperties *) pData;
1510 ext_props->version = dsExts[extensionIndex].version;
1511 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1512 VK_MAX_EXTENSION_NAME);
1513 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1514 break;
1515 default:
1516 return VK_ERROR_INVALID_VALUE;
1517 };
1518
1519 return VK_SUCCESS;
1520}
1521
Tony Barbour8205d902015-04-16 15:59:00 -06001522VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxLayerCount, size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001523{
1524 if (gpu != NULL)
1525 {
Jon Ashburn630e44f2015-04-08 21:33:34 -06001526 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001527 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001528 VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001529 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001530 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001531 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001532 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001533 // This layer compatible with all GPUs
1534 *pOutLayerCount = 1;
1535 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001536 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001537 }
1538}
1539
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001540VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001541{
1542 for (uint32_t i=0; i < cmdBufferCount; i++) {
1543 // Validate that cmd buffers have been updated
1544 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001545 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001546 return result;
1547}
1548
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001549VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001550{
1551 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001552 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001553 return result;
1554}
1555
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001556VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001557{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001558 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001559 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001560 loader_platform_thread_lock_mutex(&globalLock);
1561 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1562 pNewNode->buffer = *pView;
1563 pNewNode->createInfo = *pCreateInfo;
1564 bufferMap[*pView] = pNewNode;
1565 loader_platform_thread_unlock_mutex(&globalLock);
1566 }
1567 return result;
1568}
1569
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001570VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001571{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001572 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001573 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001574 loader_platform_thread_lock_mutex(&globalLock);
1575 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1576 pNewNode->image = *pView;
1577 pNewNode->createInfo = *pCreateInfo;
1578 imageMap[*pView] = pNewNode;
1579 loader_platform_thread_unlock_mutex(&globalLock);
1580 }
1581 return result;
1582}
1583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001584static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001585{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001586 // Create LL HEAD for this Pipeline
1587 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001588 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1589 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1590 pPipeNode->pipeline = *pPipeline;
1591 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001592 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001593}
1594
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001595VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001596{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001597 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001598 // Create LL HEAD for this Pipeline
1599 char str[1024];
1600 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001601 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001602
1603 track_pipeline(pCreateInfo, pPipeline);
1604
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001605 return result;
1606}
1607
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001608VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1609 VkDevice device,
1610 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1611 VkPipeline basePipeline,
1612 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001613{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001614 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001615 // Create LL HEAD for this Pipeline
1616 char str[1024];
1617 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001618 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001619
1620 track_pipeline(pCreateInfo, pPipeline);
1621
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001622 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001623
1624 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001625}
1626
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001627VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001628{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001629 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001630 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001631 loader_platform_thread_lock_mutex(&globalLock);
1632 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1633 pNewNode->sampler = *pSampler;
1634 pNewNode->createInfo = *pCreateInfo;
1635 sampleMap[*pSampler] = pNewNode;
1636 loader_platform_thread_unlock_mutex(&globalLock);
1637 }
1638 return result;
1639}
1640
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001641VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001642{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001643 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001644 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001645 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1646 if (NULL == pNewNode) {
1647 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001648 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1649 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001650 }
1651 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001652 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1653 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1654 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001655 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001656 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1657 totalCount += pCreateInfo->pBinding[i].count;
1658 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001659 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1660 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1661 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001662 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001663 }
1664 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001665 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001666 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001667 uint32_t j = 0;
1668 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1669 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1670 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001671 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001672 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001673 }
1674 }
1675 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001676 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001677 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1678 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679 // Put new node at Head of global Layer list
1680 loader_platform_thread_lock_mutex(&globalLock);
1681 layoutMap[*pSetLayout] = pNewNode;
1682 loader_platform_thread_unlock_mutex(&globalLock);
1683 }
1684 return result;
1685}
1686
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001687VkResult VKAPI vkCreateDescriptorSetLayoutChain(VkDevice device, uint32_t setLayoutArrayCount, const VkDescriptorSetLayout* pSetLayoutArray, VkDescriptorSetLayoutChain* pLayoutChain)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001688{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001689 VkResult result = nextTable.CreateDescriptorSetLayoutChain(device, setLayoutArrayCount, pSetLayoutArray, pLayoutChain);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001690 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001691 // TODO : Need to capture the layout chains
1692 }
1693 return result;
1694}
1695
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001696VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001697{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001698 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001699 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001700 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001701 POOL_NODE* pPoolNode = poolMap.begin()->second;
1702 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001703 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001704 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001705 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001706 }
1707 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001708 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001709 }
1710 loader_platform_thread_unlock_mutex(&globalLock);
1711 }
1712 return result;
1713}
1714
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001715VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001716{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001717 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001718 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001719 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001720 POOL_NODE* pPoolNode = poolMap.begin()->second;
1721 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001722 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001723 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001724 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001725 }
1726 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001727 if (!pPoolNode->updateActive) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001729 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1730 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 -06001731 }
1732 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001733 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001734 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001735 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001736 }
1737 loader_platform_thread_unlock_mutex(&globalLock);
1738 }
1739 return result;
1740}
1741
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001742VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001743{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001744 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001745 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001746 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001747 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001748 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001749 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkBaseObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001750 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001751 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001752 if (NULL == pNewNode) {
1753 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001754 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001755 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, (VkBaseObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001756 }
1757 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001758 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001759 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1760 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001762 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1763 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001764 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1765 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001766 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001767 pNewNode->updateActive = 0;
1768 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001769 pNewNode->pool = *pDescriptorPool;
1770 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771 }
1772 loader_platform_thread_unlock_mutex(&globalLock);
1773 }
1774 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001775 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001776 }
1777 return result;
1778}
1779
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001780VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001781{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001782 VkResult result = nextTable.ResetDescriptorPool(descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001783 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001784 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785 }
1786 return result;
1787}
1788
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001789VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001790{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001791 VkResult result = nextTable.AllocDescriptorSets(descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001792 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001793 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1794 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001795 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001796 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1797 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001798 }
1799 else {
1800 for (uint32_t i = 0; i < *pCount; i++) {
1801 char str[1024];
1802 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001803 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001804 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001805 SET_NODE* pNewNode = new SET_NODE;
1806 if (NULL == pNewNode) {
1807 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001808 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1809 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 -06001810 }
1811 else {
1812 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001813 // Insert set at head of Set LL for this pool
1814 pNewNode->pNext = pPoolNode->pSets;
1815 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001816 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1817 if (NULL == pLayout) {
1818 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001819 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1820 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001821 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001822 pNewNode->pLayout = pLayout;
1823 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001824 pNewNode->set = pDescriptorSets[i];
1825 pNewNode->setUsage = setUsage;
1826 pNewNode->descriptorCount = pLayout->endIndex + 1;
1827 if (pNewNode->descriptorCount) {
1828 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1829 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1830 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1831 }
1832 setMap[pDescriptorSets[i]] = pNewNode;
1833 }
1834 }
1835 }
1836 }
1837 return result;
1838}
1839
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001840VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001841{
1842 for (uint32_t i = 0; i < count; i++) {
1843 clearDescriptorSet(pDescriptorSets[i]);
1844 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001845 nextTable.ClearDescriptorSets(descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001846}
1847
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001848VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849{
1850 SET_NODE* pSet = getSetNode(descriptorSet);
1851 if (!dsUpdateActive(descriptorSet)) {
1852 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001853 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1854 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 -06001855 }
1856 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001857 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001858 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001859 }
1860
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001861 nextTable.UpdateDescriptors(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862}
1863
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001864VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001866 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001867 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868 return result;
1869}
1870
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001871VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001872{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001873 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001874 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001875 return result;
1876}
1877
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001878VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001879{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001880 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001881 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001882 return result;
1883}
1884
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001885VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001886{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001887 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001888 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001889 return result;
1890}
1891
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001892VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001893{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001894 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001895 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001896 loader_platform_thread_lock_mutex(&globalLock);
1897 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1898 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1899 pCB->cmdBuffer = *pCmdBuffer;
1900 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001901 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001902 pCB->lastVtxBinding = MAX_BINDING;
1903 cmdBufferMap[*pCmdBuffer] = pCB;
1904 loader_platform_thread_unlock_mutex(&globalLock);
1905 updateCBTracking(*pCmdBuffer);
1906 }
1907 return result;
1908}
1909
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001910VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001911{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001912 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001913 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001914 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1915 if (pCB) {
1916 if (CB_NEW != pCB->state)
1917 resetCB(cmdBuffer);
1918 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001919 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001920 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001921 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001922 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001923 }
1924 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001925 }
1926 else {
1927 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001928 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1929 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001930 }
1931 updateCBTracking(cmdBuffer);
1932 }
1933 return result;
1934}
1935
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001936VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001937{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001938 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001939 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001940 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1941 if (pCB) {
1942 pCB->state = CB_UPDATE_COMPLETE;
1943 printCB(cmdBuffer);
1944 }
1945 else {
1946 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001947 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1948 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001949 }
1950 updateCBTracking(cmdBuffer);
1951 //cbDumpDotFile("cb_dump.dot");
1952 }
1953 return result;
1954}
1955
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001956VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001957{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001958 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001959 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001960 resetCB(cmdBuffer);
1961 updateCBTracking(cmdBuffer);
1962 }
1963 return result;
1964}
1965
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001966VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001967{
1968 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1969 if (pCB) {
1970 updateCBTracking(cmdBuffer);
1971 addCmd(pCB, CMD_BINDPIPELINE);
1972 PIPELINE_NODE* pPN = getPipeline(pipeline);
1973 if (pPN) {
1974 pCB->lastBoundPipeline = pipeline;
1975 loader_platform_thread_lock_mutex(&globalLock);
1976 g_lastBoundPipeline = pPN;
1977 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001978 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001979 }
1980 else {
1981 char str[1024];
1982 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001983 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001984 }
1985 }
1986 else {
1987 char str[1024];
1988 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001989 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001990 }
1991 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1992}
1993
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001994VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001995{
1996 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
1997 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
1998}
1999
Chia-I Wu6097f3a2015-04-17 02:00:54 +08002000VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t layoutChainSlot, uint32_t count, const VkDescriptorSet* pDescriptorSets, const uint32_t* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002001{
2002 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2003 if (pCB) {
2004 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002005 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
2006 for (uint32_t i=0; i<count; i++) {
2007 if (getSetNode(pDescriptorSets[i])) {
2008 if (dsUpdateActive(pDescriptorSets[i])) {
2009 // TODO : This check here needs to be made at QueueSubmit time
2010 /*
2011 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002012 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
2013 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 -06002014 */
2015 }
2016 loader_platform_thread_lock_mutex(&globalLock);
2017 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2018 g_lastBoundDescriptorSet = pDescriptorSets[i];
2019 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002020 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002021 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002022 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002023 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002024 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002025 else {
2026 char str[1024];
2027 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002028 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002029 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002030 }
2031 }
2032 else {
2033 char str[1024];
2034 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002035 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002036 }
Chia-I Wu6097f3a2015-04-17 02:00:54 +08002037 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layoutChainSlot, count, pDescriptorSets, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002038}
2039
Tony Barbour8205d902015-04-16 15:59:00 -06002040VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002041{
2042 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2043 if (pCB) {
2044 updateCBTracking(cmdBuffer);
2045 addCmd(pCB, CMD_BINDINDEXBUFFER);
2046 // TODO : Track idxBuffer binding
2047 }
2048 else {
2049 char str[1024];
2050 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002051 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002052 }
2053 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2054}
2055
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002056VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2057 VkCmdBuffer cmdBuffer,
2058 uint32_t startBinding,
2059 uint32_t bindingCount,
2060 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002061 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002062{
2063 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2064 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002065 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002066 updateCBTracking(cmdBuffer);
2067 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002068 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002069 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002070 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002071 char str[1024];
2072 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002073 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002074 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002075 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002076}
2077
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002078VK_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 -06002079{
2080 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2081 if (pCB) {
2082 updateCBTracking(cmdBuffer);
2083 addCmd(pCB, CMD_DRAW);
2084 pCB->drawCount[DRAW]++;
2085 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002086 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2087 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002088 synchAndPrintDSConfig(cmdBuffer);
2089 }
2090 else {
2091 char str[1024];
2092 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002093 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002094 }
2095 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2096}
2097
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002098VK_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 -06002099{
2100 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2101 if (pCB) {
2102 updateCBTracking(cmdBuffer);
2103 addCmd(pCB, CMD_DRAWINDEXED);
2104 pCB->drawCount[DRAW_INDEXED]++;
2105 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002106 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2107 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002108 synchAndPrintDSConfig(cmdBuffer);
2109 }
2110 else {
2111 char str[1024];
2112 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002113 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002114 }
2115 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2116}
2117
Tony Barbour8205d902015-04-16 15:59:00 -06002118VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002119{
2120 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2121 if (pCB) {
2122 updateCBTracking(cmdBuffer);
2123 addCmd(pCB, CMD_DRAWINDIRECT);
2124 pCB->drawCount[DRAW_INDIRECT]++;
2125 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002126 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2127 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002128 synchAndPrintDSConfig(cmdBuffer);
2129 }
2130 else {
2131 char str[1024];
2132 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002133 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002134 }
2135 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2136}
2137
Tony Barbour8205d902015-04-16 15:59:00 -06002138VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002139{
2140 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2141 if (pCB) {
2142 updateCBTracking(cmdBuffer);
2143 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2144 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2145 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002146 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2147 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002148 synchAndPrintDSConfig(cmdBuffer);
2149 }
2150 else {
2151 char str[1024];
2152 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002153 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002154 }
2155 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2156}
2157
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002158VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002159{
2160 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2161 if (pCB) {
2162 updateCBTracking(cmdBuffer);
2163 addCmd(pCB, CMD_DISPATCH);
2164 }
2165 else {
2166 char str[1024];
2167 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002168 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002169 }
2170 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2171}
2172
Tony Barbour8205d902015-04-16 15:59:00 -06002173VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002174{
2175 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2176 if (pCB) {
2177 updateCBTracking(cmdBuffer);
2178 addCmd(pCB, CMD_DISPATCHINDIRECT);
2179 }
2180 else {
2181 char str[1024];
2182 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002183 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002184 }
2185 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2186}
2187
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002188VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002189{
2190 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2191 if (pCB) {
2192 updateCBTracking(cmdBuffer);
2193 addCmd(pCB, CMD_COPYBUFFER);
2194 }
2195 else {
2196 char str[1024];
2197 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002198 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002199 }
2200 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2201}
2202
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002203VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2204 VkImage srcImage,
2205 VkImageLayout srcImageLayout,
2206 VkImage destImage,
2207 VkImageLayout destImageLayout,
2208 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002209{
2210 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2211 if (pCB) {
2212 updateCBTracking(cmdBuffer);
2213 addCmd(pCB, CMD_COPYIMAGE);
2214 }
2215 else {
2216 char str[1024];
2217 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002218 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002219 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002220 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002221}
2222
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002223VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2224 VkImage srcImage, VkImageLayout srcImageLayout,
2225 VkImage destImage, VkImageLayout destImageLayout,
2226 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002227{
2228 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2229 if (pCB) {
2230 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002231 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002232 }
2233 else {
2234 char str[1024];
2235 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002236 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002237 }
2238 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2239}
2240
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002241VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2242 VkBuffer srcBuffer,
2243 VkImage destImage, VkImageLayout destImageLayout,
2244 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002245{
2246 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2247 if (pCB) {
2248 updateCBTracking(cmdBuffer);
2249 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2250 }
2251 else {
2252 char str[1024];
2253 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002254 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002255 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002256 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002257}
2258
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002259VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2260 VkImage srcImage, VkImageLayout srcImageLayout,
2261 VkBuffer destBuffer,
2262 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002263{
2264 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2265 if (pCB) {
2266 updateCBTracking(cmdBuffer);
2267 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2268 }
2269 else {
2270 char str[1024];
2271 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002272 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002273 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002274 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002275}
2276
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002277VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002278{
2279 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2280 if (pCB) {
2281 updateCBTracking(cmdBuffer);
2282 addCmd(pCB, CMD_CLONEIMAGEDATA);
2283 }
2284 else {
2285 char str[1024];
2286 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002287 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002288 }
2289 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2290}
2291
Tony Barbour8205d902015-04-16 15:59:00 -06002292VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002293{
2294 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2295 if (pCB) {
2296 updateCBTracking(cmdBuffer);
2297 addCmd(pCB, CMD_UPDATEBUFFER);
2298 }
2299 else {
2300 char str[1024];
2301 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002302 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002303 }
2304 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2305}
2306
Tony Barbour8205d902015-04-16 15:59:00 -06002307VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002308{
2309 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2310 if (pCB) {
2311 updateCBTracking(cmdBuffer);
2312 addCmd(pCB, CMD_FILLBUFFER);
2313 }
2314 else {
2315 char str[1024];
2316 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002317 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002318 }
2319 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2320}
2321
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002322VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
2323 VkImage image, VkImageLayout imageLayout,
2324 VkClearColor color,
2325 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002326{
2327 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2328 if (pCB) {
2329 updateCBTracking(cmdBuffer);
2330 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2331 }
2332 else {
2333 char str[1024];
2334 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002335 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002336 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002337 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002338}
2339
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002340VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2341 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002342 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002343 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344{
2345 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2346 if (pCB) {
2347 updateCBTracking(cmdBuffer);
2348 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2349 }
2350 else {
2351 char str[1024];
2352 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002353 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002354 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002355 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002356}
2357
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002358VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2359 VkImage srcImage, VkImageLayout srcImageLayout,
2360 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002361 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362{
2363 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2364 if (pCB) {
2365 updateCBTracking(cmdBuffer);
2366 addCmd(pCB, CMD_RESOLVEIMAGE);
2367 }
2368 else {
2369 char str[1024];
2370 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002371 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002372 }
Tony Barbour11f74372015-04-13 15:02:52 -06002373 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002374}
2375
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002376VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002377{
2378 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2379 if (pCB) {
2380 updateCBTracking(cmdBuffer);
2381 addCmd(pCB, CMD_SETEVENT);
2382 }
2383 else {
2384 char str[1024];
2385 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002386 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002387 }
2388 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2389}
2390
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002391VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002392{
2393 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2394 if (pCB) {
2395 updateCBTracking(cmdBuffer);
2396 addCmd(pCB, CMD_RESETEVENT);
2397 }
2398 else {
2399 char str[1024];
2400 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002401 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002402 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002403 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002404}
2405
Tony Barbour8205d902015-04-16 15:59:00 -06002406VK_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 -06002407{
2408 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2409 if (pCB) {
2410 updateCBTracking(cmdBuffer);
2411 addCmd(pCB, CMD_WAITEVENTS);
2412 }
2413 else {
2414 char str[1024];
2415 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002416 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002417 }
Tony Barbour8205d902015-04-16 15:59:00 -06002418 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002419}
2420
Tony Barbour8205d902015-04-16 15:59:00 -06002421VK_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 -06002422{
2423 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2424 if (pCB) {
2425 updateCBTracking(cmdBuffer);
2426 addCmd(pCB, CMD_PIPELINEBARRIER);
2427 }
2428 else {
2429 char str[1024];
2430 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002431 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002432 }
Tony Barbour8205d902015-04-16 15:59:00 -06002433 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002434}
2435
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002436VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002437{
2438 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2439 if (pCB) {
2440 updateCBTracking(cmdBuffer);
2441 addCmd(pCB, CMD_BEGINQUERY);
2442 }
2443 else {
2444 char str[1024];
2445 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002446 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447 }
2448 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2449}
2450
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002451VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002452{
2453 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2454 if (pCB) {
2455 updateCBTracking(cmdBuffer);
2456 addCmd(pCB, CMD_ENDQUERY);
2457 }
2458 else {
2459 char str[1024];
2460 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002461 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002462 }
2463 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2464}
2465
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002466VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467{
2468 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2469 if (pCB) {
2470 updateCBTracking(cmdBuffer);
2471 addCmd(pCB, CMD_RESETQUERYPOOL);
2472 }
2473 else {
2474 char str[1024];
2475 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002476 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002477 }
2478 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2479}
2480
Tony Barbour8205d902015-04-16 15:59:00 -06002481VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002482{
2483 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2484 if (pCB) {
2485 updateCBTracking(cmdBuffer);
2486 addCmd(pCB, CMD_WRITETIMESTAMP);
2487 }
2488 else {
2489 char str[1024];
2490 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002491 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002492 }
2493 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2494}
2495
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002496VK_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 -06002497{
2498 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2499 if (pCB) {
2500 updateCBTracking(cmdBuffer);
2501 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2502 }
2503 else {
2504 char str[1024];
2505 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002506 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002507 }
2508 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2509}
2510
Tony Barbour8205d902015-04-16 15:59:00 -06002511VK_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 -06002512{
2513 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2514 if (pCB) {
2515 updateCBTracking(cmdBuffer);
2516 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2517 }
2518 else {
2519 char str[1024];
2520 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002521 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002522 }
2523 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2524}
2525
Tony Barbour8205d902015-04-16 15:59:00 -06002526VK_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 -06002527{
2528 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2529 if (pCB) {
2530 updateCBTracking(cmdBuffer);
2531 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2532 }
2533 else {
2534 char str[1024];
2535 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002536 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002537 }
2538 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2539}
2540
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002541VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002542{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002543 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002544 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002545 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002546 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002547 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002548 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2549 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002550 }
2551 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002552 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2553 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002554 }
2555 frameBufferMap[*pFramebuffer] = localFBCI;
2556 }
2557 return result;
2558}
2559
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002560VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002561{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002562 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002563 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002564 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002565 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002566 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002567 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2568 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002569 }
2570 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002571 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2572 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002573 }
2574 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002575 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2576 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002577 }
2578 renderPassMap[*pRenderPass] = localRPCI;
2579 }
2580 return result;
2581}
2582
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002583VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002584{
2585 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2586 if (pCB) {
2587 updateCBTracking(cmdBuffer);
2588 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002589 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2590 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002591 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002592 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002593 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002594 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002595 char str[1024];
2596 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002597 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002598 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002599 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002600}
2601
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002602VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002603{
2604 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2605 if (pCB) {
2606 updateCBTracking(cmdBuffer);
2607 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002608 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002609 }
2610 else {
2611 char str[1024];
2612 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002613 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002614 }
2615 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2616}
2617
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002618VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002619{
2620 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002621 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002622 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002623 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002624 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2625 pNewDbgFuncNode->pUserData = pUserData;
2626 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2627 g_pDbgFunctionHead = pNewDbgFuncNode;
2628 // force callbacks if DebugAction hasn't been set already other than initial value
2629 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002630 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002631 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002632 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002633 return result;
2634}
2635
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002636VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002637{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002638 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2639 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002640 while (pTrav) {
2641 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2642 pPrev->pNext = pTrav->pNext;
2643 if (g_pDbgFunctionHead == pTrav)
2644 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002645 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646 break;
2647 }
2648 pPrev = pTrav;
2649 pTrav = pTrav->pNext;
2650 }
2651 if (g_pDbgFunctionHead == NULL)
2652 {
2653 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002654 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002655 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002656 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002657 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002658 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002659 return result;
2660}
2661
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002662VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663{
2664 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2665 if (pCB) {
2666 updateCBTracking(cmdBuffer);
2667 addCmd(pCB, CMD_DBGMARKERBEGIN);
2668 }
2669 else {
2670 char str[1024];
2671 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002672 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002673 }
2674 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2675}
2676
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002677VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002678{
2679 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2680 if (pCB) {
2681 updateCBTracking(cmdBuffer);
2682 addCmd(pCB, CMD_DBGMARKEREND);
2683 }
2684 else {
2685 char str[1024];
2686 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002687 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002688 }
2689 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2690}
2691
2692// TODO : Want to pass in a cmdBuffer here based on which state to display
2693void drawStateDumpDotFile(char* outFileName)
2694{
2695 // TODO : Currently just setting cmdBuffer based on global var
2696 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2697 dumpGlobalDotFile(outFileName);
2698}
2699
2700void drawStateDumpCommandBufferDotFile(char* outFileName)
2701{
2702 cbDumpDotFile(outFileName);
2703}
2704
2705void drawStateDumpPngFile(char* outFileName)
2706{
2707#if defined(_WIN32)
2708// FIXME: NEED WINDOWS EQUIVALENT
2709 char str[1024];
2710 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002711 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002712#else // WIN32
2713 char dotExe[32] = "/usr/bin/dot";
2714 if( access(dotExe, X_OK) != -1) {
2715 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2716 char dotCmd[1024];
2717 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
2718 system(dotCmd);
2719 remove("/tmp/tmp.dot");
2720 }
2721 else {
2722 char str[1024];
2723 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002724 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002725 }
2726#endif // WIN32
2727}
2728
Tony Barbour8205d902015-04-16 15:59:00 -06002729VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002730{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002731 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002732
2733 if (gpu == NULL)
2734 return NULL;
2735 pCurObj = gpuw;
2736 loader_platform_thread_once(&g_initOnce, initDrawState);
2737
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002738 if (!strcmp(funcName, "vkGetProcAddr"))
2739 return (void *) vkGetProcAddr;
2740 if (!strcmp(funcName, "vkCreateDevice"))
2741 return (void*) vkCreateDevice;
2742 if (!strcmp(funcName, "vkDestroyDevice"))
2743 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002744 if (!strcmp(funcName, "vkEnumerateLayers"))
2745 return (void*) vkEnumerateLayers;
2746 if (!strcmp(funcName, "vkQueueSubmit"))
2747 return (void*) vkQueueSubmit;
2748 if (!strcmp(funcName, "vkDestroyObject"))
2749 return (void*) vkDestroyObject;
2750 if (!strcmp(funcName, "vkCreateBufferView"))
2751 return (void*) vkCreateBufferView;
2752 if (!strcmp(funcName, "vkCreateImageView"))
2753 return (void*) vkCreateImageView;
2754 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2755 return (void*) vkCreateGraphicsPipeline;
2756 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2757 return (void*) vkCreateGraphicsPipelineDerivative;
2758 if (!strcmp(funcName, "vkCreateSampler"))
2759 return (void*) vkCreateSampler;
2760 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2761 return (void*) vkCreateDescriptorSetLayout;
2762 if (!strcmp(funcName, "vkCreateDescriptorSetLayoutChain"))
2763 return (void*) vkCreateDescriptorSetLayoutChain;
2764 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2765 return (void*) vkBeginDescriptorPoolUpdate;
2766 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2767 return (void*) vkEndDescriptorPoolUpdate;
2768 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2769 return (void*) vkCreateDescriptorPool;
2770 if (!strcmp(funcName, "vkResetDescriptorPool"))
2771 return (void*) vkResetDescriptorPool;
2772 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2773 return (void*) vkAllocDescriptorSets;
2774 if (!strcmp(funcName, "vkClearDescriptorSets"))
2775 return (void*) vkClearDescriptorSets;
2776 if (!strcmp(funcName, "vkUpdateDescriptors"))
2777 return (void*) vkUpdateDescriptors;
2778 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2779 return (void*) vkCreateDynamicViewportState;
2780 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2781 return (void*) vkCreateDynamicRasterState;
2782 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2783 return (void*) vkCreateDynamicColorBlendState;
2784 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2785 return (void*) vkCreateDynamicDepthStencilState;
2786 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2787 return (void*) vkCreateCommandBuffer;
2788 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2789 return (void*) vkBeginCommandBuffer;
2790 if (!strcmp(funcName, "vkEndCommandBuffer"))
2791 return (void*) vkEndCommandBuffer;
2792 if (!strcmp(funcName, "vkResetCommandBuffer"))
2793 return (void*) vkResetCommandBuffer;
2794 if (!strcmp(funcName, "vkCmdBindPipeline"))
2795 return (void*) vkCmdBindPipeline;
2796 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2797 return (void*) vkCmdBindDynamicStateObject;
2798 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2799 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002800 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2801 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002802 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2803 return (void*) vkCmdBindIndexBuffer;
2804 if (!strcmp(funcName, "vkCmdDraw"))
2805 return (void*) vkCmdDraw;
2806 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2807 return (void*) vkCmdDrawIndexed;
2808 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2809 return (void*) vkCmdDrawIndirect;
2810 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2811 return (void*) vkCmdDrawIndexedIndirect;
2812 if (!strcmp(funcName, "vkCmdDispatch"))
2813 return (void*) vkCmdDispatch;
2814 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2815 return (void*) vkCmdDispatchIndirect;
2816 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2817 return (void*) vkCmdCopyBuffer;
2818 if (!strcmp(funcName, "vkCmdCopyImage"))
2819 return (void*) vkCmdCopyImage;
2820 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2821 return (void*) vkCmdCopyBufferToImage;
2822 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2823 return (void*) vkCmdCopyImageToBuffer;
2824 if (!strcmp(funcName, "vkCmdCloneImageData"))
2825 return (void*) vkCmdCloneImageData;
2826 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2827 return (void*) vkCmdUpdateBuffer;
2828 if (!strcmp(funcName, "vkCmdFillBuffer"))
2829 return (void*) vkCmdFillBuffer;
2830 if (!strcmp(funcName, "vkCmdClearColorImage"))
2831 return (void*) vkCmdClearColorImage;
2832 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2833 return (void*) vkCmdClearDepthStencil;
2834 if (!strcmp(funcName, "vkCmdResolveImage"))
2835 return (void*) vkCmdResolveImage;
2836 if (!strcmp(funcName, "vkCmdSetEvent"))
2837 return (void*) vkCmdSetEvent;
2838 if (!strcmp(funcName, "vkCmdResetEvent"))
2839 return (void*) vkCmdResetEvent;
2840 if (!strcmp(funcName, "vkCmdWaitEvents"))
2841 return (void*) vkCmdWaitEvents;
2842 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2843 return (void*) vkCmdPipelineBarrier;
2844 if (!strcmp(funcName, "vkCmdBeginQuery"))
2845 return (void*) vkCmdBeginQuery;
2846 if (!strcmp(funcName, "vkCmdEndQuery"))
2847 return (void*) vkCmdEndQuery;
2848 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2849 return (void*) vkCmdResetQueryPool;
2850 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2851 return (void*) vkCmdWriteTimestamp;
2852 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2853 return (void*) vkCmdInitAtomicCounters;
2854 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2855 return (void*) vkCmdLoadAtomicCounters;
2856 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2857 return (void*) vkCmdSaveAtomicCounters;
2858 if (!strcmp(funcName, "vkCreateFramebuffer"))
2859 return (void*) vkCreateFramebuffer;
2860 if (!strcmp(funcName, "vkCreateRenderPass"))
2861 return (void*) vkCreateRenderPass;
2862 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2863 return (void*) vkCmdBeginRenderPass;
2864 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2865 return (void*) vkCmdEndRenderPass;
2866 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2867 return (void*) vkDbgRegisterMsgCallback;
2868 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2869 return (void*) vkDbgUnregisterMsgCallback;
2870 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2871 return (void*) vkCmdDbgMarkerBegin;
2872 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2873 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002874 if (!strcmp("drawStateDumpDotFile", funcName))
2875 return (void*) drawStateDumpDotFile;
2876 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2877 return (void*) drawStateDumpCommandBufferDotFile;
2878 if (!strcmp("drawStateDumpPngFile", funcName))
2879 return (void*) drawStateDumpPngFile;
2880 else {
2881 if (gpuw->pGPA == NULL)
2882 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002883 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002884 }
2885}