blob: fdd82cfa429666d0e462a15fb1e6b21054b8e97f [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
Tobin Ehlis7a51d902015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Tony Barboura938abb2015-04-22 11:36:22 -060036#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060037#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060038#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060040#include "draw_state.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060041#include "vk_layer_config.h"
Jon Ashburnf0615e22015-05-25 14:11:37 -060042#include "vk_debug_marker_layer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060043// The following is #included again to catch certain OS-specific functions
44// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060046#include "vk_layer_msg.h"
47#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -060051#include "vk_layer_extension_utils.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060052
Tobin Ehlisc91330b2015-06-16 09:04:30 -060053typedef struct _layer_data {
54 debug_report_data *report_data;
55 // TODO: put instance data here
56 VkDbgMsgCallback logging_callback;
57} layer_data;
58
59static std::unordered_map<void *, layer_data *> layer_data_map;
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -060060static device_table_map draw_state_device_table_map;
61static instance_table_map draw_state_instance_table_map;
62
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060063unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
64unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
65unordered_map<uint64_t, VkAttachmentViewCreateInfo> viewMap;
66unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
67unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicVpStateMap;
68unordered_map<uint64_t, VkDynamicRasterStateCreateInfo> dynamicRsStateMap;
69unordered_map<uint64_t, VkDynamicColorBlendStateCreateInfo> dynamicCbStateMap;
70unordered_map<uint64_t, VkDynamicDepthStencilStateCreateInfo> dynamicDsStateMap;
71unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
72unordered_map<uint64_t, POOL_NODE*> poolMap;
73unordered_map<uint64_t, SET_NODE*> setMap;
74unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060075// Map for layout chains
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060076unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
77unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
78unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060079
Jon Ashburn6f8cd632015-06-01 09:37:38 -060080struct devExts {
81 bool debug_marker_enabled;
82};
83
Jon Ashburn6f8cd632015-06-01 09:37:38 -060084static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060085
Tobin Ehlis63bb9482015-03-17 16:24:32 -060086static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060087
Tobin Ehlis63bb9482015-03-17 16:24:32 -060088// TODO : This can be much smarter, using separate locks for separate global data
89static int globalLockInitialized = 0;
90static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060091#define MAX_TID 513
92static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
93static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060094
95template layer_data *get_my_data_ptr<layer_data>(
96 void *data_key,
97 std::unordered_map<void *, layer_data *> &data_map);
98
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060099debug_report_data *mdd(void* object)
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600100{
101 dispatch_key key = get_dispatch_key(object);
102 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
103#if DISPATCH_MAP_DEBUG
104 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
105#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600106 return my_data->report_data;
107}
108
109debug_report_data *mid(VkInstance object)
110{
111 dispatch_key key = get_dispatch_key(object);
112 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
113#if DISPATCH_MAP_DEBUG
114 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
115#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600116 return my_data->report_data;
117}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600118// Map actual TID to an index value and return that index
119// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
120static uint32_t getTIDIndex() {
121 loader_platform_thread_id tid = loader_platform_get_thread_id();
122 for (uint32_t i = 0; i < g_maxTID; i++) {
123 if (tid == g_tidMapping[i])
124 return i;
125 }
126 // Don't yet have mapping, set it and return newly set index
127 uint32_t retVal = (uint32_t) g_maxTID;
128 g_tidMapping[g_maxTID++] = tid;
129 assert(g_maxTID < MAX_TID);
130 return retVal;
131}
132// Return a string representation of CMD_TYPE enum
133static string cmdTypeToString(CMD_TYPE cmd)
134{
135 switch (cmd)
136 {
137 case CMD_BINDPIPELINE:
138 return "CMD_BINDPIPELINE";
139 case CMD_BINDPIPELINEDELTA:
140 return "CMD_BINDPIPELINEDELTA";
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600141 case CMD_BINDDYNAMICVIEWPORTSTATE:
142 return "CMD_BINDDYNAMICVIEWPORTSTATE";
143 case CMD_BINDDYNAMICRASTERSTATE:
144 return "CMD_BINDDYNAMICRASTERSTATE";
145 case CMD_BINDDYNAMICCOLORBLENDSTATE:
146 return "CMD_BINDDYNAMICCOLORBLENDSTATE";
147 case CMD_BINDDYNAMICDEPTHSTENCILSTATE:
148 return "CMD_BINDDYNAMICDEPTHSTENCILSTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600149 case CMD_BINDDESCRIPTORSETS:
150 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600151 case CMD_BINDINDEXBUFFER:
152 return "CMD_BINDINDEXBUFFER";
153 case CMD_BINDVERTEXBUFFER:
154 return "CMD_BINDVERTEXBUFFER";
155 case CMD_DRAW:
156 return "CMD_DRAW";
157 case CMD_DRAWINDEXED:
158 return "CMD_DRAWINDEXED";
159 case CMD_DRAWINDIRECT:
160 return "CMD_DRAWINDIRECT";
161 case CMD_DRAWINDEXEDINDIRECT:
162 return "CMD_DRAWINDEXEDINDIRECT";
163 case CMD_DISPATCH:
164 return "CMD_DISPATCH";
165 case CMD_DISPATCHINDIRECT:
166 return "CMD_DISPATCHINDIRECT";
167 case CMD_COPYBUFFER:
168 return "CMD_COPYBUFFER";
169 case CMD_COPYIMAGE:
170 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600171 case CMD_BLITIMAGE:
172 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600173 case CMD_COPYBUFFERTOIMAGE:
174 return "CMD_COPYBUFFERTOIMAGE";
175 case CMD_COPYIMAGETOBUFFER:
176 return "CMD_COPYIMAGETOBUFFER";
177 case CMD_CLONEIMAGEDATA:
178 return "CMD_CLONEIMAGEDATA";
179 case CMD_UPDATEBUFFER:
180 return "CMD_UPDATEBUFFER";
181 case CMD_FILLBUFFER:
182 return "CMD_FILLBUFFER";
183 case CMD_CLEARCOLORIMAGE:
184 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600185 case CMD_CLEARCOLORATTACHMENT:
186 return "CMD_CLEARCOLORATTACHMENT";
187 case CMD_CLEARDEPTHSTENCILIMAGE:
188 return "CMD_CLEARDEPTHSTENCILIMAGE";
189 case CMD_CLEARDEPTHSTENCILATTACHMENT:
190 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600191 case CMD_RESOLVEIMAGE:
192 return "CMD_RESOLVEIMAGE";
193 case CMD_SETEVENT:
194 return "CMD_SETEVENT";
195 case CMD_RESETEVENT:
196 return "CMD_RESETEVENT";
197 case CMD_WAITEVENTS:
198 return "CMD_WAITEVENTS";
199 case CMD_PIPELINEBARRIER:
200 return "CMD_PIPELINEBARRIER";
201 case CMD_BEGINQUERY:
202 return "CMD_BEGINQUERY";
203 case CMD_ENDQUERY:
204 return "CMD_ENDQUERY";
205 case CMD_RESETQUERYPOOL:
206 return "CMD_RESETQUERYPOOL";
207 case CMD_WRITETIMESTAMP:
208 return "CMD_WRITETIMESTAMP";
209 case CMD_INITATOMICCOUNTERS:
210 return "CMD_INITATOMICCOUNTERS";
211 case CMD_LOADATOMICCOUNTERS:
212 return "CMD_LOADATOMICCOUNTERS";
213 case CMD_SAVEATOMICCOUNTERS:
214 return "CMD_SAVEATOMICCOUNTERS";
215 case CMD_BEGINRENDERPASS:
216 return "CMD_BEGINRENDERPASS";
217 case CMD_ENDRENDERPASS:
218 return "CMD_ENDRENDERPASS";
219 case CMD_DBGMARKERBEGIN:
220 return "CMD_DBGMARKERBEGIN";
221 case CMD_DBGMARKEREND:
222 return "CMD_DBGMARKEREND";
223 default:
224 return "UNKNOWN";
225 }
226}
227// Block of code at start here for managing/tracking Pipeline state that this layer cares about
228// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600229#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600230#define MAX_SLOTS 2048
231#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
232
233static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
234
235// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
236// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
237// to that same cmd buffer by separate thread are not changing state from underneath us
238// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600239static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600240// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600241static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
242static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600244static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
245static PIPELINE_NODE* g_lastBoundPipeline = NULL;
246static uint64_t g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {0};
Dana Jansens4a3e0862015-07-30 13:22:15 -0700247static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600248#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
249
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600252// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600253static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600254{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600255 for (auto ii=dynamicVpStateMap.begin(); ii!=dynamicVpStateMap.end(); ++ii) {
256 delete[] (*ii).second.pScissors;
257 delete[] (*ii).second.pViewports;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600258 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600259 dynamicVpStateMap.clear();
260 dynamicRsStateMap.clear();
261 dynamicCbStateMap.clear();
262 dynamicDsStateMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600263}
264// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600265static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600266{
David Pinedof5997ab2015-04-27 16:36:17 -0600267 if (sampleMap.size() <= 0)
268 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600269 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600270 delete (*ii).second;
271 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600272 sampleMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600273}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600275{
276 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600277 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600278 loader_platform_thread_unlock_mutex(&globalLock);
279 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600280 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600282 return &imageMap[view.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600283 }
284}
285// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600286static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600287{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600288 if (imageMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -0600289 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600290 imageMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600291}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600293{
294 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600295 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600296 loader_platform_thread_unlock_mutex(&globalLock);
297 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600298 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600299 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600300 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301 }
302}
303// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600304static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600305{
David Pinedof5997ab2015-04-27 16:36:17 -0600306 if (bufferMap.size() <= 0)
307 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600308 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600309 delete (*ii).second;
310 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600311 bufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600312}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600314// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600316{
317 g_lastCmdBuffer[getTIDIndex()] = cb;
318 GLOBAL_CB_NODE* pCB = getCBNode(cb);
319 loader_platform_thread_lock_mutex(&globalLock);
320 g_lastGlobalCB = pCB;
321 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
322 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
323 if (g_pLastTouchedCB[i] == pCB) {
324 loader_platform_thread_unlock_mutex(&globalLock);
325 return;
326 }
327 }
328 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
329 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
330 loader_platform_thread_unlock_mutex(&globalLock);
331}
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600332static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600333{
334 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
335 if (pCB->drawCount[i])
336 return VK_TRUE;
337 }
338 return VK_FALSE;
339}
Tobin Ehlis97866202015-06-10 12:57:07 -0600340// Check object status for selected flag state
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600341static VkBool32 validate_status(GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600342{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600343 // If non-zero enable mask is present, check it against status but if enable_mask
344 // is 0 then no enable required so we should always just check status
345 if ((!enable_mask) || (enable_mask & pNode->status)) {
346 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600347 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
348 log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
349 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(pNode->cmdBuffer), fail_msg);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600350 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600351 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600352 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600353 return VK_TRUE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600354}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600355// For given dynamic state handle and type, return CreateInfo for that Dynamic State
356static void* getDynamicStateCreateInfo(const uint64_t handle, const DYNAMIC_STATE_BIND_POINT type)
357{
358 switch (type) {
359 case VK_STATE_BIND_POINT_VIEWPORT:
360 return (void*)&dynamicVpStateMap[handle];
361 case VK_STATE_BIND_POINT_RASTER:
362 return (void*)&dynamicRsStateMap[handle];
363 case VK_STATE_BIND_POINT_COLOR_BLEND:
364 return (void*)&dynamicCbStateMap[handle];
365 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
366 return (void*)&dynamicDsStateMap[handle];
367 default:
368 return NULL;
369 }
370}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600371// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600372static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600373{
374 GLOBAL_CB_NODE* pCB = getCBNode(cb);
375 if (pCB) {
376 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Mark Lobodzinski563d1bb2015-08-11 15:44:15 -0600378 if (pCB->lastBoundDynamicState[i]) {
379 void* pDynStateCI = getDynamicStateCreateInfo(pCB->lastBoundDynamicState[i], (DYNAMIC_STATE_BIND_POINT)i);
380 if (pDynStateCI) {
381 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
382 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
383 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
384 dynamic_display(pDynStateCI, " ").c_str());
385 } else {
386 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());
388 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600389 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600390 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
391 "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 -0600392 }
393 }
394 loader_platform_thread_unlock_mutex(&globalLock);
395 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600396}
397// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600398static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600399{
400 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600401 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600402 loader_platform_thread_unlock_mutex(&globalLock);
403 return NULL;
404 }
405 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600406 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600407}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600408// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600409static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
410 VkBool32 result;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600411 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");
412 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");
413 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");
414 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");
415 if (indexedDraw)
416 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");
417 return result;
418}
419// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600420static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600421 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600422 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600423 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
424 // Now complete other state checks
Tobin Ehlise4076782015-06-24 15:53:07 -0600425 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600426 result = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600427 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Mark Lobodzinskia98cf9b2015-08-04 10:54:43 -0600428 "Pipeline layout from last vkCmdBindDescriptorSets() (%#" PRIxLEAST64 ") does not match PSO Pipeline layout (%#" PRIxLEAST64 ") ", pCB->lastBoundPipelineLayout.handle, pPipe->graphicsPipelineCI.layout.handle);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600429 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600430 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600431 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 -0600432 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
433 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600434 return result;
435}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600436// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600437static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600438{
439 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600440 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600441 loader_platform_thread_unlock_mutex(&globalLock);
442 return NULL;
443 }
444 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600445 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600446}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600447// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600448static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600449{
450 // VS is required
451 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600452 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 -0600453 "Invalid Pipeline CreateInfo State: Vtx Shader required");
454 return VK_FALSE;
455 }
456 // Either both or neither TC/TE shaders should be defined
457 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
458 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600459 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 -0600460 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
461 return VK_FALSE;
462 }
463 // Compute shaders should be specified independent of Gfx shaders
464 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
465 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
466 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
467 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600468 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 -0600469 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
470 return VK_FALSE;
471 }
472 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
473 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
474 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
475 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600476 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 -0600477 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
478 return VK_FALSE;
479 }
480 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
481 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600482 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 -0600483 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
484 return VK_FALSE;
485 }
486 return VK_TRUE;
487}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600488// Init the pipeline mapping info based on pipeline create info LL tree
489// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600490static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600491{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600492 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
493 if (pBasePipeline) {
494 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600495 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600496 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
497 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600498 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600499 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600500 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600501
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600502 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600503 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600504 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600505
506 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
507 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
508
509 switch (pPSSCI->stage) {
510 case VK_SHADER_STAGE_VERTEX:
511 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
512 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600513 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600514 case VK_SHADER_STAGE_TESS_CONTROL:
515 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
516 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600517 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600518 case VK_SHADER_STAGE_TESS_EVALUATION:
519 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
520 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600521 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600522 case VK_SHADER_STAGE_GEOMETRY:
523 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
524 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600525 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600526 case VK_SHADER_STAGE_FRAGMENT:
527 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
528 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600529 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600530 case VK_SHADER_STAGE_COMPUTE:
531 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
532 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600533 break;
534 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600535 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600536 break;
537 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600538 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600539
540 if (pCreateInfo->pVertexInputState != NULL) {
541 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
542 // Copy embedded ptrs
543 pVICI = pCreateInfo->pVertexInputState;
544 pPipeline->vtxBindingCount = pVICI->bindingCount;
545 if (pPipeline->vtxBindingCount) {
546 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
547 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
548 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
549 }
550 pPipeline->vtxAttributeCount = pVICI->attributeCount;
551 if (pPipeline->vtxAttributeCount) {
552 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
553 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
554 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
555 }
556 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
557 }
Tony Barboure307f582015-07-10 15:29:03 -0600558 if (pCreateInfo->pInputAssemblyState != NULL) {
559 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600561 }
Tony Barboure307f582015-07-10 15:29:03 -0600562 if (pCreateInfo->pTessellationState != NULL) {
563 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
564 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600565 }
Tony Barboure307f582015-07-10 15:29:03 -0600566 if (pCreateInfo->pViewportState != NULL) {
567 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
568 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600569 }
Tony Barboure307f582015-07-10 15:29:03 -0600570 if (pCreateInfo->pRasterState != NULL) {
571 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
572 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600573 }
Tony Barboure307f582015-07-10 15:29:03 -0600574 if (pCreateInfo->pMultisampleState != NULL) {
575 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
576 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600577 }
Tony Barboure307f582015-07-10 15:29:03 -0600578 if (pCreateInfo->pColorBlendState != NULL) {
579 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600580 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600581 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600582 pPipeline->attachmentCount = pCBCI->attachmentCount;
583 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600584 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
585 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600586 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
587 }
Tony Barboure307f582015-07-10 15:29:03 -0600588 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600589 }
Tony Barboure307f582015-07-10 15:29:03 -0600590 if (pCreateInfo->pDepthStencilState != NULL) {
591 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
592 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600593 }
594
595 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
596 if (pCreateInfo->stageCount != 0) {
597 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
598 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
599 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
600 }
601
Tobin Ehlisde63c532015-06-18 15:59:33 -0600602 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600603}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600604
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600605// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600606static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600607{
David Pinedof5997ab2015-04-27 16:36:17 -0600608 if (pipelineMap.size() <= 0)
609 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600610 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600611 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
612 delete[] (*ii).second->graphicsPipelineCI.pStages;
613 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600614 if ((*ii).second->pVertexBindingDescriptions) {
615 delete[] (*ii).second->pVertexBindingDescriptions;
616 }
617 if ((*ii).second->pVertexAttributeDescriptions) {
618 delete[] (*ii).second->pVertexAttributeDescriptions;
619 }
620 if ((*ii).second->pAttachments) {
621 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600622 }
623 delete (*ii).second;
624 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600625 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600626}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600627// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600628static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600629{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600630 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600631 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
632 return pPipe->msStateCI.rasterSamples;
633 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600634 return 1;
635}
636// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600637static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600638{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600639 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600640 // Verify that any MSAA request in PSO matches sample# in bound FB
641 uint32_t psoNumSamples = getNumSamples(pipeline);
642 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600643 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800644 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
645 int subpassNumSamples = 0;
646 uint32_t i;
647
648 for (i = 0; i < pSD->colorCount; i++) {
649 uint32_t samples;
650
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600651 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800652 continue;
653
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600654 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800655 if (subpassNumSamples == 0) {
656 subpassNumSamples = samples;
657 } else if (subpassNumSamples != samples) {
658 subpassNumSamples = -1;
659 break;
660 }
661 }
662 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
663 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
664 if (subpassNumSamples == 0)
665 subpassNumSamples = samples;
666 else if (subpassNumSamples != samples)
667 subpassNumSamples = -1;
668 }
669
670 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600671 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
672 "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 -0600673 }
674 } else {
675 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
676 // Verify and flag error as appropriate
677 }
678 // TODO : Add more checks here
679 } else {
680 // TODO : Validate non-gfx pipeline updates
681 }
682}
683
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600684// Block of code at start here specifically for managing/tracking DSs
685
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600686// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600687static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600688{
689 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600690 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600691 loader_platform_thread_unlock_mutex(&globalLock);
692 return NULL;
693 }
694 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600695 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600696}
697// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600698static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600699{
700 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600701 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600702 loader_platform_thread_unlock_mutex(&globalLock);
703 return NULL;
704 }
705 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600706 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600707}
708
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600709static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600710 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600711 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600712 loader_platform_thread_unlock_mutex(&globalLock);
713 return NULL;
714 }
715 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600716 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600717}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600718// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600719static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600720{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600721 switch (pUpdateStruct->sType)
722 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800723 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
724 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600725 return 1;
726 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600727 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 -0600728 "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 -0600729 return 0;
730 }
731}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600732// For given update struct, return binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600733static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600734{
735 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{
750 switch (pUpdateStruct->sType)
751 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800752 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
753 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
754 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600755 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800756 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600757 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600758 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 -0600759 "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 -0600760 return 0;
761 }
762}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600763// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600764static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600765{
766 switch (pUpdateStruct->sType)
767 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800768 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
769 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
770 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600771 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800772 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600773 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600774 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 -0600775 "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 -0600776 return 0;
777 }
778}
779// For given Layout Node and binding, return index where that binding begins
780static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
781{
782 uint32_t offsetIndex = 0;
783 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800784 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600785 }
786 return offsetIndex;
787}
788// For given layout node and binding, return last index that is updated
789static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
790{
791 uint32_t offsetIndex = 0;
792 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800793 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600794 }
795 return offsetIndex-1;
796}
797// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600798static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600799{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600800 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600801}
802// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600803static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600804{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600805 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600806}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600807// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600808static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600809{
810 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600811 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600812 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600813 switch (pUpdateStruct->sType)
814 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800815 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
816 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600817 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800818 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
819 /* no need to validate */
820 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600821 break;
822 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600823 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 -0600824 "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 -0600825 return 0;
826 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600827 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600828 if (pLayout->pTypes[i] != actualType)
829 return 0;
830 }
831 return 1;
832}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600833// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
834// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
835// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600836static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600837{
838 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800839 VkWriteDescriptorSet* pWDS = NULL;
840 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600841 size_t array_size = 0;
842 size_t base_array_size = 0;
843 size_t total_array_size = 0;
844 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600845 switch (pUpdate->sType)
846 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800847 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
848 pWDS = new VkWriteDescriptorSet;
849 pNewNode = (GENERIC_HEADER*)pWDS;
850 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
851 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
852 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
853 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600854 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800855 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
856 pCDS = new VkCopyDescriptorSet;
857 pUpdate = (GENERIC_HEADER*)pCDS;
858 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600859 break;
860 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600861 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 -0600862 "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 -0600863 return NULL;
864 }
865 // Make sure that pNext for the end of shadow copy is NULL
866 pNewNode->pNext = NULL;
867 return pNewNode;
868}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800869// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600870static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600871{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800872 const VkWriteDescriptorSet *pWDS = NULL;
873 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600874 VkBool32 result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800875
876 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
877 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
878 else
879 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
880
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600881 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600882 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600883 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600884 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600885 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600886 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800887 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600888 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800889 g_lastBoundDescriptorSet = pSet->set;
890 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600891 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600892 // First verify valid update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600893 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600894 result = 0;
895 break;
896 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600897 // Make sure that binding is within bounds
Tobin Ehlisde63c532015-06-18 15:59:33 -0600898 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600899 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 -0600900 "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 -0600901 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600902 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600903 // Next verify that update falls within size of given binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600904 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour29b12062015-07-13 13:37:24 -0600905 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600906 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600907 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600908 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 -0600909 "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 -0600910 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600911 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600912 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlisde63c532015-06-18 15:59:33 -0600913 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600914 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 -0600915 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600916 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600917 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600918 // Save the update info
919 // TODO : Info message that update successful
920 // Create new update struct for this set's shadow copy
Tobin Ehlisde63c532015-06-18 15:59:33 -0600921 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600922 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600923 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 -0600924 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600925 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600926 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600927 // Insert shadow node into LL of updates for this set
928 pNewNode->pNext = pSet->pUpdateStructs;
929 pSet->pUpdateStructs = pNewNode;
930 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisde63c532015-06-18 15:59:33 -0600931 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600932 assert(j<pSet->descriptorCount);
933 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600934 }
935 }
936 }
937 }
938 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600939 }
940 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600941 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600942}
943// Free the shadowed update node for this Set
944// NOTE : Calls to this function should be wrapped in mutex
945static void freeShadowUpdateTree(SET_NODE* pSet)
946{
947 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
948 pSet->pUpdateStructs = NULL;
949 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
950 // Clear the descriptor mappings as they will now be invalid
951 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
952 while(pShadowUpdate) {
953 pFreeUpdate = pShadowUpdate;
954 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
955 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800956 VkWriteDescriptorSet * pWDS = NULL;
957 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600958 void** ppToFree = NULL;
959 switch (pFreeUpdate->sType)
960 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800961 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
962 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
963 if (pWDS->pDescriptors)
964 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600965 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800966 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600967 break;
968 default:
969 assert(0);
970 break;
971 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600972 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600973 }
974}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600975// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600976// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600977static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600978{
David Pinedof5997ab2015-04-27 16:36:17 -0600979 if (poolMap.size() <= 0)
980 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600981 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600982 SET_NODE* pSet = (*ii).second->pSets;
983 SET_NODE* pFreeSet = pSet;
984 while (pSet) {
985 pFreeSet = pSet;
986 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600987 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600988 // Free Update shadow struct tree
989 freeShadowUpdateTree(pFreeSet);
990 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200991 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600992 }
993 delete pFreeSet;
994 }
995 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200996 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600997 }
998 delete (*ii).second;
999 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001000 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001001}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001002// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001003// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001004static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001005{
David Pinedof5997ab2015-04-27 16:36:17 -06001006 if (layoutMap.size() <= 0)
1007 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001008 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001009 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001010 if (pLayout->createInfo.pBinding) {
1011 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1012 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1013 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1014 }
1015 delete[] pLayout->createInfo.pBinding;
1016 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001018 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019 }
1020 delete pLayout;
1021 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001022 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023}
1024// Currently clearing a set is removing all previous updates to that set
1025// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001026static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001027{
1028 SET_NODE* pSet = getSetNode(set);
1029 if (!pSet) {
1030 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001031 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001032 loader_platform_thread_lock_mutex(&globalLock);
1033 freeShadowUpdateTree(pSet);
1034 loader_platform_thread_unlock_mutex(&globalLock);
1035 }
1036}
1037
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001038static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001039{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001040 POOL_NODE* pPool = getPoolNode(pool);
1041 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001042 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1043 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001044 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001045 // For every set off of this pool, clear it
1046 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001047 while (pSet) {
1048 clearDescriptorSet(pSet->set);
1049 }
1050 }
1051}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001052// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001053static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001054{
1055 loader_platform_thread_lock_mutex(&globalLock);
1056 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1057 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001058 // TODO : How to pass cb as srcObj here?
1059 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1060 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001061 return NULL;
1062 }
1063 loader_platform_thread_unlock_mutex(&globalLock);
1064 return cmdBufferMap[cb];
1065}
1066// Free all CB Nodes
1067// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001068static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001069{
David Pinedof5997ab2015-04-27 16:36:17 -06001070 if (cmdBufferMap.size() <= 0)
1071 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001072 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001073 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1074 while (!cmd_node_list.empty()) {
1075 CMD_NODE* cmd_node = cmd_node_list.back();
1076 delete cmd_node;
1077 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001078 }
1079 delete (*ii).second;
1080 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001081 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001082}
Tobin Ehlise42007c2015-06-19 13:00:59 -06001083static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1084{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001085 // TODO : How to pass cb as srcObj here?
1086 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 -06001087 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1088}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001089static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1090{
1091 CMD_NODE* pCmd = new CMD_NODE;
1092 if (pCmd) {
1093 // init cmd node and append to end of cmd LL
1094 memset(pCmd, 0, sizeof(CMD_NODE));
1095 pCmd->cmdNumber = ++pCB->numCmds;
1096 pCmd->type = cmd;
1097 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001098 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001099 // TODO : How to pass cb as srcObj here?
1100 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1101 "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 -06001102 }
1103}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001104static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001105{
1106 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1107 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001108 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1109 while (!cmd_list.empty()) {
1110 delete cmd_list.back();
1111 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001112 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001113 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001114 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001115 VkFlags saveFlags = pCB->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001116 VkCmdPool savedPool = pCB->pool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001117 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1118 pCB->cmdBuffer = cb;
1119 pCB->flags = saveFlags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001120 pCB->pool = savedPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001121 pCB->lastVtxBinding = MAX_BINDING;
1122 }
1123}
Tobin Ehlis97866202015-06-10 12:57:07 -06001124// Set PSO-related status bits for CB
1125static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1126{
1127 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1128 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1129 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1130 }
1131 }
1132 if (pPipe->dsStateCI.depthWriteEnable) {
1133 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1134 }
1135}
1136// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001137static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001138 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1139 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1140 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1141 pNode->status |= CBSTATUS_RASTER_BOUND;
1142 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1143 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1144 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1145 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1146 }
1147}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001148// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001149static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001150{
1151 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1152 if (pCB) {
1153 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1154 if (!pPipeTrav) {
1155 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001156 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001157 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001158 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001159 }
1160 }
1161}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001162// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001163static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001164{
1165 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1166 if (pCB && pCB->lastBoundPipeline) {
1167 // First verify that we have a Node for bound pipeline
1168 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001169 if (!pPipeTrav) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001170 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1171 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001172 return false;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001173 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001174 // Verify Vtx binding
1175 if (MAX_BINDING != pCB->lastVtxBinding) {
1176 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1177 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001178 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 -06001179 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001180 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001181 }
1182 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001183 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 -06001184 "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 -06001185 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001186 }
1187 }
1188 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001189 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001190 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001191 }
1192 }
1193 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001194 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001195 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001196 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001197}
1198// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001199static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001200{
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001201 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.
1202 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001203 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001204 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001205 POOL_NODE* pPool = getPoolNode(pSet->pool);
1206 // Print out pool details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001207 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1208 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001209 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001210 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001211 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001212 // Print out set details
1213 char prefix[10];
1214 uint32_t index = 0;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001215 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1216 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001217 LAYOUT_NODE* pLayout = pSet->pLayout;
1218 // Print layout details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001219 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1220 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001221 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001222 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001223 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001224 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001225 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001226 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1227 if (pUpdate) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001228 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1229 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001230 sprintf(prefix, " [UC] ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001231 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001232 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001233 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001234 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001235 if (0 != pSet->descriptorCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001236 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1237 "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 -06001238 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001239 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1240 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001241 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001242 }
1243 }
1244}
1245
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001246static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001247{
1248 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001249 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001250 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001251 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001252 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001253 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1254 // TODO : Need to pass cb as srcObj here
1255 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 -06001256 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001257 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001258 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001259 // Nothing to print
1260 }
1261}
1262
1263
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001264static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001265{
Mark Lobodzinskifdb20cf2015-08-07 17:11:09 -06001266 printDSConfig(cb);
1267 printPipeline(cb);
1268 printDynamicState(cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001269}
1270
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001271static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001272{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001273 uint32_t report_flags = 0;
1274 uint32_t debug_action = 0;
1275 FILE *log_output = NULL;
1276 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001277 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001278 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1279 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001280
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001281 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001282 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001283 option_str = getLayerOption("DrawStateLogFilename");
1284 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001285 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001286 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001287 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001288 if (log_output == NULL)
1289 log_output = stdout;
1290
1291 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 -06001292 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001293
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001294 if (!globalLockInitialized)
1295 {
1296 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001297 // suggestion is to call this during vkCreateInstance(), and then we
1298 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001299 // that the layer have per-instance locks. We need to come back and
1300 // address this soon.
1301 loader_platform_thread_create_mutex(&globalLock);
1302 globalLockInitialized = 1;
1303 }
1304}
1305
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001306VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1307{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001308 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001309 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1310
1311 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001312 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1313 my_data->report_data = debug_report_create_instance(
1314 pTable,
1315 *pInstance,
1316 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001317 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001318
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001319 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001320 }
1321 return result;
1322}
1323
Jon Ashburne0fa2282015-05-20 09:00:28 -06001324/* hook DestroyInstance to remove tableInstanceMap entry */
1325VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1326{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001327 dispatch_key key = get_dispatch_key(instance);
1328 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1329 VkResult res = pTable->DestroyInstance(instance);
1330
1331 // Clean up logging callback, if any
1332 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1333 if (my_data->logging_callback) {
1334 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1335 }
1336
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001337 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001338 layer_data_map.erase(pTable);
1339
1340 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001341 return res;
1342}
1343
Jon Ashburnf0615e22015-05-25 14:11:37 -06001344static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1345{
Tony Barbour29b12062015-07-13 13:37:24 -06001346 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001347 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001348 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001349
1350 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001351 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001352 /* Found a matching extension name, mark it enabled and init dispatch table*/
1353 initDebugMarkerTable(device);
1354 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001355 }
1356
1357 }
1358}
1359
Tony Barbour8205d902015-04-16 15:59:00 -06001360VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001361{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001362 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1363 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001364 if (result == VK_SUCCESS) {
1365 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1366 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1367 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1368 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001369 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001370 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001371 return result;
1372}
1373
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001374VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001375{
1376 // Free all the memory
1377 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001378 deletePipelines();
1379 deleteSamplers();
1380 deleteImages();
1381 deleteBuffers();
1382 deleteCmdBuffers();
1383 deleteDynamicState();
1384 deletePools();
1385 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001386 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001387
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001388 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001389 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1390 VkResult result = pDisp->DestroyDevice(device);
1391 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001392 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001393 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001394 return result;
1395}
1396
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001397static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001398 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001399 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001400 VK_API_VERSION,
1401 VK_MAKE_VERSION(0, 1, 0),
1402 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001403 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001404};
1405
Tony Barbour426b9052015-06-24 16:06:58 -06001406VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001407 const char *pLayerName,
1408 uint32_t *pCount,
1409 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001410{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001411 /* DrawState does not have any global extensions */
1412 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1413}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001414
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001415VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1416 uint32_t *pCount,
1417 VkLayerProperties* pProperties)
1418{
1419 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1420 ds_global_layers,
1421 pCount, pProperties);
1422}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001423
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001424static const VkExtensionProperties ds_device_extensions[] = {
1425 {
1426 DEBUG_MARKER_EXTENSION_NAME,
1427 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001428 }
1429};
1430
1431static const VkLayerProperties ds_device_layers[] = {
1432 {
1433 "DrawState",
1434 VK_API_VERSION,
1435 VK_MAKE_VERSION(0, 1, 0),
1436 "Validation layer: DrawState",
1437 }
1438};
1439
1440VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1441 VkPhysicalDevice physicalDevice,
1442 const char* pLayerName,
1443 uint32_t* pCount,
1444 VkExtensionProperties* pProperties)
1445{
1446 /* Mem tracker does not have any physical device extensions */
1447 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1448 pCount, pProperties);
1449}
1450
1451VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1452 VkPhysicalDevice physicalDevice,
1453 uint32_t* pCount,
1454 VkLayerProperties* pProperties)
1455{
1456 /* Mem tracker's physical device layers are the same as global */
1457 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1458 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001459}
1460
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001461VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001462{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001463 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001464 for (uint32_t i=0; i < cmdBufferCount; i++) {
1465 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001466 pCB = getCBNode(pCmdBuffers[i]);
1467 loader_platform_thread_lock_mutex(&globalLock);
1468 if (CB_UPDATE_COMPLETE != pCB->state) {
1469 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001470 // TODO : How to pass cb as srcObj?
1471 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1472 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlise90b1712015-05-27 14:30:06 -06001473 loader_platform_thread_unlock_mutex(&globalLock);
1474 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001475 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001476 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001477 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001478
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001479 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001480 return result;
1481}
1482
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001483VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001484{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001485 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1486 // TODO : Clean up any internal data structures using this obj.
1487 return result;
1488}
1489
1490VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1491{
1492 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1493 // TODO : Clean up any internal data structures using this obj.
1494 return result;
1495}
1496
1497VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1498{
1499 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1500 // TODO : Clean up any internal data structures using this obj.
1501 return result;
1502}
1503
1504VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1505{
1506 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1507 // TODO : Clean up any internal data structures using this obj.
1508 return result;
1509}
1510
1511VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1512{
1513 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1514 // TODO : Clean up any internal data structures using this obj.
1515 return result;
1516}
1517
1518VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1519{
1520 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1521 // TODO : Clean up any internal data structures using this obj.
1522 return result;
1523}
1524
1525VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1526{
1527 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1528 // TODO : Clean up any internal data structures using this obj.
1529 return result;
1530}
1531
1532VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1533{
1534 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1535 // TODO : Clean up any internal data structures using this obj.
1536 return result;
1537}
1538
1539VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1540{
1541 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1542 // TODO : Clean up any internal data structures using this obj.
1543 return result;
1544}
1545
1546VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1547{
1548 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1549 // TODO : Clean up any internal data structures using this obj.
1550 return result;
1551}
1552
1553VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1554{
1555 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1556 // TODO : Clean up any internal data structures using this obj.
1557 return result;
1558}
1559
1560VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1561{
1562 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1563 // TODO : Clean up any internal data structures using this obj.
1564 return result;
1565}
1566
1567VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1568{
1569 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1570 // TODO : Clean up any internal data structures using this obj.
1571 return result;
1572}
1573
1574VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1575{
1576 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1577 // TODO : Clean up any internal data structures using this obj.
1578 return result;
1579}
1580
1581VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1582{
1583 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1584 // TODO : Clean up any internal data structures using this obj.
1585 return result;
1586}
1587
1588VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1589{
1590 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1591 // TODO : Clean up any internal data structures using this obj.
1592 return result;
1593}
1594
1595VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1596{
1597 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1598 // TODO : Clean up any internal data structures using this obj.
1599 return result;
1600}
1601
1602VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1603{
1604 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1605 // TODO : Clean up any internal data structures using this obj.
1606 return result;
1607}
1608
1609VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1610{
1611 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1612 // TODO : Clean up any internal data structures using this obj.
1613 return result;
1614}
1615
1616VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1617{
1618 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1619 // TODO : Clean up any internal data structures using this obj.
1620 return result;
1621}
1622
1623VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1624{
1625 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1626 // TODO : Clean up any internal data structures using this obj.
1627 return result;
1628}
1629
1630VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1631{
1632 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1633 // TODO : Clean up any internal data structures using this obj.
1634 return result;
1635}
1636
1637VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1638{
1639 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1640 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001641 return result;
1642}
1643
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001644VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001645{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001646 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001647 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001648 loader_platform_thread_lock_mutex(&globalLock);
1649 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1650 pNewNode->buffer = *pView;
1651 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001652 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001653 loader_platform_thread_unlock_mutex(&globalLock);
1654 }
1655 return result;
1656}
1657
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001658VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001659{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001660 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001661 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001662 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001663 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001664 loader_platform_thread_unlock_mutex(&globalLock);
1665 }
1666 return result;
1667}
1668
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001669VkResult VKAPI vkCreateAttachmentView(
1670 VkDevice device,
1671 const VkAttachmentViewCreateInfo* pCreateInfo,
1672 VkAttachmentView* pView)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001673{
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001674 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001675 if (VK_SUCCESS == result) {
1676 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001677 viewMap[pView->handle] = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001678 loader_platform_thread_unlock_mutex(&globalLock);
1679 }
1680 return result;
1681}
1682
Jon Ashburn0d60d272015-07-09 15:02:25 -06001683//TODO handle pipeline caches
1684VkResult VKAPI vkCreatePipelineCache(
1685 VkDevice device,
1686 const VkPipelineCacheCreateInfo* pCreateInfo,
1687 VkPipelineCache* pPipelineCache)
1688{
1689 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1690 return result;
1691}
1692
1693VkResult VKAPI vkDestroyPipelineCache(
1694 VkDevice device,
1695 VkPipelineCache pipelineCache)
1696{
1697 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1698 return result;
1699}
1700
1701size_t VKAPI vkGetPipelineCacheSize(
1702 VkDevice device,
1703 VkPipelineCache pipelineCache)
1704{
1705 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1706 return size;
1707}
1708
1709VkResult VKAPI vkGetPipelineCacheData(
1710 VkDevice device,
1711 VkPipelineCache pipelineCache,
1712 void* pData)
1713{
1714 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1715 return result;
1716}
1717
1718VkResult VKAPI vkMergePipelineCaches(
1719 VkDevice device,
1720 VkPipelineCache destCache,
1721 uint32_t srcCacheCount,
1722 const VkPipelineCache* pSrcCaches)
1723{
1724 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1725 return result;
1726}
1727
1728VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001729{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001730 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001731 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001732 // The order of operations here is a little convoluted but gets the job done
1733 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1734 // 2. Create state is then validated (which uses flags setup during shadowing)
1735 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1736 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001737 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001738 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001739 loader_platform_thread_unlock_mutex(&globalLock);
1740 if (VK_TRUE == valid) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001741 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001742 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1743 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001744 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001745 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001746 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001747 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001748 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001749 if (pPipeNode) {
1750 // If we allocated a pipeNode, need to clean it up here
1751 delete[] pPipeNode->pVertexBindingDescriptions;
1752 delete[] pPipeNode->pVertexAttributeDescriptions;
1753 delete[] pPipeNode->pAttachments;
1754 delete pPipeNode;
1755 }
1756 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001757 return result;
1758}
1759
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001760VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001761{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001762 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001763 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001764 loader_platform_thread_lock_mutex(&globalLock);
1765 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1766 pNewNode->sampler = *pSampler;
1767 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001768 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001769 loader_platform_thread_unlock_mutex(&globalLock);
1770 }
1771 return result;
1772}
1773
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001774VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001775{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001776 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001778 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1779 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001780 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 -06001781 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001782 }
1783 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001784 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1785 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1786 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001787 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001788 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001789 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001790 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001791 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001792 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1793 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001794 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001795 }
1796 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001797 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001798 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001799 uint32_t j = 0;
1800 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001801 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001802 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001803 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001804 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001805 }
1806 }
1807 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001809 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1810 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001811 // Put new node at Head of global Layer list
1812 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001813 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 loader_platform_thread_unlock_mutex(&globalLock);
1815 }
1816 return result;
1817}
1818
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001819VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001821 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001822 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001823 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001824 }
1825 return result;
1826}
1827
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001828VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001829{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001830 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001831 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001832 // Insert this pool into Global Pool LL at head
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001833 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1834 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001836 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001837 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001838 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 -06001839 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001840 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001841 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001842 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1843 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001845 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1846 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1848 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001849 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001850 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001851 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001852 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853 }
1854 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001855 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001856 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001857 }
1858 return result;
1859}
1860
Mike Stroyan230e6252015-04-17 12:36:38 -06001861VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001863 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001864 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001865 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001866 }
1867 return result;
1868}
1869
Cody Northropc8aa4a52015-08-03 12:47:29 -06001870VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001872 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1873 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001874 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1875 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001876 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1877 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001878 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001879 if (count == 0) {
1880 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1881 "AllocDescriptorSets called with 0 count");
1882 }
1883 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001884 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1885 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001886 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001887 SET_NODE* pNewNode = new SET_NODE;
1888 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001889 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 -06001890 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001891 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001892 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001893 // Insert set at head of Set LL for this pool
1894 pNewNode->pNext = pPoolNode->pSets;
1895 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001896 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1897 if (NULL == pLayout) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001898 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1899 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001900 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001901 pNewNode->pLayout = pLayout;
1902 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 pNewNode->set = pDescriptorSets[i];
1904 pNewNode->setUsage = setUsage;
1905 pNewNode->descriptorCount = pLayout->endIndex + 1;
1906 if (pNewNode->descriptorCount) {
1907 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1908 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1909 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1910 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001911 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001912 }
1913 }
1914 }
1915 }
1916 return result;
1917}
1918
Tony Barbourb857d312015-07-10 10:50:45 -06001919VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1920{
1921 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1922 // TODO : Clean up any internal data structures using this obj.
1923 return result;
1924}
1925
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001926VK_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 -06001927{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001928 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1929 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001930 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001931 }
1932 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001933}
1934
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001935VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001936{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001937 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001938 VkDynamicViewportStateCreateInfo local_ci;
1939 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1940 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1941 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1942 loader_platform_thread_lock_mutex(&globalLock);
1943 dynamicVpStateMap[pState->handle] = local_ci;
1944 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001945 return result;
1946}
1947
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001948VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRasterStateCreateInfo* pCreateInfo, VkDynamicRasterState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001949{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001950 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001951 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
1952 loader_platform_thread_lock_mutex(&globalLock);
1953 dynamicRsStateMap[pState->handle] = *pCreateInfo;
1954 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001955 return result;
1956}
1957
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001958VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicColorBlendStateCreateInfo* pCreateInfo, VkDynamicColorBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001959{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001960 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001961 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
1962 loader_platform_thread_lock_mutex(&globalLock);
1963 dynamicCbStateMap[pState->handle] = *pCreateInfo;
1964 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001965 return result;
1966}
1967
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001968VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDepthStencilStateCreateInfo* pCreateInfo, VkDynamicDepthStencilState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001969{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001970 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001971 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
1972 loader_platform_thread_lock_mutex(&globalLock);
1973 dynamicDsStateMap[pState->handle] = *pCreateInfo;
1974 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975 return result;
1976}
1977
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001978VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001979{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001980 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001981 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001982 loader_platform_thread_lock_mutex(&globalLock);
1983 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1984 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1985 pCB->cmdBuffer = *pCmdBuffer;
1986 pCB->flags = pCreateInfo->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001987 pCB->pool = pCreateInfo->cmdPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001988 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001989 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001990 cmdBufferMap[*pCmdBuffer] = pCB;
1991 loader_platform_thread_unlock_mutex(&globalLock);
1992 updateCBTracking(*pCmdBuffer);
1993 }
1994 return result;
1995}
1996
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001997VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001998{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001999 // Validate command buffer level
2000 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2001 if (pCB) {
2002 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
2003 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2004 // These should be NULL for a Primary CB
2005 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2006 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2007 }
2008 } else {
2009 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2010 // These should NOT be null for an Secondary CB
2011 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2012 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2013 }
2014 }
2015 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002016 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002017 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002018 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2019 if (pCB) {
2020 if (CB_NEW != pCB->state)
2021 resetCB(cmdBuffer);
2022 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002023 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002024 // TODO : Need to pass cmdBuffer as objType here
2025 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 -06002026 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002027 }
2028 updateCBTracking(cmdBuffer);
2029 }
2030 return result;
2031}
2032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002033VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002034{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002035 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2036 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2037 if (pCB) {
2038 if (pCB->state == CB_UPDATE_ACTIVE) {
2039 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2040 if (VK_SUCCESS == result) {
2041 updateCBTracking(cmdBuffer);
2042 pCB->state = CB_UPDATE_COMPLETE;
2043 // Reset CB status flags
2044 pCB->status = 0;
2045 printCB(cmdBuffer);
2046 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002047 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002048 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002049 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002050 }
2051 return result;
2052}
2053
Cody Northropf02f9f82015-07-09 18:08:05 -06002054VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002055{
Cody Northropf02f9f82015-07-09 18:08:05 -06002056 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002057 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002058 resetCB(cmdBuffer);
2059 updateCBTracking(cmdBuffer);
2060 }
2061 return result;
2062}
2063
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002064VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002065{
2066 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2067 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002068 if (pCB->state == CB_UPDATE_ACTIVE) {
2069 updateCBTracking(cmdBuffer);
2070 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002071 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002072 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2073 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002074 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002075 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2076 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002077 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002078 PIPELINE_NODE* pPN = getPipeline(pipeline);
2079 if (pPN) {
2080 pCB->lastBoundPipeline = pipeline;
2081 loader_platform_thread_lock_mutex(&globalLock);
2082 set_cb_pso_status(pCB, pPN);
2083 g_lastBoundPipeline = pPN;
2084 loader_platform_thread_unlock_mutex(&globalLock);
2085 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2086 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2087 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002088 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2089 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002090 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002091 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002092 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002093 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002094 }
2095 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002096}
2097
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002098VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002099{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002100 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2101 if (pCB) {
2102 if (pCB->state == CB_UPDATE_ACTIVE) {
2103 updateCBTracking(cmdBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002104 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002105 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002106 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2107 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002108 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002109 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002110 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2111 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002112 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 -06002113 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002114 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002115 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2116 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002117 }
2118 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002119 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002120 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002121 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002122 }
2123 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002124}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002125VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicRasterState(VkCmdBuffer cmdBuffer, VkDynamicRasterState dynamicRasterState)
2126{
2127 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2128 if (pCB) {
2129 if (pCB->state == CB_UPDATE_ACTIVE) {
2130 updateCBTracking(cmdBuffer);
2131 addCmd(pCB, CMD_BINDDYNAMICRASTERSTATE);
2132 if (!pCB->activeRenderPass) {
2133 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2134 "Incorrect call to vkCmdBindDynamicRasterState() without an active RenderPass.");
2135 }
2136 loader_platform_thread_lock_mutex(&globalLock);
2137 pCB->status |= CBSTATUS_RASTER_BOUND;
2138 if (dynamicRsStateMap.find(dynamicRasterState.handle) == dynamicRsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002139 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 -06002140 "Unable to find VkDynamicRasterState object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2141 } else {
2142 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2143 g_lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2144 }
2145 loader_platform_thread_unlock_mutex(&globalLock);
2146 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2147 } else {
2148 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicRasterState()");
2149 }
2150 }
2151}
2152VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(VkCmdBuffer cmdBuffer, VkDynamicColorBlendState dynamicColorBlendState)
2153{
2154 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2155 if (pCB) {
2156 if (pCB->state == CB_UPDATE_ACTIVE) {
2157 updateCBTracking(cmdBuffer);
2158 addCmd(pCB, CMD_BINDDYNAMICCOLORBLENDSTATE);
2159 if (!pCB->activeRenderPass) {
2160 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2161 "Incorrect call to vkCmdBindDynamicColorBlendState() without an active RenderPass.");
2162 }
2163 loader_platform_thread_lock_mutex(&globalLock);
2164 pCB->status |= CBSTATUS_COLOR_BLEND_BOUND;
2165 if (dynamicCbStateMap.find(dynamicColorBlendState.handle) == dynamicCbStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002166 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 -06002167 "Unable to find VkDynamicColorBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2168 } else {
2169 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2170 g_lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2171 }
2172 loader_platform_thread_unlock_mutex(&globalLock);
2173 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2174 } else {
2175 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicColorBlendState()");
2176 }
2177 }
2178}
2179VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(VkCmdBuffer cmdBuffer, VkDynamicDepthStencilState dynamicDepthStencilState)
2180{
2181 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2182 if (pCB) {
2183 if (pCB->state == CB_UPDATE_ACTIVE) {
2184 updateCBTracking(cmdBuffer);
2185 addCmd(pCB, CMD_BINDDYNAMICDEPTHSTENCILSTATE);
2186 if (!pCB->activeRenderPass) {
2187 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2188 "Incorrect call to vkCmdBindDynamicDepthStencilState() without an active RenderPass.");
2189 }
2190 loader_platform_thread_lock_mutex(&globalLock);
2191 pCB->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
2192 if (dynamicDsStateMap.find(dynamicDepthStencilState.handle) == dynamicDsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002193 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 -06002194 "Unable to find VkDynamicDepthStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2195 } else {
2196 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2197 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2198 }
2199 loader_platform_thread_unlock_mutex(&globalLock);
2200 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
2201 } else {
2202 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthStencilState()");
2203 }
2204 }
2205}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002206VK_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 -06002207{
2208 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2209 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002210 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002211 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002212 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2213 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002214 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002215 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 -06002216 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2217 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002218 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002219 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2220 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002221 loader_platform_thread_lock_mutex(&globalLock);
2222 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002223 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002224 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2225 g_lastBoundDescriptorSet = pDescriptorSets[i];
2226 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002227 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2228 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002229 if (!pSet->pUpdateStructs)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002230 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2231 "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 -06002232 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002233 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2234 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002235 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002236 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002237 updateCBTracking(cmdBuffer);
2238 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis9bde5922015-06-22 18:00:14 -06002239 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 -06002240 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002241 } else {
2242 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002243 }
2244 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002245}
2246
Tony Barbour8205d902015-04-16 15:59:00 -06002247VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002248{
2249 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2250 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002251 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002252 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002253 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 -06002254 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2255 } else {
2256 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2257 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002258 updateCBTracking(cmdBuffer);
2259 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002260 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2261 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002262 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002263 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2264 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002265 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266}
2267
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002268VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2269 VkCmdBuffer cmdBuffer,
2270 uint32_t startBinding,
2271 uint32_t bindingCount,
2272 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002273 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002274{
2275 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2276 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002277 if (pCB->state == CB_UPDATE_ACTIVE) {
2278 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002279 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002280 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 -06002281 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2282 } else {
2283 pCB->lastVtxBinding = startBinding + bindingCount -1;
2284 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002285 updateCBTracking(cmdBuffer);
2286 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002287 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2288 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002289 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002290 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002291 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002292 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002293 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002294}
2295
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002296VK_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 -06002297{
2298 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002299 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002300 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002301 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002302 pCB->drawCount[DRAW]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002303 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002304 // TODO : Need to pass cmdBuffer as srcObj here
2305 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002306 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2307 synchAndPrintDSConfig(cmdBuffer);
2308 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002309 updateCBTracking(cmdBuffer);
2310 addCmd(pCB, CMD_DRAW);
2311 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002312 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002313 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002314 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2315 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002316 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002317}
2318
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002319VK_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 -06002320{
2321 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002322 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002323 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002324 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002325 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002326 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002327 // TODO : Need to pass cmdBuffer as srcObj here
2328 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002329 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2330 synchAndPrintDSConfig(cmdBuffer);
2331 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002332 updateCBTracking(cmdBuffer);
2333 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002334 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2335 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002336 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002337 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2338 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002339 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002340}
2341
Tony Barbour8205d902015-04-16 15:59:00 -06002342VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002343{
2344 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002345 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002346 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002347 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002348 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002349 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002350 // TODO : Need to pass cmdBuffer as srcObj here
2351 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002352 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2353 synchAndPrintDSConfig(cmdBuffer);
2354 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002355 updateCBTracking(cmdBuffer);
2356 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002357 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2358 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002359 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002360 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2361 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002362 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002363}
2364
Tony Barbour8205d902015-04-16 15:59:00 -06002365VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002366{
2367 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002368 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002369 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002370 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002371 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002372 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002373 // TODO : Need to pass cmdBuffer as srcObj here
2374 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 -06002375 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2376 synchAndPrintDSConfig(cmdBuffer);
2377 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002378 updateCBTracking(cmdBuffer);
2379 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2380 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002381 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002382 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002383 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2384 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002385 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002386}
2387
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002388VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002389{
2390 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2391 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002392 if (pCB->state == CB_UPDATE_ACTIVE) {
2393 updateCBTracking(cmdBuffer);
2394 addCmd(pCB, CMD_DISPATCH);
2395 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002396 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002397 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2398 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002399 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002400}
2401
Tony Barbour8205d902015-04-16 15:59:00 -06002402VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002403{
2404 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2405 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002406 if (pCB->state == CB_UPDATE_ACTIVE) {
2407 updateCBTracking(cmdBuffer);
2408 addCmd(pCB, CMD_DISPATCHINDIRECT);
2409 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002410 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002411 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2412 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002413 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002414}
2415
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002416VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* 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_COPYBUFFER);
2423 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, 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 vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2431 VkImage srcImage,
2432 VkImageLayout srcImageLayout,
2433 VkImage destImage,
2434 VkImageLayout destImageLayout,
2435 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002436{
2437 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2438 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002439 if (pCB->state == CB_UPDATE_ACTIVE) {
2440 updateCBTracking(cmdBuffer);
2441 addCmd(pCB, CMD_COPYIMAGE);
2442 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002443 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002444 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2445 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002446 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447}
2448
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002449VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2450 VkImage srcImage, VkImageLayout srcImageLayout,
2451 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002452 uint32_t regionCount, const VkImageBlit* pRegions,
2453 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002454{
2455 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2456 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002457 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002458 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002459 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2460 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002461 } else {
2462 updateCBTracking(cmdBuffer);
2463 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002464 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 -06002465 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002466 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002467 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2468 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002469 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002470}
2471
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002472VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2473 VkBuffer srcBuffer,
2474 VkImage destImage, VkImageLayout destImageLayout,
2475 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002476{
2477 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2478 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002479 if (pCB->state == CB_UPDATE_ACTIVE) {
2480 updateCBTracking(cmdBuffer);
2481 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2482 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002483 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002484 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2485 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002486 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002487}
2488
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002489VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2490 VkImage srcImage, VkImageLayout srcImageLayout,
2491 VkBuffer destBuffer,
2492 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002493{
2494 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2495 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002496 if (pCB->state == CB_UPDATE_ACTIVE) {
2497 updateCBTracking(cmdBuffer);
2498 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2499 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002500 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002501 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2502 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002503 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002504}
2505
Tony Barbour8205d902015-04-16 15:59:00 -06002506VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002507{
2508 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2509 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002510 if (pCB->state == CB_UPDATE_ACTIVE) {
2511 updateCBTracking(cmdBuffer);
2512 addCmd(pCB, CMD_UPDATEBUFFER);
2513 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002514 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002515 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2516 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002517 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002518}
2519
Tony Barbour8205d902015-04-16 15:59:00 -06002520VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002521{
2522 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2523 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002524 if (pCB->state == CB_UPDATE_ACTIVE) {
2525 updateCBTracking(cmdBuffer);
2526 addCmd(pCB, CMD_FILLBUFFER);
2527 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002528 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002529 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2530 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002532}
2533
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002534VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2535 VkCmdBuffer cmdBuffer,
2536 uint32_t colorAttachment,
2537 VkImageLayout imageLayout,
2538 const VkClearColorValue* pColor,
2539 uint32_t rectCount,
2540 const VkRect3D* pRects)
2541{
2542 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2543 if (pCB) {
2544 if (pCB->state == CB_UPDATE_ACTIVE) {
2545 // Warn if this is issued prior to Draw Cmd
2546 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002547 // TODO : cmdBuffer should be srcObj
2548 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 -06002549 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2550 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2551 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002552 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002553 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 -06002554 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2555 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2556 } else {
2557 updateCBTracking(cmdBuffer);
2558 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2559 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2560 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002561 } else {
2562 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2563 }
2564 }
2565}
2566
2567VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2568 VkCmdBuffer cmdBuffer,
2569 VkImageAspectFlags imageAspectMask,
2570 VkImageLayout imageLayout,
2571 float depth,
2572 uint32_t stencil,
2573 uint32_t rectCount,
2574 const VkRect3D* pRects)
2575{
2576 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2577 if (pCB) {
2578 if (pCB->state == CB_UPDATE_ACTIVE) {
2579 // Warn if this is issued prior to Draw Cmd
2580 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002581 // TODO : cmdBuffer should be srcObj
2582 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 -06002583 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2584 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2585 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002586 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002587 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 -06002588 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2589 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2590 } else {
2591 updateCBTracking(cmdBuffer);
2592 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2593 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2594 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002595 } else {
2596 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2597 }
2598 }
2599}
2600
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002601VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2602 VkCmdBuffer cmdBuffer,
2603 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002604 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002605 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002606{
2607 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2608 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002609 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002610 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002611 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002612 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2613 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2614 } else {
2615 updateCBTracking(cmdBuffer);
2616 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2617 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2618 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002619 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002620 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2621 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002622 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002623}
2624
Chris Forbes2951d7d2015-06-22 17:21:59 +12002625VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002626 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002627 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002628 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002629{
2630 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2631 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002632 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002633 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002634 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 -06002635 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2636 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2637 } else {
2638 updateCBTracking(cmdBuffer);
2639 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2640 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2641 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002642 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002643 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2644 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002645 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002646}
2647
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002648VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2649 VkImage srcImage, VkImageLayout srcImageLayout,
2650 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002651 uint32_t regionCount, const VkImageResolve* pRegions)
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) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002656 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002657 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2658 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002659 } else {
2660 updateCBTracking(cmdBuffer);
2661 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002662 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002663 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002664 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002665 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2666 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002667 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002668}
2669
Tony Barbourc2e987e2015-06-29 16:20:35 -06002670VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002671{
2672 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2673 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002674 if (pCB->state == CB_UPDATE_ACTIVE) {
2675 updateCBTracking(cmdBuffer);
2676 addCmd(pCB, CMD_SETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002677 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002678 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002679 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2680 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002681 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002682}
2683
Tony Barbourc2e987e2015-06-29 16:20:35 -06002684VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002685{
2686 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2687 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002688 if (pCB->state == CB_UPDATE_ACTIVE) {
2689 updateCBTracking(cmdBuffer);
2690 addCmd(pCB, CMD_RESETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002691 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002692 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002693 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2694 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002695 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002696}
2697
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002698VK_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 -06002699{
2700 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2701 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002702 if (pCB->state == CB_UPDATE_ACTIVE) {
2703 updateCBTracking(cmdBuffer);
2704 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002705 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002706 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002707 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2708 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002709 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002710}
2711
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002712VK_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 -06002713{
2714 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2715 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002716 if (pCB->state == CB_UPDATE_ACTIVE) {
2717 updateCBTracking(cmdBuffer);
2718 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter73a21d32015-07-12 13:20:05 -06002719 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002720 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002721 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2722 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002723 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002724}
2725
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002726VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002727{
2728 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2729 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002730 if (pCB->state == CB_UPDATE_ACTIVE) {
2731 updateCBTracking(cmdBuffer);
2732 addCmd(pCB, CMD_BEGINQUERY);
2733 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002734 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002735 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2736 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002737 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002738}
2739
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002740VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002741{
2742 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2743 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002744 if (pCB->state == CB_UPDATE_ACTIVE) {
2745 updateCBTracking(cmdBuffer);
2746 addCmd(pCB, CMD_ENDQUERY);
2747 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002748 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002749 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2750 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002751 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002752}
2753
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002754VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002755{
2756 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2757 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002758 if (pCB->state == CB_UPDATE_ACTIVE) {
2759 updateCBTracking(cmdBuffer);
2760 addCmd(pCB, CMD_RESETQUERYPOOL);
2761 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002762 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002763 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2764 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002765 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002766}
2767
Tony Barbour8205d902015-04-16 15:59:00 -06002768VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002769{
2770 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2771 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002772 if (pCB->state == CB_UPDATE_ACTIVE) {
2773 updateCBTracking(cmdBuffer);
2774 addCmd(pCB, CMD_WRITETIMESTAMP);
2775 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002776 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002777 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2778 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002779 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002780}
2781
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002782VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002783{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002784 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002785 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002786 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002787 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002788 if (pCreateInfo->pAttachments) {
Cody Northropf110c6e2015-08-04 10:47:08 -06002789 localFBCI->pAttachments = new VkAttachmentView[localFBCI->attachmentCount];
2790 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkAttachmentView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002791 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002792 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002793 }
2794 return result;
2795}
2796
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002797VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002798{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002799 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002800 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002801 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002802 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002803 if (pCreateInfo->pAttachments) {
2804 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2805 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002806 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002807 if (pCreateInfo->pSubpasses) {
2808 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2809 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2810
2811 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2812 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2813 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002814 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002815 subpass->preserveCount;
2816 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2817
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002818 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002819 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002820 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002821 attachments += subpass->inputCount;
2822
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002823 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002824 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002825 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002826 attachments += subpass->colorCount;
2827
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002828 if (subpass->pResolveAttachments) {
2829 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002830 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002831 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002832 attachments += subpass->colorCount;
2833 }
2834
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002835 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002836 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002837 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002838 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002839 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002840 if (pCreateInfo->pDependencies) {
2841 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2842 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002843 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002844 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002845 }
2846 return result;
2847}
2848
Chia-I Wuc278df82015-07-07 11:50:03 +08002849VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002850{
2851 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2852 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002853 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002854 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002855 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2856 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002857 } else {
2858 updateCBTracking(cmdBuffer);
2859 addCmd(pCB, CMD_BEGINRENDERPASS);
2860 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002861 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002862 pCB->framebuffer = pRenderPassBegin->framebuffer;
2863 if (pCB->lastBoundPipeline) {
2864 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2865 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002866 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002867 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002868 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002869 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002870 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002871 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002872 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002873}
2874
Chia-I Wuc278df82015-07-07 11:50:03 +08002875VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2876{
2877 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2878 if (pCB) {
2879 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 Wuc278df82015-07-07 11:50:03 +08002881 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2882 } else {
2883 updateCBTracking(cmdBuffer);
2884 addCmd(pCB, CMD_NEXTSUBPASS);
2885 pCB->activeSubpass++;
2886 if (pCB->lastBoundPipeline) {
2887 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2888 }
2889 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2890 }
2891 }
2892}
2893
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002894VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002895{
2896 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2897 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002898 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002899 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 +08002900 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06002901 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002902 updateCBTracking(cmdBuffer);
2903 addCmd(pCB, CMD_ENDRENDERPASS);
2904 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08002905 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002906 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2907 }
2908 }
2909}
2910
2911VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2912{
2913 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2914 if (pCB) {
2915 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002916 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 +08002917 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2918 } else {
2919 updateCBTracking(cmdBuffer);
2920 addCmd(pCB, CMD_EXECUTECOMMANDS);
2921 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002922 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002923 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002924}
2925
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002926VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2927 VkInstance instance,
2928 VkFlags msgFlags,
2929 const PFN_vkDbgMsgCallback pfnMsgCallback,
2930 void* pUserData,
2931 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002932{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002933 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002934 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2935 if (VK_SUCCESS == res) {
2936 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2937 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2938 }
2939 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002940}
2941
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002942VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2943 VkInstance instance,
2944 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002945{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002946 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002947 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2948 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2949 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2950 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002951}
2952
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002953VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002954{
2955 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002956 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2957 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002958 // TODO : cmdBuffer should be srcObj
2959 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 -06002960 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002961 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002962 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002963 updateCBTracking(cmdBuffer);
2964 addCmd(pCB, CMD_DBGMARKERBEGIN);
2965 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002966 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002967}
2968
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002969VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002970{
2971 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002972 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2973 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002974 // TODO : cmdBuffer should be srcObj
2975 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 -06002976 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002977 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002978 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002979 updateCBTracking(cmdBuffer);
2980 addCmd(pCB, CMD_DBGMARKEREND);
2981 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002982 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2983}
2984
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002985//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2986//{
2987// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2988// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2989// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2990// "Attempt to use DbgSetObjectTag but extension disabled!");
2991// return VK_ERROR_UNAVAILABLE;
2992// }
2993// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2994//}
2995//
2996//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2997//{
2998// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2999// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3000// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3001// "Attempt to use DbgSetObjectName but extension disabled!");
3002// return VK_ERROR_UNAVAILABLE;
3003// }
3004// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3005//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003006
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003007VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003008{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003009 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003010 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003011
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003012 /* loader uses this to force layer initialization; device object is wrapped */
3013 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003014 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003015 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003016 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003017 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003018 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003019 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003020 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003021 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003022 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003023 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003024 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003025 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003026 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003027 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003028 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003029 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003030 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003031 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003032 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003033 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003034 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003035 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003036 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003037 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003038 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003039 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003040 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003041 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003042 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003043 if (!strcmp(funcName, "vkDestroyAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003044 return (PFN_vkVoidFunction) vkDestroyAttachmentView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003045 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003046 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003047 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003048 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003049 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003050 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003051 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003052 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003053 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003054 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003055 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003056 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003057 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003058 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003059 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003060 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003061 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003062 return (PFN_vkVoidFunction) vkDestroyDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003063 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003064 return (PFN_vkVoidFunction) vkDestroyDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003065 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003066 return (PFN_vkVoidFunction) vkDestroyDynamicDepthStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003067 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003068 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003069 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003070 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003071 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003072 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003073 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003074 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003075 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003076 return (PFN_vkVoidFunction) vkCreateImageView;
Tobin Ehlis44c757d2015-07-10 12:15:19 -06003077 if (!strcmp(funcName, "vkCreateAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003078 return (PFN_vkVoidFunction) vkCreateAttachmentView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003079 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003080 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003081 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003082 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003083 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003084 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003085 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003086 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003087 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003088 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003089 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003090 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003091 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003092 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003093 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003094 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003095 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003096 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003097 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003098 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003099 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003100 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003101 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003102 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003103 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003104 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003105 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003106 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003107 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003108 return (PFN_vkVoidFunction) vkCreateDynamicRasterState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003109 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003110 return (PFN_vkVoidFunction) vkCreateDynamicColorBlendState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003111 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003112 return (PFN_vkVoidFunction) vkCreateDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003113 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003114 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003115 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003116 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003117 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003118 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003119 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003120 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003121 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003122 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003123 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003124 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003125 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003126 return (PFN_vkVoidFunction) vkCmdBindDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003127 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003128 return (PFN_vkVoidFunction) vkCmdBindDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003129 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003130 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003131 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003132 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003133 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003134 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003135 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003136 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003137 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003138 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003139 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003140 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003141 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003142 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003143 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003144 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003145 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003146 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003147 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003148 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003149 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003150 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003151 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003152 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003153 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003154 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003155 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003156 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003157 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003158 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003159 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003160 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003161 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003162 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003163 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003164 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003165 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003166 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003167 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003168 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003169 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003170 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003171 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003172 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003173 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003174 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003175 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003176 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003177 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003178 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003179 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003180 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003181 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003182 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003183 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003184 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003185 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003186 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003187 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003188 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003189 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003190 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003191 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003192 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003193 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003194 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003195 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003196 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003197
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003198 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3199 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003200 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003201 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003202 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003203 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003204 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003205// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3206// return (void*) vkDbgSetObjectTag;
3207// if (!strcmp(funcName, "vkDbgSetObjectName"))
3208// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003209 }
3210 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003211 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003212 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003213 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003214 }
3215}
3216
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003217VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003218{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003219 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003220 if (instance == NULL)
3221 return NULL;
3222
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003223 /* loader uses this to force layer initialization; instance object is wrapped */
3224 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003225 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003226 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003227 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003228 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003230 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003232 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003234 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003236 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003238 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003240
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003241 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3242 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003243 if (fptr)
3244 return fptr;
3245
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003246 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003247 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003248 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003249 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003250 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003251 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003252}