blob: 83ceb385b90a88d5f70f4797a854fc86f6ca5fd2 [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
Tobin Ehlis7a51d902015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Tony Barboura938abb2015-04-22 11:36:22 -060036#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060037#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060038#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060040#include "draw_state.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060041#include "vk_layer_config.h"
Jon Ashburnf0615e22015-05-25 14:11:37 -060042#include "vk_debug_marker_layer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060043// The following is #included again to catch certain OS-specific functions
44// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060046#include "vk_layer_msg.h"
47#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -060051#include "vk_layer_extension_utils.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060052
Tobin Ehlisc91330b2015-06-16 09:04:30 -060053typedef struct _layer_data {
54 debug_report_data *report_data;
55 // TODO: put instance data here
56 VkDbgMsgCallback logging_callback;
57} layer_data;
58
59static std::unordered_map<void *, layer_data *> layer_data_map;
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -060060static device_table_map draw_state_device_table_map;
61static instance_table_map draw_state_instance_table_map;
62
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060063unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
64unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
65unordered_map<uint64_t, VkAttachmentViewCreateInfo> viewMap;
66unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
67unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicVpStateMap;
68unordered_map<uint64_t, VkDynamicRasterStateCreateInfo> dynamicRsStateMap;
69unordered_map<uint64_t, VkDynamicColorBlendStateCreateInfo> dynamicCbStateMap;
70unordered_map<uint64_t, VkDynamicDepthStencilStateCreateInfo> dynamicDsStateMap;
71unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
72unordered_map<uint64_t, POOL_NODE*> poolMap;
73unordered_map<uint64_t, SET_NODE*> setMap;
74unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060075// Map for layout chains
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060076unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
77unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
78unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060079
Jon Ashburn6f8cd632015-06-01 09:37:38 -060080struct devExts {
81 bool debug_marker_enabled;
82};
83
Jon Ashburn6f8cd632015-06-01 09:37:38 -060084static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060085
Tobin Ehlis63bb9482015-03-17 16:24:32 -060086static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060087
Tobin Ehlis63bb9482015-03-17 16:24:32 -060088// TODO : This can be much smarter, using separate locks for separate global data
89static int globalLockInitialized = 0;
90static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060091#define MAX_TID 513
92static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
93static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060094
95template layer_data *get_my_data_ptr<layer_data>(
96 void *data_key,
97 std::unordered_map<void *, layer_data *> &data_map);
98
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060099debug_report_data *mdd(void* object)
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600100{
101 dispatch_key key = get_dispatch_key(object);
102 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
103#if DISPATCH_MAP_DEBUG
104 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
105#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600106 return my_data->report_data;
107}
108
109debug_report_data *mid(VkInstance object)
110{
111 dispatch_key key = get_dispatch_key(object);
112 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
113#if DISPATCH_MAP_DEBUG
114 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
115#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600116 return my_data->report_data;
117}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600118// Map actual TID to an index value and return that index
119// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
120static uint32_t getTIDIndex() {
121 loader_platform_thread_id tid = loader_platform_get_thread_id();
122 for (uint32_t i = 0; i < g_maxTID; i++) {
123 if (tid == g_tidMapping[i])
124 return i;
125 }
126 // Don't yet have mapping, set it and return newly set index
127 uint32_t retVal = (uint32_t) g_maxTID;
128 g_tidMapping[g_maxTID++] = tid;
129 assert(g_maxTID < MAX_TID);
130 return retVal;
131}
132// Return a string representation of CMD_TYPE enum
133static string cmdTypeToString(CMD_TYPE cmd)
134{
135 switch (cmd)
136 {
137 case CMD_BINDPIPELINE:
138 return "CMD_BINDPIPELINE";
139 case CMD_BINDPIPELINEDELTA:
140 return "CMD_BINDPIPELINEDELTA";
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600141 case CMD_BINDDYNAMICVIEWPORTSTATE:
142 return "CMD_BINDDYNAMICVIEWPORTSTATE";
143 case CMD_BINDDYNAMICRASTERSTATE:
144 return "CMD_BINDDYNAMICRASTERSTATE";
145 case CMD_BINDDYNAMICCOLORBLENDSTATE:
146 return "CMD_BINDDYNAMICCOLORBLENDSTATE";
147 case CMD_BINDDYNAMICDEPTHSTENCILSTATE:
148 return "CMD_BINDDYNAMICDEPTHSTENCILSTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600149 case CMD_BINDDESCRIPTORSETS:
150 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600151 case CMD_BINDINDEXBUFFER:
152 return "CMD_BINDINDEXBUFFER";
153 case CMD_BINDVERTEXBUFFER:
154 return "CMD_BINDVERTEXBUFFER";
155 case CMD_DRAW:
156 return "CMD_DRAW";
157 case CMD_DRAWINDEXED:
158 return "CMD_DRAWINDEXED";
159 case CMD_DRAWINDIRECT:
160 return "CMD_DRAWINDIRECT";
161 case CMD_DRAWINDEXEDINDIRECT:
162 return "CMD_DRAWINDEXEDINDIRECT";
163 case CMD_DISPATCH:
164 return "CMD_DISPATCH";
165 case CMD_DISPATCHINDIRECT:
166 return "CMD_DISPATCHINDIRECT";
167 case CMD_COPYBUFFER:
168 return "CMD_COPYBUFFER";
169 case CMD_COPYIMAGE:
170 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600171 case CMD_BLITIMAGE:
172 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600173 case CMD_COPYBUFFERTOIMAGE:
174 return "CMD_COPYBUFFERTOIMAGE";
175 case CMD_COPYIMAGETOBUFFER:
176 return "CMD_COPYIMAGETOBUFFER";
177 case CMD_CLONEIMAGEDATA:
178 return "CMD_CLONEIMAGEDATA";
179 case CMD_UPDATEBUFFER:
180 return "CMD_UPDATEBUFFER";
181 case CMD_FILLBUFFER:
182 return "CMD_FILLBUFFER";
183 case CMD_CLEARCOLORIMAGE:
184 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600185 case CMD_CLEARCOLORATTACHMENT:
186 return "CMD_CLEARCOLORATTACHMENT";
187 case CMD_CLEARDEPTHSTENCILIMAGE:
188 return "CMD_CLEARDEPTHSTENCILIMAGE";
189 case CMD_CLEARDEPTHSTENCILATTACHMENT:
190 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600191 case CMD_RESOLVEIMAGE:
192 return "CMD_RESOLVEIMAGE";
193 case CMD_SETEVENT:
194 return "CMD_SETEVENT";
195 case CMD_RESETEVENT:
196 return "CMD_RESETEVENT";
197 case CMD_WAITEVENTS:
198 return "CMD_WAITEVENTS";
199 case CMD_PIPELINEBARRIER:
200 return "CMD_PIPELINEBARRIER";
201 case CMD_BEGINQUERY:
202 return "CMD_BEGINQUERY";
203 case CMD_ENDQUERY:
204 return "CMD_ENDQUERY";
205 case CMD_RESETQUERYPOOL:
206 return "CMD_RESETQUERYPOOL";
207 case CMD_WRITETIMESTAMP:
208 return "CMD_WRITETIMESTAMP";
209 case CMD_INITATOMICCOUNTERS:
210 return "CMD_INITATOMICCOUNTERS";
211 case CMD_LOADATOMICCOUNTERS:
212 return "CMD_LOADATOMICCOUNTERS";
213 case CMD_SAVEATOMICCOUNTERS:
214 return "CMD_SAVEATOMICCOUNTERS";
215 case CMD_BEGINRENDERPASS:
216 return "CMD_BEGINRENDERPASS";
217 case CMD_ENDRENDERPASS:
218 return "CMD_ENDRENDERPASS";
219 case CMD_DBGMARKERBEGIN:
220 return "CMD_DBGMARKERBEGIN";
221 case CMD_DBGMARKEREND:
222 return "CMD_DBGMARKEREND";
223 default:
224 return "UNKNOWN";
225 }
226}
227// Block of code at start here for managing/tracking Pipeline state that this layer cares about
228// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600229#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600230#define MAX_SLOTS 2048
231#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
232
233static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
234
235// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
236// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
237// to that same cmd buffer by separate thread are not changing state from underneath us
238// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600239static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600240// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600241static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
242static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600244static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
245static PIPELINE_NODE* g_lastBoundPipeline = NULL;
246static uint64_t g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {0};
247static VkDescriptorSet g_lastBoundDescriptorSet = VkDescriptorSet(0);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600248#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
249
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600252// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600253static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600254{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600255 for (auto ii=dynamicVpStateMap.begin(); ii!=dynamicVpStateMap.end(); ++ii) {
256 delete[] (*ii).second.pScissors;
257 delete[] (*ii).second.pViewports;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600258 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600259 dynamicVpStateMap.clear();
260 dynamicRsStateMap.clear();
261 dynamicCbStateMap.clear();
262 dynamicDsStateMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600263}
264// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600265static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600266{
David Pinedof5997ab2015-04-27 16:36:17 -0600267 if (sampleMap.size() <= 0)
268 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600269 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600270 delete (*ii).second;
271 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600272 sampleMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600273}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600275{
276 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600277 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600278 loader_platform_thread_unlock_mutex(&globalLock);
279 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600280 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600282 return &imageMap[view.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600283 }
284}
285// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600286static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600287{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600288 if (imageMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -0600289 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600290 imageMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600291}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600293{
294 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600295 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600296 loader_platform_thread_unlock_mutex(&globalLock);
297 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600298 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600299 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600300 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301 }
302}
303// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600304static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600305{
David Pinedof5997ab2015-04-27 16:36:17 -0600306 if (bufferMap.size() <= 0)
307 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600308 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600309 delete (*ii).second;
310 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600311 bufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600312}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600314// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600316{
317 g_lastCmdBuffer[getTIDIndex()] = cb;
318 GLOBAL_CB_NODE* pCB = getCBNode(cb);
319 loader_platform_thread_lock_mutex(&globalLock);
320 g_lastGlobalCB = pCB;
321 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
322 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
323 if (g_pLastTouchedCB[i] == pCB) {
324 loader_platform_thread_unlock_mutex(&globalLock);
325 return;
326 }
327 }
328 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
329 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
330 loader_platform_thread_unlock_mutex(&globalLock);
331}
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600332static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600333{
334 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
335 if (pCB->drawCount[i])
336 return VK_TRUE;
337 }
338 return VK_FALSE;
339}
Tobin Ehlis97866202015-06-10 12:57:07 -0600340// Check object status for selected flag state
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600341static VkBool32 validate_status(GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600342{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600343 // If non-zero enable mask is present, check it against status but if enable_mask
344 // is 0 then no enable required so we should always just check status
345 if ((!enable_mask) || (enable_mask & pNode->status)) {
346 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600347 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
348 log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
349 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(pNode->cmdBuffer), fail_msg);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600350 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600351 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600352 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600353 return VK_TRUE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600354}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600355// For given dynamic state handle and type, return CreateInfo for that Dynamic State
356static void* getDynamicStateCreateInfo(const uint64_t handle, const DYNAMIC_STATE_BIND_POINT type)
357{
358 switch (type) {
359 case VK_STATE_BIND_POINT_VIEWPORT:
360 return (void*)&dynamicVpStateMap[handle];
361 case VK_STATE_BIND_POINT_RASTER:
362 return (void*)&dynamicRsStateMap[handle];
363 case VK_STATE_BIND_POINT_COLOR_BLEND:
364 return (void*)&dynamicCbStateMap[handle];
365 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
366 return (void*)&dynamicDsStateMap[handle];
367 default:
368 return NULL;
369 }
370}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600371// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600372static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600373{
374 GLOBAL_CB_NODE* pCB = getCBNode(cb);
375 if (pCB) {
376 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600378 void* pDynStateCI = getDynamicStateCreateInfo(pCB->lastBoundDynamicState[i], (DYNAMIC_STATE_BIND_POINT)i);
379 if (pDynStateCI) {
380 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
381 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
382 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
383 dynamic_display(pDynStateCI, " ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600384 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600385 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600386 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
387 "No dynamic state of type %s bound", string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600388 }
389 }
390 loader_platform_thread_unlock_mutex(&globalLock);
391 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600392}
393// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600394static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600395{
396 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600397 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600398 loader_platform_thread_unlock_mutex(&globalLock);
399 return NULL;
400 }
401 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600402 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600403}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600404// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600405static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
406 VkBool32 result;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600407 result = validate_status(pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_BOUND, CBSTATUS_VIEWPORT_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
408 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_RASTER_BOUND, CBSTATUS_RASTER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");
409 result &= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_COLOR_BLEND_BOUND, CBSTATUS_COLOR_BLEND_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");
410 result &= validate_status(pCB, CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE, CBSTATUS_DEPTH_STENCIL_BOUND, CBSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");
411 if (indexedDraw)
412 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Index Draw attempted");
413 return result;
414}
415// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600416static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600417 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600418 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600419 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
420 // Now complete other state checks
Tobin Ehlise4076782015-06-24 15:53:07 -0600421 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600422 result = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600423 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600424 "Pipeline layout from last vkCmdBindDescriptorSets() (%s) does not match PSO Pipeline layout (%s)", pCB->lastBoundPipelineLayout, pPipe->graphicsPipelineCI.layout);
425 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600426 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600427 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis451efca2015-06-23 11:22:55 -0600428 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
429 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600430 return result;
431}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600432// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600433static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600434{
435 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600436 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600437 loader_platform_thread_unlock_mutex(&globalLock);
438 return NULL;
439 }
440 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600441 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600442}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600443// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600444static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600445{
446 // VS is required
447 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600448 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600449 "Invalid Pipeline CreateInfo State: Vtx Shader required");
450 return VK_FALSE;
451 }
452 // Either both or neither TC/TE shaders should be defined
453 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
454 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600455 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600456 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
457 return VK_FALSE;
458 }
459 // Compute shaders should be specified independent of Gfx shaders
460 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
461 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
462 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
463 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600464 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600465 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
466 return VK_FALSE;
467 }
468 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
469 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
470 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
471 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600472 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600473 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
474 return VK_FALSE;
475 }
476 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
477 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600478 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600479 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
480 return VK_FALSE;
481 }
482 return VK_TRUE;
483}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600484// Init the pipeline mapping info based on pipeline create info LL tree
485// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600486static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600487{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600488 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
489 if (pBasePipeline) {
490 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600491 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600492 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
493 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600494 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600495 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600496 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600497
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600498 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600499 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600500 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600501
502 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
503 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
504
505 switch (pPSSCI->stage) {
506 case VK_SHADER_STAGE_VERTEX:
507 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
508 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600509 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600510 case VK_SHADER_STAGE_TESS_CONTROL:
511 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
512 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600513 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600514 case VK_SHADER_STAGE_TESS_EVALUATION:
515 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
516 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600517 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600518 case VK_SHADER_STAGE_GEOMETRY:
519 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
520 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600521 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600522 case VK_SHADER_STAGE_FRAGMENT:
523 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
524 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600525 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600526 case VK_SHADER_STAGE_COMPUTE:
527 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
528 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600529 break;
530 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600531 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600532 break;
533 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600534 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600535
536 if (pCreateInfo->pVertexInputState != NULL) {
537 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
538 // Copy embedded ptrs
539 pVICI = pCreateInfo->pVertexInputState;
540 pPipeline->vtxBindingCount = pVICI->bindingCount;
541 if (pPipeline->vtxBindingCount) {
542 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
543 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
544 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
545 }
546 pPipeline->vtxAttributeCount = pVICI->attributeCount;
547 if (pPipeline->vtxAttributeCount) {
548 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
549 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
550 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
551 }
552 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
553 }
Tony Barboure307f582015-07-10 15:29:03 -0600554 if (pCreateInfo->pInputAssemblyState != NULL) {
555 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
556 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600557 }
Tony Barboure307f582015-07-10 15:29:03 -0600558 if (pCreateInfo->pTessellationState != NULL) {
559 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600561 }
Tony Barboure307f582015-07-10 15:29:03 -0600562 if (pCreateInfo->pViewportState != NULL) {
563 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
564 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600565 }
Tony Barboure307f582015-07-10 15:29:03 -0600566 if (pCreateInfo->pRasterState != NULL) {
567 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
568 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600569 }
Tony Barboure307f582015-07-10 15:29:03 -0600570 if (pCreateInfo->pMultisampleState != NULL) {
571 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
572 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600573 }
Tony Barboure307f582015-07-10 15:29:03 -0600574 if (pCreateInfo->pColorBlendState != NULL) {
575 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600576 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600577 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600578 pPipeline->attachmentCount = pCBCI->attachmentCount;
579 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600580 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
581 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600582 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
583 }
Tony Barboure307f582015-07-10 15:29:03 -0600584 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600585 }
Tony Barboure307f582015-07-10 15:29:03 -0600586 if (pCreateInfo->pDepthStencilState != NULL) {
587 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
588 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600589 }
590
591 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
592 if (pCreateInfo->stageCount != 0) {
593 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
594 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
595 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
596 }
597
Tobin Ehlisde63c532015-06-18 15:59:33 -0600598 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600599}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600600
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600601// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600602static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600603{
David Pinedof5997ab2015-04-27 16:36:17 -0600604 if (pipelineMap.size() <= 0)
605 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600606 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600607 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
608 delete[] (*ii).second->graphicsPipelineCI.pStages;
609 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600610 if ((*ii).second->pVertexBindingDescriptions) {
611 delete[] (*ii).second->pVertexBindingDescriptions;
612 }
613 if ((*ii).second->pVertexAttributeDescriptions) {
614 delete[] (*ii).second->pVertexAttributeDescriptions;
615 }
616 if ((*ii).second->pAttachments) {
617 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600618 }
619 delete (*ii).second;
620 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600621 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600622}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600623// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600625{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600626 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Courtney Goeltzenleuchtere29e9462015-07-12 14:00:58 -0600627 // TODO: msStateCI.multisampleEnable has been removed from API, is there anything left to do here?
628// if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
629// if (pPipe->msStateCI.multisampleEnable)
630// return pPipe->msStateCI.rasterSamples;
631// }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600632 return 1;
633}
634// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600635static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600636{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600637 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600638 // Verify that any MSAA request in PSO matches sample# in bound FB
639 uint32_t psoNumSamples = getNumSamples(pipeline);
640 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600641 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800642 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
643 int subpassNumSamples = 0;
644 uint32_t i;
645
646 for (i = 0; i < pSD->colorCount; i++) {
647 uint32_t samples;
648
649 if (pSD->colorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
650 continue;
651
652 samples = pRPCI->pAttachments[pSD->colorAttachments[i].attachment].samples;
653 if (subpassNumSamples == 0) {
654 subpassNumSamples = samples;
655 } else if (subpassNumSamples != samples) {
656 subpassNumSamples = -1;
657 break;
658 }
659 }
660 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
661 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
662 if (subpassNumSamples == 0)
663 subpassNumSamples = samples;
664 else if (subpassNumSamples != samples)
665 subpassNumSamples = -1;
666 }
667
668 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600669 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
670 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!", pipeline.handle, psoNumSamples, pCB->activeRenderPass.handle, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600671 }
672 } else {
673 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
674 // Verify and flag error as appropriate
675 }
676 // TODO : Add more checks here
677 } else {
678 // TODO : Validate non-gfx pipeline updates
679 }
680}
681
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600682// Block of code at start here specifically for managing/tracking DSs
683
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600684// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600685static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600686{
687 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600688 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600689 loader_platform_thread_unlock_mutex(&globalLock);
690 return NULL;
691 }
692 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600693 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600694}
695// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600696static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600697{
698 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600699 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600700 loader_platform_thread_unlock_mutex(&globalLock);
701 return NULL;
702 }
703 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600704 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600705}
706
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600707static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600708 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600709 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600710 loader_platform_thread_unlock_mutex(&globalLock);
711 return NULL;
712 }
713 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600714 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600715}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600716// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600717static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600718{
719 char str[1024];
720 switch (pUpdateStruct->sType)
721 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800722 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
723 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600724 return 1;
725 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600726 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 -0600727 "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 -0600728 return 0;
729 }
730}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600731// For given update struct, return binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600732static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600733{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600734 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600735 switch (pUpdateStruct->sType)
736 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800737 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
738 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
739 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
740 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600741 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600742 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 -0600743 "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 -0600744 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600745 }
746}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600747// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600748static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600749{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600750 char str[1024];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600751 switch (pUpdateStruct->sType)
752 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800753 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
754 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
755 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600756 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800757 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600758 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600759 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 -0600760 "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 -0600761 return 0;
762 }
763}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600764// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600765static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600766{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600767 char str[1024];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600768 switch (pUpdateStruct->sType)
769 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800770 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
771 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
772 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600773 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800774 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600775 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600776 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 -0600777 "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 -0600778 return 0;
779 }
780}
781// For given Layout Node and binding, return index where that binding begins
782static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
783{
784 uint32_t offsetIndex = 0;
785 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800786 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600787 }
788 return offsetIndex;
789}
790// For given layout node and binding, return last index that is updated
791static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
792{
793 uint32_t offsetIndex = 0;
794 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800795 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600796 }
797 return offsetIndex-1;
798}
799// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600800static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600801{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600802 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600803}
804// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600805static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600806{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600807 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600808}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600809// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600810static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600811{
812 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600813 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600814 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600815 switch (pUpdateStruct->sType)
816 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800817 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
818 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600819 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800820 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
821 /* no need to validate */
822 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600823 break;
824 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600825 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 -0600826 "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 -0600827 return 0;
828 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600829 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600830 if (pLayout->pTypes[i] != actualType)
831 return 0;
832 }
833 return 1;
834}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600835// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
836// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
837// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600838static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600839{
840 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800841 VkWriteDescriptorSet* pWDS = NULL;
842 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600843 size_t array_size = 0;
844 size_t base_array_size = 0;
845 size_t total_array_size = 0;
846 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600847 switch (pUpdate->sType)
848 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800849 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
850 pWDS = new VkWriteDescriptorSet;
851 pNewNode = (GENERIC_HEADER*)pWDS;
852 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
853 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
854 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
855 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600856 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800857 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
858 pCDS = new VkCopyDescriptorSet;
859 pUpdate = (GENERIC_HEADER*)pCDS;
860 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600861 break;
862 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600863 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 -0600864 "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 -0600865 return NULL;
866 }
867 // Make sure that pNext for the end of shadow copy is NULL
868 pNewNode->pNext = NULL;
869 return pNewNode;
870}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800871// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600872static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600873{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800874 const VkWriteDescriptorSet *pWDS = NULL;
875 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600876 VkBool32 result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800877
878 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
879 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
880 else
881 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
882
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600883 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600884 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600885 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600886 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600887 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600888 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800889 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600890 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800891 g_lastBoundDescriptorSet = pSet->set;
892 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600893 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600894 // First verify valid update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600895 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600896 result = 0;
897 break;
898 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600899 // Make sure that binding is within bounds
Tobin Ehlisde63c532015-06-18 15:59:33 -0600900 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600901 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 -0600902 "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 -0600903 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600904 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600905 // Next verify that update falls within size of given binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600906 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour29b12062015-07-13 13:37:24 -0600907 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600908 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600909 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
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_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600911 "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 -0600912 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600913 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600914 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlisde63c532015-06-18 15:59:33 -0600915 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600916 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 -0600917 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600918 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600919 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600920 // Save the update info
921 // TODO : Info message that update successful
922 // Create new update struct for this set's shadow copy
Tobin Ehlisde63c532015-06-18 15:59:33 -0600923 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600924 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600925 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 -0600926 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600927 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600928 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600929 // Insert shadow node into LL of updates for this set
930 pNewNode->pNext = pSet->pUpdateStructs;
931 pSet->pUpdateStructs = pNewNode;
932 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisde63c532015-06-18 15:59:33 -0600933 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600934 assert(j<pSet->descriptorCount);
935 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600936 }
937 }
938 }
939 }
940 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600941 }
942 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600943 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600944}
945// Free the shadowed update node for this Set
946// NOTE : Calls to this function should be wrapped in mutex
947static void freeShadowUpdateTree(SET_NODE* pSet)
948{
949 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
950 pSet->pUpdateStructs = NULL;
951 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
952 // Clear the descriptor mappings as they will now be invalid
953 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
954 while(pShadowUpdate) {
955 pFreeUpdate = pShadowUpdate;
956 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
957 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800958 VkWriteDescriptorSet * pWDS = NULL;
959 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600960 void** ppToFree = NULL;
961 switch (pFreeUpdate->sType)
962 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800963 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
964 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
965 if (pWDS->pDescriptors)
966 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600967 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800968 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600969 break;
970 default:
971 assert(0);
972 break;
973 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600974 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600975 }
976}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600977// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600978// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600979static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600980{
David Pinedof5997ab2015-04-27 16:36:17 -0600981 if (poolMap.size() <= 0)
982 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600983 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600984 SET_NODE* pSet = (*ii).second->pSets;
985 SET_NODE* pFreeSet = pSet;
986 while (pSet) {
987 pFreeSet = pSet;
988 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600989 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600990 // Free Update shadow struct tree
991 freeShadowUpdateTree(pFreeSet);
992 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200993 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600994 }
995 delete pFreeSet;
996 }
997 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200998 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600999 }
1000 delete (*ii).second;
1001 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001002 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001003}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001004// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001005// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001006static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001007{
David Pinedof5997ab2015-04-27 16:36:17 -06001008 if (layoutMap.size() <= 0)
1009 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001010 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001011 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001012 if (pLayout->createInfo.pBinding) {
1013 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1014 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1015 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1016 }
1017 delete[] pLayout->createInfo.pBinding;
1018 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001020 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001021 }
1022 delete pLayout;
1023 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001024 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001025}
1026// Currently clearing a set is removing all previous updates to that set
1027// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001028static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001029{
1030 SET_NODE* pSet = getSetNode(set);
1031 if (!pSet) {
1032 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001033 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001034 loader_platform_thread_lock_mutex(&globalLock);
1035 freeShadowUpdateTree(pSet);
1036 loader_platform_thread_unlock_mutex(&globalLock);
1037 }
1038}
1039
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001040static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001041{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001042 POOL_NODE* pPool = getPoolNode(pool);
1043 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001044 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1045 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001046 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001047 // For every set off of this pool, clear it
1048 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001049 while (pSet) {
1050 clearDescriptorSet(pSet->set);
1051 }
1052 }
1053}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001054// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001055static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001056{
1057 loader_platform_thread_lock_mutex(&globalLock);
1058 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1059 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001060 // TODO : How to pass cb as srcObj here?
1061 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1062 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001063 return NULL;
1064 }
1065 loader_platform_thread_unlock_mutex(&globalLock);
1066 return cmdBufferMap[cb];
1067}
1068// Free all CB Nodes
1069// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001070static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001071{
David Pinedof5997ab2015-04-27 16:36:17 -06001072 if (cmdBufferMap.size() <= 0)
1073 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001074 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001075 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1076 while (!cmd_node_list.empty()) {
1077 CMD_NODE* cmd_node = cmd_node_list.back();
1078 delete cmd_node;
1079 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001080 }
1081 delete (*ii).second;
1082 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001083 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001084}
Tobin Ehlise42007c2015-06-19 13:00:59 -06001085static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1086{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001087 // TODO : How to pass cb as srcObj here?
1088 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 -06001089 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1090}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001091static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1092{
1093 CMD_NODE* pCmd = new CMD_NODE;
1094 if (pCmd) {
1095 // init cmd node and append to end of cmd LL
1096 memset(pCmd, 0, sizeof(CMD_NODE));
1097 pCmd->cmdNumber = ++pCB->numCmds;
1098 pCmd->type = cmd;
1099 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001100 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001101 // TODO : How to pass cb as srcObj here?
1102 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1103 "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 -06001104 }
1105}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001106static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001107{
1108 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1109 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001110 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1111 while (!cmd_list.empty()) {
1112 delete cmd_list.back();
1113 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001114 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001115 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001116 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001117 VkFlags saveFlags = pCB->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001118 VkCmdPool savedPool = pCB->pool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001119 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1120 pCB->cmdBuffer = cb;
1121 pCB->flags = saveFlags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001122 pCB->pool = savedPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001123 pCB->lastVtxBinding = MAX_BINDING;
1124 }
1125}
Tobin Ehlis97866202015-06-10 12:57:07 -06001126// Set PSO-related status bits for CB
1127static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1128{
1129 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1130 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1131 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1132 }
1133 }
1134 if (pPipe->dsStateCI.depthWriteEnable) {
1135 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1136 }
1137}
1138// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001139static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001140 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1141 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1142 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1143 pNode->status |= CBSTATUS_RASTER_BOUND;
1144 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1145 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1146 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1147 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1148 }
1149}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001150// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001151static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001152{
1153 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1154 if (pCB) {
1155 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1156 if (!pPipeTrav) {
1157 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001158 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001159 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001160 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001161 }
1162 }
1163}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001164// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001165static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001166{
1167 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1168 if (pCB && pCB->lastBoundPipeline) {
1169 // First verify that we have a Node for bound pipeline
1170 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001171 if (!pPipeTrav) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001172 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1173 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001174 return false;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001175 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001176 // Verify Vtx binding
1177 if (MAX_BINDING != pCB->lastVtxBinding) {
1178 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1179 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001180 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 -06001181 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001182 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001183 }
1184 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001185 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 -06001186 "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 -06001187 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001188 }
1189 }
1190 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001191 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001192 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001193 }
1194 }
1195 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001196 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001197 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001198 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001199}
1200// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001201static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001202{
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001203 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.
1204 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001205 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001206 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001207 POOL_NODE* pPool = getPoolNode(pSet->pool);
1208 // Print out pool details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001209 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1210 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001211 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001212 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001213 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001214 // Print out set details
1215 char prefix[10];
1216 uint32_t index = 0;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001217 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1218 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001219 LAYOUT_NODE* pLayout = pSet->pLayout;
1220 // Print layout details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001221 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1222 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001223 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001224 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001225 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001226 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001227 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001228 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1229 if (pUpdate) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001230 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1231 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001232 sprintf(prefix, " [UC] ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001233 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001234 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001235 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001236 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001237 if (0 != pSet->descriptorCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001238 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1239 "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 -06001240 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001241 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1242 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001243 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001244 }
1245 }
1246}
1247
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001248static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001249{
1250 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001251 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001252 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001253 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001254 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001255 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1256 // TODO : Need to pass cb as srcObj here
1257 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 -06001258 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001259 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001260 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001261 // Nothing to print
1262 }
1263}
1264
1265
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001266static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001267{
Tobin Ehlis33ce8fd2015-07-10 18:25:07 -06001268 // TODO : Re-enable these print funcs
1269// printDSConfig(cb);
1270// printPipeline(cb);
1271// printDynamicState(cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001272}
1273
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001274static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001275{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001276 uint32_t report_flags = 0;
1277 uint32_t debug_action = 0;
1278 FILE *log_output = NULL;
1279 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001280 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001281 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1282 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001283
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001284 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001285 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001286 option_str = getLayerOption("DrawStateLogFilename");
1287 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001288 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001289 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001290 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001291 if (log_output == NULL)
1292 log_output = stdout;
1293
1294 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 -06001295 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001296
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001297 if (!globalLockInitialized)
1298 {
1299 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001300 // suggestion is to call this during vkCreateInstance(), and then we
1301 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001302 // that the layer have per-instance locks. We need to come back and
1303 // address this soon.
1304 loader_platform_thread_create_mutex(&globalLock);
1305 globalLockInitialized = 1;
1306 }
1307}
1308
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001309VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1310{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001311 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001312 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1313
1314 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001315 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1316 my_data->report_data = debug_report_create_instance(
1317 pTable,
1318 *pInstance,
1319 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001320 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001321
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001322 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001323 }
1324 return result;
1325}
1326
Jon Ashburne0fa2282015-05-20 09:00:28 -06001327/* hook DestroyInstance to remove tableInstanceMap entry */
1328VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1329{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001330 dispatch_key key = get_dispatch_key(instance);
1331 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1332 VkResult res = pTable->DestroyInstance(instance);
1333
1334 // Clean up logging callback, if any
1335 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1336 if (my_data->logging_callback) {
1337 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1338 }
1339
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001340 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001341 layer_data_map.erase(pTable);
1342
1343 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001344 return res;
1345}
1346
Jon Ashburnf0615e22015-05-25 14:11:37 -06001347static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1348{
Tony Barbour29b12062015-07-13 13:37:24 -06001349 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001350 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001351 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001352
1353 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001354 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001355 /* Found a matching extension name, mark it enabled and init dispatch table*/
1356 initDebugMarkerTable(device);
1357 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001358 }
1359
1360 }
1361}
1362
Tony Barbour8205d902015-04-16 15:59:00 -06001363VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001364{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001365 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1366 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001367 if (result == VK_SUCCESS) {
1368 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1369 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1370 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1371 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001372 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001373 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001374 return result;
1375}
1376
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001377VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001378{
1379 // Free all the memory
1380 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001381 deletePipelines();
1382 deleteSamplers();
1383 deleteImages();
1384 deleteBuffers();
1385 deleteCmdBuffers();
1386 deleteDynamicState();
1387 deletePools();
1388 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001389 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001390
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001391 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001392 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1393 VkResult result = pDisp->DestroyDevice(device);
1394 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001395 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001396 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001397 return result;
1398}
1399
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001400static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001401 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001402 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001403 VK_API_VERSION,
1404 VK_MAKE_VERSION(0, 1, 0),
1405 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001406 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001407};
1408
Tony Barbour426b9052015-06-24 16:06:58 -06001409VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001410 const char *pLayerName,
1411 uint32_t *pCount,
1412 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001413{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001414 /* DrawState does not have any global extensions */
1415 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1416}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001417
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001418VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1419 uint32_t *pCount,
1420 VkLayerProperties* pProperties)
1421{
1422 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1423 ds_global_layers,
1424 pCount, pProperties);
1425}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001426
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001427static const VkExtensionProperties ds_device_extensions[] = {
1428 {
1429 DEBUG_MARKER_EXTENSION_NAME,
1430 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001431 }
1432};
1433
1434static const VkLayerProperties ds_device_layers[] = {
1435 {
1436 "DrawState",
1437 VK_API_VERSION,
1438 VK_MAKE_VERSION(0, 1, 0),
1439 "Validation layer: DrawState",
1440 }
1441};
1442
1443VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1444 VkPhysicalDevice physicalDevice,
1445 const char* pLayerName,
1446 uint32_t* pCount,
1447 VkExtensionProperties* pProperties)
1448{
1449 /* Mem tracker does not have any physical device extensions */
1450 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1451 pCount, pProperties);
1452}
1453
1454VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1455 VkPhysicalDevice physicalDevice,
1456 uint32_t* pCount,
1457 VkLayerProperties* pProperties)
1458{
1459 /* Mem tracker's physical device layers are the same as global */
1460 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1461 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001462}
1463
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001464VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001465{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001466 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001467 for (uint32_t i=0; i < cmdBufferCount; i++) {
1468 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001469 pCB = getCBNode(pCmdBuffers[i]);
1470 loader_platform_thread_lock_mutex(&globalLock);
1471 if (CB_UPDATE_COMPLETE != pCB->state) {
1472 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001473 // TODO : How to pass cb as srcObj?
1474 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1475 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlise90b1712015-05-27 14:30:06 -06001476 loader_platform_thread_unlock_mutex(&globalLock);
1477 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001478 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001479 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001480 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001481
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001482 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001483 return result;
1484}
1485
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001486VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001487{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001488 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1489 // TODO : Clean up any internal data structures using this obj.
1490 return result;
1491}
1492
1493VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1494{
1495 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1496 // TODO : Clean up any internal data structures using this obj.
1497 return result;
1498}
1499
1500VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1501{
1502 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1503 // TODO : Clean up any internal data structures using this obj.
1504 return result;
1505}
1506
1507VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1508{
1509 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1510 // TODO : Clean up any internal data structures using this obj.
1511 return result;
1512}
1513
1514VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1515{
1516 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1517 // TODO : Clean up any internal data structures using this obj.
1518 return result;
1519}
1520
1521VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1522{
1523 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1524 // TODO : Clean up any internal data structures using this obj.
1525 return result;
1526}
1527
1528VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1529{
1530 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1531 // TODO : Clean up any internal data structures using this obj.
1532 return result;
1533}
1534
1535VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1536{
1537 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1538 // TODO : Clean up any internal data structures using this obj.
1539 return result;
1540}
1541
1542VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1543{
1544 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1545 // TODO : Clean up any internal data structures using this obj.
1546 return result;
1547}
1548
1549VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1550{
1551 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1552 // TODO : Clean up any internal data structures using this obj.
1553 return result;
1554}
1555
1556VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1557{
1558 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1559 // TODO : Clean up any internal data structures using this obj.
1560 return result;
1561}
1562
1563VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1564{
1565 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1566 // TODO : Clean up any internal data structures using this obj.
1567 return result;
1568}
1569
1570VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1571{
1572 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1573 // TODO : Clean up any internal data structures using this obj.
1574 return result;
1575}
1576
1577VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1578{
1579 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1580 // TODO : Clean up any internal data structures using this obj.
1581 return result;
1582}
1583
1584VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1585{
1586 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1587 // TODO : Clean up any internal data structures using this obj.
1588 return result;
1589}
1590
1591VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1592{
1593 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1594 // TODO : Clean up any internal data structures using this obj.
1595 return result;
1596}
1597
1598VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1599{
1600 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1601 // TODO : Clean up any internal data structures using this obj.
1602 return result;
1603}
1604
1605VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1606{
1607 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1608 // TODO : Clean up any internal data structures using this obj.
1609 return result;
1610}
1611
1612VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1613{
1614 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1615 // TODO : Clean up any internal data structures using this obj.
1616 return result;
1617}
1618
1619VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1620{
1621 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1622 // TODO : Clean up any internal data structures using this obj.
1623 return result;
1624}
1625
1626VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1627{
1628 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1629 // TODO : Clean up any internal data structures using this obj.
1630 return result;
1631}
1632
1633VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1634{
1635 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1636 // TODO : Clean up any internal data structures using this obj.
1637 return result;
1638}
1639
1640VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1641{
1642 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1643 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001644 return result;
1645}
1646
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001647VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001648{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001649 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001650 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001651 loader_platform_thread_lock_mutex(&globalLock);
1652 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1653 pNewNode->buffer = *pView;
1654 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001655 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001656 loader_platform_thread_unlock_mutex(&globalLock);
1657 }
1658 return result;
1659}
1660
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001661VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001662{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001663 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001664 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001665 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001666 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001667 loader_platform_thread_unlock_mutex(&globalLock);
1668 }
1669 return result;
1670}
1671
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001672VkResult VKAPI vkCreateAttachmentView(
1673 VkDevice device,
1674 const VkAttachmentViewCreateInfo* pCreateInfo,
1675 VkAttachmentView* pView)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001676{
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001677 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001678 if (VK_SUCCESS == result) {
1679 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001680 viewMap[pView->handle] = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001681 loader_platform_thread_unlock_mutex(&globalLock);
1682 }
1683 return result;
1684}
1685
Jon Ashburn0d60d272015-07-09 15:02:25 -06001686//TODO handle pipeline caches
1687VkResult VKAPI vkCreatePipelineCache(
1688 VkDevice device,
1689 const VkPipelineCacheCreateInfo* pCreateInfo,
1690 VkPipelineCache* pPipelineCache)
1691{
1692 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1693 return result;
1694}
1695
1696VkResult VKAPI vkDestroyPipelineCache(
1697 VkDevice device,
1698 VkPipelineCache pipelineCache)
1699{
1700 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1701 return result;
1702}
1703
1704size_t VKAPI vkGetPipelineCacheSize(
1705 VkDevice device,
1706 VkPipelineCache pipelineCache)
1707{
1708 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1709 return size;
1710}
1711
1712VkResult VKAPI vkGetPipelineCacheData(
1713 VkDevice device,
1714 VkPipelineCache pipelineCache,
1715 void* pData)
1716{
1717 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1718 return result;
1719}
1720
1721VkResult VKAPI vkMergePipelineCaches(
1722 VkDevice device,
1723 VkPipelineCache destCache,
1724 uint32_t srcCacheCount,
1725 const VkPipelineCache* pSrcCaches)
1726{
1727 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1728 return result;
1729}
1730
1731VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001732{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001733 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001734 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001735 // The order of operations here is a little convoluted but gets the job done
1736 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1737 // 2. Create state is then validated (which uses flags setup during shadowing)
1738 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1739 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001740 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001741 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001742 loader_platform_thread_unlock_mutex(&globalLock);
1743 if (VK_TRUE == valid) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001744 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001745 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1746 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001747 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001748 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001749 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001750 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001751 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001752 if (pPipeNode) {
1753 // If we allocated a pipeNode, need to clean it up here
1754 delete[] pPipeNode->pVertexBindingDescriptions;
1755 delete[] pPipeNode->pVertexAttributeDescriptions;
1756 delete[] pPipeNode->pAttachments;
1757 delete pPipeNode;
1758 }
1759 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001760 return result;
1761}
1762
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001763VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001764{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001765 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001766 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001767 loader_platform_thread_lock_mutex(&globalLock);
1768 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1769 pNewNode->sampler = *pSampler;
1770 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001771 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001772 loader_platform_thread_unlock_mutex(&globalLock);
1773 }
1774 return result;
1775}
1776
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001777VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001778{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001779 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001780 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001781 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1782 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001783 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 -06001784 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785 }
1786 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001787 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1788 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1789 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001790 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001791 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001792 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001793 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001794 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001795 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1796 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001797 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001798 }
1799 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001800 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001801 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001802 uint32_t j = 0;
1803 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001804 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001805 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001806 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001807 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808 }
1809 }
1810 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001811 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001812 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1813 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 // Put new node at Head of global Layer list
1815 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001816 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001817 loader_platform_thread_unlock_mutex(&globalLock);
1818 }
1819 return result;
1820}
1821
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001822VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001823{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001824 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001825 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001826 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001827 }
1828 return result;
1829}
1830
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001831VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001832{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001833 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001834 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001835 // Insert this pool into Global Pool LL at head
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001836 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1837 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001838 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001839 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001840 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001841 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 -06001842 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001843 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001844 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001845 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1846 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001848 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1849 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001850 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1851 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001852 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001854 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001855 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001856 }
1857 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001858 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001859 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001860 }
1861 return result;
1862}
1863
Mike Stroyan230e6252015-04-17 12:36:38 -06001864VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001865{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001866 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001867 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001868 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001869 }
1870 return result;
1871}
1872
Mike Stroyan230e6252015-04-17 12:36:38 -06001873VK_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 -06001874{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001875 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 -06001876 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001877 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1878 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001879 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1880 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001881 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001882 for (uint32_t i = 0; i < *pCount; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001883 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1884 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001885 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001886 SET_NODE* pNewNode = new SET_NODE;
1887 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001888 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 -06001889 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001890 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001891 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001892 // Insert set at head of Set LL for this pool
1893 pNewNode->pNext = pPoolNode->pSets;
1894 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001895 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1896 if (NULL == pLayout) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001897 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1898 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001899 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001900 pNewNode->pLayout = pLayout;
1901 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001902 pNewNode->set = pDescriptorSets[i];
1903 pNewNode->setUsage = setUsage;
1904 pNewNode->descriptorCount = pLayout->endIndex + 1;
1905 if (pNewNode->descriptorCount) {
1906 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1907 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1908 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1909 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001910 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001911 }
1912 }
1913 }
1914 }
1915 return result;
1916}
1917
Tony Barbourb857d312015-07-10 10:50:45 -06001918VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1919{
1920 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1921 // TODO : Clean up any internal data structures using this obj.
1922 return result;
1923}
1924
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001925VK_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 -06001926{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001927 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1928 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001929 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001930 }
1931 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001932}
1933
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001934VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001935{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001936 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001937 VkDynamicViewportStateCreateInfo local_ci;
1938 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1939 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1940 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1941 loader_platform_thread_lock_mutex(&globalLock);
1942 dynamicVpStateMap[pState->handle] = local_ci;
1943 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001944 return result;
1945}
1946
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001947VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRasterStateCreateInfo* pCreateInfo, VkDynamicRasterState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001948{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001949 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001950 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
1951 loader_platform_thread_lock_mutex(&globalLock);
1952 dynamicRsStateMap[pState->handle] = *pCreateInfo;
1953 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001954 return result;
1955}
1956
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001957VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicColorBlendStateCreateInfo* pCreateInfo, VkDynamicColorBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001958{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001959 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001960 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
1961 loader_platform_thread_lock_mutex(&globalLock);
1962 dynamicCbStateMap[pState->handle] = *pCreateInfo;
1963 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001964 return result;
1965}
1966
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001967VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDepthStencilStateCreateInfo* pCreateInfo, VkDynamicDepthStencilState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001968{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001969 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001970 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
1971 loader_platform_thread_lock_mutex(&globalLock);
1972 dynamicDsStateMap[pState->handle] = *pCreateInfo;
1973 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001974 return result;
1975}
1976
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001977VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001978{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001979 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001980 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001981 loader_platform_thread_lock_mutex(&globalLock);
1982 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1983 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1984 pCB->cmdBuffer = *pCmdBuffer;
1985 pCB->flags = pCreateInfo->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001986 pCB->pool = pCreateInfo->cmdPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001987 pCB->lastVtxBinding = MAX_BINDING;
1988 cmdBufferMap[*pCmdBuffer] = pCB;
1989 loader_platform_thread_unlock_mutex(&globalLock);
1990 updateCBTracking(*pCmdBuffer);
1991 }
1992 return result;
1993}
1994
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001995VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001996{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001997 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001998 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001999 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2000 if (pCB) {
2001 if (CB_NEW != pCB->state)
2002 resetCB(cmdBuffer);
2003 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002004 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002005 // TODO : Need to pass cmdBuffer as objType here
2006 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 -06002007 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002008 }
2009 updateCBTracking(cmdBuffer);
2010 }
2011 return result;
2012}
2013
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002014VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002015{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002016 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2017 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2018 if (pCB) {
2019 if (pCB->state == CB_UPDATE_ACTIVE) {
2020 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2021 if (VK_SUCCESS == result) {
2022 updateCBTracking(cmdBuffer);
2023 pCB->state = CB_UPDATE_COMPLETE;
2024 // Reset CB status flags
2025 pCB->status = 0;
2026 printCB(cmdBuffer);
2027 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002028 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002029 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002030 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002031 }
2032 return result;
2033}
2034
Cody Northropf02f9f82015-07-09 18:08:05 -06002035VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002036{
Cody Northropf02f9f82015-07-09 18:08:05 -06002037 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002038 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002039 resetCB(cmdBuffer);
2040 updateCBTracking(cmdBuffer);
2041 }
2042 return result;
2043}
2044
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002045VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002046{
2047 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2048 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002049 if (pCB->state == CB_UPDATE_ACTIVE) {
2050 updateCBTracking(cmdBuffer);
2051 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002052 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002053 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2054 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002055 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002056 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2057 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002058 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002059 PIPELINE_NODE* pPN = getPipeline(pipeline);
2060 if (pPN) {
2061 pCB->lastBoundPipeline = pipeline;
2062 loader_platform_thread_lock_mutex(&globalLock);
2063 set_cb_pso_status(pCB, pPN);
2064 g_lastBoundPipeline = pPN;
2065 loader_platform_thread_unlock_mutex(&globalLock);
2066 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2067 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2068 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002069 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2070 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002071 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002072 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002073 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002074 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002075 }
2076 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002077}
2078
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002079VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002080{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002081 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2082 if (pCB) {
2083 if (pCB->state == CB_UPDATE_ACTIVE) {
2084 updateCBTracking(cmdBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002085 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002086 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002087 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2088 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002089 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002090 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002091 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2092 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002093 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 -06002094 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002095 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002096 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2097 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002098 }
2099 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002100 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002101 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002102 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002103 }
2104 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002105}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002106VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicRasterState(VkCmdBuffer cmdBuffer, VkDynamicRasterState dynamicRasterState)
2107{
2108 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2109 if (pCB) {
2110 if (pCB->state == CB_UPDATE_ACTIVE) {
2111 updateCBTracking(cmdBuffer);
2112 addCmd(pCB, CMD_BINDDYNAMICRASTERSTATE);
2113 if (!pCB->activeRenderPass) {
2114 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2115 "Incorrect call to vkCmdBindDynamicRasterState() without an active RenderPass.");
2116 }
2117 loader_platform_thread_lock_mutex(&globalLock);
2118 pCB->status |= CBSTATUS_RASTER_BOUND;
2119 if (dynamicRsStateMap.find(dynamicRasterState.handle) == dynamicRsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002120 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 -06002121 "Unable to find VkDynamicRasterState object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2122 } else {
2123 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2124 g_lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2125 }
2126 loader_platform_thread_unlock_mutex(&globalLock);
2127 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2128 } else {
2129 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicRasterState()");
2130 }
2131 }
2132}
2133VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(VkCmdBuffer cmdBuffer, VkDynamicColorBlendState dynamicColorBlendState)
2134{
2135 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2136 if (pCB) {
2137 if (pCB->state == CB_UPDATE_ACTIVE) {
2138 updateCBTracking(cmdBuffer);
2139 addCmd(pCB, CMD_BINDDYNAMICCOLORBLENDSTATE);
2140 if (!pCB->activeRenderPass) {
2141 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2142 "Incorrect call to vkCmdBindDynamicColorBlendState() without an active RenderPass.");
2143 }
2144 loader_platform_thread_lock_mutex(&globalLock);
2145 pCB->status |= CBSTATUS_COLOR_BLEND_BOUND;
2146 if (dynamicCbStateMap.find(dynamicColorBlendState.handle) == dynamicCbStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002147 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 -06002148 "Unable to find VkDynamicColorBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2149 } else {
2150 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2151 g_lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2152 }
2153 loader_platform_thread_unlock_mutex(&globalLock);
2154 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2155 } else {
2156 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicColorBlendState()");
2157 }
2158 }
2159}
2160VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(VkCmdBuffer cmdBuffer, VkDynamicDepthStencilState dynamicDepthStencilState)
2161{
2162 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2163 if (pCB) {
2164 if (pCB->state == CB_UPDATE_ACTIVE) {
2165 updateCBTracking(cmdBuffer);
2166 addCmd(pCB, CMD_BINDDYNAMICDEPTHSTENCILSTATE);
2167 if (!pCB->activeRenderPass) {
2168 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2169 "Incorrect call to vkCmdBindDynamicDepthStencilState() without an active RenderPass.");
2170 }
2171 loader_platform_thread_lock_mutex(&globalLock);
2172 pCB->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
2173 if (dynamicDsStateMap.find(dynamicDepthStencilState.handle) == dynamicDsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002174 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 -06002175 "Unable to find VkDynamicDepthStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2176 } else {
2177 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2178 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2179 }
2180 loader_platform_thread_unlock_mutex(&globalLock);
2181 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
2182 } else {
2183 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthStencilState()");
2184 }
2185 }
2186}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002187VK_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 -06002188{
2189 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2190 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002191 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002192 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002193 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2194 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002195 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002196 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 -06002197 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2198 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002199 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002200 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2201 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002202 loader_platform_thread_lock_mutex(&globalLock);
2203 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002204 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002205 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2206 g_lastBoundDescriptorSet = pDescriptorSets[i];
2207 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002208 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2209 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002210 if (!pSet->pUpdateStructs)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002211 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2212 "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 -06002213 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002214 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2215 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002216 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002217 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002218 updateCBTracking(cmdBuffer);
2219 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis9bde5922015-06-22 18:00:14 -06002220 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 -06002221 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002222 } else {
2223 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002224 }
2225 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002226}
2227
Tony Barbour8205d902015-04-16 15:59:00 -06002228VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002229{
2230 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2231 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002232 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002233 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002234 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 -06002235 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2236 } else {
2237 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2238 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002239 updateCBTracking(cmdBuffer);
2240 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002241 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2242 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002243 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002244 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2245 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002246 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002247}
2248
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002249VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2250 VkCmdBuffer cmdBuffer,
2251 uint32_t startBinding,
2252 uint32_t bindingCount,
2253 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002254 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002255{
2256 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2257 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002258 if (pCB->state == CB_UPDATE_ACTIVE) {
2259 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002260 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002261 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 -06002262 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2263 } else {
2264 pCB->lastVtxBinding = startBinding + bindingCount -1;
2265 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002266 updateCBTracking(cmdBuffer);
2267 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002268 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2269 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002270 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002271 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002272 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002273 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002274 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002275}
2276
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002277VK_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 -06002278{
2279 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002280 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002281 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002282 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002283 pCB->drawCount[DRAW]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002284 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002285 // TODO : Need to pass cmdBuffer as srcObj here
2286 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 -06002287 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2288 synchAndPrintDSConfig(cmdBuffer);
2289 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002290 updateCBTracking(cmdBuffer);
2291 addCmd(pCB, CMD_DRAW);
2292 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002293 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002294 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002295 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2296 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002297 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002298}
2299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002300VK_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 -06002301{
2302 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002303 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002304 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002305 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002306 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002307 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002308 // TODO : Need to pass cmdBuffer as srcObj here
2309 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 -06002310 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2311 synchAndPrintDSConfig(cmdBuffer);
2312 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002313 updateCBTracking(cmdBuffer);
2314 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002315 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2316 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002317 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002318 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2319 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002320 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002321}
2322
Tony Barbour8205d902015-04-16 15:59:00 -06002323VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002324{
2325 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002326 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002327 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002328 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002329 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002330 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002331 // TODO : Need to pass cmdBuffer as srcObj here
2332 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 -06002333 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2334 synchAndPrintDSConfig(cmdBuffer);
2335 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002336 updateCBTracking(cmdBuffer);
2337 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002338 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2339 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002340 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002341 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2342 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002343 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344}
2345
Tony Barbour8205d902015-04-16 15:59:00 -06002346VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002347{
2348 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002349 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002350 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002351 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002352 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002353 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002354 // TODO : Need to pass cmdBuffer as srcObj here
2355 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 -06002356 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2357 synchAndPrintDSConfig(cmdBuffer);
2358 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002359 updateCBTracking(cmdBuffer);
2360 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2361 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002362 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002363 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002364 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2365 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002366 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002367}
2368
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002369VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002370{
2371 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2372 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002373 if (pCB->state == CB_UPDATE_ACTIVE) {
2374 updateCBTracking(cmdBuffer);
2375 addCmd(pCB, CMD_DISPATCH);
2376 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002377 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002378 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2379 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002380 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002381}
2382
Tony Barbour8205d902015-04-16 15:59:00 -06002383VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002384{
2385 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2386 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002387 if (pCB->state == CB_UPDATE_ACTIVE) {
2388 updateCBTracking(cmdBuffer);
2389 addCmd(pCB, CMD_DISPATCHINDIRECT);
2390 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002391 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002392 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2393 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002394 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002395}
2396
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002397VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002398{
2399 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2400 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002401 if (pCB->state == CB_UPDATE_ACTIVE) {
2402 updateCBTracking(cmdBuffer);
2403 addCmd(pCB, CMD_COPYBUFFER);
2404 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002405 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002406 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2407 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002408 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002409}
2410
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002411VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2412 VkImage srcImage,
2413 VkImageLayout srcImageLayout,
2414 VkImage destImage,
2415 VkImageLayout destImageLayout,
2416 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002417{
2418 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2419 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002420 if (pCB->state == CB_UPDATE_ACTIVE) {
2421 updateCBTracking(cmdBuffer);
2422 addCmd(pCB, CMD_COPYIMAGE);
2423 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002424 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002425 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2426 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002427 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002428}
2429
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002430VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2431 VkImage srcImage, VkImageLayout srcImageLayout,
2432 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002433 uint32_t regionCount, const VkImageBlit* pRegions,
2434 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002435{
2436 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2437 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002438 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002439 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002440 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2441 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002442 } else {
2443 updateCBTracking(cmdBuffer);
2444 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002445 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 -06002446 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002447 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002448 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2449 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002450 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002451}
2452
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002453VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2454 VkBuffer srcBuffer,
2455 VkImage destImage, VkImageLayout destImageLayout,
2456 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002457{
2458 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2459 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002460 if (pCB->state == CB_UPDATE_ACTIVE) {
2461 updateCBTracking(cmdBuffer);
2462 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2463 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002464 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002465 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2466 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002468}
2469
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002470VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2471 VkImage srcImage, VkImageLayout srcImageLayout,
2472 VkBuffer destBuffer,
2473 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002474{
2475 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2476 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002477 if (pCB->state == CB_UPDATE_ACTIVE) {
2478 updateCBTracking(cmdBuffer);
2479 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2480 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002481 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002482 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2483 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002485}
2486
Tony Barbour8205d902015-04-16 15:59:00 -06002487VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002488{
2489 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2490 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002491 if (pCB->state == CB_UPDATE_ACTIVE) {
2492 updateCBTracking(cmdBuffer);
2493 addCmd(pCB, CMD_UPDATEBUFFER);
2494 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002495 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002496 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2497 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002498 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002499}
2500
Tony Barbour8205d902015-04-16 15:59:00 -06002501VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002502{
2503 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2504 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002505 if (pCB->state == CB_UPDATE_ACTIVE) {
2506 updateCBTracking(cmdBuffer);
2507 addCmd(pCB, CMD_FILLBUFFER);
2508 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002509 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002510 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2511 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002512 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513}
2514
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002515VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2516 VkCmdBuffer cmdBuffer,
2517 uint32_t colorAttachment,
2518 VkImageLayout imageLayout,
2519 const VkClearColorValue* pColor,
2520 uint32_t rectCount,
2521 const VkRect3D* pRects)
2522{
2523 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2524 if (pCB) {
2525 if (pCB->state == CB_UPDATE_ACTIVE) {
2526 // Warn if this is issued prior to Draw Cmd
2527 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002528 // TODO : cmdBuffer should be srcObj
2529 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 -06002530 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2531 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2532 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002533 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002534 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 -06002535 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2536 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2537 } else {
2538 updateCBTracking(cmdBuffer);
2539 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2540 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2541 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002542 } else {
2543 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2544 }
2545 }
2546}
2547
2548VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2549 VkCmdBuffer cmdBuffer,
2550 VkImageAspectFlags imageAspectMask,
2551 VkImageLayout imageLayout,
2552 float depth,
2553 uint32_t stencil,
2554 uint32_t rectCount,
2555 const VkRect3D* pRects)
2556{
2557 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2558 if (pCB) {
2559 if (pCB->state == CB_UPDATE_ACTIVE) {
2560 // Warn if this is issued prior to Draw Cmd
2561 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002562 // TODO : cmdBuffer should be srcObj
2563 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 -06002564 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2565 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2566 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002567 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002568 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 -06002569 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2570 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2571 } else {
2572 updateCBTracking(cmdBuffer);
2573 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2574 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2575 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002576 } else {
2577 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2578 }
2579 }
2580}
2581
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002582VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2583 VkCmdBuffer cmdBuffer,
2584 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002585 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002586 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002587{
2588 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2589 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002590 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002591 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002592 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 -06002593 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2594 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2595 } else {
2596 updateCBTracking(cmdBuffer);
2597 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2598 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2599 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002600 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002601 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2602 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002603 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604}
2605
Chris Forbes2951d7d2015-06-22 17:21:59 +12002606VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002607 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002608 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002609 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002610{
2611 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2612 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002613 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002614 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002615 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 -06002616 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2617 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2618 } else {
2619 updateCBTracking(cmdBuffer);
2620 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2621 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2622 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002623 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002624 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2625 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002626 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002627}
2628
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002629VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2630 VkImage srcImage, VkImageLayout srcImageLayout,
2631 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002632 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002633{
2634 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2635 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002636 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002637 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002638 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2639 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002640 } else {
2641 updateCBTracking(cmdBuffer);
2642 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002643 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002644 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002645 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002646 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2647 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002648 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002649}
2650
Tony Barbourc2e987e2015-06-29 16:20:35 -06002651VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002652{
2653 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2654 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002655 if (pCB->state == CB_UPDATE_ACTIVE) {
2656 updateCBTracking(cmdBuffer);
2657 addCmd(pCB, CMD_SETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002658 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002659 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002660 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2661 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002662 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663}
2664
Tony Barbourc2e987e2015-06-29 16:20:35 -06002665VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002666{
2667 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2668 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002669 if (pCB->state == CB_UPDATE_ACTIVE) {
2670 updateCBTracking(cmdBuffer);
2671 addCmd(pCB, CMD_RESETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002672 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002673 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002674 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2675 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002676 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002677}
2678
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002679VK_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 -06002680{
2681 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2682 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002683 if (pCB->state == CB_UPDATE_ACTIVE) {
2684 updateCBTracking(cmdBuffer);
2685 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002686 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002687 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002688 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2689 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002690 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002691}
2692
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002693VK_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 -06002694{
2695 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2696 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002697 if (pCB->state == CB_UPDATE_ACTIVE) {
2698 updateCBTracking(cmdBuffer);
2699 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter73a21d32015-07-12 13:20:05 -06002700 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002701 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002702 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2703 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002704 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002705}
2706
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002707VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002708{
2709 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2710 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002711 if (pCB->state == CB_UPDATE_ACTIVE) {
2712 updateCBTracking(cmdBuffer);
2713 addCmd(pCB, CMD_BEGINQUERY);
2714 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002715 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002716 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2717 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002718 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002719}
2720
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002721VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002722{
2723 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2724 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002725 if (pCB->state == CB_UPDATE_ACTIVE) {
2726 updateCBTracking(cmdBuffer);
2727 addCmd(pCB, CMD_ENDQUERY);
2728 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002729 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002730 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2731 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002732 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002733}
2734
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002735VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002736{
2737 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2738 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002739 if (pCB->state == CB_UPDATE_ACTIVE) {
2740 updateCBTracking(cmdBuffer);
2741 addCmd(pCB, CMD_RESETQUERYPOOL);
2742 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002743 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002744 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2745 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002746 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002747}
2748
Tony Barbour8205d902015-04-16 15:59:00 -06002749VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002750{
2751 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2752 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002753 if (pCB->state == CB_UPDATE_ACTIVE) {
2754 updateCBTracking(cmdBuffer);
2755 addCmd(pCB, CMD_WRITETIMESTAMP);
2756 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002757 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002758 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2759 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002760 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002761}
2762
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002763VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002764{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002765 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002766 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002767 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002768 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002769 if (pCreateInfo->pAttachments) {
2770 localFBCI->pAttachments = new VkAttachmentBindInfo[localFBCI->attachmentCount];
2771 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkAttachmentBindInfo));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002772 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002773 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002774 }
2775 return result;
2776}
2777
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002778VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002779{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002780 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002781 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002782 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002783 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002784 if (pCreateInfo->pAttachments) {
2785 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2786 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002787 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002788 if (pCreateInfo->pSubpasses) {
2789 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2790 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2791
2792 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2793 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2794 const uint32_t attachmentCount = subpass->inputCount +
2795 subpass->colorCount * (1 + (bool) subpass->resolveAttachments) +
2796 subpass->preserveCount;
2797 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2798
2799 memcpy(attachments, subpass->inputAttachments,
2800 sizeof(attachments[0]) * subpass->inputCount);
2801 subpass->inputAttachments = attachments;
2802 attachments += subpass->inputCount;
2803
2804 memcpy(attachments, subpass->colorAttachments,
2805 sizeof(attachments[0]) * subpass->colorCount);
2806 subpass->colorAttachments = attachments;
2807 attachments += subpass->colorCount;
2808
2809 if (subpass->resolveAttachments) {
2810 memcpy(attachments, subpass->resolveAttachments,
2811 sizeof(attachments[0]) * subpass->colorCount);
2812 subpass->resolveAttachments = attachments;
2813 attachments += subpass->colorCount;
2814 }
2815
2816 memcpy(attachments, subpass->preserveAttachments,
2817 sizeof(attachments[0]) * subpass->preserveCount);
2818 subpass->preserveAttachments = attachments;
2819 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002820 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002821 if (pCreateInfo->pDependencies) {
2822 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2823 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002824 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002825 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002826 }
2827 return result;
2828}
2829
Chia-I Wuc278df82015-07-07 11:50:03 +08002830VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002831{
2832 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2833 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002834 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002835 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002836 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2837 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002838 } else {
2839 updateCBTracking(cmdBuffer);
2840 addCmd(pCB, CMD_BEGINRENDERPASS);
2841 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002842 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002843 pCB->framebuffer = pRenderPassBegin->framebuffer;
2844 if (pCB->lastBoundPipeline) {
2845 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2846 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002847 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002848 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002849 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002850 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002851 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002852 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002853 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002854}
2855
Chia-I Wuc278df82015-07-07 11:50:03 +08002856VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2857{
2858 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2859 if (pCB) {
2860 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002861 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 +08002862 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2863 } else {
2864 updateCBTracking(cmdBuffer);
2865 addCmd(pCB, CMD_NEXTSUBPASS);
2866 pCB->activeSubpass++;
2867 if (pCB->lastBoundPipeline) {
2868 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2869 }
2870 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2871 }
2872 }
2873}
2874
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002875VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002876{
2877 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2878 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002879 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002880 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 +08002881 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06002882 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002883 updateCBTracking(cmdBuffer);
2884 addCmd(pCB, CMD_ENDRENDERPASS);
2885 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08002886 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002887 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2888 }
2889 }
2890}
2891
2892VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2893{
2894 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2895 if (pCB) {
2896 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002897 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 +08002898 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2899 } else {
2900 updateCBTracking(cmdBuffer);
2901 addCmd(pCB, CMD_EXECUTECOMMANDS);
2902 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002903 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002904 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002905}
2906
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002907VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2908 VkInstance instance,
2909 VkFlags msgFlags,
2910 const PFN_vkDbgMsgCallback pfnMsgCallback,
2911 void* pUserData,
2912 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002913{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002914 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002915 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2916 if (VK_SUCCESS == res) {
2917 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2918 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2919 }
2920 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002921}
2922
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002923VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2924 VkInstance instance,
2925 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002926{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002927 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002928 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2929 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2930 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2931 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002932}
2933
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002934VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002935{
2936 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002937 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2938 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002939 // TODO : cmdBuffer should be srcObj
2940 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 -06002941 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002942 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002943 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002944 updateCBTracking(cmdBuffer);
2945 addCmd(pCB, CMD_DBGMARKERBEGIN);
2946 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002947 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002948}
2949
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002950VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002951{
2952 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002953 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2954 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002955 // TODO : cmdBuffer should be srcObj
2956 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 -06002957 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002958 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002959 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002960 updateCBTracking(cmdBuffer);
2961 addCmd(pCB, CMD_DBGMARKEREND);
2962 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002963 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2964}
2965
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002966//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2967//{
2968// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2969// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2970// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2971// "Attempt to use DbgSetObjectTag but extension disabled!");
2972// return VK_ERROR_UNAVAILABLE;
2973// }
2974// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2975//}
2976//
2977//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2978//{
2979// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2980// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2981// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2982// "Attempt to use DbgSetObjectName but extension disabled!");
2983// return VK_ERROR_UNAVAILABLE;
2984// }
2985// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
2986//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002987
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002988VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002989{
Jon Ashburn1245cec2015-05-18 13:20:15 -06002990 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002991 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06002992
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002993 /* loader uses this to force layer initialization; device object is wrapped */
2994 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002995 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002996 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06002997 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06002998 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06002999 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003000 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003001 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003002 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003003 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003004 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003005 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003006 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003007 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003008 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003009 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003010 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003011 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003012 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003013 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003014 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003015 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003016 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003017 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003018 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003019 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003020 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003021 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003022 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003023 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003024 if (!strcmp(funcName, "vkDestroyAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003025 return (PFN_vkVoidFunction) vkDestroyAttachmentView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003026 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003027 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003028 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003029 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003030 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003031 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003032 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003033 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003034 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003035 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003036 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003037 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003038 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003039 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003040 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003041 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003042 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003043 return (PFN_vkVoidFunction) vkDestroyDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003044 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003045 return (PFN_vkVoidFunction) vkDestroyDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003046 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003047 return (PFN_vkVoidFunction) vkDestroyDynamicDepthStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003048 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003049 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003050 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003051 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003052 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003053 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003054 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003055 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003056 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003057 return (PFN_vkVoidFunction) vkCreateImageView;
Tobin Ehlis44c757d2015-07-10 12:15:19 -06003058 if (!strcmp(funcName, "vkCreateAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003059 return (PFN_vkVoidFunction) vkCreateAttachmentView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003060 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003061 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003062 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003063 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003064 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003065 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003066 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003067 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003068 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003069 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003070 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003071 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003072 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003073 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003074 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003075 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003076 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003077 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003078 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003079 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003080 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003081 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003082 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003083 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003084 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003085 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003086 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003087 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003088 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003089 return (PFN_vkVoidFunction) vkCreateDynamicRasterState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003090 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003091 return (PFN_vkVoidFunction) vkCreateDynamicColorBlendState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003092 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003093 return (PFN_vkVoidFunction) vkCreateDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003094 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003095 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003096 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003097 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003098 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003099 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003100 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003101 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003102 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003103 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003104 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003105 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003106 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003107 return (PFN_vkVoidFunction) vkCmdBindDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003108 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003109 return (PFN_vkVoidFunction) vkCmdBindDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003110 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003111 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003112 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003113 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003114 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003115 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003116 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003117 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003118 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003120 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003122 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003124 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003126 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003128 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003130 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003132 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003134 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003136 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003138 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003140 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003142 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003143 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003144 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003145 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003146 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003147 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003148 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003150 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003152 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003154 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003156 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003158 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003160 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003161 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003162 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003163 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003164 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003165 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003166 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003167 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003168 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003169 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003170 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003172 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003173 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003174 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003175 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003176 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003177 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003178
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003179 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3180 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003181 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003182 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003183 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003184 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003185 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003186// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3187// return (void*) vkDbgSetObjectTag;
3188// if (!strcmp(funcName, "vkDbgSetObjectName"))
3189// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003190 }
3191 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003192 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003193 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003194 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003195 }
3196}
3197
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003198VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003199{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003200 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003201 if (instance == NULL)
3202 return NULL;
3203
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003204 /* loader uses this to force layer initialization; instance object is wrapped */
3205 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003206 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003208 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003209 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003210 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003211 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003212 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003213 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003214 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003215 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003216 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003217 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003218 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003219 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003220 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003221
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003222 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3223 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003224 if (fptr)
3225 return fptr;
3226
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003227 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003228 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003229 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003230 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003231 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003232 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003233}