blob: d21dc60b403b15bccdc966f3af46ad28c2ab0392 [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};
Dana Jansens4a3e0862015-07-30 13:22:15 -0700247static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
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];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600627 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
628 return pPipe->msStateCI.rasterSamples;
629 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600630 return 1;
631}
632// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600633static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600634{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600635 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600636 // Verify that any MSAA request in PSO matches sample# in bound FB
637 uint32_t psoNumSamples = getNumSamples(pipeline);
638 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600639 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800640 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
641 int subpassNumSamples = 0;
642 uint32_t i;
643
644 for (i = 0; i < pSD->colorCount; i++) {
645 uint32_t samples;
646
647 if (pSD->colorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
648 continue;
649
650 samples = pRPCI->pAttachments[pSD->colorAttachments[i].attachment].samples;
651 if (subpassNumSamples == 0) {
652 subpassNumSamples = samples;
653 } else if (subpassNumSamples != samples) {
654 subpassNumSamples = -1;
655 break;
656 }
657 }
658 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
659 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
660 if (subpassNumSamples == 0)
661 subpassNumSamples = samples;
662 else if (subpassNumSamples != samples)
663 subpassNumSamples = -1;
664 }
665
666 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600667 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
668 "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 -0600669 }
670 } else {
671 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
672 // Verify and flag error as appropriate
673 }
674 // TODO : Add more checks here
675 } else {
676 // TODO : Validate non-gfx pipeline updates
677 }
678}
679
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600680// Block of code at start here specifically for managing/tracking DSs
681
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600682// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600683static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600684{
685 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600686 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600687 loader_platform_thread_unlock_mutex(&globalLock);
688 return NULL;
689 }
690 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600691 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600692}
693// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600694static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600695{
696 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600697 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600698 loader_platform_thread_unlock_mutex(&globalLock);
699 return NULL;
700 }
701 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600702 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600703}
704
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600705static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600706 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600707 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600708 loader_platform_thread_unlock_mutex(&globalLock);
709 return NULL;
710 }
711 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600712 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600713}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600714// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600715static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600716{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600717 switch (pUpdateStruct->sType)
718 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800719 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
720 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600721 return 1;
722 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600723 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 -0600724 "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 -0600725 return 0;
726 }
727}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600728// For given update struct, return binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600729static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600730{
731 switch (pUpdateStruct->sType)
732 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800733 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
734 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
735 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
736 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600737 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600738 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 -0600739 "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 -0600740 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600741 }
742}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600743// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600744static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600745{
746 switch (pUpdateStruct->sType)
747 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800748 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
749 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
750 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600751 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800752 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600753 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600754 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 -0600755 "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 -0600756 return 0;
757 }
758}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600759// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600760static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600761{
762 switch (pUpdateStruct->sType)
763 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800764 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
765 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
766 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600767 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800768 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600769 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600770 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 -0600771 "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 -0600772 return 0;
773 }
774}
775// For given Layout Node and binding, return index where that binding begins
776static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
777{
778 uint32_t offsetIndex = 0;
779 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800780 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600781 }
782 return offsetIndex;
783}
784// For given layout node and binding, return last index that is updated
785static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
786{
787 uint32_t offsetIndex = 0;
788 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800789 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600790 }
791 return offsetIndex-1;
792}
793// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600794static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600795{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600796 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600797}
798// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600799static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600800{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600801 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600802}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600803// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600804static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600805{
806 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600807 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600808 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600809 switch (pUpdateStruct->sType)
810 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800811 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
812 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600813 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800814 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
815 /* no need to validate */
816 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600817 break;
818 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600819 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 -0600820 "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 -0600821 return 0;
822 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600823 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600824 if (pLayout->pTypes[i] != actualType)
825 return 0;
826 }
827 return 1;
828}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
830// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
831// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600832static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600833{
834 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800835 VkWriteDescriptorSet* pWDS = NULL;
836 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600837 size_t array_size = 0;
838 size_t base_array_size = 0;
839 size_t total_array_size = 0;
840 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600841 switch (pUpdate->sType)
842 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800843 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
844 pWDS = new VkWriteDescriptorSet;
845 pNewNode = (GENERIC_HEADER*)pWDS;
846 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
847 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
848 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
849 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600850 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800851 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
852 pCDS = new VkCopyDescriptorSet;
853 pUpdate = (GENERIC_HEADER*)pCDS;
854 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600855 break;
856 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600857 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 -0600858 "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 -0600859 return NULL;
860 }
861 // Make sure that pNext for the end of shadow copy is NULL
862 pNewNode->pNext = NULL;
863 return pNewNode;
864}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800865// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600866static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600867{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800868 const VkWriteDescriptorSet *pWDS = NULL;
869 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600870 VkBool32 result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800871
872 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
873 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
874 else
875 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
876
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600877 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600878 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600879 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600881 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600882 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800883 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600884 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800885 g_lastBoundDescriptorSet = pSet->set;
886 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600887 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600888 // First verify valid update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600889 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600890 result = 0;
891 break;
892 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600893 // Make sure that binding is within bounds
Tobin Ehlisde63c532015-06-18 15:59:33 -0600894 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600895 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 -0600896 "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 -0600897 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600898 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600899 // Next verify that update falls within size of given binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600900 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour29b12062015-07-13 13:37:24 -0600901 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600902 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600903 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600904 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 -0600905 "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 -0600906 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600907 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600908 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlisde63c532015-06-18 15:59:33 -0600909 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600910 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 -0600911 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600912 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600913 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600914 // Save the update info
915 // TODO : Info message that update successful
916 // Create new update struct for this set's shadow copy
Tobin Ehlisde63c532015-06-18 15:59:33 -0600917 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600918 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600919 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 -0600920 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600921 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600922 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600923 // Insert shadow node into LL of updates for this set
924 pNewNode->pNext = pSet->pUpdateStructs;
925 pSet->pUpdateStructs = pNewNode;
926 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisde63c532015-06-18 15:59:33 -0600927 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600928 assert(j<pSet->descriptorCount);
929 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600930 }
931 }
932 }
933 }
934 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600935 }
936 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600937 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600938}
939// Free the shadowed update node for this Set
940// NOTE : Calls to this function should be wrapped in mutex
941static void freeShadowUpdateTree(SET_NODE* pSet)
942{
943 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
944 pSet->pUpdateStructs = NULL;
945 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
946 // Clear the descriptor mappings as they will now be invalid
947 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
948 while(pShadowUpdate) {
949 pFreeUpdate = pShadowUpdate;
950 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
951 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800952 VkWriteDescriptorSet * pWDS = NULL;
953 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600954 void** ppToFree = NULL;
955 switch (pFreeUpdate->sType)
956 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800957 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
958 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
959 if (pWDS->pDescriptors)
960 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600961 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800962 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600963 break;
964 default:
965 assert(0);
966 break;
967 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600968 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600969 }
970}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600971// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600972// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600973static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600974{
David Pinedof5997ab2015-04-27 16:36:17 -0600975 if (poolMap.size() <= 0)
976 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600977 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600978 SET_NODE* pSet = (*ii).second->pSets;
979 SET_NODE* pFreeSet = pSet;
980 while (pSet) {
981 pFreeSet = pSet;
982 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600983 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600984 // Free Update shadow struct tree
985 freeShadowUpdateTree(pFreeSet);
986 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200987 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600988 }
989 delete pFreeSet;
990 }
991 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200992 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600993 }
994 delete (*ii).second;
995 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600996 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600997}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600998// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600999// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001000static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001001{
David Pinedof5997ab2015-04-27 16:36:17 -06001002 if (layoutMap.size() <= 0)
1003 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001004 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001005 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001006 if (pLayout->createInfo.pBinding) {
1007 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1008 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1009 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1010 }
1011 delete[] pLayout->createInfo.pBinding;
1012 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001013 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001014 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001015 }
1016 delete pLayout;
1017 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001018 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019}
1020// Currently clearing a set is removing all previous updates to that set
1021// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001022static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023{
1024 SET_NODE* pSet = getSetNode(set);
1025 if (!pSet) {
1026 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001027 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001028 loader_platform_thread_lock_mutex(&globalLock);
1029 freeShadowUpdateTree(pSet);
1030 loader_platform_thread_unlock_mutex(&globalLock);
1031 }
1032}
1033
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001034static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001035{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001036 POOL_NODE* pPool = getPoolNode(pool);
1037 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001038 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1039 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001040 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001041 // For every set off of this pool, clear it
1042 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001043 while (pSet) {
1044 clearDescriptorSet(pSet->set);
1045 }
1046 }
1047}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001048// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001049static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001050{
1051 loader_platform_thread_lock_mutex(&globalLock);
1052 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1053 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001054 // TODO : How to pass cb as srcObj here?
1055 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1056 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001057 return NULL;
1058 }
1059 loader_platform_thread_unlock_mutex(&globalLock);
1060 return cmdBufferMap[cb];
1061}
1062// Free all CB Nodes
1063// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001064static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001065{
David Pinedof5997ab2015-04-27 16:36:17 -06001066 if (cmdBufferMap.size() <= 0)
1067 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001068 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001069 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1070 while (!cmd_node_list.empty()) {
1071 CMD_NODE* cmd_node = cmd_node_list.back();
1072 delete cmd_node;
1073 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001074 }
1075 delete (*ii).second;
1076 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001077 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001078}
Tobin Ehlise42007c2015-06-19 13:00:59 -06001079static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1080{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001081 // TODO : How to pass cb as srcObj here?
1082 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 -06001083 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1084}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001085static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1086{
1087 CMD_NODE* pCmd = new CMD_NODE;
1088 if (pCmd) {
1089 // init cmd node and append to end of cmd LL
1090 memset(pCmd, 0, sizeof(CMD_NODE));
1091 pCmd->cmdNumber = ++pCB->numCmds;
1092 pCmd->type = cmd;
1093 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001094 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001095 // TODO : How to pass cb as srcObj here?
1096 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1097 "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 -06001098 }
1099}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001100static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001101{
1102 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1103 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001104 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1105 while (!cmd_list.empty()) {
1106 delete cmd_list.back();
1107 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001108 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001109 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001110 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001111 VkFlags saveFlags = pCB->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001112 VkCmdPool savedPool = pCB->pool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001113 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1114 pCB->cmdBuffer = cb;
1115 pCB->flags = saveFlags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001116 pCB->pool = savedPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001117 pCB->lastVtxBinding = MAX_BINDING;
1118 }
1119}
Tobin Ehlis97866202015-06-10 12:57:07 -06001120// Set PSO-related status bits for CB
1121static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1122{
1123 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1124 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1125 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1126 }
1127 }
1128 if (pPipe->dsStateCI.depthWriteEnable) {
1129 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1130 }
1131}
1132// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001133static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001134 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1135 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1136 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1137 pNode->status |= CBSTATUS_RASTER_BOUND;
1138 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1139 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1140 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1141 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1142 }
1143}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001144// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001146{
1147 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1148 if (pCB) {
1149 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1150 if (!pPipeTrav) {
1151 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001152 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001153 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001154 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001155 }
1156 }
1157}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001158// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001159static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001160{
1161 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1162 if (pCB && pCB->lastBoundPipeline) {
1163 // First verify that we have a Node for bound pipeline
1164 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001165 if (!pPipeTrav) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001166 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1167 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001168 return false;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001169 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001170 // Verify Vtx binding
1171 if (MAX_BINDING != pCB->lastVtxBinding) {
1172 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1173 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001174 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 -06001175 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001176 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001177 }
1178 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001179 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 -06001180 "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 -06001181 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001182 }
1183 }
1184 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001185 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001186 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001187 }
1188 }
1189 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001190 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001191 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001192 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001193}
1194// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001195static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001196{
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001197 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.
1198 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001199 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001200 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001201 POOL_NODE* pPool = getPoolNode(pSet->pool);
1202 // Print out pool details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001203 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1204 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001205 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001206 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001207 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001208 // Print out set details
1209 char prefix[10];
1210 uint32_t index = 0;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001211 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1212 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001213 LAYOUT_NODE* pLayout = pSet->pLayout;
1214 // Print layout details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001215 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1216 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001217 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001218 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001219 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001220 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001221 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001222 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1223 if (pUpdate) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001224 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1225 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001226 sprintf(prefix, " [UC] ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001227 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001228 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001229 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001230 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001231 if (0 != pSet->descriptorCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001232 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1233 "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 -06001234 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001235 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1236 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001237 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001238 }
1239 }
1240}
1241
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001242static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001243{
1244 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001245 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001246 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001247 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001248 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001249 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1250 // TODO : Need to pass cb as srcObj here
1251 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 -06001252 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001253 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001254 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001255 // Nothing to print
1256 }
1257}
1258
1259
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001260static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001261{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -06001262 // TODO : Re-enable these print funcs
1263// printDSConfig(cb);
1264// printPipeline(cb);
1265// printDynamicState(cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001266}
1267
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001268static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001269{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001270 uint32_t report_flags = 0;
1271 uint32_t debug_action = 0;
1272 FILE *log_output = NULL;
1273 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001274 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001275 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1276 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001277
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001278 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001279 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001280 option_str = getLayerOption("DrawStateLogFilename");
1281 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001282 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001283 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001284 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001285 if (log_output == NULL)
1286 log_output = stdout;
1287
1288 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 -06001289 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001290
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001291 if (!globalLockInitialized)
1292 {
1293 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001294 // suggestion is to call this during vkCreateInstance(), and then we
1295 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001296 // that the layer have per-instance locks. We need to come back and
1297 // address this soon.
1298 loader_platform_thread_create_mutex(&globalLock);
1299 globalLockInitialized = 1;
1300 }
1301}
1302
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001303VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1304{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001305 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001306 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1307
1308 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001309 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1310 my_data->report_data = debug_report_create_instance(
1311 pTable,
1312 *pInstance,
1313 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001314 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001315
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001316 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001317 }
1318 return result;
1319}
1320
Jon Ashburne0fa2282015-05-20 09:00:28 -06001321/* hook DestroyInstance to remove tableInstanceMap entry */
1322VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1323{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001324 dispatch_key key = get_dispatch_key(instance);
1325 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1326 VkResult res = pTable->DestroyInstance(instance);
1327
1328 // Clean up logging callback, if any
1329 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1330 if (my_data->logging_callback) {
1331 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1332 }
1333
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001334 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001335 layer_data_map.erase(pTable);
1336
1337 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001338 return res;
1339}
1340
Jon Ashburnf0615e22015-05-25 14:11:37 -06001341static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1342{
Tony Barbour29b12062015-07-13 13:37:24 -06001343 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001344 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001345 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001346
1347 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001348 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001349 /* Found a matching extension name, mark it enabled and init dispatch table*/
1350 initDebugMarkerTable(device);
1351 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001352 }
1353
1354 }
1355}
1356
Tony Barbour8205d902015-04-16 15:59:00 -06001357VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001358{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001359 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1360 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001361 if (result == VK_SUCCESS) {
1362 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1363 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1364 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1365 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001366 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001367 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001368 return result;
1369}
1370
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001371VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001372{
1373 // Free all the memory
1374 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001375 deletePipelines();
1376 deleteSamplers();
1377 deleteImages();
1378 deleteBuffers();
1379 deleteCmdBuffers();
1380 deleteDynamicState();
1381 deletePools();
1382 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001383 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001384
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001385 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001386 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1387 VkResult result = pDisp->DestroyDevice(device);
1388 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001389 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001390 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001391 return result;
1392}
1393
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001394static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001395 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001396 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001397 VK_API_VERSION,
1398 VK_MAKE_VERSION(0, 1, 0),
1399 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001400 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001401};
1402
Tony Barbour426b9052015-06-24 16:06:58 -06001403VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001404 const char *pLayerName,
1405 uint32_t *pCount,
1406 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001407{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001408 /* DrawState does not have any global extensions */
1409 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1410}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001411
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001412VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1413 uint32_t *pCount,
1414 VkLayerProperties* pProperties)
1415{
1416 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1417 ds_global_layers,
1418 pCount, pProperties);
1419}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001420
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001421static const VkExtensionProperties ds_device_extensions[] = {
1422 {
1423 DEBUG_MARKER_EXTENSION_NAME,
1424 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001425 }
1426};
1427
1428static const VkLayerProperties ds_device_layers[] = {
1429 {
1430 "DrawState",
1431 VK_API_VERSION,
1432 VK_MAKE_VERSION(0, 1, 0),
1433 "Validation layer: DrawState",
1434 }
1435};
1436
1437VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1438 VkPhysicalDevice physicalDevice,
1439 const char* pLayerName,
1440 uint32_t* pCount,
1441 VkExtensionProperties* pProperties)
1442{
1443 /* Mem tracker does not have any physical device extensions */
1444 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1445 pCount, pProperties);
1446}
1447
1448VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1449 VkPhysicalDevice physicalDevice,
1450 uint32_t* pCount,
1451 VkLayerProperties* pProperties)
1452{
1453 /* Mem tracker's physical device layers are the same as global */
1454 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1455 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001456}
1457
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001458VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001459{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001460 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001461 for (uint32_t i=0; i < cmdBufferCount; i++) {
1462 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001463 pCB = getCBNode(pCmdBuffers[i]);
1464 loader_platform_thread_lock_mutex(&globalLock);
1465 if (CB_UPDATE_COMPLETE != pCB->state) {
1466 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001467 // TODO : How to pass cb as srcObj?
1468 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1469 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlise90b1712015-05-27 14:30:06 -06001470 loader_platform_thread_unlock_mutex(&globalLock);
1471 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001472 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001473 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001474 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001475
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001476 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001477 return result;
1478}
1479
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001480VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001481{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001482 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1483 // TODO : Clean up any internal data structures using this obj.
1484 return result;
1485}
1486
1487VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1488{
1489 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1490 // TODO : Clean up any internal data structures using this obj.
1491 return result;
1492}
1493
1494VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1495{
1496 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1497 // TODO : Clean up any internal data structures using this obj.
1498 return result;
1499}
1500
1501VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1502{
1503 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1504 // TODO : Clean up any internal data structures using this obj.
1505 return result;
1506}
1507
1508VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1509{
1510 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1511 // TODO : Clean up any internal data structures using this obj.
1512 return result;
1513}
1514
1515VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1516{
1517 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1518 // TODO : Clean up any internal data structures using this obj.
1519 return result;
1520}
1521
1522VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1523{
1524 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1525 // TODO : Clean up any internal data structures using this obj.
1526 return result;
1527}
1528
1529VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1530{
1531 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1532 // TODO : Clean up any internal data structures using this obj.
1533 return result;
1534}
1535
1536VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1537{
1538 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1539 // TODO : Clean up any internal data structures using this obj.
1540 return result;
1541}
1542
1543VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1544{
1545 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1546 // TODO : Clean up any internal data structures using this obj.
1547 return result;
1548}
1549
1550VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1551{
1552 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1553 // TODO : Clean up any internal data structures using this obj.
1554 return result;
1555}
1556
1557VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1558{
1559 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1560 // TODO : Clean up any internal data structures using this obj.
1561 return result;
1562}
1563
1564VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1565{
1566 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1567 // TODO : Clean up any internal data structures using this obj.
1568 return result;
1569}
1570
1571VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1572{
1573 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1574 // TODO : Clean up any internal data structures using this obj.
1575 return result;
1576}
1577
1578VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1579{
1580 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1581 // TODO : Clean up any internal data structures using this obj.
1582 return result;
1583}
1584
1585VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1586{
1587 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1588 // TODO : Clean up any internal data structures using this obj.
1589 return result;
1590}
1591
1592VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1593{
1594 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1595 // TODO : Clean up any internal data structures using this obj.
1596 return result;
1597}
1598
1599VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1600{
1601 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1602 // TODO : Clean up any internal data structures using this obj.
1603 return result;
1604}
1605
1606VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1607{
1608 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1609 // TODO : Clean up any internal data structures using this obj.
1610 return result;
1611}
1612
1613VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1614{
1615 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1616 // TODO : Clean up any internal data structures using this obj.
1617 return result;
1618}
1619
1620VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1621{
1622 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1623 // TODO : Clean up any internal data structures using this obj.
1624 return result;
1625}
1626
1627VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1628{
1629 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1630 // TODO : Clean up any internal data structures using this obj.
1631 return result;
1632}
1633
1634VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1635{
1636 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1637 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001638 return result;
1639}
1640
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001641VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001642{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001643 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001644 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001645 loader_platform_thread_lock_mutex(&globalLock);
1646 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1647 pNewNode->buffer = *pView;
1648 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001649 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001650 loader_platform_thread_unlock_mutex(&globalLock);
1651 }
1652 return result;
1653}
1654
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001655VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001656{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001657 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001658 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001659 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001660 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001661 loader_platform_thread_unlock_mutex(&globalLock);
1662 }
1663 return result;
1664}
1665
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001666VkResult VKAPI vkCreateAttachmentView(
1667 VkDevice device,
1668 const VkAttachmentViewCreateInfo* pCreateInfo,
1669 VkAttachmentView* pView)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001670{
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001671 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001672 if (VK_SUCCESS == result) {
1673 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001674 viewMap[pView->handle] = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001675 loader_platform_thread_unlock_mutex(&globalLock);
1676 }
1677 return result;
1678}
1679
Jon Ashburn0d60d272015-07-09 15:02:25 -06001680//TODO handle pipeline caches
1681VkResult VKAPI vkCreatePipelineCache(
1682 VkDevice device,
1683 const VkPipelineCacheCreateInfo* pCreateInfo,
1684 VkPipelineCache* pPipelineCache)
1685{
1686 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1687 return result;
1688}
1689
1690VkResult VKAPI vkDestroyPipelineCache(
1691 VkDevice device,
1692 VkPipelineCache pipelineCache)
1693{
1694 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1695 return result;
1696}
1697
1698size_t VKAPI vkGetPipelineCacheSize(
1699 VkDevice device,
1700 VkPipelineCache pipelineCache)
1701{
1702 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1703 return size;
1704}
1705
1706VkResult VKAPI vkGetPipelineCacheData(
1707 VkDevice device,
1708 VkPipelineCache pipelineCache,
1709 void* pData)
1710{
1711 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1712 return result;
1713}
1714
1715VkResult VKAPI vkMergePipelineCaches(
1716 VkDevice device,
1717 VkPipelineCache destCache,
1718 uint32_t srcCacheCount,
1719 const VkPipelineCache* pSrcCaches)
1720{
1721 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1722 return result;
1723}
1724
1725VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001726{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001727 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001728 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001729 // The order of operations here is a little convoluted but gets the job done
1730 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1731 // 2. Create state is then validated (which uses flags setup during shadowing)
1732 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1733 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001734 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001735 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001736 loader_platform_thread_unlock_mutex(&globalLock);
1737 if (VK_TRUE == valid) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001738 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001739 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1740 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001741 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001742 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001743 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001744 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001745 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001746 if (pPipeNode) {
1747 // If we allocated a pipeNode, need to clean it up here
1748 delete[] pPipeNode->pVertexBindingDescriptions;
1749 delete[] pPipeNode->pVertexAttributeDescriptions;
1750 delete[] pPipeNode->pAttachments;
1751 delete pPipeNode;
1752 }
1753 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001754 return result;
1755}
1756
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001757VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001758{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001759 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001760 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761 loader_platform_thread_lock_mutex(&globalLock);
1762 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1763 pNewNode->sampler = *pSampler;
1764 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001765 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001766 loader_platform_thread_unlock_mutex(&globalLock);
1767 }
1768 return result;
1769}
1770
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001771VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001772{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001773 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001774 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001775 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1776 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001777 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 -06001778 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001779 }
1780 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001781 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1782 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1783 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001784 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001785 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001786 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001787 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001788 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001789 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1790 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001791 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001792 }
1793 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001794 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001795 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001796 uint32_t j = 0;
1797 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001798 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001799 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001800 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001801 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001802 }
1803 }
1804 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001805 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001806 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1807 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808 // Put new node at Head of global Layer list
1809 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001810 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001811 loader_platform_thread_unlock_mutex(&globalLock);
1812 }
1813 return result;
1814}
1815
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001816VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001817{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001818 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001819 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001820 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001821 }
1822 return result;
1823}
1824
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001825VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001826{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001827 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001828 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001829 // Insert this pool into Global Pool LL at head
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001830 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1831 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001832 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001833 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001834 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001835 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 -06001836 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001837 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001838 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001839 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1840 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001841 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001842 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1843 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1845 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001846 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001848 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001849 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001850 }
1851 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001852 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001853 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001854 }
1855 return result;
1856}
1857
Mike Stroyan230e6252015-04-17 12:36:38 -06001858VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001859{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001860 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001861 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001862 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001863 }
1864 return result;
1865}
1866
Mike Stroyan230e6252015-04-17 12:36:38 -06001867VK_LAYER_EXPORT VkResult VKAPI 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 -06001868{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001869 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 -06001870 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001871 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1872 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001873 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1874 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001875 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001876 for (uint32_t i = 0; i < *pCount; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001877 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1878 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001879 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001880 SET_NODE* pNewNode = new SET_NODE;
1881 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001882 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 -06001883 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001884 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001885 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001886 // Insert set at head of Set LL for this pool
1887 pNewNode->pNext = pPoolNode->pSets;
1888 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001889 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1890 if (NULL == pLayout) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001891 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1892 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001893 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001894 pNewNode->pLayout = pLayout;
1895 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001896 pNewNode->set = pDescriptorSets[i];
1897 pNewNode->setUsage = setUsage;
1898 pNewNode->descriptorCount = pLayout->endIndex + 1;
1899 if (pNewNode->descriptorCount) {
1900 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1901 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1902 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1903 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001904 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001905 }
1906 }
1907 }
1908 }
1909 return result;
1910}
1911
Tony Barbourb857d312015-07-10 10:50:45 -06001912VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1913{
1914 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1915 // TODO : Clean up any internal data structures using this obj.
1916 return result;
1917}
1918
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001919VK_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 -06001920{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001921 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1922 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001923 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001924 }
1925 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001926}
1927
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001928VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001929{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001930 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001931 VkDynamicViewportStateCreateInfo local_ci;
1932 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1933 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1934 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1935 loader_platform_thread_lock_mutex(&globalLock);
1936 dynamicVpStateMap[pState->handle] = local_ci;
1937 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001938 return result;
1939}
1940
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001941VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRasterStateCreateInfo* pCreateInfo, VkDynamicRasterState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001942{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001943 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001944 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
1945 loader_platform_thread_lock_mutex(&globalLock);
1946 dynamicRsStateMap[pState->handle] = *pCreateInfo;
1947 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001948 return result;
1949}
1950
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001951VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicColorBlendStateCreateInfo* pCreateInfo, VkDynamicColorBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001952{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001953 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001954 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
1955 loader_platform_thread_lock_mutex(&globalLock);
1956 dynamicCbStateMap[pState->handle] = *pCreateInfo;
1957 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001958 return result;
1959}
1960
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001961VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDepthStencilStateCreateInfo* pCreateInfo, VkDynamicDepthStencilState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001962{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001963 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001964 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
1965 loader_platform_thread_lock_mutex(&globalLock);
1966 dynamicDsStateMap[pState->handle] = *pCreateInfo;
1967 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001968 return result;
1969}
1970
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001971VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001972{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001973 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001974 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975 loader_platform_thread_lock_mutex(&globalLock);
1976 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1977 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1978 pCB->cmdBuffer = *pCmdBuffer;
1979 pCB->flags = pCreateInfo->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001980 pCB->pool = pCreateInfo->cmdPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001981 pCB->lastVtxBinding = MAX_BINDING;
1982 cmdBufferMap[*pCmdBuffer] = pCB;
1983 loader_platform_thread_unlock_mutex(&globalLock);
1984 updateCBTracking(*pCmdBuffer);
1985 }
1986 return result;
1987}
1988
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001989VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001990{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001991 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001992 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001993 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1994 if (pCB) {
1995 if (CB_NEW != pCB->state)
1996 resetCB(cmdBuffer);
1997 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001998 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001999 // TODO : Need to pass cmdBuffer as objType here
2000 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 -06002001 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002002 }
2003 updateCBTracking(cmdBuffer);
2004 }
2005 return result;
2006}
2007
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002008VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002009{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002010 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2011 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2012 if (pCB) {
2013 if (pCB->state == CB_UPDATE_ACTIVE) {
2014 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2015 if (VK_SUCCESS == result) {
2016 updateCBTracking(cmdBuffer);
2017 pCB->state = CB_UPDATE_COMPLETE;
2018 // Reset CB status flags
2019 pCB->status = 0;
2020 printCB(cmdBuffer);
2021 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002022 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002023 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002024 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002025 }
2026 return result;
2027}
2028
Cody Northropf02f9f82015-07-09 18:08:05 -06002029VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002030{
Cody Northropf02f9f82015-07-09 18:08:05 -06002031 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002032 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002033 resetCB(cmdBuffer);
2034 updateCBTracking(cmdBuffer);
2035 }
2036 return result;
2037}
2038
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002039VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002040{
2041 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2042 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002043 if (pCB->state == CB_UPDATE_ACTIVE) {
2044 updateCBTracking(cmdBuffer);
2045 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002046 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002047 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2048 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002049 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002050 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2051 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002052 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002053 PIPELINE_NODE* pPN = getPipeline(pipeline);
2054 if (pPN) {
2055 pCB->lastBoundPipeline = pipeline;
2056 loader_platform_thread_lock_mutex(&globalLock);
2057 set_cb_pso_status(pCB, pPN);
2058 g_lastBoundPipeline = pPN;
2059 loader_platform_thread_unlock_mutex(&globalLock);
2060 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2061 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2062 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002063 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2064 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002065 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002066 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002067 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002068 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002069 }
2070 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002071}
2072
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002073VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002074{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002075 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2076 if (pCB) {
2077 if (pCB->state == CB_UPDATE_ACTIVE) {
2078 updateCBTracking(cmdBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002079 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002080 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002081 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2082 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002083 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002084 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002085 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2086 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002087 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 -06002088 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002089 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002090 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2091 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002092 }
2093 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002094 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002095 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002096 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002097 }
2098 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002099}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002100VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicRasterState(VkCmdBuffer cmdBuffer, VkDynamicRasterState dynamicRasterState)
2101{
2102 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2103 if (pCB) {
2104 if (pCB->state == CB_UPDATE_ACTIVE) {
2105 updateCBTracking(cmdBuffer);
2106 addCmd(pCB, CMD_BINDDYNAMICRASTERSTATE);
2107 if (!pCB->activeRenderPass) {
2108 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2109 "Incorrect call to vkCmdBindDynamicRasterState() without an active RenderPass.");
2110 }
2111 loader_platform_thread_lock_mutex(&globalLock);
2112 pCB->status |= CBSTATUS_RASTER_BOUND;
2113 if (dynamicRsStateMap.find(dynamicRasterState.handle) == dynamicRsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002114 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 -06002115 "Unable to find VkDynamicRasterState object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2116 } else {
2117 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2118 g_lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2119 }
2120 loader_platform_thread_unlock_mutex(&globalLock);
2121 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2122 } else {
2123 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicRasterState()");
2124 }
2125 }
2126}
2127VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(VkCmdBuffer cmdBuffer, VkDynamicColorBlendState dynamicColorBlendState)
2128{
2129 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2130 if (pCB) {
2131 if (pCB->state == CB_UPDATE_ACTIVE) {
2132 updateCBTracking(cmdBuffer);
2133 addCmd(pCB, CMD_BINDDYNAMICCOLORBLENDSTATE);
2134 if (!pCB->activeRenderPass) {
2135 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2136 "Incorrect call to vkCmdBindDynamicColorBlendState() without an active RenderPass.");
2137 }
2138 loader_platform_thread_lock_mutex(&globalLock);
2139 pCB->status |= CBSTATUS_COLOR_BLEND_BOUND;
2140 if (dynamicCbStateMap.find(dynamicColorBlendState.handle) == dynamicCbStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002141 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 -06002142 "Unable to find VkDynamicColorBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2143 } else {
2144 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2145 g_lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2146 }
2147 loader_platform_thread_unlock_mutex(&globalLock);
2148 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2149 } else {
2150 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicColorBlendState()");
2151 }
2152 }
2153}
2154VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(VkCmdBuffer cmdBuffer, VkDynamicDepthStencilState dynamicDepthStencilState)
2155{
2156 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2157 if (pCB) {
2158 if (pCB->state == CB_UPDATE_ACTIVE) {
2159 updateCBTracking(cmdBuffer);
2160 addCmd(pCB, CMD_BINDDYNAMICDEPTHSTENCILSTATE);
2161 if (!pCB->activeRenderPass) {
2162 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2163 "Incorrect call to vkCmdBindDynamicDepthStencilState() without an active RenderPass.");
2164 }
2165 loader_platform_thread_lock_mutex(&globalLock);
2166 pCB->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
2167 if (dynamicDsStateMap.find(dynamicDepthStencilState.handle) == dynamicDsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002168 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 -06002169 "Unable to find VkDynamicDepthStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2170 } else {
2171 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2172 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2173 }
2174 loader_platform_thread_unlock_mutex(&globalLock);
2175 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
2176 } else {
2177 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthStencilState()");
2178 }
2179 }
2180}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002181VK_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 -06002182{
2183 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2184 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002185 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002186 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002187 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2188 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002189 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002190 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 -06002191 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2192 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002193 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002194 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2195 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002196 loader_platform_thread_lock_mutex(&globalLock);
2197 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002198 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002199 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2200 g_lastBoundDescriptorSet = pDescriptorSets[i];
2201 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002202 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2203 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002204 if (!pSet->pUpdateStructs)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002205 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2206 "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 -06002207 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002208 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2209 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002210 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002211 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002212 updateCBTracking(cmdBuffer);
2213 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis9bde5922015-06-22 18:00:14 -06002214 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 -06002215 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002216 } else {
2217 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002218 }
2219 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002220}
2221
Tony Barbour8205d902015-04-16 15:59:00 -06002222VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002223{
2224 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2225 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002226 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002227 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002228 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 -06002229 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2230 } else {
2231 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2232 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002233 updateCBTracking(cmdBuffer);
2234 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002235 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2236 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002237 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002238 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2239 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002240 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002241}
2242
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002243VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2244 VkCmdBuffer cmdBuffer,
2245 uint32_t startBinding,
2246 uint32_t bindingCount,
2247 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002248 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002249{
2250 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2251 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002252 if (pCB->state == CB_UPDATE_ACTIVE) {
2253 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002254 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002255 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 -06002256 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2257 } else {
2258 pCB->lastVtxBinding = startBinding + bindingCount -1;
2259 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002260 updateCBTracking(cmdBuffer);
2261 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002262 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2263 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002264 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002265 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002266 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002267 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002268 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002269}
2270
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002271VK_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 -06002272{
2273 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002274 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002275 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002276 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002277 pCB->drawCount[DRAW]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002278 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002279 // TODO : Need to pass cmdBuffer as srcObj here
2280 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 -06002281 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2282 synchAndPrintDSConfig(cmdBuffer);
2283 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002284 updateCBTracking(cmdBuffer);
2285 addCmd(pCB, CMD_DRAW);
2286 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002287 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002288 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002289 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2290 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002291 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002292}
2293
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002294VK_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 -06002295{
2296 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002297 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002298 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002299 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002300 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002301 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002302 // TODO : Need to pass cmdBuffer as srcObj here
2303 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 -06002304 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2305 synchAndPrintDSConfig(cmdBuffer);
2306 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002307 updateCBTracking(cmdBuffer);
2308 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002309 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2310 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002311 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002312 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2313 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002314 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002315}
2316
Tony Barbour8205d902015-04-16 15:59:00 -06002317VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002318{
2319 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002320 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002321 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002322 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002323 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002324 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002325 // TODO : Need to pass cmdBuffer as srcObj here
2326 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 -06002327 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2328 synchAndPrintDSConfig(cmdBuffer);
2329 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002330 updateCBTracking(cmdBuffer);
2331 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002332 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2333 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002334 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002335 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2336 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002337 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002338}
2339
Tony Barbour8205d902015-04-16 15:59:00 -06002340VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002341{
2342 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002343 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002345 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002346 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002347 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002348 // TODO : Need to pass cmdBuffer as srcObj here
2349 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 -06002350 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2351 synchAndPrintDSConfig(cmdBuffer);
2352 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002353 updateCBTracking(cmdBuffer);
2354 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2355 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002356 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002357 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002358 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2359 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002360 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002361}
2362
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002363VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002364{
2365 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2366 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002367 if (pCB->state == CB_UPDATE_ACTIVE) {
2368 updateCBTracking(cmdBuffer);
2369 addCmd(pCB, CMD_DISPATCH);
2370 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002371 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002372 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2373 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002374 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002375}
2376
Tony Barbour8205d902015-04-16 15:59:00 -06002377VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002378{
2379 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2380 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002381 if (pCB->state == CB_UPDATE_ACTIVE) {
2382 updateCBTracking(cmdBuffer);
2383 addCmd(pCB, CMD_DISPATCHINDIRECT);
2384 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002385 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002386 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2387 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002388 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002389}
2390
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002391VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002392{
2393 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2394 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002395 if (pCB->state == CB_UPDATE_ACTIVE) {
2396 updateCBTracking(cmdBuffer);
2397 addCmd(pCB, CMD_COPYBUFFER);
2398 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002399 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002400 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2401 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002402 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002403}
2404
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002405VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2406 VkImage srcImage,
2407 VkImageLayout srcImageLayout,
2408 VkImage destImage,
2409 VkImageLayout destImageLayout,
2410 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002411{
2412 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2413 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002414 if (pCB->state == CB_UPDATE_ACTIVE) {
2415 updateCBTracking(cmdBuffer);
2416 addCmd(pCB, CMD_COPYIMAGE);
2417 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002418 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002419 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2420 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002421 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002422}
2423
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002424VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2425 VkImage srcImage, VkImageLayout srcImageLayout,
2426 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002427 uint32_t regionCount, const VkImageBlit* pRegions,
2428 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002429{
2430 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2431 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002432 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002433 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002434 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2435 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002436 } else {
2437 updateCBTracking(cmdBuffer);
2438 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002439 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 -06002440 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002441 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002442 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2443 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002444 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002445}
2446
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002447VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2448 VkBuffer srcBuffer,
2449 VkImage destImage, VkImageLayout destImageLayout,
2450 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002451{
2452 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2453 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002454 if (pCB->state == CB_UPDATE_ACTIVE) {
2455 updateCBTracking(cmdBuffer);
2456 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2457 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002458 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002459 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2460 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002461 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002462}
2463
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002464VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2465 VkImage srcImage, VkImageLayout srcImageLayout,
2466 VkBuffer destBuffer,
2467 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002468{
2469 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2470 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002471 if (pCB->state == CB_UPDATE_ACTIVE) {
2472 updateCBTracking(cmdBuffer);
2473 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2474 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002475 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002476 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2477 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002478 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002479}
2480
Tony Barbour8205d902015-04-16 15:59:00 -06002481VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002482{
2483 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2484 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002485 if (pCB->state == CB_UPDATE_ACTIVE) {
2486 updateCBTracking(cmdBuffer);
2487 addCmd(pCB, CMD_UPDATEBUFFER);
2488 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002489 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002490 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2491 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002492 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002493}
2494
Tony Barbour8205d902015-04-16 15:59:00 -06002495VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002496{
2497 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2498 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002499 if (pCB->state == CB_UPDATE_ACTIVE) {
2500 updateCBTracking(cmdBuffer);
2501 addCmd(pCB, CMD_FILLBUFFER);
2502 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002503 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002504 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2505 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002506 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002507}
2508
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002509VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2510 VkCmdBuffer cmdBuffer,
2511 uint32_t colorAttachment,
2512 VkImageLayout imageLayout,
2513 const VkClearColorValue* pColor,
2514 uint32_t rectCount,
2515 const VkRect3D* pRects)
2516{
2517 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2518 if (pCB) {
2519 if (pCB->state == CB_UPDATE_ACTIVE) {
2520 // Warn if this is issued prior to Draw Cmd
2521 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002522 // TODO : cmdBuffer should be srcObj
2523 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 -06002524 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2525 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2526 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002527 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002528 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 -06002529 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2530 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2531 } else {
2532 updateCBTracking(cmdBuffer);
2533 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2534 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2535 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002536 } else {
2537 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2538 }
2539 }
2540}
2541
2542VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2543 VkCmdBuffer cmdBuffer,
2544 VkImageAspectFlags imageAspectMask,
2545 VkImageLayout imageLayout,
2546 float depth,
2547 uint32_t stencil,
2548 uint32_t rectCount,
2549 const VkRect3D* pRects)
2550{
2551 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2552 if (pCB) {
2553 if (pCB->state == CB_UPDATE_ACTIVE) {
2554 // Warn if this is issued prior to Draw Cmd
2555 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002556 // TODO : cmdBuffer should be srcObj
2557 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 -06002558 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2559 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2560 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002561 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002562 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 -06002563 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2564 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2565 } else {
2566 updateCBTracking(cmdBuffer);
2567 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2568 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2569 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002570 } else {
2571 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2572 }
2573 }
2574}
2575
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002576VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2577 VkCmdBuffer cmdBuffer,
2578 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002579 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002580 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002581{
2582 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2583 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002584 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002585 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002586 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 -06002587 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2588 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2589 } else {
2590 updateCBTracking(cmdBuffer);
2591 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2592 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2593 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002594 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002595 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2596 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002597 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002598}
2599
Chris Forbes2951d7d2015-06-22 17:21:59 +12002600VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002601 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002602 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002603 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604{
2605 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2606 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002607 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002608 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002609 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 -06002610 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2611 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2612 } else {
2613 updateCBTracking(cmdBuffer);
2614 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2615 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2616 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002617 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002618 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2619 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002620 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002621}
2622
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002623VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2624 VkImage srcImage, VkImageLayout srcImageLayout,
2625 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002626 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002627{
2628 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2629 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002630 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002631 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002632 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2633 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002634 } else {
2635 updateCBTracking(cmdBuffer);
2636 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002637 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002638 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002639 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002640 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2641 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002642 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002643}
2644
Tony Barbourc2e987e2015-06-29 16:20:35 -06002645VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646{
2647 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2648 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002649 if (pCB->state == CB_UPDATE_ACTIVE) {
2650 updateCBTracking(cmdBuffer);
2651 addCmd(pCB, CMD_SETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002652 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002653 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002654 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2655 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002656 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002657}
2658
Tony Barbourc2e987e2015-06-29 16:20:35 -06002659VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002660{
2661 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2662 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002663 if (pCB->state == CB_UPDATE_ACTIVE) {
2664 updateCBTracking(cmdBuffer);
2665 addCmd(pCB, CMD_RESETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002666 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002667 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002668 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2669 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002670 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002671}
2672
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002673VK_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 -06002674{
2675 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2676 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002677 if (pCB->state == CB_UPDATE_ACTIVE) {
2678 updateCBTracking(cmdBuffer);
2679 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002680 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002681 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002682 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2683 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002684 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002685}
2686
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002687VK_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 -06002688{
2689 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2690 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002691 if (pCB->state == CB_UPDATE_ACTIVE) {
2692 updateCBTracking(cmdBuffer);
2693 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter73a21d32015-07-12 13:20:05 -06002694 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002695 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002696 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2697 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002698 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002699}
2700
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002701VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002702{
2703 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2704 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002705 if (pCB->state == CB_UPDATE_ACTIVE) {
2706 updateCBTracking(cmdBuffer);
2707 addCmd(pCB, CMD_BEGINQUERY);
2708 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002709 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002710 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2711 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002712 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002713}
2714
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002715VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002716{
2717 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2718 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002719 if (pCB->state == CB_UPDATE_ACTIVE) {
2720 updateCBTracking(cmdBuffer);
2721 addCmd(pCB, CMD_ENDQUERY);
2722 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002723 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002724 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2725 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002726 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002727}
2728
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002729VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002730{
2731 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2732 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002733 if (pCB->state == CB_UPDATE_ACTIVE) {
2734 updateCBTracking(cmdBuffer);
2735 addCmd(pCB, CMD_RESETQUERYPOOL);
2736 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002737 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002738 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2739 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002740 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002741}
2742
Tony Barbour8205d902015-04-16 15:59:00 -06002743VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002744{
2745 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2746 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002747 if (pCB->state == CB_UPDATE_ACTIVE) {
2748 updateCBTracking(cmdBuffer);
2749 addCmd(pCB, CMD_WRITETIMESTAMP);
2750 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002751 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002752 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2753 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002754 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002755}
2756
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002757VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002758{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002759 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002760 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002761 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002762 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002763 if (pCreateInfo->pAttachments) {
2764 localFBCI->pAttachments = new VkAttachmentBindInfo[localFBCI->attachmentCount];
2765 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002766 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002767 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002768 }
2769 return result;
2770}
2771
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002772VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002773{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002774 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002775 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002776 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002777 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002778 if (pCreateInfo->pAttachments) {
2779 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2780 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002781 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002782 if (pCreateInfo->pSubpasses) {
2783 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2784 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2785
2786 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2787 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2788 const uint32_t attachmentCount = subpass->inputCount +
Tony Barbourb2cc40a2015-07-13 15:28:47 -06002789 subpass->colorCount * (1 + (subpass->resolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002790 subpass->preserveCount;
2791 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2792
2793 memcpy(attachments, subpass->inputAttachments,
2794 sizeof(attachments[0]) * subpass->inputCount);
2795 subpass->inputAttachments = attachments;
2796 attachments += subpass->inputCount;
2797
2798 memcpy(attachments, subpass->colorAttachments,
2799 sizeof(attachments[0]) * subpass->colorCount);
2800 subpass->colorAttachments = attachments;
2801 attachments += subpass->colorCount;
2802
2803 if (subpass->resolveAttachments) {
2804 memcpy(attachments, subpass->resolveAttachments,
2805 sizeof(attachments[0]) * subpass->colorCount);
2806 subpass->resolveAttachments = attachments;
2807 attachments += subpass->colorCount;
2808 }
2809
2810 memcpy(attachments, subpass->preserveAttachments,
2811 sizeof(attachments[0]) * subpass->preserveCount);
2812 subpass->preserveAttachments = attachments;
2813 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002814 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002815 if (pCreateInfo->pDependencies) {
2816 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2817 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002818 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002819 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002820 }
2821 return result;
2822}
2823
Chia-I Wuc278df82015-07-07 11:50:03 +08002824VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002825{
2826 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2827 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002828 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002829 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002830 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2831 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002832 } else {
2833 updateCBTracking(cmdBuffer);
2834 addCmd(pCB, CMD_BEGINRENDERPASS);
2835 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002836 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002837 pCB->framebuffer = pRenderPassBegin->framebuffer;
2838 if (pCB->lastBoundPipeline) {
2839 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2840 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002841 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002842 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002843 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002844 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002845 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002846 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002847 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002848}
2849
Chia-I Wuc278df82015-07-07 11:50:03 +08002850VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2851{
2852 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2853 if (pCB) {
2854 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002855 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 +08002856 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2857 } else {
2858 updateCBTracking(cmdBuffer);
2859 addCmd(pCB, CMD_NEXTSUBPASS);
2860 pCB->activeSubpass++;
2861 if (pCB->lastBoundPipeline) {
2862 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2863 }
2864 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2865 }
2866 }
2867}
2868
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002869VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002870{
2871 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2872 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002873 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002874 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 +08002875 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06002876 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002877 updateCBTracking(cmdBuffer);
2878 addCmd(pCB, CMD_ENDRENDERPASS);
2879 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08002880 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002881 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2882 }
2883 }
2884}
2885
2886VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2887{
2888 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2889 if (pCB) {
2890 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002891 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 +08002892 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2893 } else {
2894 updateCBTracking(cmdBuffer);
2895 addCmd(pCB, CMD_EXECUTECOMMANDS);
2896 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002897 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002898 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002899}
2900
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002901VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2902 VkInstance instance,
2903 VkFlags msgFlags,
2904 const PFN_vkDbgMsgCallback pfnMsgCallback,
2905 void* pUserData,
2906 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002907{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002908 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002909 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2910 if (VK_SUCCESS == res) {
2911 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2912 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2913 }
2914 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002915}
2916
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002917VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2918 VkInstance instance,
2919 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002920{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002921 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002922 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2923 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2924 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2925 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002926}
2927
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002928VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002929{
2930 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002931 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2932 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002933 // TODO : cmdBuffer should be srcObj
2934 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 -06002935 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002936 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002937 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002938 updateCBTracking(cmdBuffer);
2939 addCmd(pCB, CMD_DBGMARKERBEGIN);
2940 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002941 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002942}
2943
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002944VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002945{
2946 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002947 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2948 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002949 // TODO : cmdBuffer should be srcObj
2950 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 -06002951 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002952 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002953 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002954 updateCBTracking(cmdBuffer);
2955 addCmd(pCB, CMD_DBGMARKEREND);
2956 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002957 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2958}
2959
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002960//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2961//{
2962// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2963// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2964// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2965// "Attempt to use DbgSetObjectTag but extension disabled!");
2966// return VK_ERROR_UNAVAILABLE;
2967// }
2968// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2969//}
2970//
2971//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2972//{
2973// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2974// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2975// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2976// "Attempt to use DbgSetObjectName but extension disabled!");
2977// return VK_ERROR_UNAVAILABLE;
2978// }
2979// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
2980//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002981
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002982VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002983{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002984 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002985 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002986
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002987 /* loader uses this to force layer initialization; device object is wrapped */
2988 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002989 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002990 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002991 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06002992 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002993 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002994 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002995 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002996 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002997 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002998 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002999 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003000 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003001 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003002 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003003 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003004 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003005 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003006 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003007 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003008 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003009 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003010 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003011 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003012 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003013 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003014 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003015 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003016 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003017 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003018 if (!strcmp(funcName, "vkDestroyAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003019 return (PFN_vkVoidFunction) vkDestroyAttachmentView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003020 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003021 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003022 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003023 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003024 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003025 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003026 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003027 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003028 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003029 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003030 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003031 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003032 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003033 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003034 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003035 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003036 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003037 return (PFN_vkVoidFunction) vkDestroyDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003038 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003039 return (PFN_vkVoidFunction) vkDestroyDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003040 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003041 return (PFN_vkVoidFunction) vkDestroyDynamicDepthStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003042 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003043 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003044 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003045 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003046 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003047 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003048 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003049 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003050 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003051 return (PFN_vkVoidFunction) vkCreateImageView;
Tobin Ehlis44c757d2015-07-10 12:15:19 -06003052 if (!strcmp(funcName, "vkCreateAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003053 return (PFN_vkVoidFunction) vkCreateAttachmentView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003054 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003055 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003056 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003057 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003058 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003059 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003060 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003061 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003062 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003063 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003064 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003065 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003066 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003067 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003068 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003069 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003070 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003071 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003072 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003073 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003074 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003075 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003076 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003077 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003078 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003079 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003080 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003081 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003082 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003083 return (PFN_vkVoidFunction) vkCreateDynamicRasterState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003084 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003085 return (PFN_vkVoidFunction) vkCreateDynamicColorBlendState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003086 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003087 return (PFN_vkVoidFunction) vkCreateDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003088 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003089 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003090 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003091 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003092 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003093 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003094 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003095 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003096 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003097 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003098 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003099 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003100 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003101 return (PFN_vkVoidFunction) vkCmdBindDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003102 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003103 return (PFN_vkVoidFunction) vkCmdBindDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003104 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003105 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003106 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003107 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003108 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003109 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003110 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003111 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003112 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003113 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003114 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003115 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003116 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003117 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003118 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003120 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003122 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003124 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003126 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003128 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003130 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003132 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003134 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003136 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003138 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003140 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003142 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003143 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003144 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003145 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003146 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003147 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003148 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003150 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003152 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003154 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003156 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003158 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003160 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003161 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003162 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003163 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003164 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003165 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003166 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003167 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003168 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003169 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003170 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003172
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003173 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3174 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003175 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003176 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003177 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003178 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003179 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003180// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3181// return (void*) vkDbgSetObjectTag;
3182// if (!strcmp(funcName, "vkDbgSetObjectName"))
3183// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003184 }
3185 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003186 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003187 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003188 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003189 }
3190}
3191
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003192VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003193{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003194 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003195 if (instance == NULL)
3196 return NULL;
3197
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003198 /* loader uses this to force layer initialization; instance object is wrapped */
3199 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003200 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003201 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003202 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003203 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003204 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003205 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003206 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003207 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003208 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003209 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003210 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003211 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003212 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003213 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003214 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003215
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003216 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3217 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003218 if (fptr)
3219 return fptr;
3220
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003221 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003222 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003223 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003224 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003225 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003226 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003227}