blob: cb3e683363dc191c81c5213ded35455ad87e552f [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
30#include "loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060033#pragma GCC diagnostic ignored "-Wwrite-strings"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060034#include "vk_struct_graphviz_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060035#pragma GCC diagnostic warning "-Wwrite-strings"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060036#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060037#include "draw_state.h"
38#include "layers_config.h"
39// The following is #included again to catch certain OS-specific functions
40// being used:
41#include "loader_platform.h"
42#include "layers_msg.h"
43
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060044unordered_map<VkSampler, SAMPLER_NODE*> sampleMap;
45unordered_map<VkImageView, IMAGE_NODE*> imageMap;
46unordered_map<VkBufferView, BUFFER_NODE*> bufferMap;
47unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*> dynamicStateMap;
48unordered_map<VkPipeline, PIPELINE_NODE*> pipelineMap;
49unordered_map<VkDescriptorPool, POOL_NODE*> poolMap;
50unordered_map<VkDescriptorSet, SET_NODE*> setMap;
51unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060052// Map for layout chains
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060053unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*> cmdBufferMap;
54unordered_map<VkRenderPass, VkRenderPassCreateInfo*> renderPassMap;
55unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060056
Jon Ashburn301c5f02015-04-06 10:58:22 -060057static VkLayerDispatchTable nextTable;
58static VkBaseLayerObject *pCurObj;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060059static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
60// TODO : This can be much smarter, using separate locks for separate global data
61static int globalLockInitialized = 0;
62static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060063#define MAX_TID 513
64static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
65static uint32_t g_maxTID = 0;
66// Map actual TID to an index value and return that index
67// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
68static uint32_t getTIDIndex() {
69 loader_platform_thread_id tid = loader_platform_get_thread_id();
70 for (uint32_t i = 0; i < g_maxTID; i++) {
71 if (tid == g_tidMapping[i])
72 return i;
73 }
74 // Don't yet have mapping, set it and return newly set index
75 uint32_t retVal = (uint32_t) g_maxTID;
76 g_tidMapping[g_maxTID++] = tid;
77 assert(g_maxTID < MAX_TID);
78 return retVal;
79}
80// Return a string representation of CMD_TYPE enum
81static string cmdTypeToString(CMD_TYPE cmd)
82{
83 switch (cmd)
84 {
85 case CMD_BINDPIPELINE:
86 return "CMD_BINDPIPELINE";
87 case CMD_BINDPIPELINEDELTA:
88 return "CMD_BINDPIPELINEDELTA";
89 case CMD_BINDDYNAMICSTATEOBJECT:
90 return "CMD_BINDDYNAMICSTATEOBJECT";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060091 case CMD_BINDDESCRIPTORSETS:
92 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -060093 case CMD_BINDINDEXBUFFER:
94 return "CMD_BINDINDEXBUFFER";
95 case CMD_BINDVERTEXBUFFER:
96 return "CMD_BINDVERTEXBUFFER";
97 case CMD_DRAW:
98 return "CMD_DRAW";
99 case CMD_DRAWINDEXED:
100 return "CMD_DRAWINDEXED";
101 case CMD_DRAWINDIRECT:
102 return "CMD_DRAWINDIRECT";
103 case CMD_DRAWINDEXEDINDIRECT:
104 return "CMD_DRAWINDEXEDINDIRECT";
105 case CMD_DISPATCH:
106 return "CMD_DISPATCH";
107 case CMD_DISPATCHINDIRECT:
108 return "CMD_DISPATCHINDIRECT";
109 case CMD_COPYBUFFER:
110 return "CMD_COPYBUFFER";
111 case CMD_COPYIMAGE:
112 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600113 case CMD_BLITIMAGE:
114 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600115 case CMD_COPYBUFFERTOIMAGE:
116 return "CMD_COPYBUFFERTOIMAGE";
117 case CMD_COPYIMAGETOBUFFER:
118 return "CMD_COPYIMAGETOBUFFER";
119 case CMD_CLONEIMAGEDATA:
120 return "CMD_CLONEIMAGEDATA";
121 case CMD_UPDATEBUFFER:
122 return "CMD_UPDATEBUFFER";
123 case CMD_FILLBUFFER:
124 return "CMD_FILLBUFFER";
125 case CMD_CLEARCOLORIMAGE:
126 return "CMD_CLEARCOLORIMAGE";
127 case CMD_CLEARCOLORIMAGERAW:
128 return "CMD_CLEARCOLORIMAGERAW";
129 case CMD_CLEARDEPTHSTENCIL:
130 return "CMD_CLEARDEPTHSTENCIL";
131 case CMD_RESOLVEIMAGE:
132 return "CMD_RESOLVEIMAGE";
133 case CMD_SETEVENT:
134 return "CMD_SETEVENT";
135 case CMD_RESETEVENT:
136 return "CMD_RESETEVENT";
137 case CMD_WAITEVENTS:
138 return "CMD_WAITEVENTS";
139 case CMD_PIPELINEBARRIER:
140 return "CMD_PIPELINEBARRIER";
141 case CMD_BEGINQUERY:
142 return "CMD_BEGINQUERY";
143 case CMD_ENDQUERY:
144 return "CMD_ENDQUERY";
145 case CMD_RESETQUERYPOOL:
146 return "CMD_RESETQUERYPOOL";
147 case CMD_WRITETIMESTAMP:
148 return "CMD_WRITETIMESTAMP";
149 case CMD_INITATOMICCOUNTERS:
150 return "CMD_INITATOMICCOUNTERS";
151 case CMD_LOADATOMICCOUNTERS:
152 return "CMD_LOADATOMICCOUNTERS";
153 case CMD_SAVEATOMICCOUNTERS:
154 return "CMD_SAVEATOMICCOUNTERS";
155 case CMD_BEGINRENDERPASS:
156 return "CMD_BEGINRENDERPASS";
157 case CMD_ENDRENDERPASS:
158 return "CMD_ENDRENDERPASS";
159 case CMD_DBGMARKERBEGIN:
160 return "CMD_DBGMARKERBEGIN";
161 case CMD_DBGMARKEREND:
162 return "CMD_DBGMARKEREND";
163 default:
164 return "UNKNOWN";
165 }
166}
167// Block of code at start here for managing/tracking Pipeline state that this layer cares about
168// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600169#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600170#define MAX_SLOTS 2048
171#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
172
173static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
174
175// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
176// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
177// to that same cmd buffer by separate thread are not changing state from underneath us
178// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600179static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600180// Track the last group of CBs touched for displaying to dot file
181static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
182static uint32_t g_lastTouchedCBIndex = 0;
183// Track the last global DrawState of interest touched by any thread
184static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
185static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600186static DYNAMIC_STATE_NODE* g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {NULL};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187static VkDescriptorSet g_lastBoundDescriptorSet = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600188#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
189
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600190//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600191
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192static void insertDynamicState(const VkDynamicStateObject state, const GENERIC_HEADER* pCreateInfo, VkStateBindPoint bindPoint)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600193{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600194 VkDynamicVpStateCreateInfo* pVPCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600195 size_t scSize = 0;
196 size_t vpSize = 0;
197 loader_platform_thread_lock_mutex(&globalLock);
198 DYNAMIC_STATE_NODE* pStateNode = new DYNAMIC_STATE_NODE;
199 pStateNode->stateObj = state;
200 switch (pCreateInfo->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600201 case VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600202 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo));
203 pVPCI = (VkDynamicVpStateCreateInfo*)pCreateInfo;
204 pStateNode->create_info.vpci.pScissors = new VkRect[pStateNode->create_info.vpci.viewportAndScissorCount];
205 pStateNode->create_info.vpci.pViewports = new VkViewport[pStateNode->create_info.vpci.viewportAndScissorCount];
206 scSize = pVPCI->viewportAndScissorCount * sizeof(VkRect);
207 vpSize = pVPCI->viewportAndScissorCount * sizeof(VkViewport);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600208 memcpy((void*)pStateNode->create_info.vpci.pScissors, pVPCI->pScissors, scSize);
209 memcpy((void*)pStateNode->create_info.vpci.pViewports, pVPCI->pViewports, vpSize);
210 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211 case VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600212 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600213 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600214 case VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600215 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600216 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600217 case VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600218 memcpy(&pStateNode->create_info, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600219 break;
220 default:
221 assert(0);
222 break;
223 }
224 pStateNode->pCreateInfo = (GENERIC_HEADER*)&pStateNode->create_info.cbci;
225 dynamicStateMap[state] = pStateNode;
226 loader_platform_thread_unlock_mutex(&globalLock);
227}
228// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600229static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600230{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600231 for (unordered_map<VkDynamicStateObject, DYNAMIC_STATE_NODE*>::iterator ii=dynamicStateMap.begin(); ii!=dynamicStateMap.end(); ++ii) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600232 if (VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO == (*ii).second->create_info.vpci.sType) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600233 delete[] (*ii).second->create_info.vpci.pScissors;
234 delete[] (*ii).second->create_info.vpci.pViewports;
235 }
236 delete (*ii).second;
237 }
238}
239// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600240static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600241{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600242 for (unordered_map<VkSampler, SAMPLER_NODE*>::iterator ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243 delete (*ii).second;
244 }
245}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600246static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600247{
248 loader_platform_thread_lock_mutex(&globalLock);
249 if (imageMap.find(view) == imageMap.end()) {
250 loader_platform_thread_unlock_mutex(&globalLock);
251 return NULL;
252 }
253 else {
254 loader_platform_thread_unlock_mutex(&globalLock);
255 return &imageMap[view]->createInfo;
256 }
257}
258// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600259static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600260{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600261 for (unordered_map<VkImageView, IMAGE_NODE*>::iterator ii=imageMap.begin(); ii!=imageMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600262 delete (*ii).second;
263 }
264}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600265static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600266{
267 loader_platform_thread_lock_mutex(&globalLock);
268 if (bufferMap.find(view) == bufferMap.end()) {
269 loader_platform_thread_unlock_mutex(&globalLock);
270 return NULL;
271 }
272 else {
273 loader_platform_thread_unlock_mutex(&globalLock);
274 return &bufferMap[view]->createInfo;
275 }
276}
277// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600278static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600279{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600280 for (unordered_map<VkBufferView, BUFFER_NODE*>::iterator ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281 delete (*ii).second;
282 }
283}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600284static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600285
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600286static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600287{
288 g_lastCmdBuffer[getTIDIndex()] = cb;
289 GLOBAL_CB_NODE* pCB = getCBNode(cb);
290 loader_platform_thread_lock_mutex(&globalLock);
291 g_lastGlobalCB = pCB;
292 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
293 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
294 if (g_pLastTouchedCB[i] == pCB) {
295 loader_platform_thread_unlock_mutex(&globalLock);
296 return;
297 }
298 }
299 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
300 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
301 loader_platform_thread_unlock_mutex(&globalLock);
302}
303
304// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600305static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600306{
307 GLOBAL_CB_NODE* pCB = getCBNode(cb);
308 if (pCB) {
309 loader_platform_thread_lock_mutex(&globalLock);
310 char str[4*1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600311 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600312 if (pCB->lastBoundDynamicState[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313 sprintf(str, "Reporting CreateInfo for currently bound %s object %p", string_VkStateBindPoint((VkStateBindPoint)i), pCB->lastBoundDynamicState[i]->stateObj);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600314 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", str);
315 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCB->lastBoundDynamicState[i]->stateObj, 0, DRAWSTATE_NONE, "DS", dynamic_display(pCB->lastBoundDynamicState[i]->pCreateInfo, " ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600316 break;
317 }
318 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600319 sprintf(str, "No dynamic state of type %s bound", string_VkStateBindPoint((VkStateBindPoint)i));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600320 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600321 }
322 }
323 loader_platform_thread_unlock_mutex(&globalLock);
324 }
325 else {
326 char str[1024];
327 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600328 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600329 }
330}
331// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600332static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600333{
334 loader_platform_thread_lock_mutex(&globalLock);
335 if (pipelineMap.find(pipeline) == pipelineMap.end()) {
336 loader_platform_thread_unlock_mutex(&globalLock);
337 return NULL;
338 }
339 loader_platform_thread_unlock_mutex(&globalLock);
340 return pipelineMap[pipeline];
341}
342
343// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600344static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600345{
346 loader_platform_thread_lock_mutex(&globalLock);
347 if (sampleMap.find(sampler) == sampleMap.end()) {
348 loader_platform_thread_unlock_mutex(&globalLock);
349 return NULL;
350 }
351 loader_platform_thread_unlock_mutex(&globalLock);
352 return &sampleMap[sampler]->createInfo;
353}
354
355// Init the pipeline mapping info based on pipeline create info LL tree
356// Threading note : Calls to this function should wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600357static void initPipeline(PIPELINE_NODE* pPipeline, const VkGraphicsPipelineCreateInfo* pCreateInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600358{
359 // First init create info, we'll shadow the structs as we go down the tree
Tobin Ehlis2464b882015-04-01 08:40:34 -0600360 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600361 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600362 GENERIC_HEADER* pTrav = (GENERIC_HEADER*)pCreateInfo->pNext;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600363 GENERIC_HEADER* pPrev = (GENERIC_HEADER*)&pPipeline->graphicsPipelineCI; // Hold prev ptr to tie chain of structs together
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600364 size_t bufferSize = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600365 VkPipelineVertexInputCreateInfo* pVICI = NULL;
366 VkPipelineCbStateCreateInfo* pCBCI = NULL;
367 VkPipelineShaderStageCreateInfo* pTmpPSSCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600368 while (pTrav) {
369 switch (pTrav->sType) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600370 case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600371 pTmpPSSCI = (VkPipelineShaderStageCreateInfo*)pTrav;
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600372 switch (pTmpPSSCI->shader.stage) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600373 case VK_SHADER_STAGE_VERTEX:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600374 pPrev->pNext = &pPipeline->vsCI;
375 pPrev = (GENERIC_HEADER*)&pPipeline->vsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600376 memcpy(&pPipeline->vsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600377 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 case VK_SHADER_STAGE_TESS_CONTROL:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600379 pPrev->pNext = &pPipeline->tcsCI;
380 pPrev = (GENERIC_HEADER*)&pPipeline->tcsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600381 memcpy(&pPipeline->tcsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600382 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600383 case VK_SHADER_STAGE_TESS_EVALUATION:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600384 pPrev->pNext = &pPipeline->tesCI;
385 pPrev = (GENERIC_HEADER*)&pPipeline->tesCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600386 memcpy(&pPipeline->tesCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600387 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388 case VK_SHADER_STAGE_GEOMETRY:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600389 pPrev->pNext = &pPipeline->gsCI;
390 pPrev = (GENERIC_HEADER*)&pPipeline->gsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600391 memcpy(&pPipeline->gsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600392 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600393 case VK_SHADER_STAGE_FRAGMENT:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600394 pPrev->pNext = &pPipeline->fsCI;
395 pPrev = (GENERIC_HEADER*)&pPipeline->fsCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600396 memcpy(&pPipeline->fsCI, pTmpPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600397 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600398 case VK_SHADER_STAGE_COMPUTE:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600399 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600400 break;
401 default:
402 // TODO : Flag error
403 break;
404 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600405 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406 case VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600407 pPrev->pNext = &pPipeline->vertexInputCI;
408 pPrev = (GENERIC_HEADER*)&pPipeline->vertexInputCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409 memcpy((void*)&pPipeline->vertexInputCI, pTrav, sizeof(VkPipelineVertexInputCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600410 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411 pVICI = (VkPipelineVertexInputCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600412 pPipeline->vtxBindingCount = pVICI->bindingCount;
413 if (pPipeline->vtxBindingCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600414 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
415 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
416 memcpy((void*)pPipeline->pVertexBindingDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600417 }
418 pPipeline->vtxAttributeCount = pVICI->attributeCount;
419 if (pPipeline->vtxAttributeCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600420 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
421 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
422 memcpy((void*)pPipeline->pVertexAttributeDescriptions, ((VkPipelineVertexInputCreateInfo*)pTrav)->pVertexAttributeDescriptions, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600423 }
424 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600425 case VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600426 pPrev->pNext = &pPipeline->iaStateCI;
427 pPrev = (GENERIC_HEADER*)&pPipeline->iaStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600428 memcpy((void*)&pPipeline->iaStateCI, pTrav, sizeof(VkPipelineIaStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600429 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600430 case VK_STRUCTURE_TYPE_PIPELINE_TESS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600431 pPrev->pNext = &pPipeline->tessStateCI;
432 pPrev = (GENERIC_HEADER*)&pPipeline->tessStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600433 memcpy((void*)&pPipeline->tessStateCI, pTrav, sizeof(VkPipelineTessStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600434 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600435 case VK_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600436 pPrev->pNext = &pPipeline->vpStateCI;
437 pPrev = (GENERIC_HEADER*)&pPipeline->vpStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600438 memcpy((void*)&pPipeline->vpStateCI, pTrav, sizeof(VkPipelineVpStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600439 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600440 case VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600441 pPrev->pNext = &pPipeline->rsStateCI;
442 pPrev = (GENERIC_HEADER*)&pPipeline->rsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600443 memcpy((void*)&pPipeline->rsStateCI, pTrav, sizeof(VkPipelineRsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600444 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600445 case VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600446 pPrev->pNext = &pPipeline->msStateCI;
447 pPrev = (GENERIC_HEADER*)&pPipeline->msStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600448 memcpy((void*)&pPipeline->msStateCI, pTrav, sizeof(VkPipelineMsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600449 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600450 case VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600451 pPrev->pNext = &pPipeline->cbStateCI;
452 pPrev = (GENERIC_HEADER*)&pPipeline->cbStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600453 memcpy((void*)&pPipeline->cbStateCI, pTrav, sizeof(VkPipelineCbStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600454 // Copy embedded ptrs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600455 pCBCI = (VkPipelineCbStateCreateInfo*)pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600456 pPipeline->attachmentCount = pCBCI->attachmentCount;
457 if (pPipeline->attachmentCount) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600458 pPipeline->pAttachments = new VkPipelineCbAttachmentState[pPipeline->attachmentCount];
459 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineCbAttachmentState);
460 memcpy((void*)pPipeline->pAttachments, ((VkPipelineCbStateCreateInfo*)pTrav)->pAttachments, bufferSize);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600461 }
462 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600463 case VK_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO:
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600464 pPrev->pNext = &pPipeline->dsStateCI;
465 pPrev = (GENERIC_HEADER*)&pPipeline->dsStateCI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466 memcpy((void*)&pPipeline->dsStateCI, pTrav, sizeof(VkPipelineDsStateCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600467 break;
468 default:
469 assert(0);
470 break;
471 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600472 pTrav = (GENERIC_HEADER*)pTrav->pNext;
473 }
474 pipelineMap[pPipeline->pipeline] = pPipeline;
475}
476// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600477static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600478{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600479 for (unordered_map<VkPipeline, PIPELINE_NODE*>::iterator ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600480 if ((*ii).second->pVertexBindingDescriptions) {
481 delete[] (*ii).second->pVertexBindingDescriptions;
482 }
483 if ((*ii).second->pVertexAttributeDescriptions) {
484 delete[] (*ii).second->pVertexAttributeDescriptions;
485 }
486 if ((*ii).second->pAttachments) {
487 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600488 }
489 delete (*ii).second;
490 }
491}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600492// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600493static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600494{
495 PIPELINE_NODE* pPipe = pipelineMap[pipeline];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600496 if (VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600497 if (pPipe->msStateCI.multisampleEnable)
498 return pPipe->msStateCI.samples;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600499 }
500 return 1;
501}
502// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600503static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600504{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600506 // Verify that any MSAA request in PSO matches sample# in bound FB
507 uint32_t psoNumSamples = getNumSamples(pipeline);
508 if (pCB->activeRenderPass) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600509 VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass];
510 VkFramebufferCreateInfo* pFBCI = frameBufferMap[pCB->framebuffer];
Tobin Ehlis2464b882015-04-01 08:40:34 -0600511 if (psoNumSamples != pFBCI->sampleCount) {
512 char str[1024];
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600513 sprintf(str, "Num samples mismatche! Binding PSO (%p) with %u samples while current RenderPass (%p) uses FB (%p) with %u samples!", (void*)pipeline, psoNumSamples, (void*)pCB->activeRenderPass, (void*)pCB->framebuffer, pFBCI->sampleCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600514 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS", str);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600515 }
516 } else {
517 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
518 // Verify and flag error as appropriate
519 }
520 // TODO : Add more checks here
521 } else {
522 // TODO : Validate non-gfx pipeline updates
523 }
524}
525
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600526// Block of code at start here specifically for managing/tracking DSs
527
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600528// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600529static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600530{
531 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600532 if (poolMap.find(pool) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600533 loader_platform_thread_unlock_mutex(&globalLock);
534 return NULL;
535 }
536 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600537 return poolMap[pool];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600538}
539// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600540static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600541{
542 loader_platform_thread_lock_mutex(&globalLock);
543 if (setMap.find(set) == setMap.end()) {
544 loader_platform_thread_unlock_mutex(&globalLock);
545 return NULL;
546 }
547 loader_platform_thread_unlock_mutex(&globalLock);
548 return setMap[set];
549}
550
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600551// Return VK_TRUE if DS Exists and is within an vkBeginDescriptorPoolUpdate() call sequence, otherwise VK_FALSE
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600552static bool32_t dsUpdateActive(VkDescriptorSet ds)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600553{
554 // Note, both "get" functions use global mutex so this guy does not
555 SET_NODE* pTrav = getSetNode(ds);
556 if (pTrav) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600557 POOL_NODE* pPool = getPoolNode(pTrav->pool);
558 if (pPool) {
559 return pPool->updateActive;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600560 }
561 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600562 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600563}
564
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600565static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600566 loader_platform_thread_lock_mutex(&globalLock);
567 if (layoutMap.find(layout) == layoutMap.end()) {
568 loader_platform_thread_unlock_mutex(&globalLock);
569 return NULL;
570 }
571 loader_platform_thread_unlock_mutex(&globalLock);
572 return layoutMap[layout];
573}
574
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600575// For given update struct, return binding
576static uint32_t getUpdateBinding(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600577{
578 switch (pUpdateStruct->sType)
579 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600580 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600581 return ((VkUpdateSamplers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600583 return ((VkUpdateSamplerTextures*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600585 return ((VkUpdateImages*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600586 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600587 return ((VkUpdateBuffers*)pUpdateStruct)->binding;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600588 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600589 return ((VkUpdateAsCopy*)pUpdateStruct)->binding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600590 default:
591 // TODO : Flag specific error for this case
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600592 assert(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600593 return 0;
594 }
595}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600596// Return count for given update struct
597static uint32_t getUpdateArrayIndex(const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600598{
599 switch (pUpdateStruct->sType)
600 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600601 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600602 return (((VkUpdateSamplers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600603 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600604 return (((VkUpdateSamplerTextures*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600605 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600606 return (((VkUpdateImages*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600607 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600608 return (((VkUpdateBuffers*)pUpdateStruct)->arrayIndex);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600609 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600610 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600611 return (((VkUpdateAsCopy*)pUpdateStruct)->arrayElement);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600612 default:
613 // TODO : Flag specific error for this case
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600614 assert(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600615 return 0;
616 }
617}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600618// Return count for given update struct
619static uint32_t getUpdateCount(const GENERIC_HEADER* pUpdateStruct)
620{
621 switch (pUpdateStruct->sType)
622 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600623 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624 return (((VkUpdateSamplers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600626 return (((VkUpdateSamplerTextures*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600627 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600628 return (((VkUpdateImages*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600629 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600630 return (((VkUpdateBuffers*)pUpdateStruct)->count);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600631 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600632 // TODO : Need to understand this case better and make sure code is correct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600633 return (((VkUpdateAsCopy*)pUpdateStruct)->count);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600634 default:
635 // TODO : Flag specific error for this case
636 assert(0);
637 return 0;
638 }
639}
640// For given Layout Node and binding, return index where that binding begins
641static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
642{
643 uint32_t offsetIndex = 0;
644 for (uint32_t i = 0; i<binding; i++) {
645 offsetIndex += pLayout->createInfo.pBinding[i].count;
646 }
647 return offsetIndex;
648}
649// For given layout node and binding, return last index that is updated
650static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
651{
652 uint32_t offsetIndex = 0;
653 for (uint32_t i = 0; i<=binding; i++) {
654 offsetIndex += pLayout->createInfo.pBinding[i].count;
655 }
656 return offsetIndex-1;
657}
658// For given layout and update, return the first overall index of the layout that is update
659static uint32_t getUpdateStartIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
660{
661 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct));
662}
663// For given layout and update, return the last overall index of the layout that is update
664static uint32_t getUpdateEndIndex(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
665{
666 return (getBindingStartIndex(pLayout, getUpdateBinding(pUpdateStruct))+getUpdateArrayIndex(pUpdateStruct)+getUpdateCount(pUpdateStruct)-1);
667}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600668// Verify that the descriptor type in the update struct matches what's expected by the layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600669static bool32_t validateUpdateType(const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600670{
671 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600672 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600673 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600674 switch (pUpdateStruct->sType)
675 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600676 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
677 actualType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600678 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600679 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
680 actualType = VK_DESCRIPTOR_TYPE_SAMPLER_TEXTURE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600681 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600682 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600683 actualType = ((VkUpdateImages*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600684 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600686 actualType = ((VkUpdateBuffers*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600687 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600688 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600689 actualType = ((VkUpdateAsCopy*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600690 break;
691 default:
692 // TODO : Flag specific error for this case
693 return 0;
694 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600695 for (i = getUpdateStartIndex(pLayout, pUpdateStruct); i <= getUpdateEndIndex(pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600696 if (pLayout->pTypes[i] != actualType)
697 return 0;
698 }
699 return 1;
700}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600701// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
702// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
703// NOTE : Calls to this function should be wrapped in mutex
704static GENERIC_HEADER* shadowUpdateNode(GENERIC_HEADER* pUpdate)
705{
706 GENERIC_HEADER* pNewNode = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600707 VkUpdateSamplers* pUS = NULL;
708 VkUpdateSamplerTextures* pUST = NULL;
709 VkUpdateBuffers* pUB = NULL;
710 VkUpdateImages* pUI = NULL;
711 VkUpdateAsCopy* pUAC = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600712 size_t array_size = 0;
713 size_t base_array_size = 0;
714 size_t total_array_size = 0;
715 size_t baseBuffAddr = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600716 VkImageViewAttachInfo** ppLocalImageViews = NULL;
717 VkBufferViewAttachInfo** ppLocalBufferViews = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600718 char str[1024];
719 switch (pUpdate->sType)
720 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600721 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600722 pUS = new VkUpdateSamplers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600723 pNewNode = (GENERIC_HEADER*)pUS;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724 memcpy(pUS, pUpdate, sizeof(VkUpdateSamplers));
725 pUS->pSamplers = new VkSampler[pUS->count];
726 array_size = sizeof(VkSampler) * pUS->count;
727 memcpy((void*)pUS->pSamplers, ((VkUpdateSamplers*)pUpdate)->pSamplers, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600728 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600729 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600730 pUST = new VkUpdateSamplerTextures;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600731 pNewNode = (GENERIC_HEADER*)pUST;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732 memcpy(pUST, pUpdate, sizeof(VkUpdateSamplerTextures));
733 pUST->pSamplerImageViews = new VkSamplerImageViewInfo[pUST->count];
734 array_size = sizeof(VkSamplerImageViewInfo) * pUST->count;
735 memcpy((void*)pUST->pSamplerImageViews, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews, array_size);
Tobin Ehliseaf28662015-04-08 10:58:37 -0600736 for (uint32_t i = 0; i < pUST->count; i++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600737 VkImageViewAttachInfo** ppIV = (VkImageViewAttachInfo**)&pUST->pSamplerImageViews[i].pImageView;
738 *ppIV = new VkImageViewAttachInfo;
739 memcpy((void*)*ppIV, ((VkUpdateSamplerTextures*)pUpdate)->pSamplerImageViews[i].pImageView, sizeof(VkImageViewAttachInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600740 }
741 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600742 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600743 pUI = new VkUpdateImages;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600744 pNewNode = (GENERIC_HEADER*)pUI;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600745 memcpy(pUI, pUpdate, sizeof(VkUpdateImages));
746 pUI->pImageViews = new VkImageViewAttachInfo[pUI->count];
747 array_size = (sizeof(VkImageViewAttachInfo) * pUI->count);
748 memcpy((void*)pUI->pImageViews, ((VkUpdateImages*)pUpdate)->pImageViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600749 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600751 pUB = new VkUpdateBuffers;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600752 pNewNode = (GENERIC_HEADER*)pUB;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600753 memcpy(pUB, pUpdate, sizeof(VkUpdateBuffers));
754 pUB->pBufferViews = new VkBufferViewAttachInfo[pUB->count];
755 array_size = (sizeof(VkBufferViewAttachInfo) * pUB->count);
756 memcpy((void*)pUB->pBufferViews, ((VkUpdateBuffers*)pUpdate)->pBufferViews, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600757 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600759 pUAC = new VkUpdateAsCopy;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600760 pUpdate = (GENERIC_HEADER*)pUAC;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600761 memcpy(pUAC, pUpdate, sizeof(VkUpdateAsCopy));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600762 break;
763 default:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764 sprintf(str, "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600765 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600766 return NULL;
767 }
768 // Make sure that pNext for the end of shadow copy is NULL
769 pNewNode->pNext = NULL;
770 return pNewNode;
771}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600772// For given ds, update its mapping based on ppUpdateArray
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600773static void dsUpdate(VkDescriptorSet ds, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600774{
775 SET_NODE* pSet = getSetNode(ds);
776 loader_platform_thread_lock_mutex(&globalLock);
777 g_lastBoundDescriptorSet = pSet->set;
778 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600779 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600780 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600781 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600782 for (uint32_t i = 0; i < updateCount; i++) {
783 GENERIC_HEADER* pUpdate = (GENERIC_HEADER*)ppUpdateArray[i];
784 pLayout = pSet->pLayout;
785 // Make sure that binding is within bounds
786 if (pLayout->createInfo.count < getUpdateBinding(pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600787 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600788 sprintf(str, "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, getUpdateBinding(pUpdate), string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600789 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600790 }
791 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600792 // Next verify that update falls within size of given binding
793 if (getBindingEndIndex(pLayout, getUpdateBinding(pUpdate)) < getUpdateEndIndex(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600794 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600795 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600796 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
797 sprintf(str, "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), getUpdateBinding(pUpdate), DSstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600798 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600799 }
800 else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600801 // Layout bindings match w/ update ok, now verify that update is of the right type
802 if (!validateUpdateType(pLayout, pUpdate)) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600803 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600804 sprintf(str, "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600805 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600806 }
807 else {
808 // Save the update info
809 // TODO : Info message that update successful
810 // Create new update struct for this set's shadow copy
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600811 GENERIC_HEADER* pNewNode = shadowUpdateNode(pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600812 if (NULL == pNewNode) {
813 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600814 sprintf(str, "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
815 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, ds, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600816 }
817 else {
818 // Insert shadow node into LL of updates for this set
819 pNewNode->pNext = pSet->pUpdateStructs;
820 pSet->pUpdateStructs = pNewNode;
821 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600822 for (uint32_t j = getUpdateStartIndex(pLayout, pUpdate); j <= getUpdateEndIndex(pLayout, pUpdate); j++) {
823 assert(j<pSet->descriptorCount);
824 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600825 }
826 }
827 }
828 }
829 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600830 }
831 loader_platform_thread_unlock_mutex(&globalLock);
832}
833// Free the shadowed update node for this Set
834// NOTE : Calls to this function should be wrapped in mutex
835static void freeShadowUpdateTree(SET_NODE* pSet)
836{
837 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
838 pSet->pUpdateStructs = NULL;
839 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
840 // Clear the descriptor mappings as they will now be invalid
841 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
842 while(pShadowUpdate) {
843 pFreeUpdate = pShadowUpdate;
844 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
845 uint32_t index = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600846 VkUpdateSamplers* pUS = NULL;
847 VkUpdateSamplerTextures* pUST = NULL;
848 VkUpdateImages* pUI = NULL;
849 VkUpdateBuffers* pUB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600850 void** ppToFree = NULL;
851 switch (pFreeUpdate->sType)
852 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600853 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600854 pUS = (VkUpdateSamplers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600855 if (pUS->pSamplers)
856 delete[] pUS->pSamplers;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600857 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600858 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600859 pUST = (VkUpdateSamplerTextures*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600860 if (pUST->pSamplerImageViews) {
861 for (index = 0; index < pUST->count; index++) {
862 if (pUST->pSamplerImageViews[index].pImageView) {
863 delete pUST->pSamplerImageViews[index].pImageView;
864 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600865 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600866 delete[] pUST->pSamplerImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600867 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600868 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600870 pUI = (VkUpdateImages*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600871 if (pUI->pImageViews)
872 delete[] pUI->pImageViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600873 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600874 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600875 pUB = (VkUpdateBuffers*)pFreeUpdate;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600876 if (pUB->pBufferViews)
877 delete[] pUB->pBufferViews;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600878 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600879 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880 break;
881 default:
882 assert(0);
883 break;
884 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600885 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600886 }
887}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600888// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600889// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600890static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600891{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600892 for (unordered_map<VkDescriptorPool, POOL_NODE*>::iterator ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600893 SET_NODE* pSet = (*ii).second->pSets;
894 SET_NODE* pFreeSet = pSet;
895 while (pSet) {
896 pFreeSet = pSet;
897 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600898 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600899 // Free Update shadow struct tree
900 freeShadowUpdateTree(pFreeSet);
901 if (pFreeSet->ppDescriptors) {
902 delete pFreeSet->ppDescriptors;
903 }
904 delete pFreeSet;
905 }
906 if ((*ii).second->createInfo.pTypeCount) {
907 delete (*ii).second->createInfo.pTypeCount;
908 }
909 delete (*ii).second;
910 }
911}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600912// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600913// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600914static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600915{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600916 for (unordered_map<VkDescriptorSetLayout, LAYOUT_NODE*>::iterator ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600917 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600918 if (pLayout->createInfo.pBinding) {
919 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
920 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
921 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
922 }
923 delete[] pLayout->createInfo.pBinding;
924 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600925 if (pLayout->pTypes) {
926 delete pLayout->pTypes;
927 }
928 delete pLayout;
929 }
930}
931// Currently clearing a set is removing all previous updates to that set
932// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600933static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600934{
935 SET_NODE* pSet = getSetNode(set);
936 if (!pSet) {
937 // TODO : Return error
938 }
939 else {
940 loader_platform_thread_lock_mutex(&globalLock);
941 freeShadowUpdateTree(pSet);
942 loader_platform_thread_unlock_mutex(&globalLock);
943 }
944}
945
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600946static void clearDescriptorPool(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600947{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600948 POOL_NODE* pPool = getPoolNode(pool);
949 if (!pPool) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600950 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600951 sprintf(str, "Unable to find pool node for pool %p specified in vkClearDescriptorPool() call", (void*)pool);
952 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600953 }
954 else
955 {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600956 // For every set off of this pool, clear it
957 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600958 while (pSet) {
959 clearDescriptorSet(pSet->set);
960 }
961 }
962}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600963// Code here to manage the Cmd buffer LL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600964static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600965{
966 loader_platform_thread_lock_mutex(&globalLock);
967 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
968 loader_platform_thread_unlock_mutex(&globalLock);
969 return NULL;
970 }
971 loader_platform_thread_unlock_mutex(&globalLock);
972 return cmdBufferMap[cb];
973}
974// Free all CB Nodes
975// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600976static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600977{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600978 for (unordered_map<VkCmdBuffer, GLOBAL_CB_NODE*>::iterator ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600979 while (!(*ii).second->pCmds.empty()) {
980 delete (*ii).second->pCmds.back();
981 (*ii).second->pCmds.pop_back();
982 }
983 delete (*ii).second;
984 }
985}
986static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
987{
988 CMD_NODE* pCmd = new CMD_NODE;
989 if (pCmd) {
990 // init cmd node and append to end of cmd LL
991 memset(pCmd, 0, sizeof(CMD_NODE));
992 pCmd->cmdNumber = ++pCB->numCmds;
993 pCmd->type = cmd;
994 pCB->pCmds.push_back(pCmd);
995 }
996 else {
997 char str[1024];
998 sprintf(str, "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %p", (void*)pCB->cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600999 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCB->cmdBuffer, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001000 }
1001}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001002static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001003{
1004 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1005 if (pCB) {
1006 while (!pCB->pCmds.empty()) {
1007 delete pCB->pCmds.back();
1008 pCB->pCmds.pop_back();
1009 }
1010 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001011 VkFlags saveFlags = pCB->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001012 uint32_t saveQueueNodeIndex = pCB->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001013 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1014 pCB->cmdBuffer = cb;
1015 pCB->flags = saveFlags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001016 pCB->queueNodeIndex = saveQueueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017 pCB->lastVtxBinding = MAX_BINDING;
1018 }
1019}
1020// Set the last bound dynamic state of given type
1021// TODO : Need to track this per cmdBuffer and correlate cmdBuffer for Draw w/ last bound for that cmdBuffer?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001022static void setLastBoundDynamicState(const VkCmdBuffer cmdBuffer, const VkDynamicStateObject state, const VkStateBindPoint sType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023{
1024 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1025 if (pCB) {
1026 updateCBTracking(cmdBuffer);
1027 loader_platform_thread_lock_mutex(&globalLock);
1028 addCmd(pCB, CMD_BINDDYNAMICSTATEOBJECT);
1029 if (dynamicStateMap.find(state) == dynamicStateMap.end()) {
1030 char str[1024];
1031 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001032 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001033 }
1034 else {
1035 pCB->lastBoundDynamicState[sType] = dynamicStateMap[state];
1036 g_lastBoundDynamicState[sType] = dynamicStateMap[state];
1037 }
1038 loader_platform_thread_unlock_mutex(&globalLock);
1039 }
1040 else {
1041 char str[1024];
1042 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001043 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001044 }
1045}
1046// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001047static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001048{
1049 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1050 if (pCB) {
1051 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1052 if (!pPipeTrav) {
1053 // nothing to print
1054 }
1055 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001056 string pipeStr = vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001057 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", pipeStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001058 }
1059 }
1060}
1061// Common Dot dumping code
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001062static void dsCoreDumpDot(const VkDescriptorSet ds, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001063{
1064 SET_NODE* pSet = getSetNode(ds);
1065 if (pSet) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001066 POOL_NODE* pPool = getPoolNode(pSet->pool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001067 char tmp_str[4*1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001068 fprintf(pOutFile, "subgraph cluster_DescriptorPool\n{\nlabel=\"Descriptor Pool\"\n");
1069 sprintf(tmp_str, "Pool (%p)", pPool->pool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001070 char* pGVstr = vk_gv_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001071 fprintf(pOutFile, "%s", pGVstr);
1072 free(pGVstr);
1073 fprintf(pOutFile, "subgraph cluster_DescriptorSet\n{\nlabel=\"Descriptor Set (%p)\"\n", pSet->set);
1074 sprintf(tmp_str, "Descriptor Set (%p)", pSet->set);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001075 LAYOUT_NODE* pLayout = pSet->pLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001076 uint32_t layout_index = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001077 ++layout_index;
1078 sprintf(tmp_str, "LAYOUT%u", layout_index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001079 pGVstr = vk_gv_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001080 fprintf(pOutFile, "%s", pGVstr);
1081 free(pGVstr);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001082 if (pSet->pUpdateStructs) {
1083 pGVstr = dynamic_gv_display(pSet->pUpdateStructs, "Descriptor Updates");
1084 fprintf(pOutFile, "%s", pGVstr);
1085 free(pGVstr);
1086 }
1087 if (pSet->ppDescriptors) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001088 fprintf(pOutFile, "\"DESCRIPTORS\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD COLSPAN=\"2\" PORT=\"desc\">DESCRIPTORS</TD></TR>");
1089 uint32_t i = 0;
1090 for (i=0; i < pSet->descriptorCount; i++) {
1091 if (pSet->ppDescriptors[i]) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001092 fprintf(pOutFile, "<TR><TD PORT=\"slot%u\">slot%u</TD><TD>%s</TD></TR>", i, i, string_VkStructureType(pSet->ppDescriptors[i]->sType));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001093 }
1094 }
1095#define NUM_COLORS 7
1096 vector<string> edgeColors;
1097 edgeColors.push_back("0000ff");
1098 edgeColors.push_back("ff00ff");
1099 edgeColors.push_back("ffff00");
1100 edgeColors.push_back("00ff00");
1101 edgeColors.push_back("000000");
1102 edgeColors.push_back("00ffff");
1103 edgeColors.push_back("ff0000");
1104 uint32_t colorIdx = 0;
1105 fprintf(pOutFile, "</TABLE>>\n];\n");
1106 // Now add the views that are mapped to active descriptors
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001107 VkUpdateSamplers* pUS = NULL;
1108 VkUpdateSamplerTextures* pUST = NULL;
1109 VkUpdateImages* pUI = NULL;
1110 VkUpdateBuffers* pUB = NULL;
1111 VkUpdateAsCopy* pUAC = NULL;
1112 VkSamplerCreateInfo* pSCI = NULL;
1113 VkImageViewCreateInfo* pIVCI = NULL;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001114 VkBufferViewCreateInfo* pBVCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001115 void** ppNextPtr = NULL;
1116 void* pSaveNext = NULL;
1117 for (i=0; i < pSet->descriptorCount; i++) {
1118 if (pSet->ppDescriptors[i]) {
1119 switch (pSet->ppDescriptors[i]->sType)
1120 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001121 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001122 pUS = (VkUpdateSamplers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001123 pSCI = getSamplerCreateInfo(pUS->pSamplers[i-pUS->arrayIndex]);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001124 if (pSCI) {
1125 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001126 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001127 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1128 }
1129 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001130 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001131 pUST = (VkUpdateSamplerTextures*)pSet->ppDescriptors[i];
Courtney Goeltzenleuchterd38dcc92015-04-09 11:43:10 -06001132 pSCI = getSamplerCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].sampler);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001133 if (pSCI) {
1134 sprintf(tmp_str, "SAMPLER%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001135 fprintf(pOutFile, "%s", vk_gv_print_vksamplercreateinfo(pSCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001136 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1137 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001138 pIVCI = getImageViewCreateInfo(pUST->pSamplerImageViews[i-pUST->arrayIndex].pImageView->view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001139 if (pIVCI) {
1140 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001141 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001142 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1143 }
1144 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001145 case VK_STRUCTURE_TYPE_UPDATE_IMAGES:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001146 pUI = (VkUpdateImages*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001147 pIVCI = getImageViewCreateInfo(pUI->pImageViews[i-pUI->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001148 if (pIVCI) {
1149 sprintf(tmp_str, "IMAGE_VIEW%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001150 fprintf(pOutFile, "%s", vk_gv_print_vkimageviewcreateinfo(pIVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001151 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1152 }
1153 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001154 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001155 pUB = (VkUpdateBuffers*)pSet->ppDescriptors[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001156 pBVCI = getBufferViewCreateInfo(pUB->pBufferViews[i-pUB->arrayIndex].view);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001157 if (pBVCI) {
1158 sprintf(tmp_str, "BUFFER_VIEW%u", i);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001159 fprintf(pOutFile, "%s", vk_gv_print_vkbufferviewcreateinfo(pBVCI, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001160 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1161 }
1162 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001163 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001164 pUAC = (VkUpdateAsCopy*)pSet->ppDescriptors[i];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001165 // TODO : Need to validate this code
1166 // Save off pNext and set to NULL while printing this struct, then restore it
1167 ppNextPtr = (void**)&pUAC->pNext;
1168 pSaveNext = *ppNextPtr;
1169 *ppNextPtr = NULL;
1170 sprintf(tmp_str, "UPDATE_AS_COPY%u", i);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001171 fprintf(pOutFile, "%s", vk_gv_print_vkupdateascopy(pUAC, tmp_str));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001172 fprintf(pOutFile, "\"DESCRIPTORS\":slot%u -> \"%s\" [color=\"#%s\"];\n", i, tmp_str, edgeColors[colorIdx].c_str());
1173 // Restore next ptr
1174 *ppNextPtr = pSaveNext;
1175 break;
1176 default:
1177 break;
1178 }
1179 colorIdx = (colorIdx+1) % NUM_COLORS;
1180 }
1181 }
1182 }
1183 fprintf(pOutFile, "}\n");
1184 fprintf(pOutFile, "}\n");
1185 }
1186}
1187// Dump subgraph w/ DS info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001188static void dsDumpDot(const VkCmdBuffer cb, FILE* pOutFile)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001189{
1190 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1191 if (pCB && pCB->lastBoundDescriptorSet) {
1192 dsCoreDumpDot(pCB->lastBoundDescriptorSet, pOutFile);
1193 }
1194}
1195// Dump a GraphViz dot file showing the Cmd Buffers
1196static void cbDumpDotFile(string outFileName)
1197{
1198 // Print CB Chain for each CB
1199 FILE* pOutFile;
1200 pOutFile = fopen(outFileName.c_str(), "w");
1201 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1202 fprintf(pOutFile, "subgraph cluster_cmdBuffers\n{\nlabel=\"Command Buffers\"\n");
1203 GLOBAL_CB_NODE* pCB = NULL;
1204 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
1205 pCB = g_pLastTouchedCB[i];
1206 if (pCB) {
1207 fprintf(pOutFile, "subgraph cluster_cmdBuffer%u\n{\nlabel=\"Command Buffer #%u\"\n", i, i);
1208 uint32_t instNum = 0;
1209 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1210 if (instNum) {
1211 fprintf(pOutFile, "\"CB%pCMD%u\" -> \"CB%pCMD%u\" [];\n", (void*)pCB->cmdBuffer, instNum-1, (void*)pCB->cmdBuffer, instNum);
1212 }
1213 if (pCB == g_lastGlobalCB) {
1214 fprintf(pOutFile, "\"CB%pCMD%u\" [\nlabel=<<TABLE BGCOLOR=\"#00FF00\" BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD>CMD#</TD><TD>%u</TD></TR><TR><TD>CMD Type</TD><TD>%s</TD></TR></TABLE>>\n];\n", (void*)pCB->cmdBuffer, instNum, instNum, cmdTypeToString((*ii)->type).c_str());
1215 }
1216 else {
1217 fprintf(pOutFile, "\"CB%pCMD%u\" [\nlabel=<<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\"> <TR><TD>CMD#</TD><TD>%u</TD></TR><TR><TD>CMD Type</TD><TD>%s</TD></TR></TABLE>>\n];\n", (void*)pCB->cmdBuffer, instNum, instNum, cmdTypeToString((*ii)->type).c_str());
1218 }
1219 ++instNum;
1220 }
1221 fprintf(pOutFile, "}\n");
1222 }
1223 }
1224 fprintf(pOutFile, "}\n");
1225 fprintf(pOutFile, "}\n"); // close main graph "g"
1226 fclose(pOutFile);
1227}
1228// Dump a GraphViz dot file showing the pipeline for last bound global state
1229static void dumpGlobalDotFile(char *outFileName)
1230{
1231 PIPELINE_NODE *pPipeTrav = g_lastBoundPipeline;
1232 if (pPipeTrav) {
1233 FILE* pOutFile;
1234 pOutFile = fopen(outFileName, "w");
1235 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1236 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1237 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001238 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001239 if (g_lastBoundDynamicState[i] && g_lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001240 pGVstr = dynamic_gv_display(g_lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001241 fprintf(pOutFile, "%s", pGVstr);
1242 free(pGVstr);
1243 }
1244 }
1245 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1246 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001247 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001248 fprintf(pOutFile, "%s", pGVstr);
1249 free(pGVstr);
1250 fprintf(pOutFile, "}\n");
1251 dsCoreDumpDot(g_lastBoundDescriptorSet, pOutFile);
1252 fprintf(pOutFile, "}\n"); // close main graph "g"
1253 fclose(pOutFile);
1254 }
1255}
1256// Dump a GraphViz dot file showing the pipeline for a given CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001257static void dumpDotFile(const VkCmdBuffer cb, string outFileName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001258{
1259 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1260 if (pCB) {
1261 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1262 if (pPipeTrav) {
1263 FILE* pOutFile;
1264 pOutFile = fopen(outFileName.c_str(), "w");
1265 fprintf(pOutFile, "digraph g {\ngraph [\nrankdir = \"TB\"\n];\nnode [\nfontsize = \"16\"\nshape = \"plaintext\"\n];\nedge [\n];\n");
1266 fprintf(pOutFile, "subgraph cluster_dynamicState\n{\nlabel=\"Dynamic State\"\n");
1267 char* pGVstr = NULL;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001268 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001269 if (pCB->lastBoundDynamicState[i] && pCB->lastBoundDynamicState[i]->pCreateInfo) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001270 pGVstr = dynamic_gv_display(pCB->lastBoundDynamicState[i]->pCreateInfo, string_VkStateBindPoint((VkStateBindPoint)i));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001271 fprintf(pOutFile, "%s", pGVstr);
1272 free(pGVstr);
1273 }
1274 }
1275 fprintf(pOutFile, "}\n"); // close dynamicState subgraph
1276 fprintf(pOutFile, "subgraph cluster_PipelineStateObject\n{\nlabel=\"Pipeline State Object\"\n");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001277 pGVstr = vk_gv_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "PSO HEAD");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001278 fprintf(pOutFile, "%s", pGVstr);
1279 free(pGVstr);
1280 fprintf(pOutFile, "}\n");
1281 dsDumpDot(cb, pOutFile);
1282 fprintf(pOutFile, "}\n"); // close main graph "g"
1283 fclose(pOutFile);
1284 }
1285 }
1286}
1287// Verify VB Buffer binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001288static void validateVBBinding(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001289{
1290 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1291 if (pCB && pCB->lastBoundPipeline) {
1292 // First verify that we have a Node for bound pipeline
1293 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1294 char str[1024];
1295 if (!pPipeTrav) {
1296 sprintf(str, "Can't find last bound Pipeline %p!", (void*)pCB->lastBoundPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001297 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001298 }
1299 else {
1300 // Verify Vtx binding
1301 if (MAX_BINDING != pCB->lastVtxBinding) {
1302 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1303 if (0 == pPipeTrav->vtxBindingCount) {
1304 sprintf(str, "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001305 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001306 }
1307 else {
1308 sprintf(str, "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001309 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001310 }
1311 }
1312 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001313 string tmpStr = vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmpStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001315 }
1316 }
1317 }
1318 }
1319}
1320// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001321static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001322{
1323 char tmp_str[1024];
1324 char ds_config_str[1024*256] = {0}; // TODO : Currently making this buffer HUGE w/o overrun protection. Need to be smarter, start smaller, and grow as needed.
1325 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1326 if (pCB) {
1327 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001328 POOL_NODE* pPool = getPoolNode(pSet->pool);
1329 // Print out pool details
1330 sprintf(tmp_str, "Details for pool %p.", (void*)pPool->pool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001331 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001332 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001333 sprintf(ds_config_str, "%s", poolStr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001334 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001335 // Print out set details
1336 char prefix[10];
1337 uint32_t index = 0;
1338 sprintf(tmp_str, "Details for descriptor set %p.", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001339 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001340 LAYOUT_NODE* pLayout = pSet->pLayout;
1341 // Print layout details
1342 sprintf(tmp_str, "Layout #%u, (object %p) for DS %p.", index+1, (void*)pLayout->layout, (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001343 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001344 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001345 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001346 sprintf(ds_config_str, "%s", DSLstr.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001347 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001348 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001349 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1350 if (pUpdate) {
1351 sprintf(tmp_str, "Update Chain [UC] for descriptor set %p:", (void*)pSet->set);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001352 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001353 sprintf(prefix, " [UC] ");
1354 sprintf(ds_config_str, "%s", dynamic_display(pUpdate, prefix).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001355 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", ds_config_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001356 // TODO : If there is a "view" associated with this update, print CI for that view
1357 }
1358 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001359 sprintf(tmp_str, "No Update Chain for descriptor set %p (vkUpdateDescriptors has not been called)", (void*)pSet->set);
1360 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", tmp_str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001361 }
1362 }
1363}
1364
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001365static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001366{
1367 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1368 if (pCB) {
1369 char str[1024];
1370 sprintf(str, "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001371 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001372 for (vector<CMD_NODE*>::iterator ii=pCB->pCmds.begin(); ii!=pCB->pCmds.end(); ++ii) {
1373 sprintf(str, " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001374 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001375 }
1376 }
1377 else {
1378 // Nothing to print
1379 }
1380}
1381
1382
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001383static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001384{
1385 printDSConfig(cb);
1386 printPipeline(cb);
1387 printDynamicState(cb);
1388 static int autoDumpOnce = 0;
1389 if (autoDumpOnce) {
1390 autoDumpOnce = 0;
1391 dumpDotFile(cb, "pipeline_dump.dot");
1392 cbDumpDotFile("cb_dump.dot");
1393#if defined(_WIN32)
1394// FIXME: NEED WINDOWS EQUIVALENT
1395#else // WIN32
1396 // Convert dot to svg if dot available
1397 if(access( "/usr/bin/dot", X_OK) != -1) {
1398 system("/usr/bin/dot pipeline_dump.dot -Tsvg -o pipeline_dump.svg");
1399 }
1400#endif // WIN32
1401 }
1402}
1403
1404static void initDrawState(void)
1405{
1406 const char *strOpt;
1407 // initialize DrawState options
1408 getLayerOptionEnum("DrawStateReportLevel", (uint32_t *) &g_reportingLevel);
1409 g_actionIsDefault = getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &g_debugAction);
1410
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001411 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001412 {
1413 strOpt = getLayerOption("DrawStateLogFilename");
1414 if (strOpt)
1415 {
1416 g_logFile = fopen(strOpt, "w");
1417 }
1418 if (g_logFile == NULL)
1419 g_logFile = stdout;
1420 }
1421 // initialize Layer dispatch table
1422 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001423 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001424 fpNextGPA = pCurObj->pGPA;
1425 assert(fpNextGPA);
1426
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001427 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalGpu) pCurObj->nextObject);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001428
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001429 PFN_vkGetProcAddr fpGetProcAddr = (PFN_vkGetProcAddr)fpNextGPA((VkPhysicalGpu) pCurObj->nextObject, (char *) "vkGetProcAddr");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001430 nextTable.GetProcAddr = fpGetProcAddr;
1431
1432 if (!globalLockInitialized)
1433 {
1434 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001435 // suggestion is to call this during vkCreateInstance(), and then we
1436 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001437 // that the layer have per-instance locks. We need to come back and
1438 // address this soon.
1439 loader_platform_thread_create_mutex(&globalLock);
1440 globalLockInitialized = 1;
1441 }
1442}
1443
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001444VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001445{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001446 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001447 pCurObj = gpuw;
1448 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001449 VkResult result = nextTable.CreateDevice((VkPhysicalGpu)gpuw->nextObject, pCreateInfo, pDevice);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001450 return result;
1451}
1452
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001453VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001454{
1455 // Free all the memory
1456 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001457 deletePipelines();
1458 deleteSamplers();
1459 deleteImages();
1460 deleteBuffers();
1461 deleteCmdBuffers();
1462 deleteDynamicState();
1463 deletePools();
1464 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001465 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001466 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001467 return result;
1468}
1469
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001470VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
Jon Ashburn25566352015-04-02 12:06:28 -06001471{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001472 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001473 VkResult result;
Jon Ashburn25566352015-04-02 12:06:28 -06001474 /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */
1475 if (!strcmp(pExtName, "DrawState") || !strcmp(pExtName, "drawStateDumpDotFile") ||
1476 !strcmp(pExtName, "drawStateDumpCommandBufferDotFile") || !strcmp(pExtName, "drawStateDumpPngFile"))
1477 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001478 result = VK_SUCCESS;
Jon Ashburn25566352015-04-02 12:06:28 -06001479 } else if (nextTable.GetExtensionSupport != NULL)
1480 {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001481 result = nextTable.GetExtensionSupport((VkPhysicalGpu)gpuw->nextObject, pExtName);
Jon Ashburn25566352015-04-02 12:06:28 -06001482 } else
1483 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001484 result = VK_ERROR_INVALID_EXTENSION;
Jon Ashburn25566352015-04-02 12:06:28 -06001485 }
1486 return result;
1487}
1488
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001489VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount, size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001490{
1491 if (gpu != NULL)
1492 {
Jon Ashburn301c5f02015-04-06 10:58:22 -06001493 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001494 pCurObj = gpuw;
1495 loader_platform_thread_once(&g_initOnce, initDrawState);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001496 VkResult result = nextTable.EnumerateLayers((VkPhysicalGpu)gpuw->nextObject, maxLayerCount, maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001497 return result;
1498 } else
1499 {
1500 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001501 return VK_ERROR_INVALID_POINTER;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001502 // This layer compatible with all GPUs
1503 *pOutLayerCount = 1;
1504 strncpy((char *) pOutLayers[0], "DrawState", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001505 return VK_SUCCESS;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001506 }
1507}
1508
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001509VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001510{
1511 for (uint32_t i=0; i < cmdBufferCount; i++) {
1512 // Validate that cmd buffers have been updated
1513 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001514 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001515 return result;
1516}
1517
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001518VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001519{
1520 // TODO : When wrapped objects (such as dynamic state) are destroyed, need to clean up memory
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001521 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001522 return result;
1523}
1524
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001525VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001526{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001527 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001528 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001529 loader_platform_thread_lock_mutex(&globalLock);
1530 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1531 pNewNode->buffer = *pView;
1532 pNewNode->createInfo = *pCreateInfo;
1533 bufferMap[*pView] = pNewNode;
1534 loader_platform_thread_unlock_mutex(&globalLock);
1535 }
1536 return result;
1537}
1538
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001539VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001540{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001541 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001542 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001543 loader_platform_thread_lock_mutex(&globalLock);
1544 IMAGE_NODE *pNewNode = new IMAGE_NODE;
1545 pNewNode->image = *pView;
1546 pNewNode->createInfo = *pCreateInfo;
1547 imageMap[*pView] = pNewNode;
1548 loader_platform_thread_unlock_mutex(&globalLock);
1549 }
1550 return result;
1551}
1552
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001553static void track_pipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001554{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001555 // Create LL HEAD for this Pipeline
1556 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001557 PIPELINE_NODE* pPipeNode = new PIPELINE_NODE;
1558 memset((void*)pPipeNode, 0, sizeof(PIPELINE_NODE));
1559 pPipeNode->pipeline = *pPipeline;
1560 initPipeline(pPipeNode, pCreateInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001561 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001562}
1563
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001564VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001565{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001566 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001567 // Create LL HEAD for this Pipeline
1568 char str[1024];
1569 sprintf(str, "Created Gfx Pipeline %p", (void*)*pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001570 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001571
1572 track_pipeline(pCreateInfo, pPipeline);
1573
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001574 return result;
1575}
1576
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001577VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1578 VkDevice device,
1579 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1580 VkPipeline basePipeline,
1581 VkPipeline* pPipeline)
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001582{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001583 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001584 // Create LL HEAD for this Pipeline
1585 char str[1024];
1586 sprintf(str, "Created Gfx Pipeline %p (derived from pipeline %p)", (void*)*pPipeline, basePipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001587 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, *pPipeline, 0, DRAWSTATE_NONE, "DS", str);
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001588
1589 track_pipeline(pCreateInfo, pPipeline);
1590
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001591 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001592}
1593
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001594VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001595{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001596 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001597 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001598 loader_platform_thread_lock_mutex(&globalLock);
1599 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1600 pNewNode->sampler = *pSampler;
1601 pNewNode->createInfo = *pCreateInfo;
1602 sampleMap[*pSampler] = pNewNode;
1603 loader_platform_thread_unlock_mutex(&globalLock);
1604 }
1605 return result;
1606}
1607
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001608VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001609{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001610 VkResult result = nextTable.CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001611 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001612 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1613 if (NULL == pNewNode) {
1614 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001615 sprintf(str, "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
1616 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pSetLayout, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001617 }
1618 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001619 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1620 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1621 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001622 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001623 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1624 totalCount += pCreateInfo->pBinding[i].count;
1625 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001626 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
1627 *ppIS = new VkSampler[pCreateInfo->pBinding[i].count];
1628 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].count*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001629 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001630 }
1631 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001632 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001633 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001634 uint32_t j = 0;
1635 for (uint32_t i=0; i<pCreateInfo->count; i++) {
1636 for (j = 0; j < pCreateInfo->pBinding[i].count; j++) {
1637 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001638 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001639 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001640 }
1641 }
1642 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001643 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001644 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1645 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001646 // Put new node at Head of global Layer list
1647 loader_platform_thread_lock_mutex(&globalLock);
1648 layoutMap[*pSetLayout] = pNewNode;
1649 loader_platform_thread_unlock_mutex(&globalLock);
1650 }
1651 return result;
1652}
1653
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001654VkResult VKAPI vkCreateDescriptorSetLayoutChain(VkDevice device, uint32_t setLayoutArrayCount, const VkDescriptorSetLayout* pSetLayoutArray, VkDescriptorSetLayoutChain* pLayoutChain)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001655{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001656 VkResult result = nextTable.CreateDescriptorSetLayoutChain(device, setLayoutArrayCount, pSetLayoutArray, pLayoutChain);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001657 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001658 // TODO : Need to capture the layout chains
1659 }
1660 return result;
1661}
1662
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001663VK_LAYER_EXPORT VkResult VKAPI vkBeginDescriptorPoolUpdate(VkDevice device, VkDescriptorUpdateMode updateMode)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001664{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001665 VkResult result = nextTable.BeginDescriptorPoolUpdate(device, updateMode);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001666 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001667 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001668 POOL_NODE* pPoolNode = poolMap.begin()->second;
1669 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001670 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001671 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001672 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001673 }
1674 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001675 pPoolNode->updateActive = 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001676 }
1677 loader_platform_thread_unlock_mutex(&globalLock);
1678 }
1679 return result;
1680}
1681
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001682VK_LAYER_EXPORT VkResult VKAPI vkEndDescriptorPoolUpdate(VkDevice device, VkCmdBuffer cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001684 VkResult result = nextTable.EndDescriptorPoolUpdate(device, cmd);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001685 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001686 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001687 POOL_NODE* pPoolNode = poolMap.begin()->second;
1688 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001689 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001690 sprintf(str, "Unable to find pool node");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001691 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_INTERNAL_ERROR, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001692 }
1693 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001694 if (!pPoolNode->updateActive) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001695 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001696 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkEndDescriptorPoolUpdate()!");
1697 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_DS_END_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001698 }
1699 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001700 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001701 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001702 pPoolNode->updateActive = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001703 }
1704 loader_platform_thread_unlock_mutex(&globalLock);
1705 }
1706 return result;
1707}
1708
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001709VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001710{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001711 VkResult result = nextTable.CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001712 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001713 // Insert this pool into Global Pool LL at head
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001714 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001715 sprintf(str, "Created Descriptor Pool %p", (void*)*pDescriptorPool);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001716 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (VkBaseObject)pDescriptorPool, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001717 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001718 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001719 if (NULL == pNewNode) {
1720 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001721 sprintf(str, "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001722 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, (VkBaseObject)*pDescriptorPool, 0, DRAWSTATE_OUT_OF_MEMORY, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001723 }
1724 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001725 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001726 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1727 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001729 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1730 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001731 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1732 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001733 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001734 pNewNode->updateActive = 0;
1735 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001736 pNewNode->pool = *pDescriptorPool;
1737 poolMap[*pDescriptorPool] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001738 }
1739 loader_platform_thread_unlock_mutex(&globalLock);
1740 }
1741 else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001742 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001743 }
1744 return result;
1745}
1746
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001747VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001748{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001749 VkResult result = nextTable.ResetDescriptorPool(descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001750 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001751 clearDescriptorPool(descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001752 }
1753 return result;
1754}
1755
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001756VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001757{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001758 VkResult result = nextTable.AllocDescriptorSets(descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001759 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001760 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1761 if (!pPoolNode) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001762 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001763 sprintf(str, "Unable to find pool node for pool %p specified in vkAllocDescriptorSets() call", (void*)descriptorPool);
1764 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorPool, 0, DRAWSTATE_INVALID_POOL, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001765 }
1766 else {
1767 for (uint32_t i = 0; i < *pCount; i++) {
1768 char str[1024];
1769 sprintf(str, "Created Descriptor Set %p", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001770 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001771 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001772 SET_NODE* pNewNode = new SET_NODE;
1773 if (NULL == pNewNode) {
1774 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001775 sprintf(str, "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
1776 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 -06001777 }
1778 else {
1779 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001780 // Insert set at head of Set LL for this pool
1781 pNewNode->pNext = pPoolNode->pSets;
1782 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001783 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1784 if (NULL == pLayout) {
1785 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001786 sprintf(str, "Unable to find set layout node for layout %p specified in vkAllocDescriptorSets() call", (void*)pSetLayouts[i]);
1787 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSetLayouts[i], 0, DRAWSTATE_INVALID_LAYOUT, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001788 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001789 pNewNode->pLayout = pLayout;
1790 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001791 pNewNode->set = pDescriptorSets[i];
1792 pNewNode->setUsage = setUsage;
1793 pNewNode->descriptorCount = pLayout->endIndex + 1;
1794 if (pNewNode->descriptorCount) {
1795 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1796 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1797 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1798 }
1799 setMap[pDescriptorSets[i]] = pNewNode;
1800 }
1801 }
1802 }
1803 }
1804 return result;
1805}
1806
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001807VK_LAYER_EXPORT void VKAPI vkClearDescriptorSets(VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808{
1809 for (uint32_t i = 0; i < count; i++) {
1810 clearDescriptorSet(pDescriptorSets[i]);
1811 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001812 nextTable.ClearDescriptorSets(descriptorPool, count, pDescriptorSets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001813}
1814
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001815VK_LAYER_EXPORT void VKAPI vkUpdateDescriptors(VkDescriptorSet descriptorSet, uint32_t updateCount, const void** ppUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001816{
1817 SET_NODE* pSet = getSetNode(descriptorSet);
1818 if (!dsUpdateActive(descriptorSet)) {
1819 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001820 sprintf(str, "You must call vkBeginDescriptorPoolUpdate() before this call to vkUpdateDescriptors()!");
1821 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pSet->pool, 0, DRAWSTATE_UPDATE_WITHOUT_BEGIN, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001822 }
1823 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001824 // pUpdateChain is a Linked-list of VK_UPDATE_* structures defining the mappings for the descriptors
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001825 dsUpdate(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001826 }
1827
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001828 nextTable.UpdateDescriptors(descriptorSet, updateCount, ppUpdateArray);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001829}
1830
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001831VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo, VkDynamicVpStateObject* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001832{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001833 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001834 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_VIEWPORT);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835 return result;
1836}
1837
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001838VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo, VkDynamicRsStateObject* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001839{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001840 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001841 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_RASTER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001842 return result;
1843}
1844
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001845VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo, VkDynamicCbStateObject* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001846{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001847 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_COLOR_BLEND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849 return result;
1850}
1851
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001852VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo, VkDynamicDsStateObject* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001854 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001855 insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_DEPTH_STENCIL);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001856 return result;
1857}
1858
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001859VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001860{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001861 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001862 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001863 loader_platform_thread_lock_mutex(&globalLock);
1864 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1865 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1866 pCB->cmdBuffer = *pCmdBuffer;
1867 pCB->flags = pCreateInfo->flags;
Courtney Goeltzenleuchterf3168062015-03-05 18:09:39 -07001868 pCB->queueNodeIndex = pCreateInfo->queueNodeIndex;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001869 pCB->lastVtxBinding = MAX_BINDING;
1870 cmdBufferMap[*pCmdBuffer] = pCB;
1871 loader_platform_thread_unlock_mutex(&globalLock);
1872 updateCBTracking(*pCmdBuffer);
1873 }
1874 return result;
1875}
1876
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001877VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001878{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001879 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001880 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1882 if (pCB) {
1883 if (CB_NEW != pCB->state)
1884 resetCB(cmdBuffer);
1885 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001886 if (pBeginInfo->pNext) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001887 VkCmdBufferGraphicsBeginInfo* pCbGfxBI = (VkCmdBufferGraphicsBeginInfo*)pBeginInfo->pNext;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001888 if (VK_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO == pCbGfxBI->sType) {
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001889 pCB->activeRenderPass = pCbGfxBI->renderPassContinue.renderPass;
Tobin Ehlis2464b882015-04-01 08:40:34 -06001890 }
1891 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001892 }
1893 else {
1894 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001895 sprintf(str, "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1896 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001897 }
1898 updateCBTracking(cmdBuffer);
1899 }
1900 return result;
1901}
1902
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001903VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001904{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001905 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001907 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1908 if (pCB) {
1909 pCB->state = CB_UPDATE_COMPLETE;
1910 printCB(cmdBuffer);
1911 }
1912 else {
1913 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001914 sprintf(str, "In vkEndCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
1915 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001916 }
1917 updateCBTracking(cmdBuffer);
1918 //cbDumpDotFile("cb_dump.dot");
1919 }
1920 return result;
1921}
1922
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001923VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001924{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001925 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001926 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001927 resetCB(cmdBuffer);
1928 updateCBTracking(cmdBuffer);
1929 }
1930 return result;
1931}
1932
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001933VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001934{
1935 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1936 if (pCB) {
1937 updateCBTracking(cmdBuffer);
1938 addCmd(pCB, CMD_BINDPIPELINE);
1939 PIPELINE_NODE* pPN = getPipeline(pipeline);
1940 if (pPN) {
1941 pCB->lastBoundPipeline = pipeline;
1942 loader_platform_thread_lock_mutex(&globalLock);
1943 g_lastBoundPipeline = pPN;
1944 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis2464b882015-04-01 08:40:34 -06001945 validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001946 }
1947 else {
1948 char str[1024];
1949 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001950 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, DRAWSTATE_INVALID_PIPELINE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001951 }
1952 }
1953 else {
1954 char str[1024];
1955 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001956 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001957 }
1958 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1959}
1960
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001961VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001962{
1963 setLastBoundDynamicState(cmdBuffer, state, stateBindPoint);
1964 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
1965}
1966
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001967VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkDescriptorSetLayoutChain layoutChain, uint32_t layoutChainSlot, uint32_t count, const VkDescriptorSet* pDescriptorSets, const uint32_t* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001968{
1969 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1970 if (pCB) {
1971 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001972 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
1973 for (uint32_t i=0; i<count; i++) {
1974 if (getSetNode(pDescriptorSets[i])) {
1975 if (dsUpdateActive(pDescriptorSets[i])) {
1976 // TODO : This check here needs to be made at QueueSubmit time
1977 /*
1978 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001979 sprintf(str, "You must call vkEndDescriptorPoolUpdate(%p) before this call to vkCmdBindDescriptorSet()!", (void*)descriptorSet);
1980 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, descriptorSet, 0, DRAWSTATE_BINDING_DS_NO_END_UPDATE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001981 */
1982 }
1983 loader_platform_thread_lock_mutex(&globalLock);
1984 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
1985 g_lastBoundDescriptorSet = pDescriptorSets[i];
1986 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001987 char str[1024];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001988 sprintf(str, "DS %p bound on pipeline %s", (void*)pDescriptorSets[i], string_VkPipelineBindPoint(pipelineBindPoint));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001989 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001990 synchAndPrintDSConfig(cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001991 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001992 else {
1993 char str[1024];
1994 sprintf(str, "Attempt to bind DS %p that doesn't exist!", (void*)pDescriptorSets[i]);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001995 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pDescriptorSets[i], 0, DRAWSTATE_INVALID_SET, "DS", str);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001996 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001997 }
1998 }
1999 else {
2000 char str[1024];
2001 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002002 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002003 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002004 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layoutChain, layoutChainSlot, count, pDescriptorSets, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002005}
2006
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002007VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002008{
2009 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2010 if (pCB) {
2011 updateCBTracking(cmdBuffer);
2012 addCmd(pCB, CMD_BINDINDEXBUFFER);
2013 // TODO : Track idxBuffer binding
2014 }
2015 else {
2016 char str[1024];
2017 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002018 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002019 }
2020 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2021}
2022
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002023VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t binding)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002024{
2025 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2026 if (pCB) {
2027 updateCBTracking(cmdBuffer);
2028 addCmd(pCB, CMD_BINDVERTEXBUFFER);
2029 pCB->lastVtxBinding = binding;
2030 validateVBBinding(cmdBuffer);
2031 }
2032 else {
2033 char str[1024];
2034 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002035 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002036 }
2037 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
2038}
2039
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002040VK_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 -06002041{
2042 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2043 if (pCB) {
2044 updateCBTracking(cmdBuffer);
2045 addCmd(pCB, CMD_DRAW);
2046 pCB->drawCount[DRAW]++;
2047 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002048 sprintf(str, "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2049 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002050 synchAndPrintDSConfig(cmdBuffer);
2051 }
2052 else {
2053 char str[1024];
2054 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002055 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002056 }
2057 nextTable.CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2058}
2059
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002060VK_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 -06002061{
2062 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2063 if (pCB) {
2064 updateCBTracking(cmdBuffer);
2065 addCmd(pCB, CMD_DRAWINDEXED);
2066 pCB->drawCount[DRAW_INDEXED]++;
2067 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002068 sprintf(str, "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2069 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002070 synchAndPrintDSConfig(cmdBuffer);
2071 }
2072 else {
2073 char str[1024];
2074 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002075 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002076 }
2077 nextTable.CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2078}
2079
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002080VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002081{
2082 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2083 if (pCB) {
2084 updateCBTracking(cmdBuffer);
2085 addCmd(pCB, CMD_DRAWINDIRECT);
2086 pCB->drawCount[DRAW_INDIRECT]++;
2087 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002088 sprintf(str, "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2089 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002090 synchAndPrintDSConfig(cmdBuffer);
2091 }
2092 else {
2093 char str[1024];
2094 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002095 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002096 }
2097 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2098}
2099
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002100VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002101{
2102 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2103 if (pCB) {
2104 updateCBTracking(cmdBuffer);
2105 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2106 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
2107 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002108 sprintf(str, "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2109 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_NONE, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002110 synchAndPrintDSConfig(cmdBuffer);
2111 }
2112 else {
2113 char str[1024];
2114 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002115 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002116 }
2117 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2118}
2119
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002120VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002121{
2122 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2123 if (pCB) {
2124 updateCBTracking(cmdBuffer);
2125 addCmd(pCB, CMD_DISPATCH);
2126 }
2127 else {
2128 char str[1024];
2129 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002130 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002131 }
2132 nextTable.CmdDispatch(cmdBuffer, x, y, z);
2133}
2134
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002135VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002136{
2137 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2138 if (pCB) {
2139 updateCBTracking(cmdBuffer);
2140 addCmd(pCB, CMD_DISPATCHINDIRECT);
2141 }
2142 else {
2143 char str[1024];
2144 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002145 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002146 }
2147 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
2148}
2149
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002150VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002151{
2152 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2153 if (pCB) {
2154 updateCBTracking(cmdBuffer);
2155 addCmd(pCB, CMD_COPYBUFFER);
2156 }
2157 else {
2158 char str[1024];
2159 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002160 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002161 }
2162 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
2163}
2164
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002165VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2166 VkImage srcImage,
2167 VkImageLayout srcImageLayout,
2168 VkImage destImage,
2169 VkImageLayout destImageLayout,
2170 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002171{
2172 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2173 if (pCB) {
2174 updateCBTracking(cmdBuffer);
2175 addCmd(pCB, CMD_COPYIMAGE);
2176 }
2177 else {
2178 char str[1024];
2179 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002180 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002181 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002182 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002183}
2184
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002185VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2186 VkImage srcImage, VkImageLayout srcImageLayout,
2187 VkImage destImage, VkImageLayout destImageLayout,
2188 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002189{
2190 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2191 if (pCB) {
2192 updateCBTracking(cmdBuffer);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06002193 addCmd(pCB, CMD_BLITIMAGE);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002194 }
2195 else {
2196 char str[1024];
2197 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002198 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002199 }
2200 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
2201}
2202
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002203VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2204 VkBuffer srcBuffer,
2205 VkImage destImage, VkImageLayout destImageLayout,
2206 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002207{
2208 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2209 if (pCB) {
2210 updateCBTracking(cmdBuffer);
2211 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
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 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002218 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002219}
2220
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002221VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2222 VkImage srcImage, VkImageLayout srcImageLayout,
2223 VkBuffer destBuffer,
2224 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002225{
2226 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2227 if (pCB) {
2228 updateCBTracking(cmdBuffer);
2229 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2230 }
2231 else {
2232 char str[1024];
2233 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002234 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002235 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002236 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002237}
2238
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002239VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002240{
2241 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2242 if (pCB) {
2243 updateCBTracking(cmdBuffer);
2244 addCmd(pCB, CMD_CLONEIMAGEDATA);
2245 }
2246 else {
2247 char str[1024];
2248 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002249 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002250 }
2251 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
2252}
2253
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002254VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002255{
2256 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2257 if (pCB) {
2258 updateCBTracking(cmdBuffer);
2259 addCmd(pCB, CMD_UPDATEBUFFER);
2260 }
2261 else {
2262 char str[1024];
2263 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002264 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002265 }
2266 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
2267}
2268
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002269VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002270{
2271 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2272 if (pCB) {
2273 updateCBTracking(cmdBuffer);
2274 addCmd(pCB, CMD_FILLBUFFER);
2275 }
2276 else {
2277 char str[1024];
2278 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002279 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002280 }
2281 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
2282}
2283
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002284VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
2285 VkImage image, VkImageLayout imageLayout,
2286 VkClearColor color,
2287 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002288{
2289 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2290 if (pCB) {
2291 updateCBTracking(cmdBuffer);
2292 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2293 }
2294 else {
2295 char str[1024];
2296 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002297 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002298 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002299 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002300}
2301
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002302VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
2303 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002304 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002305 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002306{
2307 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2308 if (pCB) {
2309 updateCBTracking(cmdBuffer);
2310 addCmd(pCB, CMD_CLEARDEPTHSTENCIL);
2311 }
2312 else {
2313 char str[1024];
2314 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002315 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002316 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002317 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002318}
2319
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002320VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2321 VkImage srcImage, VkImageLayout srcImageLayout,
2322 VkImage destImage, VkImageLayout destImageLayout,
2323 uint32_t rectCount, const VkImageResolve* pRects)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002324{
2325 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2326 if (pCB) {
2327 updateCBTracking(cmdBuffer);
2328 addCmd(pCB, CMD_RESOLVEIMAGE);
2329 }
2330 else {
2331 char str[1024];
2332 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002333 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002334 }
Courtney Goeltzenleuchter45334842015-04-13 16:16:56 -06002335 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, rectCount, pRects);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002336}
2337
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002338VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002339{
2340 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2341 if (pCB) {
2342 updateCBTracking(cmdBuffer);
2343 addCmd(pCB, CMD_SETEVENT);
2344 }
2345 else {
2346 char str[1024];
2347 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002348 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002349 }
2350 nextTable.CmdSetEvent(cmdBuffer, event, pipeEvent);
2351}
2352
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002353VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipeEvent pipeEvent)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002354{
2355 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2356 if (pCB) {
2357 updateCBTracking(cmdBuffer);
2358 addCmd(pCB, CMD_RESETEVENT);
2359 }
2360 else {
2361 char str[1024];
2362 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002363 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002364 }
Courtney Goeltzenleuchteraa86e0e2015-03-24 18:02:34 -06002365 nextTable.CmdResetEvent(cmdBuffer, event, pipeEvent);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002366}
2367
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002368VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, const VkEventWaitInfo* pWaitInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002369{
2370 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2371 if (pCB) {
2372 updateCBTracking(cmdBuffer);
2373 addCmd(pCB, CMD_WAITEVENTS);
2374 }
2375 else {
2376 char str[1024];
2377 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002378 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002379 }
2380 nextTable.CmdWaitEvents(cmdBuffer, pWaitInfo);
2381}
2382
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002383VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, const VkPipelineBarrier* pBarrier)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002384{
2385 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2386 if (pCB) {
2387 updateCBTracking(cmdBuffer);
2388 addCmd(pCB, CMD_PIPELINEBARRIER);
2389 }
2390 else {
2391 char str[1024];
2392 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002393 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002394 }
2395 nextTable.CmdPipelineBarrier(cmdBuffer, pBarrier);
2396}
2397
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002398VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002399{
2400 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2401 if (pCB) {
2402 updateCBTracking(cmdBuffer);
2403 addCmd(pCB, CMD_BEGINQUERY);
2404 }
2405 else {
2406 char str[1024];
2407 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002408 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002409 }
2410 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
2411}
2412
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002413VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
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_ENDQUERY);
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 }
2425 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
2426}
2427
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002428VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002429{
2430 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2431 if (pCB) {
2432 updateCBTracking(cmdBuffer);
2433 addCmd(pCB, CMD_RESETQUERYPOOL);
2434 }
2435 else {
2436 char str[1024];
2437 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002438 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002439 }
2440 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
2441}
2442
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002443VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkGpuSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002444{
2445 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2446 if (pCB) {
2447 updateCBTracking(cmdBuffer);
2448 addCmd(pCB, CMD_WRITETIMESTAMP);
2449 }
2450 else {
2451 char str[1024];
2452 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002453 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002454 }
2455 nextTable.CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
2456}
2457
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002458VK_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 -06002459{
2460 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2461 if (pCB) {
2462 updateCBTracking(cmdBuffer);
2463 addCmd(pCB, CMD_INITATOMICCOUNTERS);
2464 }
2465 else {
2466 char str[1024];
2467 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002468 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002469 }
2470 nextTable.CmdInitAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, pData);
2471}
2472
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002473VK_LAYER_EXPORT void VKAPI vkCmdLoadAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer srcBuffer, VkGpuSize srcOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002474{
2475 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2476 if (pCB) {
2477 updateCBTracking(cmdBuffer);
2478 addCmd(pCB, CMD_LOADATOMICCOUNTERS);
2479 }
2480 else {
2481 char str[1024];
2482 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002483 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484 }
2485 nextTable.CmdLoadAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, srcBuffer, srcOffset);
2486}
2487
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002488VK_LAYER_EXPORT void VKAPI vkCmdSaveAtomicCounters(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, uint32_t startCounter, uint32_t counterCount, VkBuffer destBuffer, VkGpuSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002489{
2490 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2491 if (pCB) {
2492 updateCBTracking(cmdBuffer);
2493 addCmd(pCB, CMD_SAVEATOMICCOUNTERS);
2494 }
2495 else {
2496 char str[1024];
2497 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002498 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002499 }
2500 nextTable.CmdSaveAtomicCounters(cmdBuffer, pipelineBindPoint, startCounter, counterCount, destBuffer, destOffset);
2501}
2502
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002503VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002504{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002505 VkResult result = nextTable.CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002506 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002507 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002508 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002509 if (pCreateInfo->pColorAttachments) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002510 localFBCI->pColorAttachments = new VkColorAttachmentBindInfo[localFBCI->colorAttachmentCount];
2511 memcpy((void*)localFBCI->pColorAttachments, pCreateInfo->pColorAttachments, localFBCI->colorAttachmentCount*sizeof(VkColorAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002512 }
2513 if (pCreateInfo->pDepthStencilAttachment) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002514 localFBCI->pDepthStencilAttachment = new VkDepthStencilBindInfo[localFBCI->colorAttachmentCount];
2515 memcpy((void*)localFBCI->pDepthStencilAttachment, pCreateInfo->pDepthStencilAttachment, localFBCI->colorAttachmentCount*sizeof(VkDepthStencilBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002516 }
2517 frameBufferMap[*pFramebuffer] = localFBCI;
2518 }
2519 return result;
2520}
2521
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002522VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002523{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002524 VkResult result = nextTable.CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002525 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002526 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002527 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002528 if (pCreateInfo->pColorLoadOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002529 localRPCI->pColorLoadOps = new VkAttachmentLoadOp[localRPCI->colorAttachmentCount];
2530 memcpy((void*)localRPCI->pColorLoadOps, pCreateInfo->pColorLoadOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentLoadOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002531 }
2532 if (pCreateInfo->pColorStoreOps) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002533 localRPCI->pColorStoreOps = new VkAttachmentStoreOp[localRPCI->colorAttachmentCount];
2534 memcpy((void*)localRPCI->pColorStoreOps, pCreateInfo->pColorStoreOps, localRPCI->colorAttachmentCount*sizeof(VkAttachmentStoreOp));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002535 }
2536 if (pCreateInfo->pColorLoadClearValues) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002537 localRPCI->pColorLoadClearValues = new VkClearColor[localRPCI->colorAttachmentCount];
2538 memcpy((void*)localRPCI->pColorLoadClearValues, pCreateInfo->pColorLoadClearValues, localRPCI->colorAttachmentCount*sizeof(VkClearColor));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002539 }
2540 renderPassMap[*pRenderPass] = localRPCI;
2541 }
2542 return result;
2543}
2544
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002545VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBegin *pRenderPassBegin)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002546{
2547 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2548 if (pCB) {
2549 updateCBTracking(cmdBuffer);
2550 addCmd(pCB, CMD_BEGINRENDERPASS);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002551 pCB->activeRenderPass = pRenderPassBegin->renderPass;
2552 pCB->framebuffer = pRenderPassBegin->framebuffer;
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002553 if (pCB->lastBoundPipeline) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002554 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002555 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002556 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002557 char str[1024];
2558 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002559 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002560 }
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002561 nextTable.CmdBeginRenderPass(cmdBuffer, pRenderPassBegin);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002562}
2563
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002564VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer, VkRenderPass renderPass)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002565{
2566 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2567 if (pCB) {
2568 updateCBTracking(cmdBuffer);
2569 addCmd(pCB, CMD_ENDRENDERPASS);
Tobin Ehlis2464b882015-04-01 08:40:34 -06002570 pCB->activeRenderPass = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002571 }
2572 else {
2573 char str[1024];
2574 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002575 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002576 }
2577 nextTable.CmdEndRenderPass(cmdBuffer, renderPass);
2578}
2579
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002580VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002581{
2582 // This layer intercepts callbacks
Tobin Ehliseaf28662015-04-08 10:58:37 -06002583 VK_LAYER_DBG_FUNCTION_NODE* pNewDbgFuncNode = new VK_LAYER_DBG_FUNCTION_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002584 if (!pNewDbgFuncNode)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002585 return VK_ERROR_OUT_OF_MEMORY;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002586 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
2587 pNewDbgFuncNode->pUserData = pUserData;
2588 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
2589 g_pDbgFunctionHead = pNewDbgFuncNode;
2590 // force callbacks if DebugAction hasn't been set already other than initial value
2591 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002592 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002593 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002594 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002595 return result;
2596}
2597
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002598VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002599{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002600 VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;
2601 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002602 while (pTrav) {
2603 if (pTrav->pfnMsgCallback == pfnMsgCallback) {
2604 pPrev->pNext = pTrav->pNext;
2605 if (g_pDbgFunctionHead == pTrav)
2606 g_pDbgFunctionHead = pTrav->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06002607 delete pTrav;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002608 break;
2609 }
2610 pPrev = pTrav;
2611 pTrav = pTrav->pNext;
2612 }
2613 if (g_pDbgFunctionHead == NULL)
2614 {
2615 if (g_actionIsDefault)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002616 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002617 else
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002618 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002619 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002620 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002621 return result;
2622}
2623
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002624VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625{
2626 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2627 if (pCB) {
2628 updateCBTracking(cmdBuffer);
2629 addCmd(pCB, CMD_DBGMARKERBEGIN);
2630 }
2631 else {
2632 char str[1024];
2633 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002634 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002635 }
2636 nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
2637}
2638
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002639VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002640{
2641 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2642 if (pCB) {
2643 updateCBTracking(cmdBuffer);
2644 addCmd(pCB, CMD_DBGMARKEREND);
2645 }
2646 else {
2647 char str[1024];
2648 sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002649 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002650 }
2651 nextTable.CmdDbgMarkerEnd(cmdBuffer);
2652}
2653
2654// TODO : Want to pass in a cmdBuffer here based on which state to display
2655void drawStateDumpDotFile(char* outFileName)
2656{
2657 // TODO : Currently just setting cmdBuffer based on global var
2658 //dumpDotFile(g_lastDrawStateCmdBuffer, outFileName);
2659 dumpGlobalDotFile(outFileName);
2660}
2661
2662void drawStateDumpCommandBufferDotFile(char* outFileName)
2663{
2664 cbDumpDotFile(outFileName);
2665}
2666
2667void drawStateDumpPngFile(char* outFileName)
2668{
2669#if defined(_WIN32)
2670// FIXME: NEED WINDOWS EQUIVALENT
2671 char str[1024];
2672 sprintf(str, "Cannot execute dot program yet on Windows.");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002673 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002674#else // WIN32
2675 char dotExe[32] = "/usr/bin/dot";
2676 if( access(dotExe, X_OK) != -1) {
2677 dumpDotFile(g_lastCmdBuffer[getTIDIndex()], "/tmp/tmp.dot");
2678 char dotCmd[1024];
2679 sprintf(dotCmd, "%s /tmp/tmp.dot -Tpng -o %s", dotExe, outFileName);
2680 system(dotCmd);
2681 remove("/tmp/tmp.dot");
2682 }
2683 else {
2684 char str[1024];
2685 sprintf(str, "Cannot execute dot program at (%s) to dump requested %s file.", dotExe, outFileName);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002686 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, NULL, 0, DRAWSTATE_MISSING_DOT_PROGRAM, "DS", str);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002687 }
2688#endif // WIN32
2689}
2690
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002691VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002692{
Jon Ashburn301c5f02015-04-06 10:58:22 -06002693 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002694
2695 if (gpu == NULL)
2696 return NULL;
2697 pCurObj = gpuw;
2698 loader_platform_thread_once(&g_initOnce, initDrawState);
2699
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002700 if (!strcmp(funcName, "vkGetProcAddr"))
2701 return (void *) vkGetProcAddr;
2702 if (!strcmp(funcName, "vkCreateDevice"))
2703 return (void*) vkCreateDevice;
2704 if (!strcmp(funcName, "vkDestroyDevice"))
2705 return (void*) vkDestroyDevice;
2706 if (!strcmp(funcName, "vkGetExtensionSupport"))
2707 return (void*) vkGetExtensionSupport;
2708 if (!strcmp(funcName, "vkEnumerateLayers"))
2709 return (void*) vkEnumerateLayers;
2710 if (!strcmp(funcName, "vkQueueSubmit"))
2711 return (void*) vkQueueSubmit;
2712 if (!strcmp(funcName, "vkDestroyObject"))
2713 return (void*) vkDestroyObject;
2714 if (!strcmp(funcName, "vkCreateBufferView"))
2715 return (void*) vkCreateBufferView;
2716 if (!strcmp(funcName, "vkCreateImageView"))
2717 return (void*) vkCreateImageView;
2718 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2719 return (void*) vkCreateGraphicsPipeline;
2720 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2721 return (void*) vkCreateGraphicsPipelineDerivative;
2722 if (!strcmp(funcName, "vkCreateSampler"))
2723 return (void*) vkCreateSampler;
2724 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
2725 return (void*) vkCreateDescriptorSetLayout;
2726 if (!strcmp(funcName, "vkCreateDescriptorSetLayoutChain"))
2727 return (void*) vkCreateDescriptorSetLayoutChain;
2728 if (!strcmp(funcName, "vkBeginDescriptorPoolUpdate"))
2729 return (void*) vkBeginDescriptorPoolUpdate;
2730 if (!strcmp(funcName, "vkEndDescriptorPoolUpdate"))
2731 return (void*) vkEndDescriptorPoolUpdate;
2732 if (!strcmp(funcName, "vkCreateDescriptorPool"))
2733 return (void*) vkCreateDescriptorPool;
2734 if (!strcmp(funcName, "vkResetDescriptorPool"))
2735 return (void*) vkResetDescriptorPool;
2736 if (!strcmp(funcName, "vkAllocDescriptorSets"))
2737 return (void*) vkAllocDescriptorSets;
2738 if (!strcmp(funcName, "vkClearDescriptorSets"))
2739 return (void*) vkClearDescriptorSets;
2740 if (!strcmp(funcName, "vkUpdateDescriptors"))
2741 return (void*) vkUpdateDescriptors;
2742 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2743 return (void*) vkCreateDynamicViewportState;
2744 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2745 return (void*) vkCreateDynamicRasterState;
2746 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2747 return (void*) vkCreateDynamicColorBlendState;
2748 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2749 return (void*) vkCreateDynamicDepthStencilState;
2750 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2751 return (void*) vkCreateCommandBuffer;
2752 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2753 return (void*) vkBeginCommandBuffer;
2754 if (!strcmp(funcName, "vkEndCommandBuffer"))
2755 return (void*) vkEndCommandBuffer;
2756 if (!strcmp(funcName, "vkResetCommandBuffer"))
2757 return (void*) vkResetCommandBuffer;
2758 if (!strcmp(funcName, "vkCmdBindPipeline"))
2759 return (void*) vkCmdBindPipeline;
2760 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2761 return (void*) vkCmdBindDynamicStateObject;
2762 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2763 return (void*) vkCmdBindDescriptorSets;
2764 if (!strcmp(funcName, "vkCmdBindVertexBuffer"))
2765 return (void*) vkCmdBindVertexBuffer;
2766 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2767 return (void*) vkCmdBindIndexBuffer;
2768 if (!strcmp(funcName, "vkCmdDraw"))
2769 return (void*) vkCmdDraw;
2770 if (!strcmp(funcName, "vkCmdDrawIndexed"))
2771 return (void*) vkCmdDrawIndexed;
2772 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2773 return (void*) vkCmdDrawIndirect;
2774 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2775 return (void*) vkCmdDrawIndexedIndirect;
2776 if (!strcmp(funcName, "vkCmdDispatch"))
2777 return (void*) vkCmdDispatch;
2778 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2779 return (void*) vkCmdDispatchIndirect;
2780 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2781 return (void*) vkCmdCopyBuffer;
2782 if (!strcmp(funcName, "vkCmdCopyImage"))
2783 return (void*) vkCmdCopyImage;
2784 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2785 return (void*) vkCmdCopyBufferToImage;
2786 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2787 return (void*) vkCmdCopyImageToBuffer;
2788 if (!strcmp(funcName, "vkCmdCloneImageData"))
2789 return (void*) vkCmdCloneImageData;
2790 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2791 return (void*) vkCmdUpdateBuffer;
2792 if (!strcmp(funcName, "vkCmdFillBuffer"))
2793 return (void*) vkCmdFillBuffer;
2794 if (!strcmp(funcName, "vkCmdClearColorImage"))
2795 return (void*) vkCmdClearColorImage;
2796 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2797 return (void*) vkCmdClearDepthStencil;
2798 if (!strcmp(funcName, "vkCmdResolveImage"))
2799 return (void*) vkCmdResolveImage;
2800 if (!strcmp(funcName, "vkCmdSetEvent"))
2801 return (void*) vkCmdSetEvent;
2802 if (!strcmp(funcName, "vkCmdResetEvent"))
2803 return (void*) vkCmdResetEvent;
2804 if (!strcmp(funcName, "vkCmdWaitEvents"))
2805 return (void*) vkCmdWaitEvents;
2806 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
2807 return (void*) vkCmdPipelineBarrier;
2808 if (!strcmp(funcName, "vkCmdBeginQuery"))
2809 return (void*) vkCmdBeginQuery;
2810 if (!strcmp(funcName, "vkCmdEndQuery"))
2811 return (void*) vkCmdEndQuery;
2812 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2813 return (void*) vkCmdResetQueryPool;
2814 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
2815 return (void*) vkCmdWriteTimestamp;
2816 if (!strcmp(funcName, "vkCmdInitAtomicCounters"))
2817 return (void*) vkCmdInitAtomicCounters;
2818 if (!strcmp(funcName, "vkCmdLoadAtomicCounters"))
2819 return (void*) vkCmdLoadAtomicCounters;
2820 if (!strcmp(funcName, "vkCmdSaveAtomicCounters"))
2821 return (void*) vkCmdSaveAtomicCounters;
2822 if (!strcmp(funcName, "vkCreateFramebuffer"))
2823 return (void*) vkCreateFramebuffer;
2824 if (!strcmp(funcName, "vkCreateRenderPass"))
2825 return (void*) vkCreateRenderPass;
2826 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
2827 return (void*) vkCmdBeginRenderPass;
2828 if (!strcmp(funcName, "vkCmdEndRenderPass"))
2829 return (void*) vkCmdEndRenderPass;
2830 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2831 return (void*) vkDbgRegisterMsgCallback;
2832 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2833 return (void*) vkDbgUnregisterMsgCallback;
2834 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
2835 return (void*) vkCmdDbgMarkerBegin;
2836 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
2837 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002838 if (!strcmp("drawStateDumpDotFile", funcName))
2839 return (void*) drawStateDumpDotFile;
2840 if (!strcmp("drawStateDumpCommandBufferDotFile", funcName))
2841 return (void*) drawStateDumpCommandBufferDotFile;
2842 if (!strcmp("drawStateDumpPngFile", funcName))
2843 return (void*) drawStateDumpPngFile;
2844 else {
2845 if (gpuw->pGPA == NULL)
2846 return NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002847 return gpuw->pGPA((VkPhysicalGpu)gpuw->nextObject, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002848 }
2849}