blob: 20ccd701aa74fde899c2c9f56d7c8a410493b2d9 [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
30#include "loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060036#include "vk_struct_graphviz_helper.h"
Tony Barboura938abb2015-04-22 11:36:22 -060037#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060038#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060039#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060040#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060041#include "draw_state.h"
42#include "layers_config.h"
43// The following is #included again to catch certain OS-specific functions
44// being used:
45#include "loader_platform.h"
46#include "layers_msg.h"
47
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060048unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
49unordered_map<VkImageView, IMAGE_NODE*> imageMap;
50unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
51unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
52unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
53unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
54unordered_map<VkDescriptorSet, SET_NODE*> setMap;
55unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060056// Map for layout chains
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060057unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
58unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
59unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060060
Jon Ashburn301c5f02015-04-06 10:58:22 -060061static VkLayerDispatchTable nextTable;
62static VkBaseLayerObject *pCurObj;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060063static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
64// TODO : This can be much smarter, using separate locks for separate global data
65static int globalLockInitialized = 0;
66static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060067#define MAX_TID 513
68static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
69static uint32_t g_maxTID = 0;
70// Map actual TID to an index value and return that index
71// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
72static uint32_t getTIDIndex() {
73 loader_platform_thread_id tid = loader_platform_get_thread_id();
74 for (uint32_t i = 0; i < g_maxTID; i++) {
75 if (tid == g_tidMapping[i])
76 return i;
77 }
78 // Don't yet have mapping, set it and return newly set index
79 uint32_t retVal = (uint32_t) g_maxTID;
80 g_tidMapping[g_maxTID++] = tid;
81 assert(g_maxTID < MAX_TID);
82 return retVal;
83}
84// Return a string representation of CMD_TYPE enum
85static string cmdTypeToString(CMD_TYPE cmd)
86{
87 switch (cmd)
88 {
89 case CMD_BINDPIPELINE:
90 return "CMD_BINDPIPELINE";
91 case CMD_BINDPIPELINEDELTA:
92 return "CMD_BINDPIPELINEDELTA";
93 case CMD_BINDDYNAMICSTATEOBJECT:
94 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060095 case CMD_BINDDESCRIPTORSETS:
96 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -060097 case CMD_BINDINDEXBUFFER:
98 return "CMD_BINDINDEXBUFFER";
99 case CMD_BINDVERTEXBUFFER:
100 return "CMD_BINDVERTEXBUFFER";
101 case CMD_DRAW:
102 return "CMD_DRAW";
103 case CMD_DRAWINDEXED:
104 return "CMD_DRAWINDEXED";
105 case CMD_DRAWINDIRECT:
106 return "CMD_DRAWINDIRECT";
107 case CMD_DRAWINDEXEDINDIRECT:
108 return "CMD_DRAWINDEXEDINDIRECT";
109 case CMD_DISPATCH:
110 return "CMD_DISPATCH";
111 case CMD_DISPATCHINDIRECT:
112 return "CMD_DISPATCHINDIRECT";
113 case CMD_COPYBUFFER:
114 return "CMD_COPYBUFFER";
115 case CMD_COPYIMAGE:
116 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600117 case CMD_BLITIMAGE:
118 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600119 case CMD_COPYBUFFERTOIMAGE:
120 return "CMD_COPYBUFFERTOIMAGE";
121 case CMD_COPYIMAGETOBUFFER:
122 return "CMD_COPYIMAGETOBUFFER";
123 case CMD_CLONEIMAGEDATA:
124 return "CMD_CLONEIMAGEDATA";
125 case CMD_UPDATEBUFFER:
126 return "CMD_UPDATEBUFFER";
127 case CMD_FILLBUFFER:
128 return "CMD_FILLBUFFER";
129 case CMD_CLEARCOLORIMAGE:
130 return "CMD_CLEARCOLORIMAGE";
131 case CMD_CLEARCOLORIMAGERAW:
132 return "CMD_CLEARCOLORIMAGERAW";
133 case CMD_CLEARDEPTHSTENCIL:
134 return "CMD_CLEARDEPTHSTENCIL";
135 case CMD_RESOLVEIMAGE:
136 return "CMD_RESOLVEIMAGE";
137 case CMD_SETEVENT:
138 return "CMD_SETEVENT";
139 case CMD_RESETEVENT:
140 return "CMD_RESETEVENT";
141 case CMD_WAITEVENTS:
142 return "CMD_WAITEVENTS";
143 case CMD_PIPELINEBARRIER:
144 return "CMD_PIPELINEBARRIER";
145 case CMD_BEGINQUERY:
146 return "CMD_BEGINQUERY";
147 case CMD_ENDQUERY:
148 return "CMD_ENDQUERY";
149 case CMD_RESETQUERYPOOL:
150 return "CMD_RESETQUERYPOOL";
151 case CMD_WRITETIMESTAMP:
152 return "CMD_WRITETIMESTAMP";
153 case CMD_INITATOMICCOUNTERS:
154 return "CMD_INITATOMICCOUNTERS";
155 case CMD_LOADATOMICCOUNTERS:
156 return "CMD_LOADATOMICCOUNTERS";
157 case CMD_SAVEATOMICCOUNTERS:
158 return "CMD_SAVEATOMICCOUNTERS";
159 case CMD_BEGINRENDERPASS:
160 return "CMD_BEGINRENDERPASS";
161 case CMD_ENDRENDERPASS:
162 return "CMD_ENDRENDERPASS";
163 case CMD_DBGMARKERBEGIN:
164 return "CMD_DBGMARKERBEGIN";
165 case CMD_DBGMARKEREND:
166 return "CMD_DBGMARKEREND";
167 default:
168 return "UNKNOWN";
169 }
170}
171// Block of code at start here for managing/tracking Pipeline state that this layer cares about
172// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600173#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600174#define MAX_SLOTS 2048
175#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
176
177static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
178
179// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
180// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
181// to that same cmd buffer by separate thread are not changing state from underneath us
182// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600183static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600184// Track the last group of CBs touched for displaying to dot file
185static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
186static uint32_t g_lastTouchedCBIndex = 0;
187// Track the last global DrawState of interest touched by any thread
188static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
189static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600190static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600191static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600192#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
193
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600194//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600195
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600196static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600197{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600198 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600199 size_t scSize = 0;
200 size_t vpSize = 0;
201 loader_platform_thread_lock_mutex(&globalLock);
202 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
203 pStateNode->stateObj = state;
204 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600205 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600206 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
207 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
208 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
209 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
210 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
211 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600212 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
213 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
214 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600215 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600216 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600217 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600218 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600219 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600220 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600221 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600222 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600223 break;
224 default:
225 assert(0);
226 break;
227 }
228 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
229 dynamicStateMap[state] = pStateNode;
230 loader_platform_thread_unlock_mutex(&globalLock);
231}
232// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600233static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600234{
David Pinedof5997ab2015-04-27 16:36:17 -0600235 if (dynamicStateMap.size() <= 0)
236 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600237 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600238 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis63bb9482015-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 Ehliseaf28662015-04-08 10:58:37 -0600246static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600247{
David Pinedof5997ab2015-04-27 16:36:17 -0600248 if (sampleMap.size() <= 0)
249 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600250 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251 delete (*ii).second;
252 }
253}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600254static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-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 Ehliseaf28662015-04-08 10:58:37 -0600267static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600268{
David Pinedof5997ab2015-04-27 16:36:17 -0600269 if (imageMap.size() <= 0)
270 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600271 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600272 delete (*ii).second;
273 }
274}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600275static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-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 Ehliseaf28662015-04-08 10:58:37 -0600288static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600289{
David Pinedof5997ab2015-04-27 16:36:17 -0600290 if (bufferMap.size() <= 0)
291 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600293 delete (*ii).second;
294 }
295}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600296static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600297
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600298static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-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 Goeltzenleuchter382489d2015-04-10 08:34:15 -0600317static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600323 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600324 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-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 Goeltzenleuchter9cc421e2015-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 Ehlis63bb9482015-03-17 16:24:32 -0600328 break;
329 }
330 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600331 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600332 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600340 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600341 }
342}
343// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600344static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-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 Goeltzenleuchter382489d2015-04-10 08:34:15 -0600356static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-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 Goeltzenleuchter382489d2015-04-10 08:34:15 -0600369static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600370{
371 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600372 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600373 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600374 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600375 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600376 size_t bufferSize = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600377 VkPipelineVertexInputCreateInfo* pVICI = NULL;
378 VkPipelineCbStateCreateInfo* pCBCI = NULL;
379 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600380 while (pTrav) {
381 switch (pTrav->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600382 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600383 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600384 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600385 case VK_SHADER_STAGE_VERTEX:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600386 pPrev->pNext = &pPipeline->vsCI;
387 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600388 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600389 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600391 pPrev->pNext = &pPipeline->tcsCI;
392 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600393 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600394 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600396 pPrev->pNext = &pPipeline->tesCI;
397 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600398 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600399 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600400 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600401 pPrev->pNext = &pPipeline->gsCI;
402 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600403 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600404 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600405 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600406 pPrev->pNext = &pPipeline->fsCI;
407 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600408 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600409 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600410 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600412 break;
413 default:
414 // TODO : Flag error
415 break;
416 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600417 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600419 pPrev->pNext = &pPipeline->vertexInputCI;
420 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600421 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600422 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600423 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600424 pPipeline->vtxBindingCount = pVICI->bindingCount;
425 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchter382489d2015-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 Ehlis63bb9482015-03-17 16:24:32 -0600429 }
430 pPipeline->vtxAttributeCount = pVICI->attributeCount;
431 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchter382489d2015-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 Ehlis63bb9482015-03-17 16:24:32 -0600435 }
436 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600437 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600438 pPrev->pNext = &pPipeline->iaStateCI;
439 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600440 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600441 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600442 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600443 pPrev->pNext = &pPipeline->tessStateCI;
444 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600445 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600446 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600447 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600448 pPrev->pNext = &pPipeline->vpStateCI;
449 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600450 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600451 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600452 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600453 pPrev->pNext = &pPipeline->rsStateCI;
454 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600455 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600456 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600457 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600458 pPrev->pNext = &pPipeline->msStateCI;
459 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600460 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600461 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600462 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600463 pPrev->pNext = &pPipeline->cbStateCI;
464 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600465 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600466 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600467 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600468 pPipeline->attachmentCount = pCBCI->attachmentCount;
469 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchter382489d2015-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 Ehlis63bb9482015-03-17 16:24:32 -0600473 }
474 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600475 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600476 pPrev->pNext = &pPipeline->dsStateCI;
477 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600478 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600479 break;
480 default:
481 assert(0);
482 break;
483 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600484 pTrav = (GENERIC_HEADER*)pTrav->pNext;
485 }
486 pipelineMap[pPipeline->pipeline] = pPipeline;
487}
488// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600489static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600490{
David Pinedof5997ab2015-04-27 16:36:17 -0600491 if (pipelineMap.size() <= 0)
492 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600493 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-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 Ehlis63bb9482015-03-17 16:24:32 -0600502 }
503 delete (*ii).second;
504 }
505}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600506// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600507static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600508{
509 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600510 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600511 if (pPipe->msStateCI.multisampleEnable)
512 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600513 }
514 return 1;
515}
516// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600517static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600518{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600519 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-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 Goeltzenleuchter382489d2015-04-10 08:34:15 -0600523 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
524 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis63826ec2015-05-21 09:06:56 -0600525 if ((psoNumSamples != pFBCI->sampleCount) || (psoNumSamples != pRPCI->sampleCount)) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600526 char str[1024];
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600527 sprintf(str, "Num samples mismatch! Binding PSO (%p) with %u samples while current RenderPass (%p) w/ %u samples uses FB (%p) with %u samples!", (void*)pipeline, psoNumSamples, (void*)pCB->activeRenderPass, pRPCI->sampleCount, (void*)pCB->framebuffer, pFBCI->sampleCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600528 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
Tobin Ehlis2464b882015-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 Ehlis63bb9482015-03-17 16:24:32 -0600540// Block of code at start here specifically for managing/tracking DSs
541
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600542// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600543static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600544{
545 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600546 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600547 loader_platform_thread_unlock_mutex(&globalLock);
548 return NULL;
549 }
550 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600551 return poolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600552}
553// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600554static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600565// Return VK_TRUE if DS Exists and is within an vkBeginDescriptorPoolUpdate() call sequence, otherwise VK_FALSE
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600566static bool32_t dsUpdateActive(VkDescriptorSet ds)
Tobin Ehlis63bb9482015-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 Ehlisdd82f6b2015-04-03 12:01:11 -0600571 POOL_NODE* pPool = getPoolNode(pTrav->pool);
572 if (pPool) {
573 return pPool->updateActive;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600574 }
575 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600576 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600577}
578
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600579static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-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}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600588// Return 1 if update struct is of valid type, 0 otherwise
589static bool32_t validUpdateStruct(const GENERIC_HEADER* pUpdateStruct)
590{
591 char str[1024];
592 switch (pUpdateStruct->sType)
593 {
594 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
595 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
596 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
597 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
598 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
599 return 1;
600 default:
601 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
602 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
603 return 0;
604 }
605}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600606// For given update struct, return binding
607static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600608{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600609 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600610 switch (pUpdateStruct->sType)
611 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600612 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600613 return ((VkUpdateSamplers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600614 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600615 return ((VkUpdateSamplerTextures*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600616 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600617 return ((VkUpdateImages*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600619 return ((VkUpdateBuffers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600620 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600621 return ((VkUpdateAsCopy*)pUpdateStruct)->binding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600622 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600623 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
624 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
625 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600626 }
627}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600628// Return count for given update struct
629static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600630{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600631 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600632 switch (pUpdateStruct->sType)
633 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600634 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600635 return (((VkUpdateSamplers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600636 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600637 return (((VkUpdateSamplerTextures*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600638 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600639 return (((VkUpdateImages*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600640 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600641 return (((VkUpdateBuffers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600642 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600643 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600644 return (((VkUpdateAsCopy*)pUpdateStruct)->arrayElement);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600645 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600646 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
647 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600648 return 0;
649 }
650}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600651// Return count for given update struct
652static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
653{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600654 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600655 switch (pUpdateStruct->sType)
656 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600657 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600658 return (((VkUpdateSamplers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600659 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600660 return (((VkUpdateSamplerTextures*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600661 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600662 return (((VkUpdateImages*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600663 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600664 return (((VkUpdateBuffers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600666 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600667 return (((VkUpdateAsCopy*)pUpdateStruct)->count);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600668 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600669 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
670 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600671 return 0;
672 }
673}
674// For given Layout Node and binding, return index where that binding begins
675static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
676{
677 uint32_t offsetIndex = 0;
678 for (uint32_t i = 0; i<binding; i++) {
679 offsetIndex += pLayout->createInfo.pBinding[i].count;
680 }
681 return offsetIndex;
682}
683// For given layout node and binding, return last index that is updated
684static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
685{
686 uint32_t offsetIndex = 0;
687 for (uint32_t i = 0; i<=binding; i++) {
688 offsetIndex += pLayout->createInfo.pBinding[i].count;
689 }
690 return offsetIndex-1;
691}
692// For given layout and update, return the first overall index of the layout that is update
693static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
694{
695 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
696}
697// For given layout and update, return the last overall index of the layout that is update
698static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
699{
700 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
701}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600702// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600703static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600704{
705 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600706 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600707 uint32_t i = 0;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600708 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600709 switch (pUpdateStruct->sType)
710 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600711 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
712 actualType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600713 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600714 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600715 actualType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600716 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600717 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600718 actualType = ((VkUpdateImages*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600719 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600720 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600721 actualType = ((VkUpdateBuffers*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600722 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600723 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724 actualType = ((VkUpdateAsCopy*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600725 break;
726 default:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600727 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
728 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600729 return 0;
730 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600731 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600732 if (pLayout->pTypes[i] != actualType)
733 return 0;
734 }
735 return 1;
736}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600737// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
738// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
739// NOTE : Calls to this function should be wrapped in mutex
740static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
741{
742 GENERIC_HEADER* pNewNode = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600743 VkUpdateSamplers* pUS = NULL;
744 VkUpdateSamplerTextures* pUST = NULL;
745 VkUpdateBuffers* pUB = NULL;
746 VkUpdateImages* pUI = NULL;
747 VkUpdateAsCopy* pUAC = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600748 size_t array_size = 0;
749 size_t base_array_size = 0;
750 size_t total_array_size = 0;
751 size_t baseBuffAddr = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600752 VkImageViewAttachInfo** ppLocalImageViews = NULL;
753 VkBufferViewAttachInfo** ppLocalBufferViews = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600754 char str[1024];
755 switch (pUpdate->sType)
756 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600757 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600758 pUS = new VkUpdateSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600759 pNewNode = (GENERIC_HEADER*)pUS;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600760 memcpy(pUS, pUpdate, sizeof(VkUpdateSamplers));
761 pUS->pSamplers = new VkSampler[pUS->count];
762 array_size = sizeof(VkSampler) * pUS->count;
763 memcpy((void*)pUS->pSamplers, ((VkUpdateSamplers*)pUpdate)->pSamplers, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600764 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600765 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600766 pUST = new VkUpdateSamplerTextures;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600767 pNewNode = (GENERIC_HEADER*)pUST;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600768 memcpy(pUST, pUpdate, sizeof(VkUpdateSamplerTextures));
769 pUST->pSamplerImageViews = new VkSamplerImageViewInfo[pUST->count];
770 array_size = sizeof(VkSamplerImageViewInfo) * pUST->count;
771 memcpy((void*)pUST->pSamplerImageViews, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews, array_size);
Tobin Ehliseaf28662015-04-08 10:58:37 -0600772 for (uint32_t i = 0; i < pUST->count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600773 VkImageViewAttachInfo** ppIV = (VkImageViewAttachInfo**)&pUST->pSamplerImageViews[i].pImageView;
774 *ppIV = new VkImageViewAttachInfo;
775 memcpy((void*)*ppIV, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews[i].pImageView, sizeof(VkImageViewAttachInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600776 }
777 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600778 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600779 pUI = new VkUpdateImages;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600780 pNewNode = (GENERIC_HEADER*)pUI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600781 memcpy(pUI, pUpdate, sizeof(VkUpdateImages));
782 pUI->pImageViews = new VkImageViewAttachInfo[pUI->count];
783 array_size = (sizeof(VkImageViewAttachInfo) * pUI->count);
784 memcpy((void*)pUI->pImageViews, ((VkUpdateImages*)pUpdate)->pImageViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600785 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600786 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600787 pUB = new VkUpdateBuffers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600788 pNewNode = (GENERIC_HEADER*)pUB;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600789 memcpy(pUB, pUpdate, sizeof(VkUpdateBuffers));
790 pUB->pBufferViews = new VkBufferViewAttachInfo[pUB->count];
791 array_size = (sizeof(VkBufferViewAttachInfo) * pUB->count);
792 memcpy((void*)pUB->pBufferViews, ((VkUpdateBuffers*)pUpdate)->pBufferViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600793 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600794 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600795 pUAC = new VkUpdateAsCopy;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600796 pUpdate = (GENERIC_HEADER*)pUAC;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600797 memcpy(pUAC, pUpdate, sizeof(VkUpdateAsCopy));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600798 break;
799 default:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600800 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600801 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600802 return NULL;
803 }
804 // Make sure that pNext for the end of shadow copy is NULL
805 pNewNode->pNext = NULL;
806 return pNewNode;
807}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600808// For given ds, update its mapping based on ppUpdateArray
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600809static bool32_t dsUpdate(VkDescriptorSet ds, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600810{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600811 bool32_t result = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600812 SET_NODE* pSet = getSetNode(ds);
813 loader_platform_thread_lock_mutex(&globalLock);
814 g_lastBoundDescriptorSet = pSet->set;
815 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600816 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600817 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600818 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600819 for (uint32_t i = 0; i < updateCount; i++) {
820 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*)ppUpdateArray[i];
821 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600822 // First verify valid update struct
823 if (!validUpdateStruct(pUpdate)) {
824 result = 0;
825 break;
826 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600827 // Make sure that binding is within bounds
828 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600830 sprintf(str, "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, getUpdateBinding(pUpdate), string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600831 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600832 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600833 }
834 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600835 // Next verify that update falls within size of given binding
836 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600837 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600838 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600839 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
840 sprintf(str, "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), getUpdateBinding(pUpdate), DSstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600841 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600842 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600843 }
844 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600845 // Layout bindings match w/ update ok, now verify that update is of the right type
846 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600847 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600848 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600849 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600850 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600851 }
852 else {
853 // Save the update info
854 // TODO : Info message that update successful
855 // Create new update struct for this set's shadow copy
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600856 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600857 if (NULL == pNewNode) {
858 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600859 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
860 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600861 result = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600862 }
863 else {
864 // Insert shadow node into LL of updates for this set
865 pNewNode->pNext = pSet->pUpdateStructs;
866 pSet->pUpdateStructs = pNewNode;
867 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600868 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
869 assert(j<pSet->descriptorCount);
870 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600871 }
872 }
873 }
874 }
875 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600876 }
877 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600878 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600879}
880// Free the shadowed update node for this Set
881// NOTE : Calls to this function should be wrapped in mutex
882static void freeShadowUpdateTree(SET_NODE* pSet)
883{
884 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
885 pSet->pUpdateStructs = NULL;
886 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
887 // Clear the descriptor mappings as they will now be invalid
888 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
889 while(pShadowUpdate) {
890 pFreeUpdate = pShadowUpdate;
891 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
892 uint32_t index = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600893 VkUpdateSamplers* pUS = NULL;
894 VkUpdateSamplerTextures* pUST = NULL;
895 VkUpdateImages* pUI = NULL;
896 VkUpdateBuffers* pUB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600897 void** ppToFree = NULL;
898 switch (pFreeUpdate->sType)
899 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600900 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600901 pUS = (VkUpdateSamplers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600902 if (pUS->pSamplers)
903 delete[] pUS->pSamplers;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600904 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600905 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600906 pUST = (VkUpdateSamplerTextures*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600907 if (pUST->pSamplerImageViews) {
908 for (index = 0; index < pUST->count; index++) {
909 if (pUST->pSamplerImageViews[index].pImageView) {
910 delete pUST->pSamplerImageViews[index].pImageView;
911 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600912 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600913 delete[] pUST->pSamplerImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600914 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600915 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600916 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600917 pUI = (VkUpdateImages*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600918 if (pUI->pImageViews)
919 delete[] pUI->pImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600920 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600921 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600922 pUB = (VkUpdateBuffers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600923 if (pUB->pBufferViews)
924 delete[] pUB->pBufferViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600925 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600926 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600927 break;
928 default:
929 assert(0);
930 break;
931 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600932 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600933 }
934}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600935// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600936// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600937static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600938{
David Pinedof5997ab2015-04-27 16:36:17 -0600939 if (poolMap.size() <= 0)
940 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600941 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600942 SET_NODE* pSet = (*ii).second->pSets;
943 SET_NODE* pFreeSet = pSet;
944 while (pSet) {
945 pFreeSet = pSet;
946 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600947 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600948 // Free Update shadow struct tree
949 freeShadowUpdateTree(pFreeSet);
950 if (pFreeSet->ppDescriptors) {
951 delete pFreeSet->ppDescriptors;
952 }
953 delete pFreeSet;
954 }
955 if ((*ii).second->createInfo.pTypeCount) {
956 delete (*ii).second->createInfo.pTypeCount;
957 }
958 delete (*ii).second;
959 }
960}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600961// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600962// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600963static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600964{
David Pinedof5997ab2015-04-27 16:36:17 -0600965 if (layoutMap.size() <= 0)
966 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600967 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600968 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600969 if (pLayout->createInfo.pBinding) {
970 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
971 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
972 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
973 }
974 delete[] pLayout->createInfo.pBinding;
975 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600976 if (pLayout->pTypes) {
977 delete pLayout->pTypes;
978 }
979 delete pLayout;
980 }
981}
982// Currently clearing a set is removing all previous updates to that set
983// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600984static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600985{
986 SET_NODE* pSet = getSetNode(set);
987 if (!pSet) {
988 // TODO : Return error
989 }
990 else {
991 loader_platform_thread_lock_mutex(&globalLock);
992 freeShadowUpdateTree(pSet);
993 loader_platform_thread_unlock_mutex(&globalLock);
994 }
995}
996
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600997static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600998{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600999 POOL_NODE* pPool = getPoolNode(pool);
1000 if (!pPool) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001001 char str[1024];
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001002 sprintf(str, "Unable to find pool node for pool %p specified in vkResetDescriptorPool() call", (void*)pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001003 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001004 }
1005 else
1006 {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001007 // For every set off of this pool, clear it
1008 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001009 while (pSet) {
1010 clearDescriptorSet(pSet->set);
1011 }
1012 }
1013}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001014// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001015static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001016{
1017 loader_platform_thread_lock_mutex(&globalLock);
1018 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1019 loader_platform_thread_unlock_mutex(&globalLock);
1020 return NULL;
1021 }
1022 loader_platform_thread_unlock_mutex(&globalLock);
1023 return cmdBufferMap[cb];
1024}
1025// Free all CB Nodes
1026// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001027static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001028{
David Pinedof5997ab2015-04-27 16:36:17 -06001029 if (cmdBufferMap.size() <= 0)
1030 return;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001031 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001032 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1033 while (!cmd_node_list.empty()) {
1034 CMD_NODE* cmd_node = cmd_node_list.back();
1035 delete cmd_node;
1036 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001037 }
1038 delete (*ii).second;
1039 }
1040}
1041static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1042{
1043 CMD_NODE* pCmd = new CMD_NODE;
1044 if (pCmd) {
1045 // init cmd node and append to end of cmd LL
1046 memset(pCmd, 0, sizeof(CMD_NODE));
1047 pCmd->cmdNumber = ++pCB->numCmds;
1048 pCmd->type = cmd;
1049 pCB->pCmds.push_back(pCmd);
1050 }
1051 else {
1052 char str[1024];
1053 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001054 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001055 }
1056}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001057static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001058{
1059 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1060 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001061 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1062 while (!cmd_list.empty()) {
1063 delete cmd_list.back();
1064 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001065 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001066 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001067 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001068 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001069 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001070 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1071 pCB->cmdBuffer = cb;
1072 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001073 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001074 pCB->lastVtxBinding = MAX_BINDING;
1075 }
1076}
1077// Set the last bound dynamic state of given type
1078// TODO : Need to track this per cmdBuffer and correlate cmdBuffer for Draw w/ last bound for that cmdBuffer?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001079static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001080{
1081 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1082 if (pCB) {
1083 updateCBTracking(cmdBuffer);
1084 loader_platform_thread_lock_mutex(&globalLock);
1085 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1086 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1087 char str[1024];
1088 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001089 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001090 }
1091 else {
1092 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1093 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1094 }
1095 loader_platform_thread_unlock_mutex(&globalLock);
1096 }
1097 else {
1098 char str[1024];
1099 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001100 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001101 }
1102}
1103// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001104static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001105{
1106 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1107 if (pCB) {
1108 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1109 if (!pPipeTrav) {
1110 // nothing to print
1111 }
1112 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001113 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001114 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001115 }
1116 }
1117}
1118// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001119static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001120{
1121 SET_NODE* pSet = getSetNode(ds);
1122 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001123 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001124 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001125 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1126 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001127 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001128 fprintf(pOutFile, "%s", pGVstr);
1129 free(pGVstr);
1130 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1131 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001132 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001133 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001134 ++layout_index;
1135 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001136 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001137 fprintf(pOutFile, "%s", pGVstr);
1138 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001139 if (pSet->pUpdateStructs) {
1140 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1141 fprintf(pOutFile, "%s", pGVstr);
1142 free(pGVstr);
1143 }
1144 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001145 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1146 uint32_t i = 0;
1147 for (i=0; i < pSet->descriptorCount; i++) {
1148 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001149 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_VkStructureType(pSet->ppDescriptors[i]->sType));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001150 }
1151 }
1152#define NUM_COLORS 7
1153 vector<string> edgeColors;
1154 edgeColors.push_back("0000ff");
1155 edgeColors.push_back("ff00ff");
1156 edgeColors.push_back("ffff00");
1157 edgeColors.push_back("00ff00");
1158 edgeColors.push_back("000000");
1159 edgeColors.push_back("00ffff");
1160 edgeColors.push_back("ff0000");
1161 uint32_t colorIdx = 0;
1162 fprintf(pOutFile, "</TABLE>>\n];\n");
1163 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001164 VkUpdateSamplers* pUS = NULL;
1165 VkUpdateSamplerTextures* pUST = NULL;
1166 VkUpdateImages* pUI = NULL;
1167 VkUpdateBuffers* pUB = NULL;
1168 VkUpdateAsCopy* pUAC = NULL;
1169 VkSamplerCreateInfo* pSCI = NULL;
1170 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001171 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001172 void** ppNextPtr = NULL;
1173 void* pSaveNext = NULL;
1174 for (i=0; i < pSet->descriptorCount; i++) {
1175 if (pSet->ppDescriptors[i]) {
1176 switch (pSet->ppDescriptors[i]->sType)
1177 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001178 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001179 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001180 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001181 if (pSCI) {
1182 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001183 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001187 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001188 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001189 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001190 if (pSCI) {
1191 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001192 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001193 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1194 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001195 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001196 if (pIVCI) {
1197 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001198 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001199 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1200 }
1201 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001202 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001203 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001204 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001205 if (pIVCI) {
1206 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001207 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001208 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1209 }
1210 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001211 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001212 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001213 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001214 if (pBVCI) {
1215 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001216 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001217 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1218 }
1219 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001220 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001221 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001222 // TODO : Need to validate this code
1223 // Save off pNext and set to NULL while printing this struct, then restore it
1224 ppNextPtr = (void**)&pUAC->pNext;
1225 pSaveNext = *ppNextPtr;
1226 *ppNextPtr = NULL;
1227 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001228 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001229 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1230 // Restore next ptr
1231 *ppNextPtr = pSaveNext;
1232 break;
1233 default:
1234 break;
1235 }
1236 colorIdx = (colorIdx+1) % NUM_COLORS;
1237 }
1238 }
1239 }
1240 fprintf(pOutFile, "}\n");
1241 fprintf(pOutFile, "}\n");
1242 }
1243}
1244// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001245static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001246{
1247 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1248 if (pCB && pCB->lastBoundDescriptorSet) {
1249 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1250 }
1251}
1252// Dump a GraphViz dot file showing the Cmd Buffers
1253static void cbDumpDotFile(string outFileName)
1254{
1255 // Print CB Chain for each CB
1256 FILE* pOutFile;
1257 pOutFile = fopen(outFileName.c_str(), "w");
1258 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1259 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1260 GLOBAL_CB_NODE* pCB = NULL;
1261 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1262 pCB = g_pLastTouchedCB[i];
David Pinedof5997ab2015-04-27 16:36:17 -06001263 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001264 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1265 uint32_t instNum = 0;
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001266 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1267 for (vector<CMD_NODE*>::iterator ii= cmd_list.begin(); ii!= cmd_list.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001268 if (instNum) {
1269 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1270 }
1271 if (pCB == g_lastGlobalCB) {
1272 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());
1273 }
1274 else {
1275 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());
1276 }
1277 ++instNum;
1278 }
1279 fprintf(pOutFile, "}\n");
1280 }
1281 }
1282 fprintf(pOutFile, "}\n");
1283 fprintf(pOutFile, "}\n"); // close main graph "g"
1284 fclose(pOutFile);
1285}
1286// Dump a GraphViz dot file showing the pipeline for last bound global state
1287static void dumpGlobalDotFile(char *outFileName)
1288{
1289 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1290 if (pPipeTrav) {
1291 FILE* pOutFile;
1292 pOutFile = fopen(outFileName, "w");
1293 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1294 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1295 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001296 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001297 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001298 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001299 fprintf(pOutFile, "%s", pGVstr);
1300 free(pGVstr);
1301 }
1302 }
1303 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1304 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001305 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001306 fprintf(pOutFile, "%s", pGVstr);
1307 free(pGVstr);
1308 fprintf(pOutFile, "}\n");
1309 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1310 fprintf(pOutFile, "}\n"); // close main graph "g"
1311 fclose(pOutFile);
1312 }
1313}
1314// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001315static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001316{
1317 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1318 if (pCB) {
1319 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1320 if (pPipeTrav) {
1321 FILE* pOutFile;
1322 pOutFile = fopen(outFileName.c_str(), "w");
1323 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1324 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1325 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001326 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001327 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001328 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001329 fprintf(pOutFile, "%s", pGVstr);
1330 free(pGVstr);
1331 }
1332 }
1333 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1334 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001335 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001336 fprintf(pOutFile, "%s", pGVstr);
1337 free(pGVstr);
1338 fprintf(pOutFile, "}\n");
1339 dsDumpDot(cb, pOutFile);
1340 fprintf(pOutFile, "}\n"); // close main graph "g"
1341 fclose(pOutFile);
1342 }
1343 }
1344}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001345// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001346static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001347{
1348 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1349 if (pCB && pCB->lastBoundPipeline) {
1350 // First verify that we have a Node for bound pipeline
1351 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1352 char str[1024];
1353 if (!pPipeTrav) {
1354 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001355 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001356 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001357 }
1358 else {
1359 // Verify Vtx binding
1360 if (MAX_BINDING != pCB->lastVtxBinding) {
1361 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1362 if (0 == pPipeTrav->vtxBindingCount) {
1363 sprintf(str, "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001364 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001365 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001366 }
1367 else {
1368 sprintf(str, "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001369 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001370 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001371 }
1372 }
1373 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001374 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001375 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001376 }
1377 }
1378 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001379 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001380 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001381 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001382}
1383// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001384static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001385{
1386 char tmp_str[1024];
1387 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.
1388 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1389 if (pCB) {
1390 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001391 POOL_NODE* pPool = getPoolNode(pSet->pool);
1392 // Print out pool details
1393 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001394 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001395 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001396 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001397 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001398 // Print out set details
1399 char prefix[10];
1400 uint32_t index = 0;
1401 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001402 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001403 LAYOUT_NODE* pLayout = pSet->pLayout;
1404 // Print layout details
1405 sprintf(tmp_str, "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001406 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001407 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001408 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001409 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001410 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001411 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001412 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1413 if (pUpdate) {
1414 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001415 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001416 sprintf(prefix, " [UC] ");
1417 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001418 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001419 // TODO : If there is a "view" associated with this update, print CI for that view
1420 }
1421 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001422 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1423 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001424 }
1425 }
1426}
1427
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001428static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001429{
1430 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001431 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001432 char str[1024];
1433 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001434 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001435 vector<CMD_NODE*> pCmds = pCB->pCmds;
1436 for (vector<CMD_NODE*>::iterator ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001437 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001438 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001439 }
1440 }
1441 else {
1442 // Nothing to print
1443 }
1444}
1445
1446
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001447static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001448{
1449 printDSConfig(cb);
1450 printPipeline(cb);
1451 printDynamicState(cb);
1452 static int autoDumpOnce = 0;
1453 if (autoDumpOnce) {
1454 autoDumpOnce = 0;
1455 dumpDotFile(cb, "pipeline_dump.dot");
1456 cbDumpDotFile("cb_dump.dot");
1457#if defined(_WIN32)
1458// FIXME: NEED WINDOWS EQUIVALENT
1459#else // WIN32
1460 // Convert dot to svg if dot available
1461 if(access( "/usr/bin/dot", X_OK) != -1) {
Tony Barbour22a30862015-04-22 09:02:32 -06001462 int retval = system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1463 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001464 }
1465#endif // WIN32
1466 }
1467}
1468
1469static void initDrawState(void)
1470{
1471 const char *strOpt;
1472 // initialize DrawState options
1473 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1474 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1475
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001476 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001477 {
1478 strOpt = getLayerOption("DrawStateLogFilename");
1479 if (strOpt)
1480 {
1481 g_logFile = fopen(strOpt, "w");
1482 }
1483 if (g_logFile == NULL)
1484 g_logFile = stdout;
1485 }
1486 // initialize Layer dispatch table
1487 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001488 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001489 fpNextGPA = pCurObj->pGPA;
1490 assert(fpNextGPA);
1491
Tony Barbour8205d902015-04-16 15:59:00 -06001492 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001493
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001494 if (!globalLockInitialized)
1495 {
1496 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001497 // suggestion is to call this during vkCreateInstance(), and then we
1498 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001499 // that the layer have per-instance locks. We need to come back and
1500 // address this soon.
1501 loader_platform_thread_create_mutex(&globalLock);
1502 globalLockInitialized = 1;
1503 }
1504}
1505
Tony Barbour8205d902015-04-16 15:59:00 -06001506VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001507{
Jon Ashburn630e44f2015-04-08 21:33:34 -06001508 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001509 loader_platform_thread_once(&g_initOnce, initDrawState);
Jon Ashburn630e44f2015-04-08 21:33:34 -06001510 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001511 return result;
1512}
1513
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001514VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001515{
1516 // Free all the memory
1517 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001518 deletePipelines();
1519 deleteSamplers();
1520 deleteImages();
1521 deleteBuffers();
1522 deleteCmdBuffers();
1523 deleteDynamicState();
1524 deletePools();
1525 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001526 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001527 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001528 return result;
1529}
1530
Jon Ashburneb2728b2015-04-10 14:33:07 -06001531struct extProps {
1532 uint32_t version;
1533 const char * const name;
1534};
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001535#define DRAW_STATE_LAYER_EXT_ARRAY_SIZE 5
Jon Ashburneb2728b2015-04-10 14:33:07 -06001536static const struct extProps dsExts[DRAW_STATE_LAYER_EXT_ARRAY_SIZE] = {
1537 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001538 0x10, "DrawState",
1539 0x10, "Validation",
1540 0x10, "drawStateDumpDotFile",
1541 0x10, "drawStateDumpCommandBufferDotFile",
1542 0x10, "drawStateDumpPngFile"
Jon Ashburneb2728b2015-04-10 14:33:07 -06001543};
1544
1545VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
1546 VkExtensionInfoType infoType,
1547 uint32_t extensionIndex,
1548 size_t* pDataSize,
1549 void* pData)
1550{
Jon Ashburneb2728b2015-04-10 14:33:07 -06001551 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
1552 VkExtensionProperties *ext_props;
1553 uint32_t *count;
1554
1555 if (pDataSize == NULL)
1556 return VK_ERROR_INVALID_POINTER;
1557
1558 switch (infoType) {
1559 case VK_EXTENSION_INFO_TYPE_COUNT:
1560 *pDataSize = sizeof(uint32_t);
1561 if (pData == NULL)
1562 return VK_SUCCESS;
1563 count = (uint32_t *) pData;
1564 *count = DRAW_STATE_LAYER_EXT_ARRAY_SIZE;
1565 break;
1566 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1567 *pDataSize = sizeof(VkExtensionProperties);
1568 if (pData == NULL)
1569 return VK_SUCCESS;
1570 if (extensionIndex >= DRAW_STATE_LAYER_EXT_ARRAY_SIZE)
1571 return VK_ERROR_INVALID_VALUE;
1572 ext_props = (VkExtensionProperties *) pData;
1573 ext_props->version = dsExts[extensionIndex].version;
1574 strncpy(ext_props->extName, dsExts[extensionIndex].name,
1575 VK_MAX_EXTENSION_NAME);
1576 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
1577 break;
1578 default:
1579 return VK_ERROR_INVALID_VALUE;
1580 };
1581
1582 return VK_SUCCESS;
1583}
1584
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001585VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001586{
1587 if (gpu != NULL)
1588 {
Jon Ashburn630e44f2015-04-08 21:33:34 -06001589 pCurObj = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001590 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001591 VkResult result = nextTable.EnumerateLayers(gpu, maxStringSize, pLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001592 return result;
Jon Ashburn630e44f2015-04-08 21:33:34 -06001593 } else {
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001594 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001595 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001596 // This layer compatible with all GPUs
Courtney Goeltzenleuchterbb1f3602015-04-20 11:04:54 -06001597 *pLayerCount = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001598 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001599 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001600 }
1601}
1602
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001603VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001604{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001605 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001606 for (uint32_t i=0; i < cmdBufferCount; i++) {
1607 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001608 pCB = getCBNode(pCmdBuffers[i]);
1609 loader_platform_thread_lock_mutex(&globalLock);
1610 if (CB_UPDATE_COMPLETE != pCB->state) {
1611 // Flag error for using CB w/o vkEndCommandBuffer() called
1612 char str[1024];
1613 sprintf(str, "You must call vkEndCommandBuffer() on CB %p before this call to vkQueueSubmit()!", pCB->cmdBuffer);
1614 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS", str);
Tobin Ehlise90b1712015-05-27 14:30:06 -06001615 loader_platform_thread_unlock_mutex(&globalLock);
1616 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001617 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001618 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001619 for (auto ii=pCB->boundDescriptorSets.begin(); ii != pCB->boundDescriptorSets.end(); ++ii) {
1620 if (dsUpdateActive(*ii)) {
1621 char str[1024];
1622 sprintf(str, "You must call vkEndDescriptorPoolUpdate() before this call to vkQueueSubmit()!");
1623 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *ii, 0, DRAWSTATE_BINDING_DS_NO_END_UPDATE, "DS", str);
Tobin Ehlise90b1712015-05-27 14:30:06 -06001624 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001625 }
1626 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001627 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001628 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001629 return result;
1630}
1631
Mike Stroyan230e6252015-04-17 12:36:38 -06001632VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001633{
1634 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Mike Stroyan230e6252015-04-17 12:36:38 -06001635 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001636 return result;
1637}
1638
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001639VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001640{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001641 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001642 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001643 loader_platform_thread_lock_mutex(&globalLock);
1644 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1645 pNewNode->buffer = *pView;
1646 pNewNode->createInfo = *pCreateInfo;
1647 bufferMap[*pView] = pNewNode;
1648 loader_platform_thread_unlock_mutex(&globalLock);
1649 }
1650 return result;
1651}
1652
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001653VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001654{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001655 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001656 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001657 loader_platform_thread_lock_mutex(&globalLock);
1658 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1659 pNewNode->image = *pView;
1660 pNewNode->createInfo = *pCreateInfo;
1661 imageMap[*pView] = pNewNode;
1662 loader_platform_thread_unlock_mutex(&globalLock);
1663 }
1664 return result;
1665}
1666
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001667static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001668{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001669 // Create LL HEAD for this Pipeline
1670 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001671 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1672 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1673 pPipeNode->pipeline = *pPipeline;
1674 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001675 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001676}
1677
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001678VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001680 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001681 // Create LL HEAD for this Pipeline
1682 char str[1024];
1683 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001684 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001685
1686 track_pipeline(pCreateInfo, pPipeline);
1687
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001688 return result;
1689}
1690
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001691VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1692 VkDevice device,
1693 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1694 VkPipeline basePipeline,
1695 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001696{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001697 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001698 // Create LL HEAD for this Pipeline
1699 char str[1024];
1700 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001701 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001702
1703 track_pipeline(pCreateInfo, pPipeline);
1704
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001705 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburnbdcd7562015-04-14 14:12:59 -06001706
1707 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001708}
1709
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001710VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001711{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001712 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001713 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001714 loader_platform_thread_lock_mutex(&globalLock);
1715 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1716 pNewNode->sampler = *pSampler;
1717 pNewNode->createInfo = *pCreateInfo;
1718 sampleMap[*pSampler] = pNewNode;
1719 loader_platform_thread_unlock_mutex(&globalLock);
1720 }
1721 return result;
1722}
1723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001724VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001725{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001726 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001727 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1729 if (NULL == pNewNode) {
1730 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001731 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1732 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001733 }
1734 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001735 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1736 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1737 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001738 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001739 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1740 totalCount += pCreateInfo->pBinding[i].count;
1741 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001742 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1743 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1744 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001745 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001746 }
1747 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001748 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001749 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001750 uint32_t j = 0;
1751 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1752 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1753 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001754 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001755 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001756 }
1757 }
1758 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001759 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001760 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1761 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001762 // Put new node at Head of global Layer list
1763 loader_platform_thread_lock_mutex(&globalLock);
1764 layoutMap[*pSetLayout] = pNewNode;
1765 loader_platform_thread_unlock_mutex(&globalLock);
1766 }
1767 return result;
1768}
1769
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001770VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001772 VkResult result = nextTable.CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001773 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001774 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001775 }
1776 return result;
1777}
1778
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001779VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001780{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001781 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001782 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001783 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001784 POOL_NODE* pPoolNode = poolMap.begin()->second;
1785 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001786 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001787 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001788 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001789 }
1790 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001791 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001792 }
1793 loader_platform_thread_unlock_mutex(&globalLock);
1794 }
1795 return result;
1796}
1797
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001798VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001800 // Perform some initial validation checks
1801 POOL_NODE* pPoolNode = NULL;
1802 loader_platform_thread_lock_mutex(&globalLock);
1803 auto poolEntry = poolMap.begin();
1804 if (poolEntry == poolMap.end()) {
1805 char str[1024];
1806 sprintf(str, "Unable to find pool node");
1807 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlise90b1712015-05-27 14:30:06 -06001808 loader_platform_thread_unlock_mutex(&globalLock);
1809 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001810 }
1811 else {
1812 pPoolNode = poolEntry->second;
1813 if (!pPoolNode->updateActive) {
1814 char str[1024];
1815 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1816 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_DS_END_WITHOUT_BEGIN, "DS", str);
Tobin Ehlise90b1712015-05-27 14:30:06 -06001817 loader_platform_thread_unlock_mutex(&globalLock);
1818 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001819 }
1820 }
1821 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001822 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001823 if (VK_SUCCESS == result) {
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001824 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825 }
1826 return result;
1827}
1828
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001829VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001830{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001831 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001832 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001833 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001834 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001835 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Mike Stroyan230e6252015-04-17 12:36:38 -06001836 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001837 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001838 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001839 if (NULL == pNewNode) {
1840 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001841 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Mike Stroyan230e6252015-04-17 12:36:38 -06001842 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, (VkObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001843 }
1844 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001845 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001846 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1847 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001848 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001849 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1850 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001851 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1852 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001853 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001854 pNewNode->updateActive = 0;
1855 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001856 pNewNode->pool = *pDescriptorPool;
1857 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001858 }
1859 loader_platform_thread_unlock_mutex(&globalLock);
1860 }
1861 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001862 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001863 }
1864 return result;
1865}
1866
Mike Stroyan230e6252015-04-17 12:36:38 -06001867VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868{
Mike Stroyan230e6252015-04-17 12:36:38 -06001869 VkResult result = nextTable.ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001870 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001871 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001872 }
1873 return result;
1874}
1875
Mike Stroyan230e6252015-04-17 12:36:38 -06001876VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001877{
Mike Stroyan230e6252015-04-17 12:36:38 -06001878 VkResult result = nextTable.AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001879 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001880 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1881 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001882 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001883 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1884 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001885 }
1886 else {
1887 for (uint32_t i = 0; i < *pCount; i++) {
1888 char str[1024];
1889 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001890 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001891 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001892 SET_NODE* pNewNode = new SET_NODE;
1893 if (NULL == pNewNode) {
1894 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001895 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1896 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001897 }
1898 else {
1899 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001900 // Insert set at head of Set LL for this pool
1901 pNewNode->pNext = pPoolNode->pSets;
1902 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1904 if (NULL == pLayout) {
1905 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1907 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001908 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001909 pNewNode->pLayout = pLayout;
1910 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001911 pNewNode->set = pDescriptorSets[i];
1912 pNewNode->setUsage = setUsage;
1913 pNewNode->descriptorCount = pLayout->endIndex + 1;
1914 if (pNewNode->descriptorCount) {
1915 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1916 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1917 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1918 }
1919 setMap[pDescriptorSets[i]] = pNewNode;
1920 }
1921 }
1922 }
1923 }
1924 return result;
1925}
1926
Mike Stroyan230e6252015-04-17 12:36:38 -06001927VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001928{
1929 for (uint32_t i = 0; i < count; i++) {
1930 clearDescriptorSet(pDescriptorSets[i]);
1931 }
Mike Stroyan230e6252015-04-17 12:36:38 -06001932 nextTable.ClearDescriptorSets(device, descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001933}
1934
Mike Stroyan230e6252015-04-17 12:36:38 -06001935VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDevice device, VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001936{
1937 SET_NODE* pSet = getSetNode(descriptorSet);
1938 if (!dsUpdateActive(descriptorSet)) {
1939 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001940 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
Tobin Ehlise90b1712015-05-27 14:30:06 -06001941 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_UPDATE_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001942 }
1943 else {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001944 // pUpdateChain is an array of VK_UPDATE_* struct ptrs defining the mappings for the descriptors
1945 if (dsUpdate(descriptorSet, updateCount, ppUpdateArray)) {
1946 nextTable.UpdateDescriptors(device, descriptorSet, updateCount, ppUpdateArray);
1947 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001948 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001949}
1950
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001951VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001952{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001953 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001954 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001955 return result;
1956}
1957
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001958VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001959{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001960 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001961 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001962 return result;
1963}
1964
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001965VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001966{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001967 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001968 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001969 return result;
1970}
1971
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001972VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001973{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001974 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tony Barbour8205d902015-04-16 15:59:00 -06001975 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001976 return result;
1977}
1978
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001979VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001980{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001981 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001982 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001983 loader_platform_thread_lock_mutex(&globalLock);
1984 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1985 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1986 pCB->cmdBuffer = *pCmdBuffer;
1987 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001988 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001989 pCB->lastVtxBinding = MAX_BINDING;
1990 cmdBufferMap[*pCmdBuffer] = pCB;
1991 loader_platform_thread_unlock_mutex(&globalLock);
1992 updateCBTracking(*pCmdBuffer);
1993 }
1994 return result;
1995}
1996
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001997VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001998{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001999 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002000 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002001 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2002 if (pCB) {
2003 if (CB_NEW != pCB->state)
2004 resetCB(cmdBuffer);
2005 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002006 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002007 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002008 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002009 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002010 }
2011 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002012 }
2013 else {
2014 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002015 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
2016 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002017 }
2018 updateCBTracking(cmdBuffer);
2019 }
2020 return result;
2021}
2022
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002023VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002024{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002025 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002026 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002027 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2028 if (pCB) {
2029 pCB->state = CB_UPDATE_COMPLETE;
2030 printCB(cmdBuffer);
2031 }
2032 else {
2033 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002034 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
2035 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002036 }
2037 updateCBTracking(cmdBuffer);
2038 //cbDumpDotFile("cb_dump.dot");
2039 }
2040 return result;
2041}
2042
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002043VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002044{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002045 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002046 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002047 resetCB(cmdBuffer);
2048 updateCBTracking(cmdBuffer);
2049 }
2050 return result;
2051}
2052
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002053VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002054{
2055 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2056 if (pCB) {
2057 updateCBTracking(cmdBuffer);
2058 addCmd(pCB, CMD_BINDPIPELINE);
2059 PIPELINE_NODE* pPN = getPipeline(pipeline);
2060 if (pPN) {
2061 pCB->lastBoundPipeline = pipeline;
2062 loader_platform_thread_lock_mutex(&globalLock);
2063 g_lastBoundPipeline = pPN;
2064 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002065 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlise9b700e2015-05-26 16:06:50 -06002066 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002067 }
2068 else {
2069 char str[1024];
2070 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002071 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002072 }
2073 }
2074 else {
2075 char str[1024];
2076 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002077 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002078 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002079}
2080
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002081VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002082{
2083 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
2084 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
2085}
2086
Cody Northrop1a01b1d2015-04-16 13:41:56 -06002087VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002088{
2089 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2090 if (pCB) {
2091 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002092 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002093 if (validateBoundPipeline(cmdBuffer)) {
2094 for (uint32_t i=0; i<setCount; i++) {
2095 if (getSetNode(pDescriptorSets[i])) {
2096 loader_platform_thread_lock_mutex(&globalLock);
2097 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
2098 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2099 g_lastBoundDescriptorSet = pDescriptorSets[i];
2100 loader_platform_thread_unlock_mutex(&globalLock);
2101 char str[1024];
2102 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
2103 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
2104 synchAndPrintDSConfig(cmdBuffer);
2105 }
2106 else {
2107 char str[1024];
2108 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
2109 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
2110 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002111 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002112 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002113 }
2114 }
2115 else {
2116 char str[1024];
2117 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002118 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002119 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002120}
2121
Tony Barbour8205d902015-04-16 15:59:00 -06002122VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002123{
2124 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2125 if (pCB) {
2126 updateCBTracking(cmdBuffer);
2127 addCmd(pCB, CMD_BINDINDEXBUFFER);
2128 // TODO : Track idxBuffer binding
2129 }
2130 else {
2131 char str[1024];
2132 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002133 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002134 }
2135 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2136}
2137
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002138VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2139 VkCmdBuffer cmdBuffer,
2140 uint32_t startBinding,
2141 uint32_t bindingCount,
2142 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002143 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002144{
2145 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2146 if (pCB) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002147 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002148 updateCBTracking(cmdBuffer);
2149 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002150 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002151 if (validateBoundPipeline(cmdBuffer)) {
2152 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2153 }
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002154 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002155 char str[1024];
2156 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002157 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002158 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002159}
2160
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002161VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002162{
2163 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2164 if (pCB) {
2165 updateCBTracking(cmdBuffer);
2166 addCmd(pCB, CMD_DRAW);
2167 pCB->drawCount[DRAW]++;
2168 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002169 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2170 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002171 synchAndPrintDSConfig(cmdBuffer);
2172 }
2173 else {
2174 char str[1024];
2175 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002176 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002177 }
2178 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2179}
2180
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002181VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002182{
2183 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2184 if (pCB) {
2185 updateCBTracking(cmdBuffer);
2186 addCmd(pCB, CMD_DRAWINDEXED);
2187 pCB->drawCount[DRAW_INDEXED]++;
2188 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002189 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2190 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002191 synchAndPrintDSConfig(cmdBuffer);
2192 }
2193 else {
2194 char str[1024];
2195 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002196 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002197 }
2198 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2199}
2200
Tony Barbour8205d902015-04-16 15:59:00 -06002201VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002202{
2203 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2204 if (pCB) {
2205 updateCBTracking(cmdBuffer);
2206 addCmd(pCB, CMD_DRAWINDIRECT);
2207 pCB->drawCount[DRAW_INDIRECT]++;
2208 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002209 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2210 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002211 synchAndPrintDSConfig(cmdBuffer);
2212 }
2213 else {
2214 char str[1024];
2215 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002216 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002217 }
2218 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2219}
2220
Tony Barbour8205d902015-04-16 15:59:00 -06002221VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002222{
2223 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2224 if (pCB) {
2225 updateCBTracking(cmdBuffer);
2226 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2227 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2228 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002229 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2230 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002231 synchAndPrintDSConfig(cmdBuffer);
2232 }
2233 else {
2234 char str[1024];
2235 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002236 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002237 }
2238 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2239}
2240
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002241VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002242{
2243 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2244 if (pCB) {
2245 updateCBTracking(cmdBuffer);
2246 addCmd(pCB, CMD_DISPATCH);
2247 }
2248 else {
2249 char str[1024];
2250 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002251 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002252 }
2253 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2254}
2255
Tony Barbour8205d902015-04-16 15:59:00 -06002256VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002257{
2258 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2259 if (pCB) {
2260 updateCBTracking(cmdBuffer);
2261 addCmd(pCB, CMD_DISPATCHINDIRECT);
2262 }
2263 else {
2264 char str[1024];
2265 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002266 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002267 }
2268 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2269}
2270
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002271VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002272{
2273 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2274 if (pCB) {
2275 updateCBTracking(cmdBuffer);
2276 addCmd(pCB, CMD_COPYBUFFER);
2277 }
2278 else {
2279 char str[1024];
2280 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002281 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002282 }
2283 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2284}
2285
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002286VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2287 VkImage srcImage,
2288 VkImageLayout srcImageLayout,
2289 VkImage destImage,
2290 VkImageLayout destImageLayout,
2291 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002292{
2293 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2294 if (pCB) {
2295 updateCBTracking(cmdBuffer);
2296 addCmd(pCB, CMD_COPYIMAGE);
2297 }
2298 else {
2299 char str[1024];
2300 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002301 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002302 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002303 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002304}
2305
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002306VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2307 VkImage srcImage, VkImageLayout srcImageLayout,
2308 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002309 uint32_t regionCount, const VkImageBlit* pRegions,
2310 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002311{
2312 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2313 if (pCB) {
2314 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002315 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002316 }
2317 else {
2318 char str[1024];
2319 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002320 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002321 }
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002322 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002323}
2324
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002325VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2326 VkBuffer srcBuffer,
2327 VkImage destImage, VkImageLayout destImageLayout,
2328 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002329{
2330 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2331 if (pCB) {
2332 updateCBTracking(cmdBuffer);
2333 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2334 }
2335 else {
2336 char str[1024];
2337 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002338 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002339 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002340 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002341}
2342
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002343VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2344 VkImage srcImage, VkImageLayout srcImageLayout,
2345 VkBuffer destBuffer,
2346 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002347{
2348 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2349 if (pCB) {
2350 updateCBTracking(cmdBuffer);
2351 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2352 }
2353 else {
2354 char str[1024];
2355 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002356 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002357 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002358 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359}
2360
Tony Barbour8205d902015-04-16 15:59:00 -06002361VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362{
2363 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2364 if (pCB) {
2365 updateCBTracking(cmdBuffer);
2366 addCmd(pCB, CMD_UPDATEBUFFER);
2367 }
2368 else {
2369 char str[1024];
2370 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002371 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002372 }
2373 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2374}
2375
Tony Barbour8205d902015-04-16 15:59:00 -06002376VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002377{
2378 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2379 if (pCB) {
2380 updateCBTracking(cmdBuffer);
2381 addCmd(pCB, CMD_FILLBUFFER);
2382 }
2383 else {
2384 char str[1024];
2385 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002386 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002387 }
2388 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2389}
2390
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002391VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2392 VkCmdBuffer cmdBuffer,
2393 VkImage image, VkImageLayout imageLayout,
2394 const VkClearColor *pColor,
2395 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002396{
2397 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2398 if (pCB) {
2399 updateCBTracking(cmdBuffer);
2400 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2401 }
2402 else {
2403 char str[1024];
2404 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002405 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002406 }
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002407 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002408}
2409
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002410VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2411 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002412 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002413 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002414{
2415 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2416 if (pCB) {
2417 updateCBTracking(cmdBuffer);
2418 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2419 }
2420 else {
2421 char str[1024];
2422 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002423 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002424 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002425 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002426}
2427
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002428VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2429 VkImage srcImage, VkImageLayout srcImageLayout,
2430 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002431 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002432{
2433 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2434 if (pCB) {
2435 updateCBTracking(cmdBuffer);
2436 addCmd(pCB, CMD_RESOLVEIMAGE);
2437 }
2438 else {
2439 char str[1024];
2440 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002441 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002442 }
Tony Barbour11f74372015-04-13 15:02:52 -06002443 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002444}
2445
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002446VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447{
2448 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2449 if (pCB) {
2450 updateCBTracking(cmdBuffer);
2451 addCmd(pCB, CMD_SETEVENT);
2452 }
2453 else {
2454 char str[1024];
2455 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002456 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002457 }
2458 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2459}
2460
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002461VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002462{
2463 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2464 if (pCB) {
2465 updateCBTracking(cmdBuffer);
2466 addCmd(pCB, CMD_RESETEVENT);
2467 }
2468 else {
2469 char str[1024];
2470 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002471 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002472 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002473 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002474}
2475
Tony Barbour8205d902015-04-16 15:59:00 -06002476VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t eventCount, const VkEvent* pEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002477{
2478 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2479 if (pCB) {
2480 updateCBTracking(cmdBuffer);
2481 addCmd(pCB, CMD_WAITEVENTS);
2482 }
2483 else {
2484 char str[1024];
2485 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002486 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002487 }
Tony Barbour8205d902015-04-16 15:59:00 -06002488 nextTable.CmdWaitEvents(cmdBuffer, waitEvent, eventCount, pEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002489}
2490
Tony Barbour8205d902015-04-16 15:59:00 -06002491VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkWaitEvent waitEvent, uint32_t pipeEventCount, const VkPipeEvent* pPipeEvents, uint32_t memBarrierCount, const void** ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002492{
2493 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2494 if (pCB) {
2495 updateCBTracking(cmdBuffer);
2496 addCmd(pCB, CMD_PIPELINEBARRIER);
2497 }
2498 else {
2499 char str[1024];
2500 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002501 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002502 }
Tony Barbour8205d902015-04-16 15:59:00 -06002503 nextTable.CmdPipelineBarrier(cmdBuffer, waitEvent, pipeEventCount, pPipeEvents, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002504}
2505
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002506VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002507{
2508 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2509 if (pCB) {
2510 updateCBTracking(cmdBuffer);
2511 addCmd(pCB, CMD_BEGINQUERY);
2512 }
2513 else {
2514 char str[1024];
2515 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002516 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002517 }
2518 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2519}
2520
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002521VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002522{
2523 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2524 if (pCB) {
2525 updateCBTracking(cmdBuffer);
2526 addCmd(pCB, CMD_ENDQUERY);
2527 }
2528 else {
2529 char str[1024];
2530 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002531 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002532 }
2533 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2534}
2535
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002536VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002537{
2538 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2539 if (pCB) {
2540 updateCBTracking(cmdBuffer);
2541 addCmd(pCB, CMD_RESETQUERYPOOL);
2542 }
2543 else {
2544 char str[1024];
2545 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002546 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002547 }
2548 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2549}
2550
Tony Barbour8205d902015-04-16 15:59:00 -06002551VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002552{
2553 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2554 if (pCB) {
2555 updateCBTracking(cmdBuffer);
2556 addCmd(pCB, CMD_WRITETIMESTAMP);
2557 }
2558 else {
2559 char str[1024];
2560 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002561 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002562 }
2563 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2564}
2565
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002566VK_LAYER_EXPORT void VKAPI vkCmdInitAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002567{
2568 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2569 if (pCB) {
2570 updateCBTracking(cmdBuffer);
2571 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2572 }
2573 else {
2574 char str[1024];
2575 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002576 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002577 }
2578 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2579}
2580
Tony Barbour8205d902015-04-16 15:59:00 -06002581VK_LAYER_EXPORT void VKAPI vkCmdLoadAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer srcBuffer, VkDeviceSize srcOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002582{
2583 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2584 if (pCB) {
2585 updateCBTracking(cmdBuffer);
2586 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2587 }
2588 else {
2589 char str[1024];
2590 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002591 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002592 }
2593 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2594}
2595
Tony Barbour8205d902015-04-16 15:59:00 -06002596VK_LAYER_EXPORT void VKAPI vkCmdSaveAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002597{
2598 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2599 if (pCB) {
2600 updateCBTracking(cmdBuffer);
2601 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2602 }
2603 else {
2604 char str[1024];
2605 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002606 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002607 }
2608 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2609}
2610
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002611VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002612{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002613 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002614 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002615 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002616 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002617 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002618 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2619 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002620 }
2621 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002622 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2623 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002624 }
2625 frameBufferMap[*pFramebuffer] = localFBCI;
2626 }
2627 return result;
2628}
2629
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002630VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002631{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002632 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002633 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002634 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002635 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002636 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002637 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2638 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002639 }
2640 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002641 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2642 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002643 }
2644 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002645 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2646 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002647 }
2648 renderPassMap[*pRenderPass] = localRPCI;
2649 }
2650 return result;
2651}
2652
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002653VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002654{
2655 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2656 if (pCB) {
2657 updateCBTracking(cmdBuffer);
2658 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002659 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2660 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002661 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002662 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002663 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002664 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002665 char str[1024];
2666 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002667 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002668 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002669 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002670}
2671
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002672VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002673{
2674 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2675 if (pCB) {
2676 updateCBTracking(cmdBuffer);
2677 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002678 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002679 }
2680 else {
2681 char str[1024];
2682 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002683 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002684 }
2685 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2686}
2687
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002688VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002689{
2690 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002691 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002692 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06002693 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002694 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2695 pNewDbgFuncNode->pUserData = pUserData;
2696 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2697 g_pDbgFunctionHead = pNewDbgFuncNode;
2698 // force callbacks if DebugAction hasn't been set already other than initial value
2699 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002700 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002701 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002702 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002703 return result;
2704}
2705
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002706VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002707{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002708 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2709 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002710 while (pTrav) {
2711 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2712 pPrev->pNext = pTrav->pNext;
2713 if (g_pDbgFunctionHead == pTrav)
2714 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002715 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002716 break;
2717 }
2718 pPrev = pTrav;
2719 pTrav = pTrav->pNext;
2720 }
2721 if (g_pDbgFunctionHead == NULL)
2722 {
2723 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002724 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002725 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002726 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002727 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002728 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002729 return result;
2730}
2731
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002732VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002733{
2734 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2735 if (pCB) {
2736 updateCBTracking(cmdBuffer);
2737 addCmd(pCB, CMD_DBGMARKERBEGIN);
2738 }
2739 else {
2740 char str[1024];
2741 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002742 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002743 }
2744 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2745}
2746
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002747VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002748{
2749 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2750 if (pCB) {
2751 updateCBTracking(cmdBuffer);
2752 addCmd(pCB, CMD_DBGMARKEREND);
2753 }
2754 else {
2755 char str[1024];
2756 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002757 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002758 }
2759 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2760}
2761
2762// TODO : Want to pass in a cmdBuffer here based on which state to display
2763void drawStateDumpDotFile(char* outFileName)
2764{
2765 // TODO : Currently just setting cmdBuffer based on global var
2766 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2767 dumpGlobalDotFile(outFileName);
2768}
2769
2770void drawStateDumpCommandBufferDotFile(char* outFileName)
2771{
2772 cbDumpDotFile(outFileName);
2773}
2774
2775void drawStateDumpPngFile(char* outFileName)
2776{
2777#if defined(_WIN32)
2778// FIXME: NEED WINDOWS EQUIVALENT
2779 char str[1024];
2780 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002781 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002782#else // WIN32
2783 char dotExe[32] = "/usr/bin/dot";
2784 if( access(dotExe, X_OK) != -1) {
2785 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2786 char dotCmd[1024];
2787 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
Tony Barbour22a30862015-04-22 09:02:32 -06002788 int retval = system(dotCmd);
2789 assert(retval != -1);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002790 remove("/tmp/tmp.dot");
2791 }
2792 else {
2793 char str[1024];
2794 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002795 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002796 }
2797#endif // WIN32
2798}
2799
Tony Barbour8205d902015-04-16 15:59:00 -06002800VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002801{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002802 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002803
2804 if (gpu == NULL)
2805 return NULL;
2806 pCurObj = gpuw;
2807 loader_platform_thread_once(&g_initOnce, initDrawState);
2808
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002809 if (!strcmp(funcName, "vkGetProcAddr"))
2810 return (void *) vkGetProcAddr;
2811 if (!strcmp(funcName, "vkCreateDevice"))
2812 return (void*) vkCreateDevice;
2813 if (!strcmp(funcName, "vkDestroyDevice"))
2814 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002815 if (!strcmp(funcName, "vkEnumerateLayers"))
2816 return (void*) vkEnumerateLayers;
2817 if (!strcmp(funcName, "vkQueueSubmit"))
2818 return (void*) vkQueueSubmit;
2819 if (!strcmp(funcName, "vkDestroyObject"))
2820 return (void*) vkDestroyObject;
2821 if (!strcmp(funcName, "vkCreateBufferView"))
2822 return (void*) vkCreateBufferView;
2823 if (!strcmp(funcName, "vkCreateImageView"))
2824 return (void*) vkCreateImageView;
2825 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2826 return (void*) vkCreateGraphicsPipeline;
2827 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2828 return (void*) vkCreateGraphicsPipelineDerivative;
2829 if (!strcmp(funcName, "vkCreateSampler"))
2830 return (void*) vkCreateSampler;
2831 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2832 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05002833 if (!strcmp(funcName, "vkCreatePipelineLayout"))
2834 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002835 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2836 return (void*) vkBeginDescriptorPoolUpdate;
2837 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2838 return (void*) vkEndDescriptorPoolUpdate;
2839 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2840 return (void*) vkCreateDescriptorPool;
2841 if (!strcmp(funcName, "vkResetDescriptorPool"))
2842 return (void*) vkResetDescriptorPool;
2843 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2844 return (void*) vkAllocDescriptorSets;
2845 if (!strcmp(funcName, "vkClearDescriptorSets"))
2846 return (void*) vkClearDescriptorSets;
2847 if (!strcmp(funcName, "vkUpdateDescriptors"))
2848 return (void*) vkUpdateDescriptors;
2849 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2850 return (void*) vkCreateDynamicViewportState;
2851 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2852 return (void*) vkCreateDynamicRasterState;
2853 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2854 return (void*) vkCreateDynamicColorBlendState;
2855 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2856 return (void*) vkCreateDynamicDepthStencilState;
2857 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2858 return (void*) vkCreateCommandBuffer;
2859 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2860 return (void*) vkBeginCommandBuffer;
2861 if (!strcmp(funcName, "vkEndCommandBuffer"))
2862 return (void*) vkEndCommandBuffer;
2863 if (!strcmp(funcName, "vkResetCommandBuffer"))
2864 return (void*) vkResetCommandBuffer;
2865 if (!strcmp(funcName, "vkCmdBindPipeline"))
2866 return (void*) vkCmdBindPipeline;
2867 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2868 return (void*) vkCmdBindDynamicStateObject;
2869 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2870 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002871 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2872 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002873 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2874 return (void*) vkCmdBindIndexBuffer;
2875 if (!strcmp(funcName, "vkCmdDraw"))
2876 return (void*) vkCmdDraw;
2877 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2878 return (void*) vkCmdDrawIndexed;
2879 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2880 return (void*) vkCmdDrawIndirect;
2881 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2882 return (void*) vkCmdDrawIndexedIndirect;
2883 if (!strcmp(funcName, "vkCmdDispatch"))
2884 return (void*) vkCmdDispatch;
2885 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2886 return (void*) vkCmdDispatchIndirect;
2887 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2888 return (void*) vkCmdCopyBuffer;
2889 if (!strcmp(funcName, "vkCmdCopyImage"))
2890 return (void*) vkCmdCopyImage;
2891 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2892 return (void*) vkCmdCopyBufferToImage;
2893 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2894 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002895 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2896 return (void*) vkCmdUpdateBuffer;
2897 if (!strcmp(funcName, "vkCmdFillBuffer"))
2898 return (void*) vkCmdFillBuffer;
2899 if (!strcmp(funcName, "vkCmdClearColorImage"))
2900 return (void*) vkCmdClearColorImage;
2901 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2902 return (void*) vkCmdClearDepthStencil;
2903 if (!strcmp(funcName, "vkCmdResolveImage"))
2904 return (void*) vkCmdResolveImage;
2905 if (!strcmp(funcName, "vkCmdSetEvent"))
2906 return (void*) vkCmdSetEvent;
2907 if (!strcmp(funcName, "vkCmdResetEvent"))
2908 return (void*) vkCmdResetEvent;
2909 if (!strcmp(funcName, "vkCmdWaitEvents"))
2910 return (void*) vkCmdWaitEvents;
2911 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2912 return (void*) vkCmdPipelineBarrier;
2913 if (!strcmp(funcName, "vkCmdBeginQuery"))
2914 return (void*) vkCmdBeginQuery;
2915 if (!strcmp(funcName, "vkCmdEndQuery"))
2916 return (void*) vkCmdEndQuery;
2917 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2918 return (void*) vkCmdResetQueryPool;
2919 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2920 return (void*) vkCmdWriteTimestamp;
2921 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2922 return (void*) vkCmdInitAtomicCounters;
2923 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2924 return (void*) vkCmdLoadAtomicCounters;
2925 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2926 return (void*) vkCmdSaveAtomicCounters;
2927 if (!strcmp(funcName, "vkCreateFramebuffer"))
2928 return (void*) vkCreateFramebuffer;
2929 if (!strcmp(funcName, "vkCreateRenderPass"))
2930 return (void*) vkCreateRenderPass;
2931 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2932 return (void*) vkCmdBeginRenderPass;
2933 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2934 return (void*) vkCmdEndRenderPass;
2935 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2936 return (void*) vkDbgRegisterMsgCallback;
2937 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2938 return (void*) vkDbgUnregisterMsgCallback;
2939 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2940 return (void*) vkCmdDbgMarkerBegin;
2941 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2942 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002943 if (!strcmp("drawStateDumpDotFile", funcName))
2944 return (void*) drawStateDumpDotFile;
2945 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2946 return (void*) drawStateDumpCommandBufferDotFile;
2947 if (!strcmp("drawStateDumpPngFile", funcName))
2948 return (void*) drawStateDumpPngFile;
2949 else {
2950 if (gpuw->pGPA == NULL)
2951 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002952 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002953 }
2954}