blob: f73e533db87866006cae2f6167ec0179dd6efbce [file] [log] [blame]
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis10ae8c12015-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060035#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036#include "vk_struct_graphviz_helper.h"
Tony Barbour18f71552015-04-22 11:36:22 -060037#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060038#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060039#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060040#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060041#include "draw_state.h"
42#include "layers_config.h"
43// The following is #included again to catch certain OS-specific functions
44// being used:
45#include "loader_platform.h"
46#include "layers_msg.h"
47
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060048unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
49unordered_map<VkImageView, IMAGE_NODE*> imageMap;
50unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
51unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
52unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
53unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
54unordered_map<VkDescriptorSet, SET_NODE*> setMap;
55unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlis793ad302015-04-03 12:01:11 -060056// Map for layout chains
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060057unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
58unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
59unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060060
Jon Ashburnbacb0f52015-04-06 10:58:22 -060061static VkLayerDispatchTable nextTable;
62static VkBaseLayerObject *pCurObj;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060063static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
64// TODO : This can be much smarter, using separate locks for separate global data
65static int globalLockInitialized = 0;
66static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060067#define MAX_TID 513
68static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
69static uint32_t g_maxTID = 0;
70// Map actual TID to an index value and return that index
71// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
72static uint32_t getTIDIndex() {
73 loader_platform_thread_id tid = loader_platform_get_thread_id();
74 for (uint32_t i = 0; i < g_maxTID; i++) {
75 if (tid == g_tidMapping[i])
76 return i;
77 }
78 // Don't yet have mapping, set it and return newly set index
79 uint32_t retVal = (uint32_t) g_maxTID;
80 g_tidMapping[g_maxTID++] = tid;
81 assert(g_maxTID < MAX_TID);
82 return retVal;
83}
84// Return a string representation of CMD_TYPE enum
85static string cmdTypeToString(CMD_TYPE cmd)
86{
87 switch (cmd)
88 {
89 case CMD_BINDPIPELINE:
90 return "CMD_BINDPIPELINE";
91 case CMD_BINDPIPELINEDELTA:
92 return "CMD_BINDPIPELINEDELTA";
93 case CMD_BINDDYNAMICSTATEOBJECT:
94 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlis793ad302015-04-03 12:01:11 -060095 case CMD_BINDDESCRIPTORSETS:
96 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060097 case CMD_BINDINDEXBUFFER:
98 return "CMD_BINDINDEXBUFFER";
99 case CMD_BINDVERTEXBUFFER:
100 return "CMD_BINDVERTEXBUFFER";
101 case CMD_DRAW:
102 return "CMD_DRAW";
103 case CMD_DRAWINDEXED:
104 return "CMD_DRAWINDEXED";
105 case CMD_DRAWINDIRECT:
106 return "CMD_DRAWINDIRECT";
107 case CMD_DRAWINDEXEDINDIRECT:
108 return "CMD_DRAWINDEXEDINDIRECT";
109 case CMD_DISPATCH:
110 return "CMD_DISPATCH";
111 case CMD_DISPATCHINDIRECT:
112 return "CMD_DISPATCHINDIRECT";
113 case CMD_COPYBUFFER:
114 return "CMD_COPYBUFFER";
115 case CMD_COPYIMAGE:
116 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600117 case CMD_BLITIMAGE:
118 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600119 case CMD_COPYBUFFERTOIMAGE:
120 return "CMD_COPYBUFFERTOIMAGE";
121 case CMD_COPYIMAGETOBUFFER:
122 return "CMD_COPYIMAGETOBUFFER";
123 case CMD_CLONEIMAGEDATA:
124 return "CMD_CLONEIMAGEDATA";
125 case CMD_UPDATEBUFFER:
126 return "CMD_UPDATEBUFFER";
127 case CMD_FILLBUFFER:
128 return "CMD_FILLBUFFER";
129 case CMD_CLEARCOLORIMAGE:
130 return "CMD_CLEARCOLORIMAGE";
131 case CMD_CLEARCOLORIMAGERAW:
132 return "CMD_CLEARCOLORIMAGERAW";
133 case CMD_CLEARDEPTHSTENCIL:
134 return "CMD_CLEARDEPTHSTENCIL";
135 case CMD_RESOLVEIMAGE:
136 return "CMD_RESOLVEIMAGE";
137 case CMD_SETEVENT:
138 return "CMD_SETEVENT";
139 case CMD_RESETEVENT:
140 return "CMD_RESETEVENT";
141 case CMD_WAITEVENTS:
142 return "CMD_WAITEVENTS";
143 case CMD_PIPELINEBARRIER:
144 return "CMD_PIPELINEBARRIER";
145 case CMD_BEGINQUERY:
146 return "CMD_BEGINQUERY";
147 case CMD_ENDQUERY:
148 return "CMD_ENDQUERY";
149 case CMD_RESETQUERYPOOL:
150 return "CMD_RESETQUERYPOOL";
151 case CMD_WRITETIMESTAMP:
152 return "CMD_WRITETIMESTAMP";
153 case CMD_INITATOMICCOUNTERS:
154 return "CMD_INITATOMICCOUNTERS";
155 case CMD_LOADATOMICCOUNTERS:
156 return "CMD_LOADATOMICCOUNTERS";
157 case CMD_SAVEATOMICCOUNTERS:
158 return "CMD_SAVEATOMICCOUNTERS";
159 case CMD_BEGINRENDERPASS:
160 return "CMD_BEGINRENDERPASS";
161 case CMD_ENDRENDERPASS:
162 return "CMD_ENDRENDERPASS";
163 case CMD_DBGMARKERBEGIN:
164 return "CMD_DBGMARKERBEGIN";
165 case CMD_DBGMARKEREND:
166 return "CMD_DBGMARKEREND";
167 default:
168 return "UNKNOWN";
169 }
170}
171// Block of code at start here for managing/tracking Pipeline state that this layer cares about
172// Just track 2 shaders for now
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600173#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600174#define MAX_SLOTS 2048
175#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
176
177static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
178
179// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
180// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
181// to that same cmd buffer by separate thread are not changing state from underneath us
182// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600183static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600184// Track the last group of CBs touched for displaying to dot file
185static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
186static uint32_t g_lastTouchedCBIndex = 0;
187// Track the last global DrawState of interest touched by any thread
188static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
189static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600190static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600191static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600192#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
193
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600194//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600195
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600196static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600197{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600198 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600199 size_t scSize = 0;
200 size_t vpSize = 0;
201 loader_platform_thread_lock_mutex(&globalLock);
202 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
203 pStateNode->stateObj = state;
204 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600205 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600206 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
207 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
208 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
209 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
210 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
211 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600212 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
213 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
214 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600215 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600216 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600217 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600218 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600219 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600220 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600221 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600222 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600223 break;
224 default:
225 assert(0);
226 break;
227 }
228 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
229 dynamicStateMap[state] = pStateNode;
230 loader_platform_thread_unlock_mutex(&globalLock);
231}
232// Free all allocated nodes for Dynamic State objs
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600233static void deleteDynamicState()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600234{
David Pinedod8f83d82015-04-27 16:36:17 -0600235 if (dynamicStateMap.size() <= 0)
236 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600237 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600238 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600239 delete[] (*ii).second->create_info.vpci.pScissors;
240 delete[] (*ii).second->create_info.vpci.pViewports;
241 }
242 delete (*ii).second;
243 }
244}
245// Free all sampler nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600246static void deleteSamplers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600247{
David Pinedod8f83d82015-04-27 16:36:17 -0600248 if (sampleMap.size() <= 0)
249 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600250 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600251 delete (*ii).second;
252 }
253}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600254static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600255{
256 loader_platform_thread_lock_mutex(&globalLock);
257 if (imageMap.find(view) == imageMap.end()) {
258 loader_platform_thread_unlock_mutex(&globalLock);
259 return NULL;
260 }
261 else {
262 loader_platform_thread_unlock_mutex(&globalLock);
263 return &imageMap[view]->createInfo;
264 }
265}
266// Free all image nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600267static void deleteImages()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600268{
David Pinedod8f83d82015-04-27 16:36:17 -0600269 if (imageMap.size() <= 0)
270 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600271 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600272 delete (*ii).second;
273 }
274}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600275static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600276{
277 loader_platform_thread_lock_mutex(&globalLock);
278 if (bufferMap.find(view) == bufferMap.end()) {
279 loader_platform_thread_unlock_mutex(&globalLock);
280 return NULL;
281 }
282 else {
283 loader_platform_thread_unlock_mutex(&globalLock);
284 return &bufferMap[view]->createInfo;
285 }
286}
287// Free all buffer nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600288static void deleteBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600289{
David Pinedod8f83d82015-04-27 16:36:17 -0600290 if (bufferMap.size() <= 0)
291 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600292 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600293 delete (*ii).second;
294 }
295}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600296static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600297
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600298static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600299{
300 g_lastCmdBuffer[getTIDIndex()] = cb;
301 GLOBAL_CB_NODE* pCB = getCBNode(cb);
302 loader_platform_thread_lock_mutex(&globalLock);
303 g_lastGlobalCB = pCB;
304 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
305 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
306 if (g_pLastTouchedCB[i] == pCB) {
307 loader_platform_thread_unlock_mutex(&globalLock);
308 return;
309 }
310 }
311 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
312 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
313 loader_platform_thread_unlock_mutex(&globalLock);
314}
315
316// Print the last bound dynamic state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600317static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600318{
319 GLOBAL_CB_NODE* pCB = getCBNode(cb);
320 if (pCB) {
321 loader_platform_thread_lock_mutex(&globalLock);
322 char str[4*1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600323 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600324 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600325 sprintf(str, "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600326 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
327 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 Ehlis10ae8c12015-03-17 16:24:32 -0600328 break;
329 }
330 else {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600331 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600332 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600333 }
334 }
335 loader_platform_thread_unlock_mutex(&globalLock);
336 }
337 else {
338 char str[1024];
339 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600340 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600341 }
342}
343// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600345{
346 loader_platform_thread_lock_mutex(&globalLock);
347 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
348 loader_platform_thread_unlock_mutex(&globalLock);
349 return NULL;
350 }
351 loader_platform_thread_unlock_mutex(&globalLock);
352 return pipelineMap[pipeline];
353}
354
355// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600356static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600357{
358 loader_platform_thread_lock_mutex(&globalLock);
359 if (sampleMap.find(sampler) == sampleMap.end()) {
360 loader_platform_thread_unlock_mutex(&globalLock);
361 return NULL;
362 }
363 loader_platform_thread_unlock_mutex(&globalLock);
364 return &sampleMap[sampler]->createInfo;
365}
366
367// Init the pipeline mapping info based on pipeline create info LL tree
368// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600369static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600370{
371 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehliseba312c2015-04-01 08:40:34 -0600372 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600373 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600374 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600375 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600376 size_t bufferSize = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600377 VkPipelineVertexInputCreateInfo* pVICI = NULL;
378 VkPipelineCbStateCreateInfo* pCBCI = NULL;
379 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600380 while (pTrav) {
381 switch (pTrav->sType) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600382 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600383 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600384 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600385 case VK_SHADER_STAGE_VERTEX:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600386 pPrev->pNext = &pPipeline->vsCI;
387 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600388 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600389 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600390 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600391 pPrev->pNext = &pPipeline->tcsCI;
392 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600393 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600394 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600395 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600396 pPrev->pNext = &pPipeline->tesCI;
397 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600398 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600399 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600400 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600401 pPrev->pNext = &pPipeline->gsCI;
402 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600404 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600405 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600406 pPrev->pNext = &pPipeline->fsCI;
407 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600408 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600409 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600410 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600411 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600412 break;
413 default:
414 // TODO : Flag error
415 break;
416 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600417 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600418 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600419 pPrev->pNext = &pPipeline->vertexInputCI;
420 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600421 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600422 // Copy embedded ptrs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600423 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600424 pPipeline->vtxBindingCount = pVICI->bindingCount;
425 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600426 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
427 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
428 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600429 }
430 pPipeline->vtxAttributeCount = pVICI->attributeCount;
431 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600432 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
433 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
434 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600435 }
436 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600437 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600438 pPrev->pNext = &pPipeline->iaStateCI;
439 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600440 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600441 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600442 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600443 pPrev->pNext = &pPipeline->tessStateCI;
444 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600445 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600446 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600447 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600448 pPrev->pNext = &pPipeline->vpStateCI;
449 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600450 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600451 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600452 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600453 pPrev->pNext = &pPipeline->rsStateCI;
454 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600455 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600456 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600457 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600458 pPrev->pNext = &pPipeline->msStateCI;
459 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600460 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600461 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600462 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600463 pPrev->pNext = &pPipeline->cbStateCI;
464 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600465 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600466 // Copy embedded ptrs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600467 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600468 pPipeline->attachmentCount = pCBCI->attachmentCount;
469 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600470 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
471 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
472 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600473 }
474 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600475 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600476 pPrev->pNext = &pPipeline->dsStateCI;
477 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600478 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600479 break;
480 default:
481 assert(0);
482 break;
483 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600484 pTrav = (GENERIC_HEADER*)pTrav->pNext;
485 }
486 pipelineMap[pPipeline->pipeline] = pPipeline;
487}
488// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600489static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600490{
David Pinedod8f83d82015-04-27 16:36:17 -0600491 if (pipelineMap.size() <= 0)
492 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600493 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600494 if ((*ii).second->pVertexBindingDescriptions) {
495 delete[] (*ii).second->pVertexBindingDescriptions;
496 }
497 if ((*ii).second->pVertexAttributeDescriptions) {
498 delete[] (*ii).second->pVertexAttributeDescriptions;
499 }
500 if ((*ii).second->pAttachments) {
501 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600502 }
503 delete (*ii).second;
504 }
505}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600506// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600507static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600508{
509 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600510 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600511 if (pPipe->msStateCI.multisampleEnable)
512 return pPipe->msStateCI.samples;
Tobin Ehliseba312c2015-04-01 08:40:34 -0600513 }
514 return 1;
515}
516// Validate state related to the PSO
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600517static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600518{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600519 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600520 // Verify that any MSAA request in PSO matches sample# in bound FB
521 uint32_t psoNumSamples = getNumSamples(pipeline);
522 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600523 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
524 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehliseba312c2015-04-01 08:40:34 -0600525 if (psoNumSamples != pFBCI->sampleCount) {
526 char str[1024];
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -0600527 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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600528 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
Tobin Ehliseba312c2015-04-01 08:40:34 -0600529 }
530 } else {
531 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
532 // Verify and flag error as appropriate
533 }
534 // TODO : Add more checks here
535 } else {
536 // TODO : Validate non-gfx pipeline updates
537 }
538}
539
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600540// Block of code at start here specifically for managing/tracking DSs
541
Tobin Ehlis793ad302015-04-03 12:01:11 -0600542// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600543static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600544{
545 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600546 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600547 loader_platform_thread_unlock_mutex(&globalLock);
548 return NULL;
549 }
550 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600551 return poolMap[pool];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600552}
553// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600554static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600555{
556 loader_platform_thread_lock_mutex(&globalLock);
557 if (setMap.find(set) == setMap.end()) {
558 loader_platform_thread_unlock_mutex(&globalLock);
559 return NULL;
560 }
561 loader_platform_thread_unlock_mutex(&globalLock);
562 return setMap[set];
563}
564
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600565// Return VK_TRUE if DS Exists and is within an vkBeginDescriptorPoolUpdate() call sequence, otherwise VK_FALSE
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600566static bool32_t dsUpdateActive(VkDescriptorSet ds)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600567{
568 // Note, both "get" functions use global mutex so this guy does not
569 SET_NODE* pTrav = getSetNode(ds);
570 if (pTrav) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600571 POOL_NODE* pPool = getPoolNode(pTrav->pool);
572 if (pPool) {
573 return pPool->updateActive;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600574 }
575 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600576 return VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600577}
578
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600579static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600580 loader_platform_thread_lock_mutex(&globalLock);
581 if (layoutMap.find(layout) == layoutMap.end()) {
582 loader_platform_thread_unlock_mutex(&globalLock);
583 return NULL;
584 }
585 loader_platform_thread_unlock_mutex(&globalLock);
586 return layoutMap[layout];
587}
588
Tobin Ehlis793ad302015-04-03 12:01:11 -0600589// For given update struct, return binding
590static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600591{
592 switch (pUpdateStruct->sType)
593 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600594 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600595 return ((VkUpdateSamplers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600596 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600597 return ((VkUpdateSamplerTextures*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600598 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600599 return ((VkUpdateImages*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600600 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600601 return ((VkUpdateBuffers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600602 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600603 return ((VkUpdateAsCopy*)pUpdateStruct)->binding;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600604 default:
605 // TODO : Flag specific error for this case
Tobin Ehlis793ad302015-04-03 12:01:11 -0600606 assert(0);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600607 return 0;
608 }
609}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600610// Return count for given update struct
611static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600612{
613 switch (pUpdateStruct->sType)
614 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600615 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600616 return (((VkUpdateSamplers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600617 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600618 return (((VkUpdateSamplerTextures*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600619 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600620 return (((VkUpdateImages*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600621 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600622 return (((VkUpdateBuffers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600623 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600624 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600625 return (((VkUpdateAsCopy*)pUpdateStruct)->arrayElement);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600626 default:
627 // TODO : Flag specific error for this case
Tobin Ehlis793ad302015-04-03 12:01:11 -0600628 assert(0);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600629 return 0;
630 }
631}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600632// Return count for given update struct
633static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
634{
635 switch (pUpdateStruct->sType)
636 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600637 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600638 return (((VkUpdateSamplers*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600639 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600640 return (((VkUpdateSamplerTextures*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600641 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600642 return (((VkUpdateImages*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600643 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600644 return (((VkUpdateBuffers*)pUpdateStruct)->count);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600645 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600646 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600647 return (((VkUpdateAsCopy*)pUpdateStruct)->count);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600648 default:
649 // TODO : Flag specific error for this case
650 assert(0);
651 return 0;
652 }
653}
654// For given Layout Node and binding, return index where that binding begins
655static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
656{
657 uint32_t offsetIndex = 0;
658 for (uint32_t i = 0; i<binding; i++) {
659 offsetIndex += pLayout->createInfo.pBinding[i].count;
660 }
661 return offsetIndex;
662}
663// For given layout node and binding, return last index that is updated
664static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
665{
666 uint32_t offsetIndex = 0;
667 for (uint32_t i = 0; i<=binding; i++) {
668 offsetIndex += pLayout->createInfo.pBinding[i].count;
669 }
670 return offsetIndex-1;
671}
672// For given layout and update, return the first overall index of the layout that is update
673static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
674{
675 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
676}
677// For given layout and update, return the last overall index of the layout that is update
678static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
679{
680 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
681}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600682// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlis793ad302015-04-03 12:01:11 -0600683static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600684{
685 // First get actual type of update
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600686 VkDescriptorType actualType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600687 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600688 switch (pUpdateStruct->sType)
689 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600690 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
691 actualType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600692 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600693 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterb9776ab2015-04-15 15:29:59 -0600694 actualType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600695 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600696 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600697 actualType = ((VkUpdateImages*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600698 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600699 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600700 actualType = ((VkUpdateBuffers*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600701 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600702 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600703 actualType = ((VkUpdateAsCopy*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600704 break;
705 default:
706 // TODO : Flag specific error for this case
707 return 0;
708 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600709 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600710 if (pLayout->pTypes[i] != actualType)
711 return 0;
712 }
713 return 1;
714}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600715// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
716// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
717// NOTE : Calls to this function should be wrapped in mutex
718static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
719{
720 GENERIC_HEADER* pNewNode = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600721 VkUpdateSamplers* pUS = NULL;
722 VkUpdateSamplerTextures* pUST = NULL;
723 VkUpdateBuffers* pUB = NULL;
724 VkUpdateImages* pUI = NULL;
725 VkUpdateAsCopy* pUAC = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600726 size_t array_size = 0;
727 size_t base_array_size = 0;
728 size_t total_array_size = 0;
729 size_t baseBuffAddr = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600730 VkImageViewAttachInfo** ppLocalImageViews = NULL;
731 VkBufferViewAttachInfo** ppLocalBufferViews = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600732 char str[1024];
733 switch (pUpdate->sType)
734 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600735 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600736 pUS = new VkUpdateSamplers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600737 pNewNode = (GENERIC_HEADER*)pUS;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600738 memcpy(pUS, pUpdate, sizeof(VkUpdateSamplers));
739 pUS->pSamplers = new VkSampler[pUS->count];
740 array_size = sizeof(VkSampler) * pUS->count;
741 memcpy((void*)pUS->pSamplers, ((VkUpdateSamplers*)pUpdate)->pSamplers, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600742 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600743 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600744 pUST = new VkUpdateSamplerTextures;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600745 pNewNode = (GENERIC_HEADER*)pUST;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600746 memcpy(pUST, pUpdate, sizeof(VkUpdateSamplerTextures));
747 pUST->pSamplerImageViews = new VkSamplerImageViewInfo[pUST->count];
748 array_size = sizeof(VkSamplerImageViewInfo) * pUST->count;
749 memcpy((void*)pUST->pSamplerImageViews, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews, array_size);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600750 for (uint32_t i = 0; i < pUST->count; i++) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600751 VkImageViewAttachInfo** ppIV = (VkImageViewAttachInfo**)&pUST->pSamplerImageViews[i].pImageView;
752 *ppIV = new VkImageViewAttachInfo;
753 memcpy((void*)*ppIV, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews[i].pImageView, sizeof(VkImageViewAttachInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600754 }
755 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600756 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600757 pUI = new VkUpdateImages;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600758 pNewNode = (GENERIC_HEADER*)pUI;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600759 memcpy(pUI, pUpdate, sizeof(VkUpdateImages));
760 pUI->pImageViews = new VkImageViewAttachInfo[pUI->count];
761 array_size = (sizeof(VkImageViewAttachInfo) * pUI->count);
762 memcpy((void*)pUI->pImageViews, ((VkUpdateImages*)pUpdate)->pImageViews, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600763 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600764 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600765 pUB = new VkUpdateBuffers;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600766 pNewNode = (GENERIC_HEADER*)pUB;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600767 memcpy(pUB, pUpdate, sizeof(VkUpdateBuffers));
768 pUB->pBufferViews = new VkBufferViewAttachInfo[pUB->count];
769 array_size = (sizeof(VkBufferViewAttachInfo) * pUB->count);
770 memcpy((void*)pUB->pBufferViews, ((VkUpdateBuffers*)pUpdate)->pBufferViews, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600771 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600772 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600773 pUAC = new VkUpdateAsCopy;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600774 pUpdate = (GENERIC_HEADER*)pUAC;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600775 memcpy(pUAC, pUpdate, sizeof(VkUpdateAsCopy));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600776 break;
777 default:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600778 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600779 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600780 return NULL;
781 }
782 // Make sure that pNext for the end of shadow copy is NULL
783 pNewNode->pNext = NULL;
784 return pNewNode;
785}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600786// For given ds, update its mapping based on ppUpdateArray
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600787static void dsUpdate(VkDescriptorSet ds, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600788{
789 SET_NODE* pSet = getSetNode(ds);
790 loader_platform_thread_lock_mutex(&globalLock);
791 g_lastBoundDescriptorSet = pSet->set;
792 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600793 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600794 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600795 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600796 for (uint32_t i = 0; i < updateCount; i++) {
797 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*)ppUpdateArray[i];
798 pLayout = pSet->pLayout;
799 // Make sure that binding is within bounds
800 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600801 char str[1024];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600802 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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600803 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600804 }
805 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600806 // Next verify that update falls within size of given binding
807 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600808 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlis793ad302015-04-03 12:01:11 -0600809 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600810 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
811 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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600812 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600813 }
814 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600815 // Layout bindings match w/ update ok, now verify that update is of the right type
816 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600817 char str[1024];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600818 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600819 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600820 }
821 else {
822 // Save the update info
823 // TODO : Info message that update successful
824 // Create new update struct for this set's shadow copy
Tobin Ehlis793ad302015-04-03 12:01:11 -0600825 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600826 if (NULL == pNewNode) {
827 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600828 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
829 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600830 }
831 else {
832 // Insert shadow node into LL of updates for this set
833 pNewNode->pNext = pSet->pUpdateStructs;
834 pSet->pUpdateStructs = pNewNode;
835 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis793ad302015-04-03 12:01:11 -0600836 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
837 assert(j<pSet->descriptorCount);
838 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600839 }
840 }
841 }
842 }
843 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600844 }
845 loader_platform_thread_unlock_mutex(&globalLock);
846}
847// Free the shadowed update node for this Set
848// NOTE : Calls to this function should be wrapped in mutex
849static void freeShadowUpdateTree(SET_NODE* pSet)
850{
851 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
852 pSet->pUpdateStructs = NULL;
853 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
854 // Clear the descriptor mappings as they will now be invalid
855 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
856 while(pShadowUpdate) {
857 pFreeUpdate = pShadowUpdate;
858 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
859 uint32_t index = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600860 VkUpdateSamplers* pUS = NULL;
861 VkUpdateSamplerTextures* pUST = NULL;
862 VkUpdateImages* pUI = NULL;
863 VkUpdateBuffers* pUB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600864 void** ppToFree = NULL;
865 switch (pFreeUpdate->sType)
866 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600867 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600868 pUS = (VkUpdateSamplers*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600869 if (pUS->pSamplers)
870 delete[] pUS->pSamplers;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600871 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600872 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600873 pUST = (VkUpdateSamplerTextures*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600874 if (pUST->pSamplerImageViews) {
875 for (index = 0; index < pUST->count; index++) {
876 if (pUST->pSamplerImageViews[index].pImageView) {
877 delete pUST->pSamplerImageViews[index].pImageView;
878 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600879 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600880 delete[] pUST->pSamplerImageViews;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600881 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600882 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600883 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600884 pUI = (VkUpdateImages*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600885 if (pUI->pImageViews)
886 delete[] pUI->pImageViews;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600887 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600888 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600889 pUB = (VkUpdateBuffers*)pFreeUpdate;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600890 if (pUB->pBufferViews)
891 delete[] pUB->pBufferViews;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600892 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600893 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600894 break;
895 default:
896 assert(0);
897 break;
898 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600899 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600900 }
901}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600902// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600903// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600904static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600905{
David Pinedod8f83d82015-04-27 16:36:17 -0600906 if (poolMap.size() <= 0)
907 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600908 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600909 SET_NODE* pSet = (*ii).second->pSets;
910 SET_NODE* pFreeSet = pSet;
911 while (pSet) {
912 pFreeSet = pSet;
913 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600914 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600915 // Free Update shadow struct tree
916 freeShadowUpdateTree(pFreeSet);
917 if (pFreeSet->ppDescriptors) {
918 delete pFreeSet->ppDescriptors;
919 }
920 delete pFreeSet;
921 }
922 if ((*ii).second->createInfo.pTypeCount) {
923 delete (*ii).second->createInfo.pTypeCount;
924 }
925 delete (*ii).second;
926 }
927}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600928// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600929// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600930static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600931{
David Pinedod8f83d82015-04-27 16:36:17 -0600932 if (layoutMap.size() <= 0)
933 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600934 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600935 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600936 if (pLayout->createInfo.pBinding) {
937 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
938 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
939 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
940 }
941 delete[] pLayout->createInfo.pBinding;
942 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600943 if (pLayout->pTypes) {
944 delete pLayout->pTypes;
945 }
946 delete pLayout;
947 }
948}
949// Currently clearing a set is removing all previous updates to that set
950// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600951static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600952{
953 SET_NODE* pSet = getSetNode(set);
954 if (!pSet) {
955 // TODO : Return error
956 }
957 else {
958 loader_platform_thread_lock_mutex(&globalLock);
959 freeShadowUpdateTree(pSet);
960 loader_platform_thread_unlock_mutex(&globalLock);
961 }
962}
963
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600964static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600965{
Tobin Ehlis793ad302015-04-03 12:01:11 -0600966 POOL_NODE* pPool = getPoolNode(pool);
967 if (!pPool) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600968 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600969 sprintf(str, "Unable to find pool node for pool %p specified in vkClearDescriptorPool() call", (void*)pool);
970 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600971 }
972 else
973 {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600974 // For every set off of this pool, clear it
975 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600976 while (pSet) {
977 clearDescriptorSet(pSet->set);
978 }
979 }
980}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600981// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600982static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600983{
984 loader_platform_thread_lock_mutex(&globalLock);
985 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
986 loader_platform_thread_unlock_mutex(&globalLock);
987 return NULL;
988 }
989 loader_platform_thread_unlock_mutex(&globalLock);
990 return cmdBufferMap[cb];
991}
992// Free all CB Nodes
993// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600994static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600995{
David Pinedod8f83d82015-04-27 16:36:17 -0600996 if (cmdBufferMap.size() <= 0)
997 return;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600998 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -0600999 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1000 while (!cmd_node_list.empty()) {
1001 CMD_NODE* cmd_node = cmd_node_list.back();
1002 delete cmd_node;
1003 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001004 }
1005 delete (*ii).second;
1006 }
1007}
1008static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1009{
1010 CMD_NODE* pCmd = new CMD_NODE;
1011 if (pCmd) {
1012 // init cmd node and append to end of cmd LL
1013 memset(pCmd, 0, sizeof(CMD_NODE));
1014 pCmd->cmdNumber = ++pCB->numCmds;
1015 pCmd->type = cmd;
1016 pCB->pCmds.push_back(pCmd);
1017 }
1018 else {
1019 char str[1024];
1020 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001021 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001022 }
1023}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001024static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001025{
1026 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1027 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001028 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1029 while (!cmd_list.empty()) {
1030 delete cmd_list.back();
1031 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001032 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001033 pCB->pCmds.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001034 // Reset CB state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001035 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001036 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001037 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1038 pCB->cmdBuffer = cb;
1039 pCB->flags = saveFlags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001040 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001041 pCB->lastVtxBinding = MAX_BINDING;
1042 }
1043}
1044// Set the last bound dynamic state of given type
1045// TODO : Need to track this per cmdBuffer and correlate cmdBuffer for Draw w/ last bound for that cmdBuffer?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001046static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001047{
1048 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1049 if (pCB) {
1050 updateCBTracking(cmdBuffer);
1051 loader_platform_thread_lock_mutex(&globalLock);
1052 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1053 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1054 char str[1024];
1055 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001056 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001057 }
1058 else {
1059 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1060 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1061 }
1062 loader_platform_thread_unlock_mutex(&globalLock);
1063 }
1064 else {
1065 char str[1024];
1066 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001067 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001068 }
1069}
1070// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001071static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001072{
1073 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1074 if (pCB) {
1075 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1076 if (!pPipeTrav) {
1077 // nothing to print
1078 }
1079 else {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001080 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001081 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001082 }
1083 }
1084}
1085// Common Dot dumping code
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001086static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001087{
1088 SET_NODE* pSet = getSetNode(ds);
1089 if (pSet) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001090 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001091 char tmp_str[4*1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001092 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1093 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001094 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001095 fprintf(pOutFile, "%s", pGVstr);
1096 free(pGVstr);
1097 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1098 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001099 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001100 uint32_t layout_index = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001101 ++layout_index;
1102 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001103 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001104 fprintf(pOutFile, "%s", pGVstr);
1105 free(pGVstr);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001106 if (pSet->pUpdateStructs) {
1107 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1108 fprintf(pOutFile, "%s", pGVstr);
1109 free(pGVstr);
1110 }
1111 if (pSet->ppDescriptors) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001112 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1113 uint32_t i = 0;
1114 for (i=0; i < pSet->descriptorCount; i++) {
1115 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001116 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_VkStructureType(pSet->ppDescriptors[i]->sType));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001117 }
1118 }
1119#define NUM_COLORS 7
1120 vector<string> edgeColors;
1121 edgeColors.push_back("0000ff");
1122 edgeColors.push_back("ff00ff");
1123 edgeColors.push_back("ffff00");
1124 edgeColors.push_back("00ff00");
1125 edgeColors.push_back("000000");
1126 edgeColors.push_back("00ffff");
1127 edgeColors.push_back("ff0000");
1128 uint32_t colorIdx = 0;
1129 fprintf(pOutFile, "</TABLE>>\n];\n");
1130 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001131 VkUpdateSamplers* pUS = NULL;
1132 VkUpdateSamplerTextures* pUST = NULL;
1133 VkUpdateImages* pUI = NULL;
1134 VkUpdateBuffers* pUB = NULL;
1135 VkUpdateAsCopy* pUAC = NULL;
1136 VkSamplerCreateInfo* pSCI = NULL;
1137 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001138 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001139 void** ppNextPtr = NULL;
1140 void* pSaveNext = NULL;
1141 for (i=0; i < pSet->descriptorCount; i++) {
1142 if (pSet->ppDescriptors[i]) {
1143 switch (pSet->ppDescriptors[i]->sType)
1144 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001145 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001146 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001147 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001148 if (pSCI) {
1149 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001150 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001154 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001155 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterf39b3ec2015-04-09 11:43:10 -06001156 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001157 if (pSCI) {
1158 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001159 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001160 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1161 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001162 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001163 if (pIVCI) {
1164 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001165 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001166 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1167 }
1168 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001169 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001170 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001171 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001172 if (pIVCI) {
1173 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001174 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001175 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1176 }
1177 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001178 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001179 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001180 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001181 if (pBVCI) {
1182 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001183 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001184 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1185 }
1186 break;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001187 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001188 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001189 // TODO : Need to validate this code
1190 // Save off pNext and set to NULL while printing this struct, then restore it
1191 ppNextPtr = (void**)&pUAC->pNext;
1192 pSaveNext = *ppNextPtr;
1193 *ppNextPtr = NULL;
1194 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001195 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001196 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1197 // Restore next ptr
1198 *ppNextPtr = pSaveNext;
1199 break;
1200 default:
1201 break;
1202 }
1203 colorIdx = (colorIdx+1) % NUM_COLORS;
1204 }
1205 }
1206 }
1207 fprintf(pOutFile, "}\n");
1208 fprintf(pOutFile, "}\n");
1209 }
1210}
1211// Dump subgraph w/ DS info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001212static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001213{
1214 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1215 if (pCB && pCB->lastBoundDescriptorSet) {
1216 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1217 }
1218}
1219// Dump a GraphViz dot file showing the Cmd Buffers
1220static void cbDumpDotFile(string outFileName)
1221{
1222 // Print CB Chain for each CB
1223 FILE* pOutFile;
1224 pOutFile = fopen(outFileName.c_str(), "w");
1225 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1226 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1227 GLOBAL_CB_NODE* pCB = NULL;
1228 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1229 pCB = g_pLastTouchedCB[i];
David Pinedod8f83d82015-04-27 16:36:17 -06001230 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001231 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1232 uint32_t instNum = 0;
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001233 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1234 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001235 if (instNum) {
1236 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1237 }
1238 if (pCB == g_lastGlobalCB) {
1239 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());
1240 }
1241 else {
1242 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());
1243 }
1244 ++instNum;
1245 }
1246 fprintf(pOutFile, "}\n");
1247 }
1248 }
1249 fprintf(pOutFile, "}\n");
1250 fprintf(pOutFile, "}\n"); // close main graph "g"
1251 fclose(pOutFile);
1252}
1253// Dump a GraphViz dot file showing the pipeline for last bound global state
1254static void dumpGlobalDotFile(char *outFileName)
1255{
1256 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1257 if (pPipeTrav) {
1258 FILE* pOutFile;
1259 pOutFile = fopen(outFileName, "w");
1260 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1261 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1262 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001263 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001264 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001265 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001266 fprintf(pOutFile, "%s", pGVstr);
1267 free(pGVstr);
1268 }
1269 }
1270 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1271 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001272 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001273 fprintf(pOutFile, "%s", pGVstr);
1274 free(pGVstr);
1275 fprintf(pOutFile, "}\n");
1276 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1277 fprintf(pOutFile, "}\n"); // close main graph "g"
1278 fclose(pOutFile);
1279 }
1280}
1281// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001282static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001283{
1284 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1285 if (pCB) {
1286 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1287 if (pPipeTrav) {
1288 FILE* pOutFile;
1289 pOutFile = fopen(outFileName.c_str(), "w");
1290 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1291 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1292 char* pGVstr = NULL;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001293 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001294 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001295 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001296 fprintf(pOutFile, "%s", pGVstr);
1297 free(pGVstr);
1298 }
1299 }
1300 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1301 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001302 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001303 fprintf(pOutFile, "%s", pGVstr);
1304 free(pGVstr);
1305 fprintf(pOutFile, "}\n");
1306 dsDumpDot(cb, pOutFile);
1307 fprintf(pOutFile, "}\n"); // close main graph "g"
1308 fclose(pOutFile);
1309 }
1310 }
1311}
1312// Verify VB Buffer binding
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001313static void validateVBBinding(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001314{
1315 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1316 if (pCB && pCB->lastBoundPipeline) {
1317 // First verify that we have a Node for bound pipeline
1318 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1319 char str[1024];
1320 if (!pPipeTrav) {
1321 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001322 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001323 }
1324 else {
1325 // Verify Vtx binding
1326 if (MAX_BINDING != pCB->lastVtxBinding) {
1327 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1328 if (0 == pPipeTrav->vtxBindingCount) {
1329 sprintf(str, "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001330 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001331 }
1332 else {
1333 sprintf(str, "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001334 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001335 }
1336 }
1337 else {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001338 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001339 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001340 }
1341 }
1342 }
1343 }
1344}
1345// Print details of DS config to stdout
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001346static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001347{
1348 char tmp_str[1024];
1349 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.
1350 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1351 if (pCB) {
1352 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001353 POOL_NODE* pPool = getPoolNode(pSet->pool);
1354 // Print out pool details
1355 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001356 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001357 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis793ad302015-04-03 12:01:11 -06001358 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001359 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001360 // Print out set details
1361 char prefix[10];
1362 uint32_t index = 0;
1363 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001364 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001365 LAYOUT_NODE* pLayout = pSet->pLayout;
1366 // Print layout details
1367 sprintf(tmp_str, "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001368 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001369 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001370 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis793ad302015-04-03 12:01:11 -06001371 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001372 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001373 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001374 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1375 if (pUpdate) {
1376 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001377 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001378 sprintf(prefix, " [UC] ");
1379 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001380 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001381 // TODO : If there is a "view" associated with this update, print CI for that view
1382 }
1383 else {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001384 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1385 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001386 }
1387 }
1388}
1389
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001390static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001391{
1392 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001393 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001394 char str[1024];
1395 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001396 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001397 vector<CMD_NODE*> pCmds = pCB->pCmds;
1398 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001399 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001400 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001401 }
1402 }
1403 else {
1404 // Nothing to print
1405 }
1406}
1407
1408
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001409static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001410{
1411 printDSConfig(cb);
1412 printPipeline(cb);
1413 printDynamicState(cb);
1414 static int autoDumpOnce = 0;
1415 if (autoDumpOnce) {
1416 autoDumpOnce = 0;
1417 dumpDotFile(cb, "pipeline_dump.dot");
1418 cbDumpDotFile("cb_dump.dot");
1419#if defined(_WIN32)
1420// FIXME: NEED WINDOWS EQUIVALENT
1421#else // WIN32
1422 // Convert dot to svg if dot available
1423 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbourf20f87b2015-04-22 09:02:32 -06001424 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1425 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001426 }
1427#endif // WIN32
1428 }
1429}
1430
1431static void initDrawState(void)
1432{
1433 const char *strOpt;
1434 // initialize DrawState options
1435 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1436 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1437
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001438 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001439 {
1440 strOpt = getLayerOption("DrawStateLogFilename");
1441 if (strOpt)
1442 {
1443 g_logFile = fopen(strOpt, "w");
1444 }
1445 if (g_logFile == NULL)
1446 g_logFile = stdout;
1447 }
1448 // initialize Layer dispatch table
1449 // TODO handle multiple GPUs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001450 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001451 fpNextGPA = pCurObj->pGPA;
1452 assert(fpNextGPA);
1453
Tony Barbourd1c35722015-04-16 15:59:00 -06001454 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001455
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001456 if (!globalLockInitialized)
1457 {
1458 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001459 // suggestion is to call this during vkCreateInstance(), and then we
1460 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001461 // that the layer have per-instance locks. We need to come back and
1462 // address this soon.
1463 loader_platform_thread_create_mutex(&globalLock);
1464 globalLockInitialized = 1;
1465 }
1466}
1467
Tony Barbourd1c35722015-04-16 15:59:00 -06001468VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001469{
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001470 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001471 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001472 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001473 return result;
1474}
1475
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001476VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001477{
1478 // Free all the memory
1479 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001480 deletePipelines();
1481 deleteSamplers();
1482 deleteImages();
1483 deleteBuffers();
1484 deleteCmdBuffers();
1485 deleteDynamicState();
1486 deletePools();
1487 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001488 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001489 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001490 return result;
1491}
1492
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001493struct extProps {
1494 uint32_t version;
1495 const char * const name;
1496};
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001497#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001498static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1499 // TODO what is the version?
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001500 0x10, "DrawState",
1501 0x10, "Validation",
1502 0x10, "drawStateDumpDotFile",
1503 0x10, "drawStateDumpCommandBufferDotFile",
1504 0x10, "drawStateDumpPngFile"
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001505};
1506
1507VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1508 VkExtensionInfoType infoType,
1509 uint32_t extensionIndex,
1510 size_t* pDataSize,
1511 void* pData)
1512{
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001513 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1514 VkExtensionProperties *ext_props;
1515 uint32_t *count;
1516
1517 if (pDataSize == NULL)
1518 return VK_ERROR_INVALID_POINTER;
1519
1520 switch (infoType) {
1521 case VK_EXTENSION_INFO_TYPE_COUNT:
1522 *pDataSize = sizeof(uint32_t);
1523 if (pData == NULL)
1524 return VK_SUCCESS;
1525 count = (uint32_t *) pData;
1526 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1527 break;
1528 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1529 *pDataSize = sizeof(VkExtensionProperties);
1530 if (pData == NULL)
1531 return VK_SUCCESS;
1532 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1533 return VK_ERROR_INVALID_VALUE;
1534 ext_props = (VkExtensionProperties *) pData;
1535 ext_props->version = dsExts[extensionIndex].version;
1536 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1537 VK_MAX_EXTENSION_NAME);
1538 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1539 break;
1540 default:
1541 return VK_ERROR_INVALID_VALUE;
1542 };
1543
1544 return VK_SUCCESS;
1545}
1546
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001547VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001548{
1549 if (gpu != NULL)
1550 {
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001551 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001552 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001553 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001554 return result;
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001555 } else {
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001556 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001557 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001558 // This layer compatible with all GPUs
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001559 *pLayerCount = 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001560 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001561 return VK_SUCCESS;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001562 }
1563}
1564
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001565VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001566{
1567 for (uint32_t i=0; i < cmdBufferCount; i++) {
1568 // Validate that cmd buffers have been updated
1569 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001570 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001571 return result;
1572}
1573
Mike Stroyanb050c682015-04-17 12:36:38 -06001574VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001575{
1576 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyanb050c682015-04-17 12:36:38 -06001577 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001578 return result;
1579}
1580
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001581VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001582{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001583 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001584 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001585 loader_platform_thread_lock_mutex(&globalLock);
1586 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1587 pNewNode->buffer = *pView;
1588 pNewNode->createInfo = *pCreateInfo;
1589 bufferMap[*pView] = pNewNode;
1590 loader_platform_thread_unlock_mutex(&globalLock);
1591 }
1592 return result;
1593}
1594
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001595VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001596{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001597 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001598 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001599 loader_platform_thread_lock_mutex(&globalLock);
1600 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1601 pNewNode->image = *pView;
1602 pNewNode->createInfo = *pCreateInfo;
1603 imageMap[*pView] = pNewNode;
1604 loader_platform_thread_unlock_mutex(&globalLock);
1605 }
1606 return result;
1607}
1608
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001609static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001610{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001611 // Create LL HEAD for this Pipeline
1612 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001613 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1614 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1615 pPipeNode->pipeline = *pPipeline;
1616 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001617 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001618}
1619
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001620VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001621{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001622 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001623 // Create LL HEAD for this Pipeline
1624 char str[1024];
1625 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001626 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001627
1628 track_pipeline(pCreateInfo, pPipeline);
1629
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001630 return result;
1631}
1632
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001633VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1634 VkDevice device,
1635 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1636 VkPipeline basePipeline,
1637 VkPipeline* pPipeline)
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001638{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001639 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001640 // Create LL HEAD for this Pipeline
1641 char str[1024];
1642 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001643 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001644
1645 track_pipeline(pCreateInfo, pPipeline);
1646
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001647 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn120cfbe2015-04-14 14:12:59 -06001648
1649 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001650}
1651
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001652VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001653{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001654 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001655 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001656 loader_platform_thread_lock_mutex(&globalLock);
1657 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1658 pNewNode->sampler = *pSampler;
1659 pNewNode->createInfo = *pCreateInfo;
1660 sampleMap[*pSampler] = pNewNode;
1661 loader_platform_thread_unlock_mutex(&globalLock);
1662 }
1663 return result;
1664}
1665
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001666VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001667{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001668 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001669 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001670 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1671 if (NULL == pNewNode) {
1672 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001673 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1674 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001675 }
1676 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001677 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1678 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1679 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001680 uint32_t totalCount = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001681 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1682 totalCount += pCreateInfo->pBinding[i].count;
1683 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001684 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1685 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1686 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001687 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001688 }
1689 if (totalCount > 0) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001690 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001691 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001692 uint32_t j = 0;
1693 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1694 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1695 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001696 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001697 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001698 }
1699 }
1700 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001701 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001702 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1703 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001704 // Put new node at Head of global Layer list
1705 loader_platform_thread_lock_mutex(&globalLock);
1706 layoutMap[*pSetLayout] = pNewNode;
1707 loader_platform_thread_unlock_mutex(&globalLock);
1708 }
1709 return result;
1710}
1711
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001712VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001713{
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001714 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001715 if (VK_SUCCESS == result) {
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001716 // TODO : Need to capture the pipeline layout
Tobin Ehlis793ad302015-04-03 12:01:11 -06001717 }
1718 return result;
1719}
1720
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001721VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlis793ad302015-04-03 12:01:11 -06001722{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001723 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001724 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001725 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001726 POOL_NODE* pPoolNode = poolMap.begin()->second;
1727 if (!pPoolNode) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001728 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001729 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001730 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001731 }
1732 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001733 pPoolNode->updateActive = 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001734 }
1735 loader_platform_thread_unlock_mutex(&globalLock);
1736 }
1737 return result;
1738}
1739
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001740VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001741{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001742 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001743 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001744 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001745 POOL_NODE* pPoolNode = poolMap.begin()->second;
1746 if (!pPoolNode) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001747 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001748 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001749 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001750 }
1751 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001752 if (!pPoolNode->updateActive) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001753 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001754 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1755 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_DS_END_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001756 }
1757 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001758 pPoolNode->updateActive = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001759 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001760 pPoolNode->updateActive = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001761 }
1762 loader_platform_thread_unlock_mutex(&globalLock);
1763 }
1764 return result;
1765}
1766
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001767VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001768{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001769 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001770 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001771 // Insert this pool into Global Pool LL at head
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001772 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -06001773 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyanb050c682015-04-17 12:36:38 -06001774 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001775 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001776 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001777 if (NULL == pNewNode) {
1778 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001779 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyanb050c682015-04-17 12:36:38 -06001780 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001781 }
1782 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001783 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001784 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1785 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001786 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001787 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1788 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001789 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1790 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001791 pNewNode->poolUsage = poolUsage;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001792 pNewNode->updateActive = 0;
1793 pNewNode->maxSets = maxSets;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001794 pNewNode->pool = *pDescriptorPool;
1795 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001796 }
1797 loader_platform_thread_unlock_mutex(&globalLock);
1798 }
1799 else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001800 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001801 }
1802 return result;
1803}
1804
Mike Stroyanb050c682015-04-17 12:36:38 -06001805VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001806{
Mike Stroyanb050c682015-04-17 12:36:38 -06001807 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001808 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001809 clearDescriptorPool(descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001810 }
1811 return result;
1812}
1813
Mike Stroyanb050c682015-04-17 12:36:38 -06001814VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001815{
Mike Stroyanb050c682015-04-17 12:36:38 -06001816 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001817 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001818 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1819 if (!pPoolNode) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001820 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001821 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1822 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001823 }
1824 else {
1825 for (uint32_t i = 0; i < *pCount; i++) {
1826 char str[1024];
1827 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001828 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001829 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001830 SET_NODE* pNewNode = new SET_NODE;
1831 if (NULL == pNewNode) {
1832 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001833 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1834 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001835 }
1836 else {
1837 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001838 // Insert set at head of Set LL for this pool
1839 pNewNode->pNext = pPoolNode->pSets;
1840 pPoolNode->pSets = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001841 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1842 if (NULL == pLayout) {
1843 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001844 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1845 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001846 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001847 pNewNode->pLayout = pLayout;
1848 pNewNode->pool = descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001849 pNewNode->set = pDescriptorSets[i];
1850 pNewNode->setUsage = setUsage;
1851 pNewNode->descriptorCount = pLayout->endIndex + 1;
1852 if (pNewNode->descriptorCount) {
1853 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1854 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1855 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1856 }
1857 setMap[pDescriptorSets[i]] = pNewNode;
1858 }
1859 }
1860 }
1861 }
1862 return result;
1863}
1864
Mike Stroyanb050c682015-04-17 12:36:38 -06001865VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001866{
1867 for (uint32_t i = 0; i < count; i++) {
1868 clearDescriptorSet(pDescriptorSets[i]);
1869 }
Mike Stroyanb050c682015-04-17 12:36:38 -06001870 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001871}
1872
Mike Stroyanb050c682015-04-17 12:36:38 -06001873VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001874{
1875 SET_NODE* pSet = getSetNode(descriptorSet);
1876 if (!dsUpdateActive(descriptorSet)) {
1877 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001878 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1879 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSet->pool, 0, DRAWSTATE_UPDATE_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001880 }
1881 else {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001882 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlis793ad302015-04-03 12:01:11 -06001883 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001884 }
1885
Mike Stroyanb050c682015-04-17 12:36:38 -06001886 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001887}
1888
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001889VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001890{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001891 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001892 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001893 return result;
1894}
1895
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001896VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001897{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001898 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001899 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001900 return result;
1901}
1902
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001903VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001904{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001905 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001906 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001907 return result;
1908}
1909
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001910VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001911{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001912 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbourd1c35722015-04-16 15:59:00 -06001913 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001914 return result;
1915}
1916
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001917VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001918{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001919 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001920 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001921 loader_platform_thread_lock_mutex(&globalLock);
1922 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1923 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1924 pCB->cmdBuffer = *pCmdBuffer;
1925 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchter18248e62015-03-05 18:09:39 -07001926 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001927 pCB->lastVtxBinding = MAX_BINDING;
1928 cmdBufferMap[*pCmdBuffer] = pCB;
1929 loader_platform_thread_unlock_mutex(&globalLock);
1930 updateCBTracking(*pCmdBuffer);
1931 }
1932 return result;
1933}
1934
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001935VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001936{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001937 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001938 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001939 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1940 if (pCB) {
1941 if (CB_NEW != pCB->state)
1942 resetCB(cmdBuffer);
1943 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001944 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001945 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001946 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06001947 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehliseba312c2015-04-01 08:40:34 -06001948 }
1949 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001950 }
1951 else {
1952 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001953 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1954 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001955 }
1956 updateCBTracking(cmdBuffer);
1957 }
1958 return result;
1959}
1960
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001961VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001962{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001963 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001964 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001965 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1966 if (pCB) {
1967 pCB->state = CB_UPDATE_COMPLETE;
1968 printCB(cmdBuffer);
1969 }
1970 else {
1971 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001972 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1973 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001974 }
1975 updateCBTracking(cmdBuffer);
1976 //cbDumpDotFile("cb_dump.dot");
1977 }
1978 return result;
1979}
1980
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001981VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001982{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001983 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001984 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001985 resetCB(cmdBuffer);
1986 updateCBTracking(cmdBuffer);
1987 }
1988 return result;
1989}
1990
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001991VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001992{
1993 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1994 if (pCB) {
1995 updateCBTracking(cmdBuffer);
1996 addCmd(pCB, CMD_BINDPIPELINE);
1997 PIPELINE_NODE* pPN = getPipeline(pipeline);
1998 if (pPN) {
1999 pCB->lastBoundPipeline = pipeline;
2000 loader_platform_thread_lock_mutex(&globalLock);
2001 g_lastBoundPipeline = pPN;
2002 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002003 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002004 }
2005 else {
2006 char str[1024];
2007 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002008 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002009 }
2010 }
2011 else {
2012 char str[1024];
2013 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002014 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002015 }
2016 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2017}
2018
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002019VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002020{
2021 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
2022 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2023}
2024
Cody Northropd4c1a502015-04-16 13:41:56 -06002025VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002026{
2027 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2028 if (pCB) {
2029 updateCBTracking(cmdBuffer);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002030 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Cody Northropd4c1a502015-04-16 13:41:56 -06002031 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06002032 if (getSetNode(pDescriptorSets[i])) {
2033 if (dsUpdateActive(pDescriptorSets[i])) {
2034 // TODO : This check here needs to be made at QueueSubmit time
2035 /*
2036 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002037 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
2038 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_BINDING_DS_NO_END_UPDATE, "DS", str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002039 */
2040 }
2041 loader_platform_thread_lock_mutex(&globalLock);
2042 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2043 g_lastBoundDescriptorSet = pDescriptorSets[i];
2044 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002045 char str[1024];
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002046 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002047 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002048 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002049 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06002050 else {
2051 char str[1024];
2052 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002053 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002054 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002055 }
2056 }
2057 else {
2058 char str[1024];
2059 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002060 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002061 }
Cody Northropd4c1a502015-04-16 13:41:56 -06002062 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002063}
2064
Tony Barbourd1c35722015-04-16 15:59:00 -06002065VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002066{
2067 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2068 if (pCB) {
2069 updateCBTracking(cmdBuffer);
2070 addCmd(pCB, CMD_BINDINDEXBUFFER);
2071 // TODO : Track idxBuffer binding
2072 }
2073 else {
2074 char str[1024];
2075 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002076 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002077 }
2078 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2079}
2080
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002081VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2082 VkCmdBuffer cmdBuffer,
2083 uint32_t startBinding,
2084 uint32_t bindingCount,
2085 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002086 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002087{
2088 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2089 if (pCB) {
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002090 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002091 updateCBTracking(cmdBuffer);
2092 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002093 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002094 validateVBBinding(cmdBuffer);
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002095 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002096 char str[1024];
2097 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002098 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002099 }
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002100 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002101}
2102
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002103VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002104{
2105 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2106 if (pCB) {
2107 updateCBTracking(cmdBuffer);
2108 addCmd(pCB, CMD_DRAW);
2109 pCB->drawCount[DRAW]++;
2110 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002111 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2112 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002113 synchAndPrintDSConfig(cmdBuffer);
2114 }
2115 else {
2116 char str[1024];
2117 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002118 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002119 }
2120 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2121}
2122
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002123VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002124{
2125 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2126 if (pCB) {
2127 updateCBTracking(cmdBuffer);
2128 addCmd(pCB, CMD_DRAWINDEXED);
2129 pCB->drawCount[DRAW_INDEXED]++;
2130 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002131 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2132 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002133 synchAndPrintDSConfig(cmdBuffer);
2134 }
2135 else {
2136 char str[1024];
2137 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002138 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002139 }
2140 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2141}
2142
Tony Barbourd1c35722015-04-16 15:59:00 -06002143VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002144{
2145 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2146 if (pCB) {
2147 updateCBTracking(cmdBuffer);
2148 addCmd(pCB, CMD_DRAWINDIRECT);
2149 pCB->drawCount[DRAW_INDIRECT]++;
2150 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002151 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2152 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002153 synchAndPrintDSConfig(cmdBuffer);
2154 }
2155 else {
2156 char str[1024];
2157 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002158 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002159 }
2160 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2161}
2162
Tony Barbourd1c35722015-04-16 15:59:00 -06002163VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002164{
2165 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2166 if (pCB) {
2167 updateCBTracking(cmdBuffer);
2168 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2169 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2170 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002171 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2172 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002173 synchAndPrintDSConfig(cmdBuffer);
2174 }
2175 else {
2176 char str[1024];
2177 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002178 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002179 }
2180 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2181}
2182
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002183VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002184{
2185 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2186 if (pCB) {
2187 updateCBTracking(cmdBuffer);
2188 addCmd(pCB, CMD_DISPATCH);
2189 }
2190 else {
2191 char str[1024];
2192 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002193 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002194 }
2195 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2196}
2197
Tony Barbourd1c35722015-04-16 15:59:00 -06002198VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002199{
2200 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2201 if (pCB) {
2202 updateCBTracking(cmdBuffer);
2203 addCmd(pCB, CMD_DISPATCHINDIRECT);
2204 }
2205 else {
2206 char str[1024];
2207 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002208 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002209 }
2210 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2211}
2212
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002213VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002214{
2215 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2216 if (pCB) {
2217 updateCBTracking(cmdBuffer);
2218 addCmd(pCB, CMD_COPYBUFFER);
2219 }
2220 else {
2221 char str[1024];
2222 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002223 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002224 }
2225 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2226}
2227
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002228VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2229 VkImage srcImage,
2230 VkImageLayout srcImageLayout,
2231 VkImage destImage,
2232 VkImageLayout destImageLayout,
2233 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002234{
2235 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2236 if (pCB) {
2237 updateCBTracking(cmdBuffer);
2238 addCmd(pCB, CMD_COPYIMAGE);
2239 }
2240 else {
2241 char str[1024];
2242 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002243 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002244 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002245 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002246}
2247
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002248VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2249 VkImage srcImage, VkImageLayout srcImageLayout,
2250 VkImage destImage, VkImageLayout destImageLayout,
2251 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002252{
2253 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2254 if (pCB) {
2255 updateCBTracking(cmdBuffer);
Tobin Ehlis793ad302015-04-03 12:01:11 -06002256 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002257 }
2258 else {
2259 char str[1024];
2260 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002261 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002262 }
2263 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2264}
2265
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002266VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2267 VkBuffer srcBuffer,
2268 VkImage destImage, VkImageLayout destImageLayout,
2269 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002270{
2271 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2272 if (pCB) {
2273 updateCBTracking(cmdBuffer);
2274 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2275 }
2276 else {
2277 char str[1024];
2278 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002279 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002280 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002281 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002282}
2283
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002284VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2285 VkImage srcImage, VkImageLayout srcImageLayout,
2286 VkBuffer destBuffer,
2287 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002288{
2289 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2290 if (pCB) {
2291 updateCBTracking(cmdBuffer);
2292 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2293 }
2294 else {
2295 char str[1024];
2296 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002297 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002298 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002299 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002300}
2301
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002302VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002303{
2304 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2305 if (pCB) {
2306 updateCBTracking(cmdBuffer);
2307 addCmd(pCB, CMD_CLONEIMAGEDATA);
2308 }
2309 else {
2310 char str[1024];
2311 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002312 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002313 }
2314 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2315}
2316
Tony Barbourd1c35722015-04-16 15:59:00 -06002317VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002318{
2319 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2320 if (pCB) {
2321 updateCBTracking(cmdBuffer);
2322 addCmd(pCB, CMD_UPDATEBUFFER);
2323 }
2324 else {
2325 char str[1024];
2326 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002327 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002328 }
2329 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2330}
2331
Tony Barbourd1c35722015-04-16 15:59:00 -06002332VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002333{
2334 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2335 if (pCB) {
2336 updateCBTracking(cmdBuffer);
2337 addCmd(pCB, CMD_FILLBUFFER);
2338 }
2339 else {
2340 char str[1024];
2341 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002342 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002343 }
2344 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2345}
2346
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002347VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2348 VkCmdBuffer cmdBuffer,
2349 VkImage image, VkImageLayout imageLayout,
2350 const VkClearColor *pColor,
2351 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002352{
2353 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2354 if (pCB) {
2355 updateCBTracking(cmdBuffer);
2356 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2357 }
2358 else {
2359 char str[1024];
2360 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002361 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002362 }
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002363 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002364}
2365
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002366VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2367 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002368 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002369 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002370{
2371 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2372 if (pCB) {
2373 updateCBTracking(cmdBuffer);
2374 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2375 }
2376 else {
2377 char str[1024];
2378 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002379 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002380 }
Courtney Goeltzenleuchtera1c9f7a2015-04-13 16:16:56 -06002381 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002382}
2383
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002384VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2385 VkImage srcImage, VkImageLayout srcImageLayout,
2386 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002387 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002388{
2389 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2390 if (pCB) {
2391 updateCBTracking(cmdBuffer);
2392 addCmd(pCB, CMD_RESOLVEIMAGE);
2393 }
2394 else {
2395 char str[1024];
2396 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002397 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002398 }
Tony Barbour6865d4a2015-04-13 15:02:52 -06002399 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002400}
2401
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002402VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002403{
2404 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2405 if (pCB) {
2406 updateCBTracking(cmdBuffer);
2407 addCmd(pCB, CMD_SETEVENT);
2408 }
2409 else {
2410 char str[1024];
2411 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002412 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002413 }
2414 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2415}
2416
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002417VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002418{
2419 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2420 if (pCB) {
2421 updateCBTracking(cmdBuffer);
2422 addCmd(pCB, CMD_RESETEVENT);
2423 }
2424 else {
2425 char str[1024];
2426 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002427 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002428 }
Courtney Goeltzenleuchter1e8f3be2015-03-24 18:02:34 -06002429 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002430}
2431
Tony Barbourd1c35722015-04-16 15:59:00 -06002432VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t eventCount, const VkEvent* pEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002433{
2434 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2435 if (pCB) {
2436 updateCBTracking(cmdBuffer);
2437 addCmd(pCB, CMD_WAITEVENTS);
2438 }
2439 else {
2440 char str[1024];
2441 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002442 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002443 }
Tony Barbourd1c35722015-04-16 15:59:00 -06002444 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002445}
2446
Tony Barbourd1c35722015-04-16 15:59:00 -06002447VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002448{
2449 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2450 if (pCB) {
2451 updateCBTracking(cmdBuffer);
2452 addCmd(pCB, CMD_PIPELINEBARRIER);
2453 }
2454 else {
2455 char str[1024];
2456 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002457 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002458 }
Tony Barbourd1c35722015-04-16 15:59:00 -06002459 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002460}
2461
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002462VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002463{
2464 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2465 if (pCB) {
2466 updateCBTracking(cmdBuffer);
2467 addCmd(pCB, CMD_BEGINQUERY);
2468 }
2469 else {
2470 char str[1024];
2471 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002472 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002473 }
2474 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2475}
2476
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002477VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002478{
2479 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2480 if (pCB) {
2481 updateCBTracking(cmdBuffer);
2482 addCmd(pCB, CMD_ENDQUERY);
2483 }
2484 else {
2485 char str[1024];
2486 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002487 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002488 }
2489 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2490}
2491
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002492VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002493{
2494 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2495 if (pCB) {
2496 updateCBTracking(cmdBuffer);
2497 addCmd(pCB, CMD_RESETQUERYPOOL);
2498 }
2499 else {
2500 char str[1024];
2501 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002502 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002503 }
2504 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2505}
2506
Tony Barbourd1c35722015-04-16 15:59:00 -06002507VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002508{
2509 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2510 if (pCB) {
2511 updateCBTracking(cmdBuffer);
2512 addCmd(pCB, CMD_WRITETIMESTAMP);
2513 }
2514 else {
2515 char str[1024];
2516 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002517 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002518 }
2519 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2520}
2521
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002522VK_LAYER_EXPORT void VKAPI vkCmdInitAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002523{
2524 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2525 if (pCB) {
2526 updateCBTracking(cmdBuffer);
2527 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2528 }
2529 else {
2530 char str[1024];
2531 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002532 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002533 }
2534 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2535}
2536
Tony Barbourd1c35722015-04-16 15:59:00 -06002537VK_LAYER_EXPORT void VKAPI vkCmdLoadAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer srcBuffer, VkDeviceSize srcOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002538{
2539 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2540 if (pCB) {
2541 updateCBTracking(cmdBuffer);
2542 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2543 }
2544 else {
2545 char str[1024];
2546 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002547 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002548 }
2549 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2550}
2551
Tony Barbourd1c35722015-04-16 15:59:00 -06002552VK_LAYER_EXPORT void VKAPI vkCmdSaveAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002553{
2554 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2555 if (pCB) {
2556 updateCBTracking(cmdBuffer);
2557 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2558 }
2559 else {
2560 char str[1024];
2561 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002562 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002563 }
2564 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2565}
2566
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002567VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002568{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002569 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002570 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002571 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002572 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002573 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002574 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2575 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002576 }
2577 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002578 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2579 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002580 }
2581 frameBufferMap[*pFramebuffer] = localFBCI;
2582 }
2583 return result;
2584}
2585
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002586VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002587{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002588 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002589 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002590 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002591 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002592 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002593 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2594 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002595 }
2596 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002597 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2598 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002599 }
2600 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002601 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2602 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002603 }
2604 renderPassMap[*pRenderPass] = localRPCI;
2605 }
2606 return result;
2607}
2608
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002609VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002610{
2611 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2612 if (pCB) {
2613 updateCBTracking(cmdBuffer);
2614 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002615 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2616 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourbadda992015-04-06 11:09:26 -06002617 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002618 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourbadda992015-04-06 11:09:26 -06002619 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002620 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002621 char str[1024];
2622 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002623 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002624 }
Courtney Goeltzenleuchter69894b72015-04-03 15:25:24 -06002625 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002626}
2627
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002628VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002629{
2630 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2631 if (pCB) {
2632 updateCBTracking(cmdBuffer);
2633 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehliseba312c2015-04-01 08:40:34 -06002634 pCB->activeRenderPass = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002635 }
2636 else {
2637 char str[1024];
2638 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002639 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002640 }
2641 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2642}
2643
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002644VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002645{
2646 // This layer intercepts callbacks
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002647 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002648 if (!pNewDbgFuncNode)
Tony Barbourd1c35722015-04-16 15:59:00 -06002649 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002650 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2651 pNewDbgFuncNode->pUserData = pUserData;
2652 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2653 g_pDbgFunctionHead = pNewDbgFuncNode;
2654 // force callbacks if DebugAction hasn't been set already other than initial value
2655 if (g_actionIsDefault) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002656 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002657 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002658 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002659 return result;
2660}
2661
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002662VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002663{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002664 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2665 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002666 while (pTrav) {
2667 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2668 pPrev->pNext = pTrav->pNext;
2669 if (g_pDbgFunctionHead == pTrav)
2670 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06002671 delete pTrav;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002672 break;
2673 }
2674 pPrev = pTrav;
2675 pTrav = pTrav->pNext;
2676 }
2677 if (g_pDbgFunctionHead == NULL)
2678 {
2679 if (g_actionIsDefault)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002680 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002681 else
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002682 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002683 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002684 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002685 return result;
2686}
2687
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002688VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002689{
2690 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2691 if (pCB) {
2692 updateCBTracking(cmdBuffer);
2693 addCmd(pCB, CMD_DBGMARKERBEGIN);
2694 }
2695 else {
2696 char str[1024];
2697 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002698 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002699 }
2700 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2701}
2702
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002703VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002704{
2705 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2706 if (pCB) {
2707 updateCBTracking(cmdBuffer);
2708 addCmd(pCB, CMD_DBGMARKEREND);
2709 }
2710 else {
2711 char str[1024];
2712 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002713 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002714 }
2715 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2716}
2717
2718// TODO : Want to pass in a cmdBuffer here based on which state to display
2719void drawStateDumpDotFile(char* outFileName)
2720{
2721 // TODO : Currently just setting cmdBuffer based on global var
2722 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2723 dumpGlobalDotFile(outFileName);
2724}
2725
2726void drawStateDumpCommandBufferDotFile(char* outFileName)
2727{
2728 cbDumpDotFile(outFileName);
2729}
2730
2731void drawStateDumpPngFile(char* outFileName)
2732{
2733#if defined(_WIN32)
2734// FIXME: NEED WINDOWS EQUIVALENT
2735 char str[1024];
2736 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002737 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002738#else // WIN32
2739 char dotExe[32] = "/usr/bin/dot";
2740 if( access(dotExe, X_OK) != -1) {
2741 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2742 char dotCmd[1024];
2743 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbourf20f87b2015-04-22 09:02:32 -06002744 int retval = system(dotCmd);
2745 assert(retval != -1);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002746 remove("/tmp/tmp.dot");
2747 }
2748 else {
2749 char str[1024];
2750 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002751 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002752 }
2753#endif // WIN32
2754}
2755
Tony Barbourd1c35722015-04-16 15:59:00 -06002756VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002757{
Jon Ashburnbacb0f52015-04-06 10:58:22 -06002758 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002759
2760 if (gpu == NULL)
2761 return NULL;
2762 pCurObj = gpuw;
2763 loader_platform_thread_once(&g_initOnce, initDrawState);
2764
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002765 if (!strcmp(funcName, "vkGetProcAddr"))
2766 return (void *) vkGetProcAddr;
2767 if (!strcmp(funcName, "vkCreateDevice"))
2768 return (void*) vkCreateDevice;
2769 if (!strcmp(funcName, "vkDestroyDevice"))
2770 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002771 if (!strcmp(funcName, "vkEnumerateLayers"))
2772 return (void*) vkEnumerateLayers;
2773 if (!strcmp(funcName, "vkQueueSubmit"))
2774 return (void*) vkQueueSubmit;
2775 if (!strcmp(funcName, "vkDestroyObject"))
2776 return (void*) vkDestroyObject;
2777 if (!strcmp(funcName, "vkCreateBufferView"))
2778 return (void*) vkCreateBufferView;
2779 if (!strcmp(funcName, "vkCreateImageView"))
2780 return (void*) vkCreateImageView;
2781 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2782 return (void*) vkCreateGraphicsPipeline;
2783 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2784 return (void*) vkCreateGraphicsPipelineDerivative;
2785 if (!strcmp(funcName, "vkCreateSampler"))
2786 return (void*) vkCreateSampler;
2787 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2788 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05002789 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2790 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002791 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2792 return (void*) vkBeginDescriptorPoolUpdate;
2793 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2794 return (void*) vkEndDescriptorPoolUpdate;
2795 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2796 return (void*) vkCreateDescriptorPool;
2797 if (!strcmp(funcName, "vkResetDescriptorPool"))
2798 return (void*) vkResetDescriptorPool;
2799 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2800 return (void*) vkAllocDescriptorSets;
2801 if (!strcmp(funcName, "vkClearDescriptorSets"))
2802 return (void*) vkClearDescriptorSets;
2803 if (!strcmp(funcName, "vkUpdateDescriptors"))
2804 return (void*) vkUpdateDescriptors;
2805 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2806 return (void*) vkCreateDynamicViewportState;
2807 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2808 return (void*) vkCreateDynamicRasterState;
2809 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2810 return (void*) vkCreateDynamicColorBlendState;
2811 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2812 return (void*) vkCreateDynamicDepthStencilState;
2813 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2814 return (void*) vkCreateCommandBuffer;
2815 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2816 return (void*) vkBeginCommandBuffer;
2817 if (!strcmp(funcName, "vkEndCommandBuffer"))
2818 return (void*) vkEndCommandBuffer;
2819 if (!strcmp(funcName, "vkResetCommandBuffer"))
2820 return (void*) vkResetCommandBuffer;
2821 if (!strcmp(funcName, "vkCmdBindPipeline"))
2822 return (void*) vkCmdBindPipeline;
2823 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2824 return (void*) vkCmdBindDynamicStateObject;
2825 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2826 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002827 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2828 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002829 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2830 return (void*) vkCmdBindIndexBuffer;
2831 if (!strcmp(funcName, "vkCmdDraw"))
2832 return (void*) vkCmdDraw;
2833 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2834 return (void*) vkCmdDrawIndexed;
2835 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2836 return (void*) vkCmdDrawIndirect;
2837 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2838 return (void*) vkCmdDrawIndexedIndirect;
2839 if (!strcmp(funcName, "vkCmdDispatch"))
2840 return (void*) vkCmdDispatch;
2841 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2842 return (void*) vkCmdDispatchIndirect;
2843 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2844 return (void*) vkCmdCopyBuffer;
2845 if (!strcmp(funcName, "vkCmdCopyImage"))
2846 return (void*) vkCmdCopyImage;
2847 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2848 return (void*) vkCmdCopyBufferToImage;
2849 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2850 return (void*) vkCmdCopyImageToBuffer;
2851 if (!strcmp(funcName, "vkCmdCloneImageData"))
2852 return (void*) vkCmdCloneImageData;
2853 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2854 return (void*) vkCmdUpdateBuffer;
2855 if (!strcmp(funcName, "vkCmdFillBuffer"))
2856 return (void*) vkCmdFillBuffer;
2857 if (!strcmp(funcName, "vkCmdClearColorImage"))
2858 return (void*) vkCmdClearColorImage;
2859 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2860 return (void*) vkCmdClearDepthStencil;
2861 if (!strcmp(funcName, "vkCmdResolveImage"))
2862 return (void*) vkCmdResolveImage;
2863 if (!strcmp(funcName, "vkCmdSetEvent"))
2864 return (void*) vkCmdSetEvent;
2865 if (!strcmp(funcName, "vkCmdResetEvent"))
2866 return (void*) vkCmdResetEvent;
2867 if (!strcmp(funcName, "vkCmdWaitEvents"))
2868 return (void*) vkCmdWaitEvents;
2869 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2870 return (void*) vkCmdPipelineBarrier;
2871 if (!strcmp(funcName, "vkCmdBeginQuery"))
2872 return (void*) vkCmdBeginQuery;
2873 if (!strcmp(funcName, "vkCmdEndQuery"))
2874 return (void*) vkCmdEndQuery;
2875 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2876 return (void*) vkCmdResetQueryPool;
2877 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2878 return (void*) vkCmdWriteTimestamp;
2879 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2880 return (void*) vkCmdInitAtomicCounters;
2881 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2882 return (void*) vkCmdLoadAtomicCounters;
2883 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2884 return (void*) vkCmdSaveAtomicCounters;
2885 if (!strcmp(funcName, "vkCreateFramebuffer"))
2886 return (void*) vkCreateFramebuffer;
2887 if (!strcmp(funcName, "vkCreateRenderPass"))
2888 return (void*) vkCreateRenderPass;
2889 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2890 return (void*) vkCmdBeginRenderPass;
2891 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2892 return (void*) vkCmdEndRenderPass;
2893 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2894 return (void*) vkDbgRegisterMsgCallback;
2895 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2896 return (void*) vkDbgUnregisterMsgCallback;
2897 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2898 return (void*) vkCmdDbgMarkerBegin;
2899 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2900 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002901 if (!strcmp("drawStateDumpDotFile", funcName))
2902 return (void*) drawStateDumpDotFile;
2903 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2904 return (void*) drawStateDumpCommandBufferDotFile;
2905 if (!strcmp("drawStateDumpPngFile", funcName))
2906 return (void*) drawStateDumpPngFile;
2907 else {
2908 if (gpuw->pGPA == NULL)
2909 return NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -06002910 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002911 }
2912}