blob: 816cf359b41d939b08e87c5b10ea96d52665dd44 [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
Tobin Ehlis7a51d902015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Tony Barboura938abb2015-04-22 11:36:22 -060036#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060037#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060038#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060040#include "draw_state.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060041#include "vk_layer_config.h"
Jon Ashburnf0615e22015-05-25 14:11:37 -060042#include "vk_debug_marker_layer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060043// The following is #included again to catch certain OS-specific functions
44// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060046#include "vk_layer_msg.h"
47#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -060051#include "vk_layer_extension_utils.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060052
Tobin Ehlisc91330b2015-06-16 09:04:30 -060053typedef struct _layer_data {
54 debug_report_data *report_data;
55 // TODO: put instance data here
56 VkDbgMsgCallback logging_callback;
57} layer_data;
58
59static std::unordered_map<void *, layer_data *> layer_data_map;
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -060060static device_table_map draw_state_device_table_map;
61static instance_table_map draw_state_instance_table_map;
62
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060063unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
64unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
65unordered_map<uint64_t, VkAttachmentViewCreateInfo> viewMap;
66unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
67unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicVpStateMap;
68unordered_map<uint64_t, VkDynamicRasterStateCreateInfo> dynamicRsStateMap;
69unordered_map<uint64_t, VkDynamicColorBlendStateCreateInfo> dynamicCbStateMap;
70unordered_map<uint64_t, VkDynamicDepthStencilStateCreateInfo> dynamicDsStateMap;
71unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
72unordered_map<uint64_t, POOL_NODE*> poolMap;
73unordered_map<uint64_t, SET_NODE*> setMap;
74unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060075// Map for layout chains
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060076unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
77unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
78unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060079
Jon Ashburn6f8cd632015-06-01 09:37:38 -060080struct devExts {
81 bool debug_marker_enabled;
82};
83
Jon Ashburn6f8cd632015-06-01 09:37:38 -060084static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060085
Tobin Ehlis63bb9482015-03-17 16:24:32 -060086static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060087
Tobin Ehlis63bb9482015-03-17 16:24:32 -060088// TODO : This can be much smarter, using separate locks for separate global data
89static int globalLockInitialized = 0;
90static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060091#define MAX_TID 513
92static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
93static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060094
95template layer_data *get_my_data_ptr<layer_data>(
96 void *data_key,
97 std::unordered_map<void *, layer_data *> &data_map);
98
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060099debug_report_data *mdd(void* object)
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600100{
101 dispatch_key key = get_dispatch_key(object);
102 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
103#if DISPATCH_MAP_DEBUG
104 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
105#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600106 return my_data->report_data;
107}
108
109debug_report_data *mid(VkInstance object)
110{
111 dispatch_key key = get_dispatch_key(object);
112 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
113#if DISPATCH_MAP_DEBUG
114 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
115#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600116 return my_data->report_data;
117}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600118// Map actual TID to an index value and return that index
119// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
120static uint32_t getTIDIndex() {
121 loader_platform_thread_id tid = loader_platform_get_thread_id();
122 for (uint32_t i = 0; i < g_maxTID; i++) {
123 if (tid == g_tidMapping[i])
124 return i;
125 }
126 // Don't yet have mapping, set it and return newly set index
127 uint32_t retVal = (uint32_t) g_maxTID;
128 g_tidMapping[g_maxTID++] = tid;
129 assert(g_maxTID < MAX_TID);
130 return retVal;
131}
132// Return a string representation of CMD_TYPE enum
133static string cmdTypeToString(CMD_TYPE cmd)
134{
135 switch (cmd)
136 {
137 case CMD_BINDPIPELINE:
138 return "CMD_BINDPIPELINE";
139 case CMD_BINDPIPELINEDELTA:
140 return "CMD_BINDPIPELINEDELTA";
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600141 case CMD_BINDDYNAMICVIEWPORTSTATE:
142 return "CMD_BINDDYNAMICVIEWPORTSTATE";
143 case CMD_BINDDYNAMICRASTERSTATE:
144 return "CMD_BINDDYNAMICRASTERSTATE";
145 case CMD_BINDDYNAMICCOLORBLENDSTATE:
146 return "CMD_BINDDYNAMICCOLORBLENDSTATE";
147 case CMD_BINDDYNAMICDEPTHSTENCILSTATE:
148 return "CMD_BINDDYNAMICDEPTHSTENCILSTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600149 case CMD_BINDDESCRIPTORSETS:
150 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600151 case CMD_BINDINDEXBUFFER:
152 return "CMD_BINDINDEXBUFFER";
153 case CMD_BINDVERTEXBUFFER:
154 return "CMD_BINDVERTEXBUFFER";
155 case CMD_DRAW:
156 return "CMD_DRAW";
157 case CMD_DRAWINDEXED:
158 return "CMD_DRAWINDEXED";
159 case CMD_DRAWINDIRECT:
160 return "CMD_DRAWINDIRECT";
161 case CMD_DRAWINDEXEDINDIRECT:
162 return "CMD_DRAWINDEXEDINDIRECT";
163 case CMD_DISPATCH:
164 return "CMD_DISPATCH";
165 case CMD_DISPATCHINDIRECT:
166 return "CMD_DISPATCHINDIRECT";
167 case CMD_COPYBUFFER:
168 return "CMD_COPYBUFFER";
169 case CMD_COPYIMAGE:
170 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600171 case CMD_BLITIMAGE:
172 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600173 case CMD_COPYBUFFERTOIMAGE:
174 return "CMD_COPYBUFFERTOIMAGE";
175 case CMD_COPYIMAGETOBUFFER:
176 return "CMD_COPYIMAGETOBUFFER";
177 case CMD_CLONEIMAGEDATA:
178 return "CMD_CLONEIMAGEDATA";
179 case CMD_UPDATEBUFFER:
180 return "CMD_UPDATEBUFFER";
181 case CMD_FILLBUFFER:
182 return "CMD_FILLBUFFER";
183 case CMD_CLEARCOLORIMAGE:
184 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600185 case CMD_CLEARCOLORATTACHMENT:
186 return "CMD_CLEARCOLORATTACHMENT";
187 case CMD_CLEARDEPTHSTENCILIMAGE:
188 return "CMD_CLEARDEPTHSTENCILIMAGE";
189 case CMD_CLEARDEPTHSTENCILATTACHMENT:
190 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600191 case CMD_RESOLVEIMAGE:
192 return "CMD_RESOLVEIMAGE";
193 case CMD_SETEVENT:
194 return "CMD_SETEVENT";
195 case CMD_RESETEVENT:
196 return "CMD_RESETEVENT";
197 case CMD_WAITEVENTS:
198 return "CMD_WAITEVENTS";
199 case CMD_PIPELINEBARRIER:
200 return "CMD_PIPELINEBARRIER";
201 case CMD_BEGINQUERY:
202 return "CMD_BEGINQUERY";
203 case CMD_ENDQUERY:
204 return "CMD_ENDQUERY";
205 case CMD_RESETQUERYPOOL:
206 return "CMD_RESETQUERYPOOL";
207 case CMD_WRITETIMESTAMP:
208 return "CMD_WRITETIMESTAMP";
209 case CMD_INITATOMICCOUNTERS:
210 return "CMD_INITATOMICCOUNTERS";
211 case CMD_LOADATOMICCOUNTERS:
212 return "CMD_LOADATOMICCOUNTERS";
213 case CMD_SAVEATOMICCOUNTERS:
214 return "CMD_SAVEATOMICCOUNTERS";
215 case CMD_BEGINRENDERPASS:
216 return "CMD_BEGINRENDERPASS";
217 case CMD_ENDRENDERPASS:
218 return "CMD_ENDRENDERPASS";
219 case CMD_DBGMARKERBEGIN:
220 return "CMD_DBGMARKERBEGIN";
221 case CMD_DBGMARKEREND:
222 return "CMD_DBGMARKEREND";
223 default:
224 return "UNKNOWN";
225 }
226}
227// Block of code at start here for managing/tracking Pipeline state that this layer cares about
228// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600229#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600230#define MAX_SLOTS 2048
231#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
232
233static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
234
235// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
236// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
237// to that same cmd buffer by separate thread are not changing state from underneath us
238// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600239static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600240// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600241static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
242static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600244static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
245static PIPELINE_NODE* g_lastBoundPipeline = NULL;
246static uint64_t g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {0};
247static VkDescriptorSet g_lastBoundDescriptorSet = VkDescriptorSet(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600248#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
249
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600252// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600253static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600254{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600255 for (auto ii=dynamicVpStateMap.begin(); ii!=dynamicVpStateMap.end(); ++ii) {
256 delete[] (*ii).second.pScissors;
257 delete[] (*ii).second.pViewports;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600258 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600259 dynamicVpStateMap.clear();
260 dynamicRsStateMap.clear();
261 dynamicCbStateMap.clear();
262 dynamicDsStateMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600263}
264// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600265static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600266{
David Pinedof5997ab2015-04-27 16:36:17 -0600267 if (sampleMap.size() <= 0)
268 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600269 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600270 delete (*ii).second;
271 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600272 sampleMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600273}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600275{
276 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600277 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600278 loader_platform_thread_unlock_mutex(&globalLock);
279 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600280 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600282 return &imageMap[view.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600283 }
284}
285// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600286static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600287{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600288 if (imageMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -0600289 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600290 imageMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600291}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600293{
294 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600295 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600296 loader_platform_thread_unlock_mutex(&globalLock);
297 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600298 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600299 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600300 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301 }
302}
303// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600304static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600305{
David Pinedof5997ab2015-04-27 16:36:17 -0600306 if (bufferMap.size() <= 0)
307 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600308 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600309 delete (*ii).second;
310 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600311 bufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600312}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600314// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600316{
317 g_lastCmdBuffer[getTIDIndex()] = cb;
318 GLOBAL_CB_NODE* pCB = getCBNode(cb);
319 loader_platform_thread_lock_mutex(&globalLock);
320 g_lastGlobalCB = pCB;
321 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
322 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
323 if (g_pLastTouchedCB[i] == pCB) {
324 loader_platform_thread_unlock_mutex(&globalLock);
325 return;
326 }
327 }
328 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
329 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
330 loader_platform_thread_unlock_mutex(&globalLock);
331}
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600332static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600333{
334 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
335 if (pCB->drawCount[i])
336 return VK_TRUE;
337 }
338 return VK_FALSE;
339}
Tobin Ehlis97866202015-06-10 12:57:07 -0600340// Check object status for selected flag state
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600341static VkBool32 validate_status(GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600342{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600343 // If non-zero enable mask is present, check it against status but if enable_mask
344 // is 0 then no enable required so we should always just check status
345 if ((!enable_mask) || (enable_mask & pNode->status)) {
346 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600347 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
348 log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
349 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(pNode->cmdBuffer), fail_msg);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600350 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600351 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600352 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600353 return VK_TRUE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600354}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600355// For given dynamic state handle and type, return CreateInfo for that Dynamic State
356static void* getDynamicStateCreateInfo(const uint64_t handle, const DYNAMIC_STATE_BIND_POINT type)
357{
358 switch (type) {
359 case VK_STATE_BIND_POINT_VIEWPORT:
360 return (void*)&dynamicVpStateMap[handle];
361 case VK_STATE_BIND_POINT_RASTER:
362 return (void*)&dynamicRsStateMap[handle];
363 case VK_STATE_BIND_POINT_COLOR_BLEND:
364 return (void*)&dynamicCbStateMap[handle];
365 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
366 return (void*)&dynamicDsStateMap[handle];
367 default:
368 return NULL;
369 }
370}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600371// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600372static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600373{
374 GLOBAL_CB_NODE* pCB = getCBNode(cb);
375 if (pCB) {
376 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600378 void* pDynStateCI = getDynamicStateCreateInfo(pCB->lastBoundDynamicState[i], (DYNAMIC_STATE_BIND_POINT)i);
379 if (pDynStateCI) {
380 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
381 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
382 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
383 dynamic_display(pDynStateCI, " ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600384 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600385 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600386 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
387 "No dynamic state of type %s bound", string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600388 }
389 }
390 loader_platform_thread_unlock_mutex(&globalLock);
391 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600392}
393// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600394static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600395{
396 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600397 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600398 loader_platform_thread_unlock_mutex(&globalLock);
399 return NULL;
400 }
401 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600402 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600403}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600404// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600405static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
406 VkBool32 result;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600407 result = validate_status(pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_BOUND, CBSTATUS_VIEWPORT_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
408 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_RASTER_BOUND, CBSTATUS_RASTER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");
409 result &= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_COLOR_BLEND_BOUND, CBSTATUS_COLOR_BLEND_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");
410 result &= validate_status(pCB, CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE, CBSTATUS_DEPTH_STENCIL_BOUND, CBSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");
411 if (indexedDraw)
412 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Index Draw attempted");
413 return result;
414}
415// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600416static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600417 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600418 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600419 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
420 // Now complete other state checks
Tobin Ehlise4076782015-06-24 15:53:07 -0600421 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600422 result = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600423 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600424 "Pipeline layout from last vkCmdBindDescriptorSets() (%s) does not match PSO Pipeline layout (%s)", pCB->lastBoundPipelineLayout, pPipe->graphicsPipelineCI.layout);
425 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600426 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600427 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis451efca2015-06-23 11:22:55 -0600428 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
429 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600430 return result;
431}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600432// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600433static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600434{
435 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600436 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600437 loader_platform_thread_unlock_mutex(&globalLock);
438 return NULL;
439 }
440 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600441 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600442}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600443// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600444static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600445{
446 // VS is required
447 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600448 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600449 "Invalid Pipeline CreateInfo State: Vtx Shader required");
450 return VK_FALSE;
451 }
452 // Either both or neither TC/TE shaders should be defined
453 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
454 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600455 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600456 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
457 return VK_FALSE;
458 }
459 // Compute shaders should be specified independent of Gfx shaders
460 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
461 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
462 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
463 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600464 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600465 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
466 return VK_FALSE;
467 }
468 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
469 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
470 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
471 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600472 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600473 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
474 return VK_FALSE;
475 }
476 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
477 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600478 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600479 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
480 return VK_FALSE;
481 }
482 return VK_TRUE;
483}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600484// Init the pipeline mapping info based on pipeline create info LL tree
485// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600486static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600487{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600488 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
489 if (pBasePipeline) {
490 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600491 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600492 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
493 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600494 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600495 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600496 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600497
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600498 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600499 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600500 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600501
502 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
503 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
504
505 switch (pPSSCI->stage) {
506 case VK_SHADER_STAGE_VERTEX:
507 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
508 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600509 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600510 case VK_SHADER_STAGE_TESS_CONTROL:
511 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
512 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600513 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600514 case VK_SHADER_STAGE_TESS_EVALUATION:
515 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
516 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600517 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600518 case VK_SHADER_STAGE_GEOMETRY:
519 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
520 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600521 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600522 case VK_SHADER_STAGE_FRAGMENT:
523 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
524 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600525 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600526 case VK_SHADER_STAGE_COMPUTE:
527 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
528 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600529 break;
530 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600531 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600532 break;
533 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600534 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600535
536 if (pCreateInfo->pVertexInputState != NULL) {
537 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
538 // Copy embedded ptrs
539 pVICI = pCreateInfo->pVertexInputState;
540 pPipeline->vtxBindingCount = pVICI->bindingCount;
541 if (pPipeline->vtxBindingCount) {
542 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
543 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
544 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
545 }
546 pPipeline->vtxAttributeCount = pVICI->attributeCount;
547 if (pPipeline->vtxAttributeCount) {
548 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
549 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
550 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
551 }
552 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
553 }
Tony Barboure307f582015-07-10 15:29:03 -0600554 if (pCreateInfo->pInputAssemblyState != NULL) {
555 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
556 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600557 }
Tony Barboure307f582015-07-10 15:29:03 -0600558 if (pCreateInfo->pTessellationState != NULL) {
559 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600561 }
Tony Barboure307f582015-07-10 15:29:03 -0600562 if (pCreateInfo->pViewportState != NULL) {
563 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
564 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600565 }
Tony Barboure307f582015-07-10 15:29:03 -0600566 if (pCreateInfo->pRasterState != NULL) {
567 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
568 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600569 }
Tony Barboure307f582015-07-10 15:29:03 -0600570 if (pCreateInfo->pMultisampleState != NULL) {
571 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
572 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600573 }
Tony Barboure307f582015-07-10 15:29:03 -0600574 if (pCreateInfo->pColorBlendState != NULL) {
575 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600576 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600577 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600578 pPipeline->attachmentCount = pCBCI->attachmentCount;
579 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600580 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
581 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600582 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
583 }
Tony Barboure307f582015-07-10 15:29:03 -0600584 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600585 }
Tony Barboure307f582015-07-10 15:29:03 -0600586 if (pCreateInfo->pDepthStencilState != NULL) {
587 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
588 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600589 }
590
591 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
592 if (pCreateInfo->stageCount != 0) {
593 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
594 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
595 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
596 }
597
Tobin Ehlisde63c532015-06-18 15:59:33 -0600598 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600599}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600600
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600601// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600602static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600603{
David Pinedof5997ab2015-04-27 16:36:17 -0600604 if (pipelineMap.size() <= 0)
605 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600606 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600607 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
608 delete[] (*ii).second->graphicsPipelineCI.pStages;
609 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600610 if ((*ii).second->pVertexBindingDescriptions) {
611 delete[] (*ii).second->pVertexBindingDescriptions;
612 }
613 if ((*ii).second->pVertexAttributeDescriptions) {
614 delete[] (*ii).second->pVertexAttributeDescriptions;
615 }
616 if ((*ii).second->pAttachments) {
617 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600618 }
619 delete (*ii).second;
620 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600621 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600622}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600623// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600625{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600626 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Courtney Goeltzenleuchtere29e9462015-07-12 14:00:58 -0600627 // TODO: msStateCI.multisampleEnable has been removed from API, is there anything left to do here?
628// if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
629// if (pPipe->msStateCI.multisampleEnable)
630// return pPipe->msStateCI.rasterSamples;
631// }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600632 return 1;
633}
634// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600635static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600636{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600637 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600638 // Verify that any MSAA request in PSO matches sample# in bound FB
639 uint32_t psoNumSamples = getNumSamples(pipeline);
640 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600641 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800642 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
643 int subpassNumSamples = 0;
644 uint32_t i;
645
646 for (i = 0; i < pSD->colorCount; i++) {
647 uint32_t samples;
648
649 if (pSD->colorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
650 continue;
651
652 samples = pRPCI->pAttachments[pSD->colorAttachments[i].attachment].samples;
653 if (subpassNumSamples == 0) {
654 subpassNumSamples = samples;
655 } else if (subpassNumSamples != samples) {
656 subpassNumSamples = -1;
657 break;
658 }
659 }
660 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
661 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
662 if (subpassNumSamples == 0)
663 subpassNumSamples = samples;
664 else if (subpassNumSamples != samples)
665 subpassNumSamples = -1;
666 }
667
668 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600669 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
670 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!", pipeline.handle, psoNumSamples, pCB->activeRenderPass.handle, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600671 }
672 } else {
673 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
674 // Verify and flag error as appropriate
675 }
676 // TODO : Add more checks here
677 } else {
678 // TODO : Validate non-gfx pipeline updates
679 }
680}
681
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600682// Block of code at start here specifically for managing/tracking DSs
683
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600684// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600685static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600686{
687 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600688 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600689 loader_platform_thread_unlock_mutex(&globalLock);
690 return NULL;
691 }
692 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600693 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600694}
695// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600696static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600697{
698 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600699 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600700 loader_platform_thread_unlock_mutex(&globalLock);
701 return NULL;
702 }
703 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600704 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600705}
706
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600707static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600708 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600709 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600710 loader_platform_thread_unlock_mutex(&globalLock);
711 return NULL;
712 }
713 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600714 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600715}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600716// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600717static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600718{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600719 switch (pUpdateStruct->sType)
720 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800721 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
722 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600723 return 1;
724 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600725 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600726 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600727 return 0;
728 }
729}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600730// For given update struct, return binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600731static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600732{
733 switch (pUpdateStruct->sType)
734 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800735 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
736 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
737 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
738 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600739 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600740 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600741 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600742 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600743 }
744}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600745// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600746static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600747{
748 switch (pUpdateStruct->sType)
749 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800750 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
751 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
752 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600753 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800754 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600755 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600756 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600757 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600758 return 0;
759 }
760}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600761// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600762static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600763{
764 switch (pUpdateStruct->sType)
765 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800766 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
767 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
768 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600769 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800770 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600771 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600772 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600773 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600774 return 0;
775 }
776}
777// For given Layout Node and binding, return index where that binding begins
778static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
779{
780 uint32_t offsetIndex = 0;
781 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800782 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600783 }
784 return offsetIndex;
785}
786// For given layout node and binding, return last index that is updated
787static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
788{
789 uint32_t offsetIndex = 0;
790 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800791 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600792 }
793 return offsetIndex-1;
794}
795// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600796static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600797{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600798 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600799}
800// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600801static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600802{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600803 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600804}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600805// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600806static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600807{
808 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600809 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600810 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600811 switch (pUpdateStruct->sType)
812 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800813 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
814 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600815 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800816 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
817 /* no need to validate */
818 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600819 break;
820 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600821 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600822 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600823 return 0;
824 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600825 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600826 if (pLayout->pTypes[i] != actualType)
827 return 0;
828 }
829 return 1;
830}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600831// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
832// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
833// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600834static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600835{
836 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800837 VkWriteDescriptorSet* pWDS = NULL;
838 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600839 size_t array_size = 0;
840 size_t base_array_size = 0;
841 size_t total_array_size = 0;
842 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600843 switch (pUpdate->sType)
844 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800845 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
846 pWDS = new VkWriteDescriptorSet;
847 pNewNode = (GENERIC_HEADER*)pWDS;
848 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
849 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
850 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
851 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600852 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800853 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
854 pCDS = new VkCopyDescriptorSet;
855 pUpdate = (GENERIC_HEADER*)pCDS;
856 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600857 break;
858 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600859 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600860 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600861 return NULL;
862 }
863 // Make sure that pNext for the end of shadow copy is NULL
864 pNewNode->pNext = NULL;
865 return pNewNode;
866}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800867// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600868static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600869{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800870 const VkWriteDescriptorSet *pWDS = NULL;
871 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600872 VkBool32 result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800873
874 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
875 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
876 else
877 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
878
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600879 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600881 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600882 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600883 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600884 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800885 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600886 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800887 g_lastBoundDescriptorSet = pSet->set;
888 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600889 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600890 // First verify valid update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600891 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600892 result = 0;
893 break;
894 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600895 // Make sure that binding is within bounds
Tobin Ehlisde63c532015-06-18 15:59:33 -0600896 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600897 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600898 "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, getUpdateBinding(device, pUpdate), string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600899 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600900 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600901 // Next verify that update falls within size of given binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600902 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour29b12062015-07-13 13:37:24 -0600903 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600904 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600905 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600906 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600907 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), getUpdateBinding(device, pUpdate), DSstr.c_str());
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600908 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600909 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600910 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlisde63c532015-06-18 15:59:33 -0600911 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600912 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600913 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600914 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600915 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600916 // Save the update info
917 // TODO : Info message that update successful
918 // Create new update struct for this set's shadow copy
Tobin Ehlisde63c532015-06-18 15:59:33 -0600919 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600920 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600921 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600922 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600923 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600924 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600925 // Insert shadow node into LL of updates for this set
926 pNewNode->pNext = pSet->pUpdateStructs;
927 pSet->pUpdateStructs = pNewNode;
928 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisde63c532015-06-18 15:59:33 -0600929 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600930 assert(j<pSet->descriptorCount);
931 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600932 }
933 }
934 }
935 }
936 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600937 }
938 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600939 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600940}
941// Free the shadowed update node for this Set
942// NOTE : Calls to this function should be wrapped in mutex
943static void freeShadowUpdateTree(SET_NODE* pSet)
944{
945 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
946 pSet->pUpdateStructs = NULL;
947 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
948 // Clear the descriptor mappings as they will now be invalid
949 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
950 while(pShadowUpdate) {
951 pFreeUpdate = pShadowUpdate;
952 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
953 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800954 VkWriteDescriptorSet * pWDS = NULL;
955 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600956 void** ppToFree = NULL;
957 switch (pFreeUpdate->sType)
958 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800959 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
960 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
961 if (pWDS->pDescriptors)
962 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600963 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800964 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600965 break;
966 default:
967 assert(0);
968 break;
969 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600970 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600971 }
972}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600973// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600974// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600975static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600976{
David Pinedof5997ab2015-04-27 16:36:17 -0600977 if (poolMap.size() <= 0)
978 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600979 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600980 SET_NODE* pSet = (*ii).second->pSets;
981 SET_NODE* pFreeSet = pSet;
982 while (pSet) {
983 pFreeSet = pSet;
984 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600985 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600986 // Free Update shadow struct tree
987 freeShadowUpdateTree(pFreeSet);
988 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200989 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600990 }
991 delete pFreeSet;
992 }
993 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200994 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600995 }
996 delete (*ii).second;
997 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600998 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600999}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001000// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001001// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001002static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001003{
David Pinedof5997ab2015-04-27 16:36:17 -06001004 if (layoutMap.size() <= 0)
1005 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001006 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001007 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001008 if (pLayout->createInfo.pBinding) {
1009 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1010 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1011 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1012 }
1013 delete[] pLayout->createInfo.pBinding;
1014 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001015 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001016 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017 }
1018 delete pLayout;
1019 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001020 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001021}
1022// Currently clearing a set is removing all previous updates to that set
1023// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001024static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001025{
1026 SET_NODE* pSet = getSetNode(set);
1027 if (!pSet) {
1028 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001029 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001030 loader_platform_thread_lock_mutex(&globalLock);
1031 freeShadowUpdateTree(pSet);
1032 loader_platform_thread_unlock_mutex(&globalLock);
1033 }
1034}
1035
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001036static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001037{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001038 POOL_NODE* pPool = getPoolNode(pool);
1039 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001040 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1041 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001042 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001043 // For every set off of this pool, clear it
1044 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001045 while (pSet) {
1046 clearDescriptorSet(pSet->set);
1047 }
1048 }
1049}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001050// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001051static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001052{
1053 loader_platform_thread_lock_mutex(&globalLock);
1054 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1055 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001056 // TODO : How to pass cb as srcObj here?
1057 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1058 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001059 return NULL;
1060 }
1061 loader_platform_thread_unlock_mutex(&globalLock);
1062 return cmdBufferMap[cb];
1063}
1064// Free all CB Nodes
1065// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001066static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001067{
David Pinedof5997ab2015-04-27 16:36:17 -06001068 if (cmdBufferMap.size() <= 0)
1069 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001070 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001071 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1072 while (!cmd_node_list.empty()) {
1073 CMD_NODE* cmd_node = cmd_node_list.back();
1074 delete cmd_node;
1075 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001076 }
1077 delete (*ii).second;
1078 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001079 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001080}
Tobin Ehlise42007c2015-06-19 13:00:59 -06001081static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1082{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001083 // TODO : How to pass cb as srcObj here?
1084 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_BEGIN_CMD_BUFFER, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06001085 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1086}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001087static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1088{
1089 CMD_NODE* pCmd = new CMD_NODE;
1090 if (pCmd) {
1091 // init cmd node and append to end of cmd LL
1092 memset(pCmd, 0, sizeof(CMD_NODE));
1093 pCmd->cmdNumber = ++pCB->numCmds;
1094 pCmd->type = cmd;
1095 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001096 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001097 // TODO : How to pass cb as srcObj here?
1098 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1099 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %#" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001100 }
1101}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001102static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001103{
1104 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1105 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001106 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1107 while (!cmd_list.empty()) {
1108 delete cmd_list.back();
1109 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001110 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001111 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001112 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001113 VkFlags saveFlags = pCB->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001114 VkCmdPool savedPool = pCB->pool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001115 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1116 pCB->cmdBuffer = cb;
1117 pCB->flags = saveFlags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001118 pCB->pool = savedPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001119 pCB->lastVtxBinding = MAX_BINDING;
1120 }
1121}
Tobin Ehlis97866202015-06-10 12:57:07 -06001122// Set PSO-related status bits for CB
1123static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1124{
1125 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1126 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1127 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1128 }
1129 }
1130 if (pPipe->dsStateCI.depthWriteEnable) {
1131 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1132 }
1133}
1134// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001135static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001136 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1137 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1138 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1139 pNode->status |= CBSTATUS_RASTER_BOUND;
1140 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1141 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1142 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1143 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1144 }
1145}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001146// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001147static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001148{
1149 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1150 if (pCB) {
1151 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1152 if (!pPipeTrav) {
1153 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001154 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001155 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001156 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001157 }
1158 }
1159}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001160// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001161static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001162{
1163 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1164 if (pCB && pCB->lastBoundPipeline) {
1165 // First verify that we have a Node for bound pipeline
1166 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001167 if (!pPipeTrav) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001168 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1169 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001170 return false;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001171 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001172 // Verify Vtx binding
1173 if (MAX_BINDING != pCB->lastVtxBinding) {
1174 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1175 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001176 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001177 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001178 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001179 }
1180 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001181 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001182 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001183 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001184 }
1185 }
1186 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001187 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001188 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001189 }
1190 }
1191 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001192 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001193 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001194 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001195}
1196// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001197static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001198{
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001199 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.
1200 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001201 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001202 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001203 POOL_NODE* pPool = getPoolNode(pSet->pool);
1204 // Print out pool details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001205 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1206 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001207 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001208 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001209 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001210 // Print out set details
1211 char prefix[10];
1212 uint32_t index = 0;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001213 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1214 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001215 LAYOUT_NODE* pLayout = pSet->pLayout;
1216 // Print layout details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001217 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1218 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001219 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001221 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001222 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001223 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001224 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1225 if (pUpdate) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001226 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1227 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001228 sprintf(prefix, " [UC] ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001229 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001230 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001231 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001232 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001233 if (0 != pSet->descriptorCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001234 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1235 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", pSet->set.handle, pSet->descriptorCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001236 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001237 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1238 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001239 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001240 }
1241 }
1242}
1243
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001244static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001245{
1246 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001247 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001248 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001249 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001250 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001251 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1252 // TODO : Need to pass cb as srcObj here
1253 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001254 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001255 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001256 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001257 // Nothing to print
1258 }
1259}
1260
1261
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001262static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001263{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -06001264 // TODO : Re-enable these print funcs
1265// printDSConfig(cb);
1266// printPipeline(cb);
1267// printDynamicState(cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001268}
1269
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001270static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001271{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001272 uint32_t report_flags = 0;
1273 uint32_t debug_action = 0;
1274 FILE *log_output = NULL;
1275 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001276 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001277 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1278 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001279
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001280 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001281 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001282 option_str = getLayerOption("DrawStateLogFilename");
1283 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001284 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001285 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001286 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001287 if (log_output == NULL)
1288 log_output = stdout;
1289
1290 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001291 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001292
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001293 if (!globalLockInitialized)
1294 {
1295 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001296 // suggestion is to call this during vkCreateInstance(), and then we
1297 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001298 // that the layer have per-instance locks. We need to come back and
1299 // address this soon.
1300 loader_platform_thread_create_mutex(&globalLock);
1301 globalLockInitialized = 1;
1302 }
1303}
1304
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001305VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1306{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001307 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001308 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1309
1310 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001311 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1312 my_data->report_data = debug_report_create_instance(
1313 pTable,
1314 *pInstance,
1315 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001316 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001317
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001318 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001319 }
1320 return result;
1321}
1322
Jon Ashburne0fa2282015-05-20 09:00:28 -06001323/* hook DestroyInstance to remove tableInstanceMap entry */
1324VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1325{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001326 dispatch_key key = get_dispatch_key(instance);
1327 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1328 VkResult res = pTable->DestroyInstance(instance);
1329
1330 // Clean up logging callback, if any
1331 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1332 if (my_data->logging_callback) {
1333 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1334 }
1335
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001336 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001337 layer_data_map.erase(pTable);
1338
1339 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001340 return res;
1341}
1342
Jon Ashburnf0615e22015-05-25 14:11:37 -06001343static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1344{
Tony Barbour29b12062015-07-13 13:37:24 -06001345 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001346 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001347 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001348
1349 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001350 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001351 /* Found a matching extension name, mark it enabled and init dispatch table*/
1352 initDebugMarkerTable(device);
1353 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001354 }
1355
1356 }
1357}
1358
Tony Barbour8205d902015-04-16 15:59:00 -06001359VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001360{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001361 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1362 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001363 if (result == VK_SUCCESS) {
1364 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1365 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1366 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1367 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001368 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001369 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001370 return result;
1371}
1372
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001373VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001374{
1375 // Free all the memory
1376 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001377 deletePipelines();
1378 deleteSamplers();
1379 deleteImages();
1380 deleteBuffers();
1381 deleteCmdBuffers();
1382 deleteDynamicState();
1383 deletePools();
1384 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001385 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001386
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001387 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001388 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1389 VkResult result = pDisp->DestroyDevice(device);
1390 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001391 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001392 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001393 return result;
1394}
1395
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001396static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001397 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001398 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001399 VK_API_VERSION,
1400 VK_MAKE_VERSION(0, 1, 0),
1401 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001402 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001403};
1404
Tony Barbour426b9052015-06-24 16:06:58 -06001405VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001406 const char *pLayerName,
1407 uint32_t *pCount,
1408 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001409{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001410 /* DrawState does not have any global extensions */
1411 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1412}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001413
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001414VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1415 uint32_t *pCount,
1416 VkLayerProperties* pProperties)
1417{
1418 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1419 ds_global_layers,
1420 pCount, pProperties);
1421}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001422
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001423static const VkExtensionProperties ds_device_extensions[] = {
1424 {
1425 DEBUG_MARKER_EXTENSION_NAME,
1426 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001427 }
1428};
1429
1430static const VkLayerProperties ds_device_layers[] = {
1431 {
1432 "DrawState",
1433 VK_API_VERSION,
1434 VK_MAKE_VERSION(0, 1, 0),
1435 "Validation layer: DrawState",
1436 }
1437};
1438
1439VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1440 VkPhysicalDevice physicalDevice,
1441 const char* pLayerName,
1442 uint32_t* pCount,
1443 VkExtensionProperties* pProperties)
1444{
1445 /* Mem tracker does not have any physical device extensions */
1446 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1447 pCount, pProperties);
1448}
1449
1450VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1451 VkPhysicalDevice physicalDevice,
1452 uint32_t* pCount,
1453 VkLayerProperties* pProperties)
1454{
1455 /* Mem tracker's physical device layers are the same as global */
1456 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1457 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001458}
1459
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001460VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001461{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001462 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001463 for (uint32_t i=0; i < cmdBufferCount; i++) {
1464 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001465 pCB = getCBNode(pCmdBuffers[i]);
1466 loader_platform_thread_lock_mutex(&globalLock);
1467 if (CB_UPDATE_COMPLETE != pCB->state) {
1468 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001469 // TODO : How to pass cb as srcObj?
1470 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1471 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlise90b1712015-05-27 14:30:06 -06001472 loader_platform_thread_unlock_mutex(&globalLock);
1473 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001474 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001475 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001476 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001477
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001478 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001479 return result;
1480}
1481
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001482VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001483{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001484 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1485 // TODO : Clean up any internal data structures using this obj.
1486 return result;
1487}
1488
1489VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1490{
1491 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1492 // TODO : Clean up any internal data structures using this obj.
1493 return result;
1494}
1495
1496VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1497{
1498 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1499 // TODO : Clean up any internal data structures using this obj.
1500 return result;
1501}
1502
1503VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1504{
1505 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1506 // TODO : Clean up any internal data structures using this obj.
1507 return result;
1508}
1509
1510VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1511{
1512 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1513 // TODO : Clean up any internal data structures using this obj.
1514 return result;
1515}
1516
1517VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1518{
1519 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1520 // TODO : Clean up any internal data structures using this obj.
1521 return result;
1522}
1523
1524VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1525{
1526 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1527 // TODO : Clean up any internal data structures using this obj.
1528 return result;
1529}
1530
1531VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1532{
1533 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1534 // TODO : Clean up any internal data structures using this obj.
1535 return result;
1536}
1537
1538VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1539{
1540 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1541 // TODO : Clean up any internal data structures using this obj.
1542 return result;
1543}
1544
1545VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1546{
1547 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1548 // TODO : Clean up any internal data structures using this obj.
1549 return result;
1550}
1551
1552VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1553{
1554 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1555 // TODO : Clean up any internal data structures using this obj.
1556 return result;
1557}
1558
1559VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1560{
1561 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1562 // TODO : Clean up any internal data structures using this obj.
1563 return result;
1564}
1565
1566VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1567{
1568 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1569 // TODO : Clean up any internal data structures using this obj.
1570 return result;
1571}
1572
1573VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1574{
1575 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1576 // TODO : Clean up any internal data structures using this obj.
1577 return result;
1578}
1579
1580VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1581{
1582 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1583 // TODO : Clean up any internal data structures using this obj.
1584 return result;
1585}
1586
1587VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1588{
1589 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1590 // TODO : Clean up any internal data structures using this obj.
1591 return result;
1592}
1593
1594VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1595{
1596 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1597 // TODO : Clean up any internal data structures using this obj.
1598 return result;
1599}
1600
1601VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1602{
1603 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1604 // TODO : Clean up any internal data structures using this obj.
1605 return result;
1606}
1607
1608VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1609{
1610 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1611 // TODO : Clean up any internal data structures using this obj.
1612 return result;
1613}
1614
1615VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1616{
1617 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1618 // TODO : Clean up any internal data structures using this obj.
1619 return result;
1620}
1621
1622VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1623{
1624 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1625 // TODO : Clean up any internal data structures using this obj.
1626 return result;
1627}
1628
1629VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1630{
1631 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1632 // TODO : Clean up any internal data structures using this obj.
1633 return result;
1634}
1635
1636VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1637{
1638 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1639 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001640 return result;
1641}
1642
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001643VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001644{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001645 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001646 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001647 loader_platform_thread_lock_mutex(&globalLock);
1648 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1649 pNewNode->buffer = *pView;
1650 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001651 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001652 loader_platform_thread_unlock_mutex(&globalLock);
1653 }
1654 return result;
1655}
1656
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001657VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001658{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001659 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001660 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001661 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001662 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001663 loader_platform_thread_unlock_mutex(&globalLock);
1664 }
1665 return result;
1666}
1667
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001668VkResult VKAPI vkCreateAttachmentView(
1669 VkDevice device,
1670 const VkAttachmentViewCreateInfo* pCreateInfo,
1671 VkAttachmentView* pView)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001672{
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001673 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001674 if (VK_SUCCESS == result) {
1675 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001676 viewMap[pView->handle] = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001677 loader_platform_thread_unlock_mutex(&globalLock);
1678 }
1679 return result;
1680}
1681
Jon Ashburn0d60d272015-07-09 15:02:25 -06001682//TODO handle pipeline caches
1683VkResult VKAPI vkCreatePipelineCache(
1684 VkDevice device,
1685 const VkPipelineCacheCreateInfo* pCreateInfo,
1686 VkPipelineCache* pPipelineCache)
1687{
1688 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1689 return result;
1690}
1691
1692VkResult VKAPI vkDestroyPipelineCache(
1693 VkDevice device,
1694 VkPipelineCache pipelineCache)
1695{
1696 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1697 return result;
1698}
1699
1700size_t VKAPI vkGetPipelineCacheSize(
1701 VkDevice device,
1702 VkPipelineCache pipelineCache)
1703{
1704 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1705 return size;
1706}
1707
1708VkResult VKAPI vkGetPipelineCacheData(
1709 VkDevice device,
1710 VkPipelineCache pipelineCache,
1711 void* pData)
1712{
1713 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1714 return result;
1715}
1716
1717VkResult VKAPI vkMergePipelineCaches(
1718 VkDevice device,
1719 VkPipelineCache destCache,
1720 uint32_t srcCacheCount,
1721 const VkPipelineCache* pSrcCaches)
1722{
1723 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1724 return result;
1725}
1726
1727VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001729 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001730 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001731 // The order of operations here is a little convoluted but gets the job done
1732 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1733 // 2. Create state is then validated (which uses flags setup during shadowing)
1734 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1735 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001736 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001737 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001738 loader_platform_thread_unlock_mutex(&globalLock);
1739 if (VK_TRUE == valid) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001740 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001741 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1742 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001743 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001744 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001745 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001746 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001747 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001748 if (pPipeNode) {
1749 // If we allocated a pipeNode, need to clean it up here
1750 delete[] pPipeNode->pVertexBindingDescriptions;
1751 delete[] pPipeNode->pVertexAttributeDescriptions;
1752 delete[] pPipeNode->pAttachments;
1753 delete pPipeNode;
1754 }
1755 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001756 return result;
1757}
1758
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001759VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001760{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001761 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001762 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001763 loader_platform_thread_lock_mutex(&globalLock);
1764 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1765 pNewNode->sampler = *pSampler;
1766 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001767 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001768 loader_platform_thread_unlock_mutex(&globalLock);
1769 }
1770 return result;
1771}
1772
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001773VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001774{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001775 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001776 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001777 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1778 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001779 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001780 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001781 }
1782 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001783 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1784 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1785 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001786 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001787 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001788 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001789 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001790 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001791 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1792 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001793 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001794 }
1795 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001796 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001797 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001798 uint32_t j = 0;
1799 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001800 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001801 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001802 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001803 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804 }
1805 }
1806 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001807 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1809 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001810 // Put new node at Head of global Layer list
1811 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001812 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001813 loader_platform_thread_unlock_mutex(&globalLock);
1814 }
1815 return result;
1816}
1817
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001818VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001819{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001820 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001821 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001822 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001823 }
1824 return result;
1825}
1826
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001827VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001828{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001829 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001830 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001831 // Insert this pool into Global Pool LL at head
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001832 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1833 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001834 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001835 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001836 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001837 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001838 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001839 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001840 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001841 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1842 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001843 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001844 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1845 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001846 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1847 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001848 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001850 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001851 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001852 }
1853 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001854 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001855 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001856 }
1857 return result;
1858}
1859
Mike Stroyan230e6252015-04-17 12:36:38 -06001860VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001861{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001862 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001863 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001864 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865 }
1866 return result;
1867}
1868
Mike Stroyan230e6252015-04-17 12:36:38 -06001869VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001870{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001871 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001872 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001873 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1874 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001875 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1876 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001877 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001878 for (uint32_t i = 0; i < *pCount; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001879 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1880 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001881 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001882 SET_NODE* pNewNode = new SET_NODE;
1883 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001884 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001885 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001886 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001887 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001888 // Insert set at head of Set LL for this pool
1889 pNewNode->pNext = pPoolNode->pSets;
1890 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001891 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1892 if (NULL == pLayout) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001893 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1894 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001895 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001896 pNewNode->pLayout = pLayout;
1897 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001898 pNewNode->set = pDescriptorSets[i];
1899 pNewNode->setUsage = setUsage;
1900 pNewNode->descriptorCount = pLayout->endIndex + 1;
1901 if (pNewNode->descriptorCount) {
1902 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1903 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1904 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1905 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001906 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001907 }
1908 }
1909 }
1910 }
1911 return result;
1912}
1913
Tony Barbourb857d312015-07-10 10:50:45 -06001914VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1915{
1916 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1917 // TODO : Clean up any internal data structures using this obj.
1918 return result;
1919}
1920
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001921VK_LAYER_EXPORT VkResult VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001922{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001923 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1924 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001925 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001926 }
1927 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001928}
1929
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001930VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001931{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001932 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001933 VkDynamicViewportStateCreateInfo local_ci;
1934 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1935 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1936 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1937 loader_platform_thread_lock_mutex(&globalLock);
1938 dynamicVpStateMap[pState->handle] = local_ci;
1939 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001940 return result;
1941}
1942
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001943VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRasterStateCreateInfo* pCreateInfo, VkDynamicRasterState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001944{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001945 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001946 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
1947 loader_platform_thread_lock_mutex(&globalLock);
1948 dynamicRsStateMap[pState->handle] = *pCreateInfo;
1949 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001950 return result;
1951}
1952
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001953VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicColorBlendStateCreateInfo* pCreateInfo, VkDynamicColorBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001954{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001955 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001956 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
1957 loader_platform_thread_lock_mutex(&globalLock);
1958 dynamicCbStateMap[pState->handle] = *pCreateInfo;
1959 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001960 return result;
1961}
1962
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001963VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDepthStencilStateCreateInfo* pCreateInfo, VkDynamicDepthStencilState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001964{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001965 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001966 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
1967 loader_platform_thread_lock_mutex(&globalLock);
1968 dynamicDsStateMap[pState->handle] = *pCreateInfo;
1969 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001970 return result;
1971}
1972
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001973VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001974{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001975 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001976 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001977 loader_platform_thread_lock_mutex(&globalLock);
1978 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1979 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1980 pCB->cmdBuffer = *pCmdBuffer;
1981 pCB->flags = pCreateInfo->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001982 pCB->pool = pCreateInfo->cmdPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001983 pCB->lastVtxBinding = MAX_BINDING;
1984 cmdBufferMap[*pCmdBuffer] = pCB;
1985 loader_platform_thread_unlock_mutex(&globalLock);
1986 updateCBTracking(*pCmdBuffer);
1987 }
1988 return result;
1989}
1990
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001991VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001992{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001993 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001994 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001995 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1996 if (pCB) {
1997 if (CB_NEW != pCB->state)
1998 resetCB(cmdBuffer);
1999 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002000 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002001 // TODO : Need to pass cmdBuffer as objType here
2002 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002003 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002004 }
2005 updateCBTracking(cmdBuffer);
2006 }
2007 return result;
2008}
2009
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002010VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002011{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002012 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2013 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2014 if (pCB) {
2015 if (pCB->state == CB_UPDATE_ACTIVE) {
2016 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2017 if (VK_SUCCESS == result) {
2018 updateCBTracking(cmdBuffer);
2019 pCB->state = CB_UPDATE_COMPLETE;
2020 // Reset CB status flags
2021 pCB->status = 0;
2022 printCB(cmdBuffer);
2023 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002024 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002025 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002026 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002027 }
2028 return result;
2029}
2030
Cody Northropf02f9f82015-07-09 18:08:05 -06002031VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002032{
Cody Northropf02f9f82015-07-09 18:08:05 -06002033 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002034 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002035 resetCB(cmdBuffer);
2036 updateCBTracking(cmdBuffer);
2037 }
2038 return result;
2039}
2040
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002041VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042{
2043 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2044 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002045 if (pCB->state == CB_UPDATE_ACTIVE) {
2046 updateCBTracking(cmdBuffer);
2047 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002048 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002049 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2050 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002051 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002052 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2053 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002054 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002055 PIPELINE_NODE* pPN = getPipeline(pipeline);
2056 if (pPN) {
2057 pCB->lastBoundPipeline = pipeline;
2058 loader_platform_thread_lock_mutex(&globalLock);
2059 set_cb_pso_status(pCB, pPN);
2060 g_lastBoundPipeline = pPN;
2061 loader_platform_thread_unlock_mutex(&globalLock);
2062 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2063 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2064 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002065 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2066 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002067 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002068 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002069 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002070 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002071 }
2072 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002073}
2074
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002075VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002076{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002077 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2078 if (pCB) {
2079 if (pCB->state == CB_UPDATE_ACTIVE) {
2080 updateCBTracking(cmdBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002081 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002082 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002083 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2084 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002085 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002086 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002087 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2088 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002089 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE, dynamicViewportState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002090 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002091 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002092 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2093 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002094 }
2095 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002096 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002097 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002098 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002099 }
2100 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002101}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002102VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicRasterState(VkCmdBuffer cmdBuffer, VkDynamicRasterState dynamicRasterState)
2103{
2104 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2105 if (pCB) {
2106 if (pCB->state == CB_UPDATE_ACTIVE) {
2107 updateCBTracking(cmdBuffer);
2108 addCmd(pCB, CMD_BINDDYNAMICRASTERSTATE);
2109 if (!pCB->activeRenderPass) {
2110 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2111 "Incorrect call to vkCmdBindDynamicRasterState() without an active RenderPass.");
2112 }
2113 loader_platform_thread_lock_mutex(&globalLock);
2114 pCB->status |= CBSTATUS_RASTER_BOUND;
2115 if (dynamicRsStateMap.find(dynamicRasterState.handle) == dynamicRsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002116 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_RASTER_STATE, dynamicRasterState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002117 "Unable to find VkDynamicRasterState object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2118 } else {
2119 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2120 g_lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2121 }
2122 loader_platform_thread_unlock_mutex(&globalLock);
2123 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2124 } else {
2125 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicRasterState()");
2126 }
2127 }
2128}
2129VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(VkCmdBuffer cmdBuffer, VkDynamicColorBlendState dynamicColorBlendState)
2130{
2131 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2132 if (pCB) {
2133 if (pCB->state == CB_UPDATE_ACTIVE) {
2134 updateCBTracking(cmdBuffer);
2135 addCmd(pCB, CMD_BINDDYNAMICCOLORBLENDSTATE);
2136 if (!pCB->activeRenderPass) {
2137 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2138 "Incorrect call to vkCmdBindDynamicColorBlendState() without an active RenderPass.");
2139 }
2140 loader_platform_thread_lock_mutex(&globalLock);
2141 pCB->status |= CBSTATUS_COLOR_BLEND_BOUND;
2142 if (dynamicCbStateMap.find(dynamicColorBlendState.handle) == dynamicCbStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002143 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_COLOR_BLEND_STATE, dynamicColorBlendState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002144 "Unable to find VkDynamicColorBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2145 } else {
2146 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2147 g_lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2148 }
2149 loader_platform_thread_unlock_mutex(&globalLock);
2150 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2151 } else {
2152 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicColorBlendState()");
2153 }
2154 }
2155}
2156VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(VkCmdBuffer cmdBuffer, VkDynamicDepthStencilState dynamicDepthStencilState)
2157{
2158 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2159 if (pCB) {
2160 if (pCB->state == CB_UPDATE_ACTIVE) {
2161 updateCBTracking(cmdBuffer);
2162 addCmd(pCB, CMD_BINDDYNAMICDEPTHSTENCILSTATE);
2163 if (!pCB->activeRenderPass) {
2164 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2165 "Incorrect call to vkCmdBindDynamicDepthStencilState() without an active RenderPass.");
2166 }
2167 loader_platform_thread_lock_mutex(&globalLock);
2168 pCB->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
2169 if (dynamicDsStateMap.find(dynamicDepthStencilState.handle) == dynamicDsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002170 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_DEPTH_STENCIL_STATE, dynamicDepthStencilState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002171 "Unable to find VkDynamicDepthStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2172 } else {
2173 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2174 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2175 }
2176 loader_platform_thread_unlock_mutex(&globalLock);
2177 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
2178 } else {
2179 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthStencilState()");
2180 }
2181 }
2182}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002183VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002184{
2185 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2186 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002187 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002188 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002189 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2190 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002191 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002192 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06002193 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2194 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002195 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002196 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2197 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002198 loader_platform_thread_lock_mutex(&globalLock);
2199 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002200 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002201 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2202 g_lastBoundDescriptorSet = pDescriptorSets[i];
2203 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002204 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2205 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002206 if (!pSet->pUpdateStructs)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002207 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2208 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002209 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002210 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2211 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002212 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002213 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002214 updateCBTracking(cmdBuffer);
2215 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis9bde5922015-06-22 18:00:14 -06002216 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002217 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002218 } else {
2219 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002220 }
2221 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002222}
2223
Tony Barbour8205d902015-04-16 15:59:00 -06002224VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002225{
2226 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2227 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002228 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002229 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002230 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06002231 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2232 } else {
2233 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2234 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002235 updateCBTracking(cmdBuffer);
2236 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002237 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2238 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002239 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002240 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2241 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002242 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002243}
2244
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002245VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2246 VkCmdBuffer cmdBuffer,
2247 uint32_t startBinding,
2248 uint32_t bindingCount,
2249 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002250 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002251{
2252 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2253 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002254 if (pCB->state == CB_UPDATE_ACTIVE) {
2255 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002256 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002257 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06002258 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2259 } else {
2260 pCB->lastVtxBinding = startBinding + bindingCount -1;
2261 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002262 updateCBTracking(cmdBuffer);
2263 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002264 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2265 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002266 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002267 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002268 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002269 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002270 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002271}
2272
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002273VK_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 -06002274{
2275 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002276 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002277 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002278 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002279 pCB->drawCount[DRAW]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002280 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002281 // TODO : Need to pass cmdBuffer as srcObj here
2282 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002283 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2284 synchAndPrintDSConfig(cmdBuffer);
2285 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002286 updateCBTracking(cmdBuffer);
2287 addCmd(pCB, CMD_DRAW);
2288 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002289 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002290 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002291 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2292 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002293 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002294}
2295
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002296VK_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 -06002297{
2298 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002299 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002300 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002301 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002302 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002303 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002304 // TODO : Need to pass cmdBuffer as srcObj here
2305 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002306 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2307 synchAndPrintDSConfig(cmdBuffer);
2308 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002309 updateCBTracking(cmdBuffer);
2310 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002311 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2312 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002313 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002314 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2315 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002316 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002317}
2318
Tony Barbour8205d902015-04-16 15:59:00 -06002319VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002320{
2321 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002322 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002323 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002324 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002325 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002326 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002327 // TODO : Need to pass cmdBuffer as srcObj here
2328 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002329 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2330 synchAndPrintDSConfig(cmdBuffer);
2331 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002332 updateCBTracking(cmdBuffer);
2333 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002334 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2335 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002336 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002337 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2338 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002339 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002340}
2341
Tony Barbour8205d902015-04-16 15:59:00 -06002342VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002343{
2344 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002345 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002346 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002347 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002348 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002349 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002350 // TODO : Need to pass cmdBuffer as srcObj here
2351 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002352 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2353 synchAndPrintDSConfig(cmdBuffer);
2354 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002355 updateCBTracking(cmdBuffer);
2356 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2357 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002358 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002359 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002360 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2361 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002362 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002363}
2364
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002365VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002366{
2367 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2368 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002369 if (pCB->state == CB_UPDATE_ACTIVE) {
2370 updateCBTracking(cmdBuffer);
2371 addCmd(pCB, CMD_DISPATCH);
2372 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002373 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002374 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2375 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002376 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002377}
2378
Tony Barbour8205d902015-04-16 15:59:00 -06002379VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002380{
2381 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2382 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002383 if (pCB->state == CB_UPDATE_ACTIVE) {
2384 updateCBTracking(cmdBuffer);
2385 addCmd(pCB, CMD_DISPATCHINDIRECT);
2386 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002387 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002388 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2389 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002390 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002391}
2392
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002393VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002394{
2395 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2396 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002397 if (pCB->state == CB_UPDATE_ACTIVE) {
2398 updateCBTracking(cmdBuffer);
2399 addCmd(pCB, CMD_COPYBUFFER);
2400 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002401 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002402 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2403 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002404 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002405}
2406
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002407VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2408 VkImage srcImage,
2409 VkImageLayout srcImageLayout,
2410 VkImage destImage,
2411 VkImageLayout destImageLayout,
2412 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002413{
2414 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2415 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002416 if (pCB->state == CB_UPDATE_ACTIVE) {
2417 updateCBTracking(cmdBuffer);
2418 addCmd(pCB, CMD_COPYIMAGE);
2419 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002420 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002421 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2422 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002423 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002424}
2425
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002426VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2427 VkImage srcImage, VkImageLayout srcImageLayout,
2428 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002429 uint32_t regionCount, const VkImageBlit* pRegions,
2430 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002431{
2432 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2433 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002434 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002435 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002436 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2437 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002438 } else {
2439 updateCBTracking(cmdBuffer);
2440 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002441 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002442 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002443 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002444 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2445 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002446 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002447}
2448
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002449VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2450 VkBuffer srcBuffer,
2451 VkImage destImage, VkImageLayout destImageLayout,
2452 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002453{
2454 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2455 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002456 if (pCB->state == CB_UPDATE_ACTIVE) {
2457 updateCBTracking(cmdBuffer);
2458 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2459 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002460 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002461 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2462 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002464}
2465
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002466VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2467 VkImage srcImage, VkImageLayout srcImageLayout,
2468 VkBuffer destBuffer,
2469 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470{
2471 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2472 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002473 if (pCB->state == CB_UPDATE_ACTIVE) {
2474 updateCBTracking(cmdBuffer);
2475 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2476 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002477 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002478 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2479 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002480 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002481}
2482
Tony Barbour8205d902015-04-16 15:59:00 -06002483VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484{
2485 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2486 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002487 if (pCB->state == CB_UPDATE_ACTIVE) {
2488 updateCBTracking(cmdBuffer);
2489 addCmd(pCB, CMD_UPDATEBUFFER);
2490 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002491 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002492 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2493 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002494 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002495}
2496
Tony Barbour8205d902015-04-16 15:59:00 -06002497VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002498{
2499 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2500 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002501 if (pCB->state == CB_UPDATE_ACTIVE) {
2502 updateCBTracking(cmdBuffer);
2503 addCmd(pCB, CMD_FILLBUFFER);
2504 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002505 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002506 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2507 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002508 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002509}
2510
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002511VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2512 VkCmdBuffer cmdBuffer,
2513 uint32_t colorAttachment,
2514 VkImageLayout imageLayout,
2515 const VkClearColorValue* pColor,
2516 uint32_t rectCount,
2517 const VkRect3D* pRects)
2518{
2519 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2520 if (pCB) {
2521 if (pCB->state == CB_UPDATE_ACTIVE) {
2522 // Warn if this is issued prior to Draw Cmd
2523 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002524 // TODO : cmdBuffer should be srcObj
2525 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002526 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2527 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2528 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002529 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002530 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002531 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2532 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2533 } else {
2534 updateCBTracking(cmdBuffer);
2535 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2536 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2537 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002538 } else {
2539 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2540 }
2541 }
2542}
2543
2544VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2545 VkCmdBuffer cmdBuffer,
2546 VkImageAspectFlags imageAspectMask,
2547 VkImageLayout imageLayout,
2548 float depth,
2549 uint32_t stencil,
2550 uint32_t rectCount,
2551 const VkRect3D* pRects)
2552{
2553 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2554 if (pCB) {
2555 if (pCB->state == CB_UPDATE_ACTIVE) {
2556 // Warn if this is issued prior to Draw Cmd
2557 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002558 // TODO : cmdBuffer should be srcObj
2559 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002560 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2561 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2562 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002563 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002564 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002565 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2566 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2567 } else {
2568 updateCBTracking(cmdBuffer);
2569 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2570 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2571 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002572 } else {
2573 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2574 }
2575 }
2576}
2577
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002578VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2579 VkCmdBuffer cmdBuffer,
2580 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002581 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002582 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002583{
2584 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2585 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002586 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002587 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002588 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002589 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2590 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2591 } else {
2592 updateCBTracking(cmdBuffer);
2593 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2594 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2595 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002596 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002597 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2598 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002599 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002600}
2601
Chris Forbes2951d7d2015-06-22 17:21:59 +12002602VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002603 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002604 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002605 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002606{
2607 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2608 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002609 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002610 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002611 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002612 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2613 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2614 } else {
2615 updateCBTracking(cmdBuffer);
2616 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2617 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2618 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002619 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002620 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2621 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002622 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002623}
2624
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002625VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2626 VkImage srcImage, VkImageLayout srcImageLayout,
2627 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002628 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002629{
2630 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2631 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002632 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002633 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002634 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2635 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002636 } else {
2637 updateCBTracking(cmdBuffer);
2638 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002639 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002640 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002641 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002642 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2643 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002644 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002645}
2646
Tony Barbourc2e987e2015-06-29 16:20:35 -06002647VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002648{
2649 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2650 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002651 if (pCB->state == CB_UPDATE_ACTIVE) {
2652 updateCBTracking(cmdBuffer);
2653 addCmd(pCB, CMD_SETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002654 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002655 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002656 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2657 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002658 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002659}
2660
Tony Barbourc2e987e2015-06-29 16:20:35 -06002661VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002662{
2663 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2664 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002665 if (pCB->state == CB_UPDATE_ACTIVE) {
2666 updateCBTracking(cmdBuffer);
2667 addCmd(pCB, CMD_RESETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002668 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002669 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002670 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2671 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002672 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002673}
2674
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002675VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags destStageMask, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002676{
2677 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2678 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002679 if (pCB->state == CB_UPDATE_ACTIVE) {
2680 updateCBTracking(cmdBuffer);
2681 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002682 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002683 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002684 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2685 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002686 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002687}
2688
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002689VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags destStageMask, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002690{
2691 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2692 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002693 if (pCB->state == CB_UPDATE_ACTIVE) {
2694 updateCBTracking(cmdBuffer);
2695 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter73a21d32015-07-12 13:20:05 -06002696 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002697 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002698 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2699 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002700 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002701}
2702
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002703VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002704{
2705 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2706 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002707 if (pCB->state == CB_UPDATE_ACTIVE) {
2708 updateCBTracking(cmdBuffer);
2709 addCmd(pCB, CMD_BEGINQUERY);
2710 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002711 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002712 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2713 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002714 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002715}
2716
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002717VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002718{
2719 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2720 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002721 if (pCB->state == CB_UPDATE_ACTIVE) {
2722 updateCBTracking(cmdBuffer);
2723 addCmd(pCB, CMD_ENDQUERY);
2724 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002725 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002726 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2727 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002728 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002729}
2730
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002731VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002732{
2733 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2734 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002735 if (pCB->state == CB_UPDATE_ACTIVE) {
2736 updateCBTracking(cmdBuffer);
2737 addCmd(pCB, CMD_RESETQUERYPOOL);
2738 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002739 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002740 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2741 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002742 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002743}
2744
Tony Barbour8205d902015-04-16 15:59:00 -06002745VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002746{
2747 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2748 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002749 if (pCB->state == CB_UPDATE_ACTIVE) {
2750 updateCBTracking(cmdBuffer);
2751 addCmd(pCB, CMD_WRITETIMESTAMP);
2752 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002753 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002754 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2755 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002756 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002757}
2758
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002759VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002760{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002761 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002762 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002763 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002764 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002765 if (pCreateInfo->pAttachments) {
2766 localFBCI->pAttachments = new VkAttachmentBindInfo[localFBCI->attachmentCount];
2767 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002768 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002769 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002770 }
2771 return result;
2772}
2773
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002774VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002775{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002776 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002777 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002778 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002779 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002780 if (pCreateInfo->pAttachments) {
2781 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2782 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002783 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002784 if (pCreateInfo->pSubpasses) {
2785 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2786 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2787
2788 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2789 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2790 const uint32_t attachmentCount = subpass->inputCount +
Tony Barbourb2cc40a2015-07-13 15:28:47 -06002791 subpass->colorCount * (1 + (subpass->resolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002792 subpass->preserveCount;
2793 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2794
2795 memcpy(attachments, subpass->inputAttachments,
2796 sizeof(attachments[0]) * subpass->inputCount);
2797 subpass->inputAttachments = attachments;
2798 attachments += subpass->inputCount;
2799
2800 memcpy(attachments, subpass->colorAttachments,
2801 sizeof(attachments[0]) * subpass->colorCount);
2802 subpass->colorAttachments = attachments;
2803 attachments += subpass->colorCount;
2804
2805 if (subpass->resolveAttachments) {
2806 memcpy(attachments, subpass->resolveAttachments,
2807 sizeof(attachments[0]) * subpass->colorCount);
2808 subpass->resolveAttachments = attachments;
2809 attachments += subpass->colorCount;
2810 }
2811
2812 memcpy(attachments, subpass->preserveAttachments,
2813 sizeof(attachments[0]) * subpass->preserveCount);
2814 subpass->preserveAttachments = attachments;
2815 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002816 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002817 if (pCreateInfo->pDependencies) {
2818 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2819 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002820 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002821 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002822 }
2823 return result;
2824}
2825
Chia-I Wuc278df82015-07-07 11:50:03 +08002826VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002827{
2828 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2829 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002830 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002831 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002832 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2833 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002834 } else {
2835 updateCBTracking(cmdBuffer);
2836 addCmd(pCB, CMD_BEGINRENDERPASS);
2837 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002838 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002839 pCB->framebuffer = pRenderPassBegin->framebuffer;
2840 if (pCB->lastBoundPipeline) {
2841 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2842 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002843 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002844 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002845 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002846 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002847 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002848 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002849 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002850}
2851
Chia-I Wuc278df82015-07-07 11:50:03 +08002852VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2853{
2854 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2855 if (pCB) {
2856 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002857 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wuc278df82015-07-07 11:50:03 +08002858 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2859 } else {
2860 updateCBTracking(cmdBuffer);
2861 addCmd(pCB, CMD_NEXTSUBPASS);
2862 pCB->activeSubpass++;
2863 if (pCB->lastBoundPipeline) {
2864 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2865 }
2866 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2867 }
2868 }
2869}
2870
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002871VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002872{
2873 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2874 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002875 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002876 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002877 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06002878 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002879 updateCBTracking(cmdBuffer);
2880 addCmd(pCB, CMD_ENDRENDERPASS);
2881 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08002882 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002883 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2884 }
2885 }
2886}
2887
2888VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2889{
2890 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2891 if (pCB) {
2892 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002893 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002894 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2895 } else {
2896 updateCBTracking(cmdBuffer);
2897 addCmd(pCB, CMD_EXECUTECOMMANDS);
2898 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002899 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002900 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002901}
2902
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002903VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2904 VkInstance instance,
2905 VkFlags msgFlags,
2906 const PFN_vkDbgMsgCallback pfnMsgCallback,
2907 void* pUserData,
2908 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002909{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002910 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002911 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2912 if (VK_SUCCESS == res) {
2913 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2914 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2915 }
2916 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002917}
2918
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002919VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2920 VkInstance instance,
2921 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002922{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002923 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002924 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2925 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2926 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2927 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002928}
2929
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002930VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002931{
2932 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002933 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2934 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002935 // TODO : cmdBuffer should be srcObj
2936 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002937 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002938 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002939 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002940 updateCBTracking(cmdBuffer);
2941 addCmd(pCB, CMD_DBGMARKERBEGIN);
2942 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002943 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002944}
2945
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002946VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002947{
2948 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002949 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2950 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002951 // TODO : cmdBuffer should be srcObj
2952 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06002953 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002954 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002955 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002956 updateCBTracking(cmdBuffer);
2957 addCmd(pCB, CMD_DBGMARKEREND);
2958 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002959 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2960}
2961
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002962//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2963//{
2964// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2965// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2966// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2967// "Attempt to use DbgSetObjectTag but extension disabled!");
2968// return VK_ERROR_UNAVAILABLE;
2969// }
2970// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2971//}
2972//
2973//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2974//{
2975// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2976// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2977// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2978// "Attempt to use DbgSetObjectName but extension disabled!");
2979// return VK_ERROR_UNAVAILABLE;
2980// }
2981// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
2982//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002983
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002984VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002985{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002986 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002987 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002988
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002989 /* loader uses this to force layer initialization; device object is wrapped */
2990 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002991 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002992 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002993 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06002994 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002995 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002996 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002997 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002998 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002999 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003000 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003001 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003002 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003003 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003004 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003005 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003006 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003007 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003008 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003009 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003010 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003011 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003012 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003013 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003014 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003015 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003016 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003017 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003018 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003019 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003020 if (!strcmp(funcName, "vkDestroyAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003021 return (PFN_vkVoidFunction) vkDestroyAttachmentView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003022 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003023 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003024 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003025 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003026 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003027 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003028 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003029 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003030 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003031 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003032 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003033 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003034 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003035 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003036 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003037 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003038 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003039 return (PFN_vkVoidFunction) vkDestroyDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003040 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003041 return (PFN_vkVoidFunction) vkDestroyDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003042 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003043 return (PFN_vkVoidFunction) vkDestroyDynamicDepthStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003044 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003045 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003046 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003047 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003048 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003049 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003050 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003051 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003052 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003053 return (PFN_vkVoidFunction) vkCreateImageView;
Tobin Ehlis44c757d2015-07-10 12:15:19 -06003054 if (!strcmp(funcName, "vkCreateAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003055 return (PFN_vkVoidFunction) vkCreateAttachmentView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003056 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003057 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003058 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003059 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003060 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003061 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003062 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003063 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003064 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003065 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003066 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003067 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003068 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003069 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003070 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003071 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003072 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003073 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003074 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003075 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003076 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003077 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003078 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003079 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003080 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003081 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003082 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003083 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003084 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003085 return (PFN_vkVoidFunction) vkCreateDynamicRasterState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003086 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003087 return (PFN_vkVoidFunction) vkCreateDynamicColorBlendState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003088 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003089 return (PFN_vkVoidFunction) vkCreateDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003090 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003091 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003092 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003093 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003094 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003095 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003096 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003097 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003098 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003099 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003100 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003101 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003102 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003103 return (PFN_vkVoidFunction) vkCmdBindDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003104 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003105 return (PFN_vkVoidFunction) vkCmdBindDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003106 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003107 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003108 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003109 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003110 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003111 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003112 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003113 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003114 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003115 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003116 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003117 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003118 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003120 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003122 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003124 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003126 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003128 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003130 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003132 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003134 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003136 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003138 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003140 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003142 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003143 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003144 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003145 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003146 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003147 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003148 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003150 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003152 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003154 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003156 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003158 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003160 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003161 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003162 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003163 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003164 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003165 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003166 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003167 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003168 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003169 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003170 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003172 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003173 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003174
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003175 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3176 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003177 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003178 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003179 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003180 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003181 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003182// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3183// return (void*) vkDbgSetObjectTag;
3184// if (!strcmp(funcName, "vkDbgSetObjectName"))
3185// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003186 }
3187 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003188 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003189 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003190 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003191 }
3192}
3193
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003194VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003195{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003196 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003197 if (instance == NULL)
3198 return NULL;
3199
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003200 /* loader uses this to force layer initialization; instance object is wrapped */
3201 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003202 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003204 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003205 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003206 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003207 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003208 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003209 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003210 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003211 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003212 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003213 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003214 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003215 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003216 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003217
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003218 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3219 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003220 if (fptr)
3221 return fptr;
3222
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003223 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003224 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003225 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003226 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003227 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003228 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003229}