blob: a425efc0ef39d75c57030f47db92a04361ee53f2 [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
Tobin Ehlis7a51d902015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Tony Barboura938abb2015-04-22 11:36:22 -060036#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060037#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060038#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060040#include "draw_state.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060041#include "vk_layer_config.h"
Jon Ashburnf0615e22015-05-25 14:11:37 -060042#include "vk_debug_marker_layer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060043// The following is #included again to catch certain OS-specific functions
44// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060046#include "vk_layer_msg.h"
47#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -060051#include "vk_layer_extension_utils.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060052
Tobin Ehlisc91330b2015-06-16 09:04:30 -060053typedef struct _layer_data {
54 debug_report_data *report_data;
55 // TODO: put instance data here
56 VkDbgMsgCallback logging_callback;
57} layer_data;
58
59static std::unordered_map<void *, layer_data *> layer_data_map;
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -060060static device_table_map draw_state_device_table_map;
61static instance_table_map draw_state_instance_table_map;
62
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060063unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
64unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
65unordered_map<uint64_t, VkAttachmentViewCreateInfo> viewMap;
66unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
67unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicVpStateMap;
68unordered_map<uint64_t, VkDynamicRasterStateCreateInfo> dynamicRsStateMap;
69unordered_map<uint64_t, VkDynamicColorBlendStateCreateInfo> dynamicCbStateMap;
70unordered_map<uint64_t, VkDynamicDepthStencilStateCreateInfo> dynamicDsStateMap;
71unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
72unordered_map<uint64_t, POOL_NODE*> poolMap;
73unordered_map<uint64_t, SET_NODE*> setMap;
74unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060075// Map for layout chains
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060076unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
77unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
78unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060079
Jon Ashburn6f8cd632015-06-01 09:37:38 -060080struct devExts {
81 bool debug_marker_enabled;
82};
83
Jon Ashburn6f8cd632015-06-01 09:37:38 -060084static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060085
Tobin Ehlis63bb9482015-03-17 16:24:32 -060086static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060087
Tobin Ehlis63bb9482015-03-17 16:24:32 -060088// TODO : This can be much smarter, using separate locks for separate global data
89static int globalLockInitialized = 0;
90static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060091#define MAX_TID 513
92static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
93static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060094
95template layer_data *get_my_data_ptr<layer_data>(
96 void *data_key,
97 std::unordered_map<void *, layer_data *> &data_map);
98
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060099debug_report_data *mdd(void* object)
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600100{
101 dispatch_key key = get_dispatch_key(object);
102 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
103#if DISPATCH_MAP_DEBUG
104 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
105#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600106 return my_data->report_data;
107}
108
109debug_report_data *mid(VkInstance object)
110{
111 dispatch_key key = get_dispatch_key(object);
112 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
113#if DISPATCH_MAP_DEBUG
114 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
115#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600116 return my_data->report_data;
117}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600118// Map actual TID to an index value and return that index
119// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
120static uint32_t getTIDIndex() {
121 loader_platform_thread_id tid = loader_platform_get_thread_id();
122 for (uint32_t i = 0; i < g_maxTID; i++) {
123 if (tid == g_tidMapping[i])
124 return i;
125 }
126 // Don't yet have mapping, set it and return newly set index
127 uint32_t retVal = (uint32_t) g_maxTID;
128 g_tidMapping[g_maxTID++] = tid;
129 assert(g_maxTID < MAX_TID);
130 return retVal;
131}
132// Return a string representation of CMD_TYPE enum
133static string cmdTypeToString(CMD_TYPE cmd)
134{
135 switch (cmd)
136 {
137 case CMD_BINDPIPELINE:
138 return "CMD_BINDPIPELINE";
139 case CMD_BINDPIPELINEDELTA:
140 return "CMD_BINDPIPELINEDELTA";
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600141 case CMD_BINDDYNAMICVIEWPORTSTATE:
142 return "CMD_BINDDYNAMICVIEWPORTSTATE";
143 case CMD_BINDDYNAMICRASTERSTATE:
144 return "CMD_BINDDYNAMICRASTERSTATE";
145 case CMD_BINDDYNAMICCOLORBLENDSTATE:
146 return "CMD_BINDDYNAMICCOLORBLENDSTATE";
147 case CMD_BINDDYNAMICDEPTHSTENCILSTATE:
148 return "CMD_BINDDYNAMICDEPTHSTENCILSTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600149 case CMD_BINDDESCRIPTORSETS:
150 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600151 case CMD_BINDINDEXBUFFER:
152 return "CMD_BINDINDEXBUFFER";
153 case CMD_BINDVERTEXBUFFER:
154 return "CMD_BINDVERTEXBUFFER";
155 case CMD_DRAW:
156 return "CMD_DRAW";
157 case CMD_DRAWINDEXED:
158 return "CMD_DRAWINDEXED";
159 case CMD_DRAWINDIRECT:
160 return "CMD_DRAWINDIRECT";
161 case CMD_DRAWINDEXEDINDIRECT:
162 return "CMD_DRAWINDEXEDINDIRECT";
163 case CMD_DISPATCH:
164 return "CMD_DISPATCH";
165 case CMD_DISPATCHINDIRECT:
166 return "CMD_DISPATCHINDIRECT";
167 case CMD_COPYBUFFER:
168 return "CMD_COPYBUFFER";
169 case CMD_COPYIMAGE:
170 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600171 case CMD_BLITIMAGE:
172 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600173 case CMD_COPYBUFFERTOIMAGE:
174 return "CMD_COPYBUFFERTOIMAGE";
175 case CMD_COPYIMAGETOBUFFER:
176 return "CMD_COPYIMAGETOBUFFER";
177 case CMD_CLONEIMAGEDATA:
178 return "CMD_CLONEIMAGEDATA";
179 case CMD_UPDATEBUFFER:
180 return "CMD_UPDATEBUFFER";
181 case CMD_FILLBUFFER:
182 return "CMD_FILLBUFFER";
183 case CMD_CLEARCOLORIMAGE:
184 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600185 case CMD_CLEARCOLORATTACHMENT:
186 return "CMD_CLEARCOLORATTACHMENT";
187 case CMD_CLEARDEPTHSTENCILIMAGE:
188 return "CMD_CLEARDEPTHSTENCILIMAGE";
189 case CMD_CLEARDEPTHSTENCILATTACHMENT:
190 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600191 case CMD_RESOLVEIMAGE:
192 return "CMD_RESOLVEIMAGE";
193 case CMD_SETEVENT:
194 return "CMD_SETEVENT";
195 case CMD_RESETEVENT:
196 return "CMD_RESETEVENT";
197 case CMD_WAITEVENTS:
198 return "CMD_WAITEVENTS";
199 case CMD_PIPELINEBARRIER:
200 return "CMD_PIPELINEBARRIER";
201 case CMD_BEGINQUERY:
202 return "CMD_BEGINQUERY";
203 case CMD_ENDQUERY:
204 return "CMD_ENDQUERY";
205 case CMD_RESETQUERYPOOL:
206 return "CMD_RESETQUERYPOOL";
207 case CMD_WRITETIMESTAMP:
208 return "CMD_WRITETIMESTAMP";
209 case CMD_INITATOMICCOUNTERS:
210 return "CMD_INITATOMICCOUNTERS";
211 case CMD_LOADATOMICCOUNTERS:
212 return "CMD_LOADATOMICCOUNTERS";
213 case CMD_SAVEATOMICCOUNTERS:
214 return "CMD_SAVEATOMICCOUNTERS";
215 case CMD_BEGINRENDERPASS:
216 return "CMD_BEGINRENDERPASS";
217 case CMD_ENDRENDERPASS:
218 return "CMD_ENDRENDERPASS";
219 case CMD_DBGMARKERBEGIN:
220 return "CMD_DBGMARKERBEGIN";
221 case CMD_DBGMARKEREND:
222 return "CMD_DBGMARKEREND";
223 default:
224 return "UNKNOWN";
225 }
226}
227// Block of code at start here for managing/tracking Pipeline state that this layer cares about
228// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600229#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600230#define MAX_SLOTS 2048
231#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
232
233static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
234
235// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
236// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
237// to that same cmd buffer by separate thread are not changing state from underneath us
238// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600239static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600240// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600241static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
242static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600243// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600244static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
245static PIPELINE_NODE* g_lastBoundPipeline = NULL;
246static uint64_t g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {0};
Dana Jansens4a3e0862015-07-30 13:22:15 -0700247static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600248#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
249
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600250//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600252// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600253static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600254{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600255 for (auto ii=dynamicVpStateMap.begin(); ii!=dynamicVpStateMap.end(); ++ii) {
256 delete[] (*ii).second.pScissors;
257 delete[] (*ii).second.pViewports;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600258 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600259 dynamicVpStateMap.clear();
260 dynamicRsStateMap.clear();
261 dynamicCbStateMap.clear();
262 dynamicDsStateMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600263}
264// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600265static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600266{
David Pinedof5997ab2015-04-27 16:36:17 -0600267 if (sampleMap.size() <= 0)
268 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600269 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600270 delete (*ii).second;
271 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600272 sampleMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600273}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600274static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600275{
276 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600277 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600278 loader_platform_thread_unlock_mutex(&globalLock);
279 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600280 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600282 return &imageMap[view.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600283 }
284}
285// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600286static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600287{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600288 if (imageMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -0600289 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600290 imageMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600291}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600292static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600293{
294 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600295 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600296 loader_platform_thread_unlock_mutex(&globalLock);
297 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600298 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600299 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600300 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301 }
302}
303// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600304static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600305{
David Pinedof5997ab2015-04-27 16:36:17 -0600306 if (bufferMap.size() <= 0)
307 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600308 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600309 delete (*ii).second;
310 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600311 bufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600312}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600313static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600314// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600315static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600316{
317 g_lastCmdBuffer[getTIDIndex()] = cb;
318 GLOBAL_CB_NODE* pCB = getCBNode(cb);
319 loader_platform_thread_lock_mutex(&globalLock);
320 g_lastGlobalCB = pCB;
321 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
322 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
323 if (g_pLastTouchedCB[i] == pCB) {
324 loader_platform_thread_unlock_mutex(&globalLock);
325 return;
326 }
327 }
328 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
329 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
330 loader_platform_thread_unlock_mutex(&globalLock);
331}
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600332static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600333{
334 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
335 if (pCB->drawCount[i])
336 return VK_TRUE;
337 }
338 return VK_FALSE;
339}
Tobin Ehlis97866202015-06-10 12:57:07 -0600340// Check object status for selected flag state
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600341static VkBool32 validate_status(GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600342{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600343 // If non-zero enable mask is present, check it against status but if enable_mask
344 // is 0 then no enable required so we should always just check status
345 if ((!enable_mask) || (enable_mask & pNode->status)) {
346 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600347 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
348 log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
349 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(pNode->cmdBuffer), fail_msg);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600350 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600351 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600352 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600353 return VK_TRUE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600354}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600355// For given dynamic state handle and type, return CreateInfo for that Dynamic State
356static void* getDynamicStateCreateInfo(const uint64_t handle, const DYNAMIC_STATE_BIND_POINT type)
357{
358 switch (type) {
359 case VK_STATE_BIND_POINT_VIEWPORT:
360 return (void*)&dynamicVpStateMap[handle];
361 case VK_STATE_BIND_POINT_RASTER:
362 return (void*)&dynamicRsStateMap[handle];
363 case VK_STATE_BIND_POINT_COLOR_BLEND:
364 return (void*)&dynamicCbStateMap[handle];
365 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
366 return (void*)&dynamicDsStateMap[handle];
367 default:
368 return NULL;
369 }
370}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600371// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600372static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600373{
374 GLOBAL_CB_NODE* pCB = getCBNode(cb);
375 if (pCB) {
376 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600378 void* pDynStateCI = getDynamicStateCreateInfo(pCB->lastBoundDynamicState[i], (DYNAMIC_STATE_BIND_POINT)i);
379 if (pDynStateCI) {
380 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
381 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
382 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
383 dynamic_display(pDynStateCI, " ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600384 break;
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600385 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600386 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
387 "No dynamic state of type %s bound", string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600388 }
389 }
390 loader_platform_thread_unlock_mutex(&globalLock);
391 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600392}
393// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600394static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600395{
396 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600397 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600398 loader_platform_thread_unlock_mutex(&globalLock);
399 return NULL;
400 }
401 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600402 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600403}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600404// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600405static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
406 VkBool32 result;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600407 result = validate_status(pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_BOUND, CBSTATUS_VIEWPORT_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
408 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_RASTER_BOUND, CBSTATUS_RASTER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");
409 result &= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_COLOR_BLEND_BOUND, CBSTATUS_COLOR_BLEND_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");
410 result &= validate_status(pCB, CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE, CBSTATUS_DEPTH_STENCIL_BOUND, CBSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");
411 if (indexedDraw)
412 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_INDEX_BUFFER_BOUND, CBSTATUS_INDEX_BUFFER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_INDEX_BUFFER_NOT_BOUND, "Index buffer object not bound to this command buffer when Index Draw attempted");
413 return result;
414}
415// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600416static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600417 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600418 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600419 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
420 // Now complete other state checks
Tobin Ehlise4076782015-06-24 15:53:07 -0600421 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600422 result = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600423 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Mark Lobodzinskia98cf9b2015-08-04 10:54:43 -0600424 "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 -0600425 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600426 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600427 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis451efca2015-06-23 11:22:55 -0600428 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
429 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600430 return result;
431}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600432// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600433static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600434{
435 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600436 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600437 loader_platform_thread_unlock_mutex(&globalLock);
438 return NULL;
439 }
440 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600441 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600442}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600443// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600444static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600445{
446 // VS is required
447 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600448 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600449 "Invalid Pipeline CreateInfo State: Vtx Shader required");
450 return VK_FALSE;
451 }
452 // Either both or neither TC/TE shaders should be defined
453 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
454 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600455 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600456 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
457 return VK_FALSE;
458 }
459 // Compute shaders should be specified independent of Gfx shaders
460 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
461 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
462 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
463 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600464 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600465 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
466 return VK_FALSE;
467 }
468 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
469 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
470 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
471 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600472 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600473 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
474 return VK_FALSE;
475 }
476 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
477 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600478 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600479 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
480 return VK_FALSE;
481 }
482 return VK_TRUE;
483}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600484// Init the pipeline mapping info based on pipeline create info LL tree
485// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600486static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600487{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600488 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
489 if (pBasePipeline) {
490 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600491 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600492 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
493 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600494 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600495 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600496 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600497
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600498 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600499 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600500 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600501
502 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
503 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
504
505 switch (pPSSCI->stage) {
506 case VK_SHADER_STAGE_VERTEX:
507 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
508 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600509 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600510 case VK_SHADER_STAGE_TESS_CONTROL:
511 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
512 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600513 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600514 case VK_SHADER_STAGE_TESS_EVALUATION:
515 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
516 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600517 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600518 case VK_SHADER_STAGE_GEOMETRY:
519 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
520 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600521 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600522 case VK_SHADER_STAGE_FRAGMENT:
523 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
524 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600525 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600526 case VK_SHADER_STAGE_COMPUTE:
527 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
528 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600529 break;
530 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600531 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600532 break;
533 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600534 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600535
536 if (pCreateInfo->pVertexInputState != NULL) {
537 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
538 // Copy embedded ptrs
539 pVICI = pCreateInfo->pVertexInputState;
540 pPipeline->vtxBindingCount = pVICI->bindingCount;
541 if (pPipeline->vtxBindingCount) {
542 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
543 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
544 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
545 }
546 pPipeline->vtxAttributeCount = pVICI->attributeCount;
547 if (pPipeline->vtxAttributeCount) {
548 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
549 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
550 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
551 }
552 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
553 }
Tony Barboure307f582015-07-10 15:29:03 -0600554 if (pCreateInfo->pInputAssemblyState != NULL) {
555 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
556 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600557 }
Tony Barboure307f582015-07-10 15:29:03 -0600558 if (pCreateInfo->pTessellationState != NULL) {
559 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600561 }
Tony Barboure307f582015-07-10 15:29:03 -0600562 if (pCreateInfo->pViewportState != NULL) {
563 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
564 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600565 }
Tony Barboure307f582015-07-10 15:29:03 -0600566 if (pCreateInfo->pRasterState != NULL) {
567 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
568 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600569 }
Tony Barboure307f582015-07-10 15:29:03 -0600570 if (pCreateInfo->pMultisampleState != NULL) {
571 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
572 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600573 }
Tony Barboure307f582015-07-10 15:29:03 -0600574 if (pCreateInfo->pColorBlendState != NULL) {
575 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600576 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600577 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600578 pPipeline->attachmentCount = pCBCI->attachmentCount;
579 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600580 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
581 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600582 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
583 }
Tony Barboure307f582015-07-10 15:29:03 -0600584 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600585 }
Tony Barboure307f582015-07-10 15:29:03 -0600586 if (pCreateInfo->pDepthStencilState != NULL) {
587 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
588 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600589 }
590
591 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
592 if (pCreateInfo->stageCount != 0) {
593 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
594 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
595 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
596 }
597
Tobin Ehlisde63c532015-06-18 15:59:33 -0600598 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600599}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600600
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600601// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600602static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600603{
David Pinedof5997ab2015-04-27 16:36:17 -0600604 if (pipelineMap.size() <= 0)
605 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600606 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600607 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
608 delete[] (*ii).second->graphicsPipelineCI.pStages;
609 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600610 if ((*ii).second->pVertexBindingDescriptions) {
611 delete[] (*ii).second->pVertexBindingDescriptions;
612 }
613 if ((*ii).second->pVertexAttributeDescriptions) {
614 delete[] (*ii).second->pVertexAttributeDescriptions;
615 }
616 if ((*ii).second->pAttachments) {
617 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600618 }
619 delete (*ii).second;
620 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600621 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600622}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600623// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600624static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600625{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600626 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600627 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
628 return pPipe->msStateCI.rasterSamples;
629 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600630 return 1;
631}
632// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600633static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600634{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600635 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600636 // Verify that any MSAA request in PSO matches sample# in bound FB
637 uint32_t psoNumSamples = getNumSamples(pipeline);
638 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600639 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800640 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
641 int subpassNumSamples = 0;
642 uint32_t i;
643
644 for (i = 0; i < pSD->colorCount; i++) {
645 uint32_t samples;
646
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600647 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800648 continue;
649
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600650 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800651 if (subpassNumSamples == 0) {
652 subpassNumSamples = samples;
653 } else if (subpassNumSamples != samples) {
654 subpassNumSamples = -1;
655 break;
656 }
657 }
658 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
659 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
660 if (subpassNumSamples == 0)
661 subpassNumSamples = samples;
662 else if (subpassNumSamples != samples)
663 subpassNumSamples = -1;
664 }
665
666 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600667 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
668 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!", pipeline.handle, psoNumSamples, pCB->activeRenderPass.handle, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600669 }
670 } else {
671 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
672 // Verify and flag error as appropriate
673 }
674 // TODO : Add more checks here
675 } else {
676 // TODO : Validate non-gfx pipeline updates
677 }
678}
679
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600680// Block of code at start here specifically for managing/tracking DSs
681
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600682// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600683static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600684{
685 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600686 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600687 loader_platform_thread_unlock_mutex(&globalLock);
688 return NULL;
689 }
690 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600691 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600692}
693// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600694static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600695{
696 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600697 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600698 loader_platform_thread_unlock_mutex(&globalLock);
699 return NULL;
700 }
701 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600702 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600703}
704
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600705static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600706 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600707 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600708 loader_platform_thread_unlock_mutex(&globalLock);
709 return NULL;
710 }
711 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600712 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600713}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600714// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600715static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600716{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600717 switch (pUpdateStruct->sType)
718 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800719 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
720 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600721 return 1;
722 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600723 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600724 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600725 return 0;
726 }
727}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600728// For given update struct, return binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600729static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600730{
731 switch (pUpdateStruct->sType)
732 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800733 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
734 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
735 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
736 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600737 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600738 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600739 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600740 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600741 }
742}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600743// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600744static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600745{
746 switch (pUpdateStruct->sType)
747 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800748 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
749 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
750 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600751 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800752 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600753 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600754 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600755 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600756 return 0;
757 }
758}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600759// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600760static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600761{
762 switch (pUpdateStruct->sType)
763 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800764 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
765 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
766 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600767 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800768 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600769 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600770 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600771 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600772 return 0;
773 }
774}
775// For given Layout Node and binding, return index where that binding begins
776static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
777{
778 uint32_t offsetIndex = 0;
779 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800780 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600781 }
782 return offsetIndex;
783}
784// For given layout node and binding, return last index that is updated
785static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
786{
787 uint32_t offsetIndex = 0;
788 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800789 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600790 }
791 return offsetIndex-1;
792}
793// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600794static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600795{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600796 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600797}
798// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600799static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600800{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600801 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600802}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600803// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600804static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600805{
806 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600807 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600808 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600809 switch (pUpdateStruct->sType)
810 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800811 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
812 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600813 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800814 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
815 /* no need to validate */
816 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600817 break;
818 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600819 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600820 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600821 return 0;
822 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600823 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600824 if (pLayout->pTypes[i] != actualType)
825 return 0;
826 }
827 return 1;
828}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
830// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
831// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600832static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600833{
834 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800835 VkWriteDescriptorSet* pWDS = NULL;
836 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600837 size_t array_size = 0;
838 size_t base_array_size = 0;
839 size_t total_array_size = 0;
840 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600841 switch (pUpdate->sType)
842 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800843 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
844 pWDS = new VkWriteDescriptorSet;
845 pNewNode = (GENERIC_HEADER*)pWDS;
846 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
847 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
848 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
849 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600850 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800851 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
852 pCDS = new VkCopyDescriptorSet;
853 pUpdate = (GENERIC_HEADER*)pCDS;
854 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600855 break;
856 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600857 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600858 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600859 return NULL;
860 }
861 // Make sure that pNext for the end of shadow copy is NULL
862 pNewNode->pNext = NULL;
863 return pNewNode;
864}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800865// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600866static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600867{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800868 const VkWriteDescriptorSet *pWDS = NULL;
869 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600870 VkBool32 result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800871
872 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
873 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
874 else
875 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
876
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600877 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600878 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600879 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600881 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600882 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800883 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600884 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800885 g_lastBoundDescriptorSet = pSet->set;
886 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600887 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600888 // First verify valid update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600889 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600890 result = 0;
891 break;
892 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600893 // Make sure that binding is within bounds
Tobin Ehlisde63c532015-06-18 15:59:33 -0600894 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600895 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600896 "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, getUpdateBinding(device, pUpdate), string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600897 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600898 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600899 // Next verify that update falls within size of given binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600900 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour29b12062015-07-13 13:37:24 -0600901 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600902 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600903 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600904 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600905 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), getUpdateBinding(device, pUpdate), DSstr.c_str());
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600906 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600907 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600908 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlisde63c532015-06-18 15:59:33 -0600909 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600910 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600911 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600912 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600913 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600914 // Save the update info
915 // TODO : Info message that update successful
916 // Create new update struct for this set's shadow copy
Tobin Ehlisde63c532015-06-18 15:59:33 -0600917 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600918 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600919 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600920 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600921 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600922 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600923 // Insert shadow node into LL of updates for this set
924 pNewNode->pNext = pSet->pUpdateStructs;
925 pSet->pUpdateStructs = pNewNode;
926 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisde63c532015-06-18 15:59:33 -0600927 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600928 assert(j<pSet->descriptorCount);
929 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600930 }
931 }
932 }
933 }
934 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600935 }
936 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600937 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600938}
939// Free the shadowed update node for this Set
940// NOTE : Calls to this function should be wrapped in mutex
941static void freeShadowUpdateTree(SET_NODE* pSet)
942{
943 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
944 pSet->pUpdateStructs = NULL;
945 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
946 // Clear the descriptor mappings as they will now be invalid
947 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
948 while(pShadowUpdate) {
949 pFreeUpdate = pShadowUpdate;
950 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
951 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800952 VkWriteDescriptorSet * pWDS = NULL;
953 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600954 void** ppToFree = NULL;
955 switch (pFreeUpdate->sType)
956 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800957 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
958 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
959 if (pWDS->pDescriptors)
960 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600961 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800962 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600963 break;
964 default:
965 assert(0);
966 break;
967 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600968 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600969 }
970}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600971// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600972// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600973static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600974{
David Pinedof5997ab2015-04-27 16:36:17 -0600975 if (poolMap.size() <= 0)
976 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600977 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600978 SET_NODE* pSet = (*ii).second->pSets;
979 SET_NODE* pFreeSet = pSet;
980 while (pSet) {
981 pFreeSet = pSet;
982 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600983 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600984 // Free Update shadow struct tree
985 freeShadowUpdateTree(pFreeSet);
986 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200987 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600988 }
989 delete pFreeSet;
990 }
991 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200992 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600993 }
994 delete (*ii).second;
995 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600996 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600997}
Tobin Ehliseaf28662015-04-08 10:58:37 -0600998// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600999// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001000static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001001{
David Pinedof5997ab2015-04-27 16:36:17 -06001002 if (layoutMap.size() <= 0)
1003 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001004 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001005 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001006 if (pLayout->createInfo.pBinding) {
1007 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1008 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1009 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1010 }
1011 delete[] pLayout->createInfo.pBinding;
1012 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001013 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001014 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001015 }
1016 delete pLayout;
1017 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001018 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019}
1020// Currently clearing a set is removing all previous updates to that set
1021// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001022static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023{
1024 SET_NODE* pSet = getSetNode(set);
1025 if (!pSet) {
1026 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001027 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001028 loader_platform_thread_lock_mutex(&globalLock);
1029 freeShadowUpdateTree(pSet);
1030 loader_platform_thread_unlock_mutex(&globalLock);
1031 }
1032}
1033
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001034static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001035{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001036 POOL_NODE* pPool = getPoolNode(pool);
1037 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001038 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1039 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001040 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001041 // For every set off of this pool, clear it
1042 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001043 while (pSet) {
1044 clearDescriptorSet(pSet->set);
1045 }
1046 }
1047}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001048// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001049static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001050{
1051 loader_platform_thread_lock_mutex(&globalLock);
1052 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1053 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001054 // TODO : How to pass cb as srcObj here?
1055 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1056 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001057 return NULL;
1058 }
1059 loader_platform_thread_unlock_mutex(&globalLock);
1060 return cmdBufferMap[cb];
1061}
1062// Free all CB Nodes
1063// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001064static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001065{
David Pinedof5997ab2015-04-27 16:36:17 -06001066 if (cmdBufferMap.size() <= 0)
1067 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001068 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001069 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1070 while (!cmd_node_list.empty()) {
1071 CMD_NODE* cmd_node = cmd_node_list.back();
1072 delete cmd_node;
1073 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001074 }
1075 delete (*ii).second;
1076 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001077 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001078}
Tobin Ehlise42007c2015-06-19 13:00:59 -06001079static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1080{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001081 // TODO : How to pass cb as srcObj here?
1082 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_BEGIN_CMD_BUFFER, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06001083 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1084}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001085static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1086{
1087 CMD_NODE* pCmd = new CMD_NODE;
1088 if (pCmd) {
1089 // init cmd node and append to end of cmd LL
1090 memset(pCmd, 0, sizeof(CMD_NODE));
1091 pCmd->cmdNumber = ++pCB->numCmds;
1092 pCmd->type = cmd;
1093 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001094 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001095 // TODO : How to pass cb as srcObj here?
1096 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1097 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %#" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001098 }
1099}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001100static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001101{
1102 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1103 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001104 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1105 while (!cmd_list.empty()) {
1106 delete cmd_list.back();
1107 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001108 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001109 pCB->pCmds.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001110 // Reset CB state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001111 VkFlags saveFlags = pCB->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001112 VkCmdPool savedPool = pCB->pool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001113 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1114 pCB->cmdBuffer = cb;
1115 pCB->flags = saveFlags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001116 pCB->pool = savedPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001117 pCB->lastVtxBinding = MAX_BINDING;
1118 }
1119}
Tobin Ehlis97866202015-06-10 12:57:07 -06001120// Set PSO-related status bits for CB
1121static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1122{
1123 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1124 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1125 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1126 }
1127 }
1128 if (pPipe->dsStateCI.depthWriteEnable) {
1129 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1130 }
1131}
1132// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001133static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001134 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1135 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1136 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1137 pNode->status |= CBSTATUS_RASTER_BOUND;
1138 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1139 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1140 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1141 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1142 }
1143}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001144// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001146{
1147 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1148 if (pCB) {
1149 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1150 if (!pPipeTrav) {
1151 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001152 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001153 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001154 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001155 }
1156 }
1157}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001158// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001159static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001160{
1161 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1162 if (pCB && pCB->lastBoundPipeline) {
1163 // First verify that we have a Node for bound pipeline
1164 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001165 if (!pPipeTrav) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001166 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1167 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001168 return false;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001169 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001170 // Verify Vtx binding
1171 if (MAX_BINDING != pCB->lastVtxBinding) {
1172 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1173 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001174 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001175 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001176 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001177 }
1178 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001179 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001180 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001181 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001182 }
1183 }
1184 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001185 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001186 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001187 }
1188 }
1189 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001190 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001191 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001192 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001193}
1194// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001195static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001196{
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001197 char ds_config_str[1024*256] = {0}; // TODO : Currently making this buffer HUGE w/o overrun protection. Need to be smarter, start smaller, and grow as needed.
1198 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001199 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001200 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001201 POOL_NODE* pPool = getPoolNode(pSet->pool);
1202 // Print out pool details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001203 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1204 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001205 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001206 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001207 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001208 // Print out set details
1209 char prefix[10];
1210 uint32_t index = 0;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001211 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1212 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001213 LAYOUT_NODE* pLayout = pSet->pLayout;
1214 // Print layout details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001215 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1216 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001217 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001218 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001219 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001220 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001221 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001222 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1223 if (pUpdate) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001224 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1225 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001226 sprintf(prefix, " [UC] ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001227 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001228 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001229 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001230 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001231 if (0 != pSet->descriptorCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001232 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1233 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", pSet->set.handle, pSet->descriptorCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001234 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001235 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1236 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001237 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001238 }
1239 }
1240}
1241
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001242static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001243{
1244 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001245 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001246 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001247 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001248 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001249 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1250 // TODO : Need to pass cb as srcObj here
1251 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001252 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001253 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001254 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001255 // Nothing to print
1256 }
1257}
1258
1259
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001260static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001261{
Mark Lobodzinskifdb20cf2015-08-07 17:11:09 -06001262 printDSConfig(cb);
1263 printPipeline(cb);
1264 printDynamicState(cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001265}
1266
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001267static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001268{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001269 uint32_t report_flags = 0;
1270 uint32_t debug_action = 0;
1271 FILE *log_output = NULL;
1272 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001273 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001274 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1275 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001276
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001277 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001278 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001279 option_str = getLayerOption("DrawStateLogFilename");
1280 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001281 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001282 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001283 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001284 if (log_output == NULL)
1285 log_output = stdout;
1286
1287 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 -06001288 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001289
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001290 if (!globalLockInitialized)
1291 {
1292 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001293 // suggestion is to call this during vkCreateInstance(), and then we
1294 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001295 // that the layer have per-instance locks. We need to come back and
1296 // address this soon.
1297 loader_platform_thread_create_mutex(&globalLock);
1298 globalLockInitialized = 1;
1299 }
1300}
1301
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001302VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1303{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001304 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001305 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1306
1307 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001308 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1309 my_data->report_data = debug_report_create_instance(
1310 pTable,
1311 *pInstance,
1312 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001313 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001314
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001315 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001316 }
1317 return result;
1318}
1319
Jon Ashburne0fa2282015-05-20 09:00:28 -06001320/* hook DestroyInstance to remove tableInstanceMap entry */
1321VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1322{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001323 dispatch_key key = get_dispatch_key(instance);
1324 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1325 VkResult res = pTable->DestroyInstance(instance);
1326
1327 // Clean up logging callback, if any
1328 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1329 if (my_data->logging_callback) {
1330 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1331 }
1332
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001333 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001334 layer_data_map.erase(pTable);
1335
1336 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001337 return res;
1338}
1339
Jon Ashburnf0615e22015-05-25 14:11:37 -06001340static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1341{
Tony Barbour29b12062015-07-13 13:37:24 -06001342 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001343 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001344 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001345
1346 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001347 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001348 /* Found a matching extension name, mark it enabled and init dispatch table*/
1349 initDebugMarkerTable(device);
1350 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001351 }
1352
1353 }
1354}
1355
Tony Barbour8205d902015-04-16 15:59:00 -06001356VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001357{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001358 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1359 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001360 if (result == VK_SUCCESS) {
1361 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1362 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1363 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1364 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001365 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001366 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001367 return result;
1368}
1369
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001370VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001371{
1372 // Free all the memory
1373 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001374 deletePipelines();
1375 deleteSamplers();
1376 deleteImages();
1377 deleteBuffers();
1378 deleteCmdBuffers();
1379 deleteDynamicState();
1380 deletePools();
1381 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001382 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001383
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001384 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001385 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1386 VkResult result = pDisp->DestroyDevice(device);
1387 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001388 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001389 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001390 return result;
1391}
1392
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001393static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001394 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001395 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001396 VK_API_VERSION,
1397 VK_MAKE_VERSION(0, 1, 0),
1398 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001399 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001400};
1401
Tony Barbour426b9052015-06-24 16:06:58 -06001402VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001403 const char *pLayerName,
1404 uint32_t *pCount,
1405 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001406{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001407 /* DrawState does not have any global extensions */
1408 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1409}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001410
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001411VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1412 uint32_t *pCount,
1413 VkLayerProperties* pProperties)
1414{
1415 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1416 ds_global_layers,
1417 pCount, pProperties);
1418}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001419
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001420static const VkExtensionProperties ds_device_extensions[] = {
1421 {
1422 DEBUG_MARKER_EXTENSION_NAME,
1423 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001424 }
1425};
1426
1427static const VkLayerProperties ds_device_layers[] = {
1428 {
1429 "DrawState",
1430 VK_API_VERSION,
1431 VK_MAKE_VERSION(0, 1, 0),
1432 "Validation layer: DrawState",
1433 }
1434};
1435
1436VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1437 VkPhysicalDevice physicalDevice,
1438 const char* pLayerName,
1439 uint32_t* pCount,
1440 VkExtensionProperties* pProperties)
1441{
1442 /* Mem tracker does not have any physical device extensions */
1443 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1444 pCount, pProperties);
1445}
1446
1447VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1448 VkPhysicalDevice physicalDevice,
1449 uint32_t* pCount,
1450 VkLayerProperties* pProperties)
1451{
1452 /* Mem tracker's physical device layers are the same as global */
1453 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1454 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001455}
1456
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001457VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001458{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001459 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001460 for (uint32_t i=0; i < cmdBufferCount; i++) {
1461 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001462 pCB = getCBNode(pCmdBuffers[i]);
1463 loader_platform_thread_lock_mutex(&globalLock);
1464 if (CB_UPDATE_COMPLETE != pCB->state) {
1465 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001466 // TODO : How to pass cb as srcObj?
1467 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1468 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlise90b1712015-05-27 14:30:06 -06001469 loader_platform_thread_unlock_mutex(&globalLock);
1470 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001471 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001472 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001473 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001474
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001475 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001476 return result;
1477}
1478
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001479VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001480{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001481 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1482 // TODO : Clean up any internal data structures using this obj.
1483 return result;
1484}
1485
1486VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1487{
1488 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1489 // TODO : Clean up any internal data structures using this obj.
1490 return result;
1491}
1492
1493VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1494{
1495 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1496 // TODO : Clean up any internal data structures using this obj.
1497 return result;
1498}
1499
1500VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1501{
1502 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1503 // TODO : Clean up any internal data structures using this obj.
1504 return result;
1505}
1506
1507VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1508{
1509 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1510 // TODO : Clean up any internal data structures using this obj.
1511 return result;
1512}
1513
1514VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1515{
1516 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1517 // TODO : Clean up any internal data structures using this obj.
1518 return result;
1519}
1520
1521VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1522{
1523 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1524 // TODO : Clean up any internal data structures using this obj.
1525 return result;
1526}
1527
1528VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1529{
1530 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1531 // TODO : Clean up any internal data structures using this obj.
1532 return result;
1533}
1534
1535VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1536{
1537 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1538 // TODO : Clean up any internal data structures using this obj.
1539 return result;
1540}
1541
1542VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1543{
1544 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1545 // TODO : Clean up any internal data structures using this obj.
1546 return result;
1547}
1548
1549VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1550{
1551 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1552 // TODO : Clean up any internal data structures using this obj.
1553 return result;
1554}
1555
1556VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1557{
1558 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1559 // TODO : Clean up any internal data structures using this obj.
1560 return result;
1561}
1562
1563VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1564{
1565 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1566 // TODO : Clean up any internal data structures using this obj.
1567 return result;
1568}
1569
1570VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1571{
1572 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1573 // TODO : Clean up any internal data structures using this obj.
1574 return result;
1575}
1576
1577VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1578{
1579 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1580 // TODO : Clean up any internal data structures using this obj.
1581 return result;
1582}
1583
1584VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1585{
1586 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1587 // TODO : Clean up any internal data structures using this obj.
1588 return result;
1589}
1590
1591VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1592{
1593 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1594 // TODO : Clean up any internal data structures using this obj.
1595 return result;
1596}
1597
1598VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1599{
1600 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1601 // TODO : Clean up any internal data structures using this obj.
1602 return result;
1603}
1604
1605VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1606{
1607 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1608 // TODO : Clean up any internal data structures using this obj.
1609 return result;
1610}
1611
1612VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1613{
1614 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1615 // TODO : Clean up any internal data structures using this obj.
1616 return result;
1617}
1618
1619VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1620{
1621 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1622 // TODO : Clean up any internal data structures using this obj.
1623 return result;
1624}
1625
1626VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1627{
1628 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1629 // TODO : Clean up any internal data structures using this obj.
1630 return result;
1631}
1632
1633VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1634{
1635 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1636 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001637 return result;
1638}
1639
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001640VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001641{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001642 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001643 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001644 loader_platform_thread_lock_mutex(&globalLock);
1645 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1646 pNewNode->buffer = *pView;
1647 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001648 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001649 loader_platform_thread_unlock_mutex(&globalLock);
1650 }
1651 return result;
1652}
1653
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001654VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001655{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001656 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001657 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001658 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001659 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001660 loader_platform_thread_unlock_mutex(&globalLock);
1661 }
1662 return result;
1663}
1664
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001665VkResult VKAPI vkCreateAttachmentView(
1666 VkDevice device,
1667 const VkAttachmentViewCreateInfo* pCreateInfo,
1668 VkAttachmentView* pView)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001669{
Tobin Ehlis44c757d2015-07-10 12:15:19 -06001670 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001671 if (VK_SUCCESS == result) {
1672 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001673 viewMap[pView->handle] = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674 loader_platform_thread_unlock_mutex(&globalLock);
1675 }
1676 return result;
1677}
1678
Jon Ashburn0d60d272015-07-09 15:02:25 -06001679//TODO handle pipeline caches
1680VkResult VKAPI vkCreatePipelineCache(
1681 VkDevice device,
1682 const VkPipelineCacheCreateInfo* pCreateInfo,
1683 VkPipelineCache* pPipelineCache)
1684{
1685 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1686 return result;
1687}
1688
1689VkResult VKAPI vkDestroyPipelineCache(
1690 VkDevice device,
1691 VkPipelineCache pipelineCache)
1692{
1693 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1694 return result;
1695}
1696
1697size_t VKAPI vkGetPipelineCacheSize(
1698 VkDevice device,
1699 VkPipelineCache pipelineCache)
1700{
1701 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1702 return size;
1703}
1704
1705VkResult VKAPI vkGetPipelineCacheData(
1706 VkDevice device,
1707 VkPipelineCache pipelineCache,
1708 void* pData)
1709{
1710 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1711 return result;
1712}
1713
1714VkResult VKAPI vkMergePipelineCaches(
1715 VkDevice device,
1716 VkPipelineCache destCache,
1717 uint32_t srcCacheCount,
1718 const VkPipelineCache* pSrcCaches)
1719{
1720 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1721 return result;
1722}
1723
1724VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001725{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001726 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001727 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001728 // The order of operations here is a little convoluted but gets the job done
1729 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1730 // 2. Create state is then validated (which uses flags setup during shadowing)
1731 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1732 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001733 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001734 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001735 loader_platform_thread_unlock_mutex(&globalLock);
1736 if (VK_TRUE == valid) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001737 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001738 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1739 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001740 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001741 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001742 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001743 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001744 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001745 if (pPipeNode) {
1746 // If we allocated a pipeNode, need to clean it up here
1747 delete[] pPipeNode->pVertexBindingDescriptions;
1748 delete[] pPipeNode->pVertexAttributeDescriptions;
1749 delete[] pPipeNode->pAttachments;
1750 delete pPipeNode;
1751 }
1752 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001753 return result;
1754}
1755
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001756VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001757{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001758 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001759 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001760 loader_platform_thread_lock_mutex(&globalLock);
1761 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1762 pNewNode->sampler = *pSampler;
1763 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001764 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001765 loader_platform_thread_unlock_mutex(&globalLock);
1766 }
1767 return result;
1768}
1769
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001770VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001772 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001773 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001774 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1775 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001776 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 -06001777 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001778 }
1779 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001780 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1781 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1782 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001783 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001784 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001785 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001786 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001787 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001788 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1789 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001790 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001791 }
1792 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001793 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001794 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001795 uint32_t j = 0;
1796 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001797 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001798 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001800 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001801 }
1802 }
1803 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001805 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1806 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001807 // Put new node at Head of global Layer list
1808 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001809 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001810 loader_platform_thread_unlock_mutex(&globalLock);
1811 }
1812 return result;
1813}
1814
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001815VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001816{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001817 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001818 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001819 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001820 }
1821 return result;
1822}
1823
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001824VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001826 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001827 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001828 // Insert this pool into Global Pool LL at head
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001829 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1830 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001831 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001832 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001833 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001834 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 -06001835 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001836 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001837 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001838 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1839 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001840 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001841 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1842 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001843 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1844 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001845 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001846 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001847 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001848 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849 }
1850 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001851 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001852 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853 }
1854 return result;
1855}
1856
Mike Stroyan230e6252015-04-17 12:36:38 -06001857VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001858{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001859 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001860 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001861 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862 }
1863 return result;
1864}
1865
Cody Northropc8aa4a52015-08-03 12:47:29 -06001866VK_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 -06001867{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001868 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1869 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001870 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1871 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001872 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1873 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001874 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001875 if (count == 0) {
1876 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1877 "AllocDescriptorSets called with 0 count");
1878 }
1879 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001880 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1881 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001882 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001883 SET_NODE* pNewNode = new SET_NODE;
1884 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001885 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 -06001886 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001887 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001888 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001889 // Insert set at head of Set LL for this pool
1890 pNewNode->pNext = pPoolNode->pSets;
1891 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001892 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1893 if (NULL == pLayout) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001894 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1895 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001896 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001897 pNewNode->pLayout = pLayout;
1898 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001899 pNewNode->set = pDescriptorSets[i];
1900 pNewNode->setUsage = setUsage;
1901 pNewNode->descriptorCount = pLayout->endIndex + 1;
1902 if (pNewNode->descriptorCount) {
1903 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1904 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1905 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1906 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001907 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001908 }
1909 }
1910 }
1911 }
1912 return result;
1913}
1914
Tony Barbourb857d312015-07-10 10:50:45 -06001915VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1916{
1917 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1918 // TODO : Clean up any internal data structures using this obj.
1919 return result;
1920}
1921
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001922VK_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 -06001923{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001924 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1925 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001926 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001927 }
1928 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001929}
1930
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001931VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001932{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001933 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001934 VkDynamicViewportStateCreateInfo local_ci;
1935 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1936 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1937 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1938 loader_platform_thread_lock_mutex(&globalLock);
1939 dynamicVpStateMap[pState->handle] = local_ci;
1940 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001941 return result;
1942}
1943
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001944VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRasterStateCreateInfo* pCreateInfo, VkDynamicRasterState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001945{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001946 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001947 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
1948 loader_platform_thread_lock_mutex(&globalLock);
1949 dynamicRsStateMap[pState->handle] = *pCreateInfo;
1950 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001951 return result;
1952}
1953
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001954VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicColorBlendStateCreateInfo* pCreateInfo, VkDynamicColorBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001955{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001956 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001957 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
1958 loader_platform_thread_lock_mutex(&globalLock);
1959 dynamicCbStateMap[pState->handle] = *pCreateInfo;
1960 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001961 return result;
1962}
1963
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001964VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDepthStencilStateCreateInfo* pCreateInfo, VkDynamicDepthStencilState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001965{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001966 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001967 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
1968 loader_platform_thread_lock_mutex(&globalLock);
1969 dynamicDsStateMap[pState->handle] = *pCreateInfo;
1970 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001971 return result;
1972}
1973
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001974VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001976 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001977 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001978 loader_platform_thread_lock_mutex(&globalLock);
1979 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1980 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1981 pCB->cmdBuffer = *pCmdBuffer;
1982 pCB->flags = pCreateInfo->flags;
Cody Northropf02f9f82015-07-09 18:08:05 -06001983 pCB->pool = pCreateInfo->cmdPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001984 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001985 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001986 cmdBufferMap[*pCmdBuffer] = pCB;
1987 loader_platform_thread_unlock_mutex(&globalLock);
1988 updateCBTracking(*pCmdBuffer);
1989 }
1990 return result;
1991}
1992
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001993VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001994{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001995 // Validate command buffer level
1996 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1997 if (pCB) {
1998 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
1999 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2000 // These should be NULL for a Primary CB
2001 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2002 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2003 }
2004 } else {
2005 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2006 // These should NOT be null for an Secondary CB
2007 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2008 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2009 }
2010 }
2011 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002012 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002013 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002014 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2015 if (pCB) {
2016 if (CB_NEW != pCB->state)
2017 resetCB(cmdBuffer);
2018 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002019 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002020 // TODO : Need to pass cmdBuffer as objType here
2021 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 -06002022 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002023 }
2024 updateCBTracking(cmdBuffer);
2025 }
2026 return result;
2027}
2028
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002029VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002030{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002031 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2032 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2033 if (pCB) {
2034 if (pCB->state == CB_UPDATE_ACTIVE) {
2035 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2036 if (VK_SUCCESS == result) {
2037 updateCBTracking(cmdBuffer);
2038 pCB->state = CB_UPDATE_COMPLETE;
2039 // Reset CB status flags
2040 pCB->status = 0;
2041 printCB(cmdBuffer);
2042 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002043 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002044 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002045 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002046 }
2047 return result;
2048}
2049
Cody Northropf02f9f82015-07-09 18:08:05 -06002050VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002051{
Cody Northropf02f9f82015-07-09 18:08:05 -06002052 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002053 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002054 resetCB(cmdBuffer);
2055 updateCBTracking(cmdBuffer);
2056 }
2057 return result;
2058}
2059
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002060VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002061{
2062 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2063 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002064 if (pCB->state == CB_UPDATE_ACTIVE) {
2065 updateCBTracking(cmdBuffer);
2066 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002067 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002068 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2069 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002070 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002071 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2072 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002073 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002074 PIPELINE_NODE* pPN = getPipeline(pipeline);
2075 if (pPN) {
2076 pCB->lastBoundPipeline = pipeline;
2077 loader_platform_thread_lock_mutex(&globalLock);
2078 set_cb_pso_status(pCB, pPN);
2079 g_lastBoundPipeline = pPN;
2080 loader_platform_thread_unlock_mutex(&globalLock);
2081 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2082 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2083 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002084 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2085 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002086 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002087 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002088 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002089 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002090 }
2091 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002092}
2093
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002094VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002095{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002096 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2097 if (pCB) {
2098 if (pCB->state == CB_UPDATE_ACTIVE) {
2099 updateCBTracking(cmdBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002100 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002101 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002102 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2103 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002104 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002105 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002106 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2107 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002108 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 -06002109 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002110 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002111 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2112 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002113 }
2114 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002115 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002116 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002117 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002118 }
2119 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002120}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002121VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicRasterState(VkCmdBuffer cmdBuffer, VkDynamicRasterState dynamicRasterState)
2122{
2123 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2124 if (pCB) {
2125 if (pCB->state == CB_UPDATE_ACTIVE) {
2126 updateCBTracking(cmdBuffer);
2127 addCmd(pCB, CMD_BINDDYNAMICRASTERSTATE);
2128 if (!pCB->activeRenderPass) {
2129 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2130 "Incorrect call to vkCmdBindDynamicRasterState() without an active RenderPass.");
2131 }
2132 loader_platform_thread_lock_mutex(&globalLock);
2133 pCB->status |= CBSTATUS_RASTER_BOUND;
2134 if (dynamicRsStateMap.find(dynamicRasterState.handle) == dynamicRsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002135 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 -06002136 "Unable to find VkDynamicRasterState object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2137 } else {
2138 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2139 g_lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2140 }
2141 loader_platform_thread_unlock_mutex(&globalLock);
2142 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2143 } else {
2144 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicRasterState()");
2145 }
2146 }
2147}
2148VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(VkCmdBuffer cmdBuffer, VkDynamicColorBlendState dynamicColorBlendState)
2149{
2150 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2151 if (pCB) {
2152 if (pCB->state == CB_UPDATE_ACTIVE) {
2153 updateCBTracking(cmdBuffer);
2154 addCmd(pCB, CMD_BINDDYNAMICCOLORBLENDSTATE);
2155 if (!pCB->activeRenderPass) {
2156 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2157 "Incorrect call to vkCmdBindDynamicColorBlendState() without an active RenderPass.");
2158 }
2159 loader_platform_thread_lock_mutex(&globalLock);
2160 pCB->status |= CBSTATUS_COLOR_BLEND_BOUND;
2161 if (dynamicCbStateMap.find(dynamicColorBlendState.handle) == dynamicCbStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002162 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 -06002163 "Unable to find VkDynamicColorBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2164 } else {
2165 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2166 g_lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2167 }
2168 loader_platform_thread_unlock_mutex(&globalLock);
2169 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2170 } else {
2171 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicColorBlendState()");
2172 }
2173 }
2174}
2175VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(VkCmdBuffer cmdBuffer, VkDynamicDepthStencilState dynamicDepthStencilState)
2176{
2177 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2178 if (pCB) {
2179 if (pCB->state == CB_UPDATE_ACTIVE) {
2180 updateCBTracking(cmdBuffer);
2181 addCmd(pCB, CMD_BINDDYNAMICDEPTHSTENCILSTATE);
2182 if (!pCB->activeRenderPass) {
2183 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2184 "Incorrect call to vkCmdBindDynamicDepthStencilState() without an active RenderPass.");
2185 }
2186 loader_platform_thread_lock_mutex(&globalLock);
2187 pCB->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
2188 if (dynamicDsStateMap.find(dynamicDepthStencilState.handle) == dynamicDsStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002189 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 -06002190 "Unable to find VkDynamicDepthStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2191 } else {
2192 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2193 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2194 }
2195 loader_platform_thread_unlock_mutex(&globalLock);
2196 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
2197 } else {
2198 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthStencilState()");
2199 }
2200 }
2201}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002202VK_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 -06002203{
2204 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2205 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002206 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002207 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002208 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2209 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002210 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002211 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 -06002212 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2213 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002214 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002215 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2216 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002217 loader_platform_thread_lock_mutex(&globalLock);
2218 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002219 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002220 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2221 g_lastBoundDescriptorSet = pDescriptorSets[i];
2222 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002223 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2224 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002225 if (!pSet->pUpdateStructs)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002226 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2227 "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 -06002228 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002229 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2230 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002231 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002232 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002233 updateCBTracking(cmdBuffer);
2234 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis9bde5922015-06-22 18:00:14 -06002235 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 -06002236 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002237 } else {
2238 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002239 }
2240 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002241}
2242
Tony Barbour8205d902015-04-16 15:59:00 -06002243VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002244{
2245 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2246 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002247 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002248 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002249 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 -06002250 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2251 } else {
2252 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2253 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002254 updateCBTracking(cmdBuffer);
2255 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002256 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2257 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002258 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002259 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2260 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002261 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002262}
2263
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002264VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2265 VkCmdBuffer cmdBuffer,
2266 uint32_t startBinding,
2267 uint32_t bindingCount,
2268 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002269 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002270{
2271 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2272 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002273 if (pCB->state == CB_UPDATE_ACTIVE) {
2274 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002275 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002276 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 -06002277 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2278 } else {
2279 pCB->lastVtxBinding = startBinding + bindingCount -1;
2280 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002281 updateCBTracking(cmdBuffer);
2282 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002283 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2284 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002285 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002286 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002287 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002288 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002289 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002290}
2291
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002292VK_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 -06002293{
2294 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002295 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002296 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002297 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002298 pCB->drawCount[DRAW]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002299 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002300 // TODO : Need to pass cmdBuffer as srcObj here
2301 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 -06002302 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2303 synchAndPrintDSConfig(cmdBuffer);
2304 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002305 updateCBTracking(cmdBuffer);
2306 addCmd(pCB, CMD_DRAW);
2307 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002308 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002309 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002310 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2311 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002312 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002313}
2314
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002315VK_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 -06002316{
2317 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002318 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002319 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002320 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002321 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002322 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002323 // TODO : Need to pass cmdBuffer as srcObj here
2324 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 -06002325 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2326 synchAndPrintDSConfig(cmdBuffer);
2327 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002328 updateCBTracking(cmdBuffer);
2329 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002330 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2331 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002332 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002333 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2334 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002335 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002336}
2337
Tony Barbour8205d902015-04-16 15:59:00 -06002338VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002339{
2340 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002341 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002342 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002343 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002344 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002345 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002346 // TODO : Need to pass cmdBuffer as srcObj here
2347 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 -06002348 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2349 synchAndPrintDSConfig(cmdBuffer);
2350 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002351 updateCBTracking(cmdBuffer);
2352 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002353 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2354 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002355 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002356 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2357 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002358 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359}
2360
Tony Barbour8205d902015-04-16 15:59:00 -06002361VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362{
2363 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002364 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002365 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002366 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002367 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002368 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002369 // TODO : Need to pass cmdBuffer as srcObj here
2370 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 -06002371 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2372 synchAndPrintDSConfig(cmdBuffer);
2373 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002374 updateCBTracking(cmdBuffer);
2375 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2376 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002377 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002378 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002379 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2380 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002381 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002382}
2383
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002384VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002385{
2386 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2387 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002388 if (pCB->state == CB_UPDATE_ACTIVE) {
2389 updateCBTracking(cmdBuffer);
2390 addCmd(pCB, CMD_DISPATCH);
2391 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002392 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002393 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2394 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002395 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002396}
2397
Tony Barbour8205d902015-04-16 15:59:00 -06002398VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002399{
2400 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2401 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002402 if (pCB->state == CB_UPDATE_ACTIVE) {
2403 updateCBTracking(cmdBuffer);
2404 addCmd(pCB, CMD_DISPATCHINDIRECT);
2405 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002406 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002407 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2408 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002409 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002410}
2411
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002412VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002413{
2414 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2415 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002416 if (pCB->state == CB_UPDATE_ACTIVE) {
2417 updateCBTracking(cmdBuffer);
2418 addCmd(pCB, CMD_COPYBUFFER);
2419 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002420 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002421 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2422 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002423 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002424}
2425
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002426VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2427 VkImage srcImage,
2428 VkImageLayout srcImageLayout,
2429 VkImage destImage,
2430 VkImageLayout destImageLayout,
2431 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002432{
2433 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2434 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002435 if (pCB->state == CB_UPDATE_ACTIVE) {
2436 updateCBTracking(cmdBuffer);
2437 addCmd(pCB, CMD_COPYIMAGE);
2438 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002439 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002440 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2441 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002442 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443}
2444
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002445VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2446 VkImage srcImage, VkImageLayout srcImageLayout,
2447 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002448 uint32_t regionCount, const VkImageBlit* pRegions,
2449 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002450{
2451 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2452 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002453 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002454 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002455 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2456 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002457 } else {
2458 updateCBTracking(cmdBuffer);
2459 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002460 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 -06002461 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002462 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002463 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2464 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002465 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002466}
2467
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002468VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2469 VkBuffer srcBuffer,
2470 VkImage destImage, VkImageLayout destImageLayout,
2471 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002472{
2473 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2474 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002475 if (pCB->state == CB_UPDATE_ACTIVE) {
2476 updateCBTracking(cmdBuffer);
2477 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2478 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002479 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002480 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2481 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002482 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002483}
2484
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002485VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2486 VkImage srcImage, VkImageLayout srcImageLayout,
2487 VkBuffer destBuffer,
2488 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002489{
2490 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2491 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002492 if (pCB->state == CB_UPDATE_ACTIVE) {
2493 updateCBTracking(cmdBuffer);
2494 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2495 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002496 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002497 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2498 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002499 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002500}
2501
Tony Barbour8205d902015-04-16 15:59:00 -06002502VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002503{
2504 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2505 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002506 if (pCB->state == CB_UPDATE_ACTIVE) {
2507 updateCBTracking(cmdBuffer);
2508 addCmd(pCB, CMD_UPDATEBUFFER);
2509 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002510 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002511 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2512 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002514}
2515
Tony Barbour8205d902015-04-16 15:59:00 -06002516VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002517{
2518 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2519 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002520 if (pCB->state == CB_UPDATE_ACTIVE) {
2521 updateCBTracking(cmdBuffer);
2522 addCmd(pCB, CMD_FILLBUFFER);
2523 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002524 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002525 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2526 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002527 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002528}
2529
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002530VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2531 VkCmdBuffer cmdBuffer,
2532 uint32_t colorAttachment,
2533 VkImageLayout imageLayout,
2534 const VkClearColorValue* pColor,
2535 uint32_t rectCount,
2536 const VkRect3D* pRects)
2537{
2538 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2539 if (pCB) {
2540 if (pCB->state == CB_UPDATE_ACTIVE) {
2541 // Warn if this is issued prior to Draw Cmd
2542 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002543 // TODO : cmdBuffer should be srcObj
2544 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 -06002545 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2546 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2547 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002548 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002549 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 -06002550 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2551 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2552 } else {
2553 updateCBTracking(cmdBuffer);
2554 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2555 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2556 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002557 } else {
2558 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2559 }
2560 }
2561}
2562
2563VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2564 VkCmdBuffer cmdBuffer,
2565 VkImageAspectFlags imageAspectMask,
2566 VkImageLayout imageLayout,
2567 float depth,
2568 uint32_t stencil,
2569 uint32_t rectCount,
2570 const VkRect3D* pRects)
2571{
2572 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2573 if (pCB) {
2574 if (pCB->state == CB_UPDATE_ACTIVE) {
2575 // Warn if this is issued prior to Draw Cmd
2576 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002577 // TODO : cmdBuffer should be srcObj
2578 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 -06002579 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2580 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2581 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002582 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002583 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 -06002584 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2585 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2586 } else {
2587 updateCBTracking(cmdBuffer);
2588 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2589 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2590 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002591 } else {
2592 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2593 }
2594 }
2595}
2596
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002597VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2598 VkCmdBuffer cmdBuffer,
2599 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002600 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002601 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002602{
2603 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2604 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002605 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002606 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002607 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 -06002608 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2609 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2610 } else {
2611 updateCBTracking(cmdBuffer);
2612 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2613 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2614 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002615 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002616 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2617 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002618 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002619}
2620
Chris Forbes2951d7d2015-06-22 17:21:59 +12002621VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002622 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002623 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002624 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625{
2626 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2627 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002628 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002629 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002630 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 -06002631 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2632 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2633 } else {
2634 updateCBTracking(cmdBuffer);
2635 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2636 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2637 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002638 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002639 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2640 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002641 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002642}
2643
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002644VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2645 VkImage srcImage, VkImageLayout srcImageLayout,
2646 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002647 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002648{
2649 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2650 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002651 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002652 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002653 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2654 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002655 } else {
2656 updateCBTracking(cmdBuffer);
2657 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002658 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002659 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002660 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002661 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2662 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002664}
2665
Tony Barbourc2e987e2015-06-29 16:20:35 -06002666VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002667{
2668 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2669 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002670 if (pCB->state == CB_UPDATE_ACTIVE) {
2671 updateCBTracking(cmdBuffer);
2672 addCmd(pCB, CMD_SETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002673 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002674 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002675 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2676 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002677 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002678}
2679
Tony Barbourc2e987e2015-06-29 16:20:35 -06002680VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002681{
2682 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2683 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002684 if (pCB->state == CB_UPDATE_ACTIVE) {
2685 updateCBTracking(cmdBuffer);
2686 addCmd(pCB, CMD_RESETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002687 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002688 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002689 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2690 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002691 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002692}
2693
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002694VK_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 -06002695{
2696 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2697 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002698 if (pCB->state == CB_UPDATE_ACTIVE) {
2699 updateCBTracking(cmdBuffer);
2700 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002701 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002702 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002703 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2704 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002705 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002706}
2707
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002708VK_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 -06002709{
2710 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2711 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002712 if (pCB->state == CB_UPDATE_ACTIVE) {
2713 updateCBTracking(cmdBuffer);
2714 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter73a21d32015-07-12 13:20:05 -06002715 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002716 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002717 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2718 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002719 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002720}
2721
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002722VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002723{
2724 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2725 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002726 if (pCB->state == CB_UPDATE_ACTIVE) {
2727 updateCBTracking(cmdBuffer);
2728 addCmd(pCB, CMD_BEGINQUERY);
2729 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002730 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002731 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2732 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002733 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002734}
2735
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002736VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002737{
2738 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2739 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002740 if (pCB->state == CB_UPDATE_ACTIVE) {
2741 updateCBTracking(cmdBuffer);
2742 addCmd(pCB, CMD_ENDQUERY);
2743 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002744 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002745 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2746 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002747 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002748}
2749
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002750VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002751{
2752 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2753 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002754 if (pCB->state == CB_UPDATE_ACTIVE) {
2755 updateCBTracking(cmdBuffer);
2756 addCmd(pCB, CMD_RESETQUERYPOOL);
2757 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002758 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002759 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2760 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002761 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002762}
2763
Tony Barbour8205d902015-04-16 15:59:00 -06002764VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002765{
2766 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2767 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002768 if (pCB->state == CB_UPDATE_ACTIVE) {
2769 updateCBTracking(cmdBuffer);
2770 addCmd(pCB, CMD_WRITETIMESTAMP);
2771 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002772 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002773 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2774 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002775 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002776}
2777
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002778VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002779{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002780 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002781 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002782 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002783 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002784 if (pCreateInfo->pAttachments) {
Cody Northropf110c6e2015-08-04 10:47:08 -06002785 localFBCI->pAttachments = new VkAttachmentView[localFBCI->attachmentCount];
2786 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkAttachmentView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002787 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002788 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002789 }
2790 return result;
2791}
2792
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002793VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002794{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002795 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002796 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002797 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002798 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002799 if (pCreateInfo->pAttachments) {
2800 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2801 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002802 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002803 if (pCreateInfo->pSubpasses) {
2804 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2805 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2806
2807 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2808 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2809 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002810 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002811 subpass->preserveCount;
2812 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2813
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002814 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002815 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002816 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002817 attachments += subpass->inputCount;
2818
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002819 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002820 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002821 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002822 attachments += subpass->colorCount;
2823
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002824 if (subpass->pResolveAttachments) {
2825 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002826 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002827 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002828 attachments += subpass->colorCount;
2829 }
2830
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002831 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002832 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002833 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002834 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002835 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002836 if (pCreateInfo->pDependencies) {
2837 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2838 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002839 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002840 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002841 }
2842 return result;
2843}
2844
Chia-I Wuc278df82015-07-07 11:50:03 +08002845VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002846{
2847 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2848 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002849 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002850 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002851 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2852 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002853 } else {
2854 updateCBTracking(cmdBuffer);
2855 addCmd(pCB, CMD_BEGINRENDERPASS);
2856 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002857 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002858 pCB->framebuffer = pRenderPassBegin->framebuffer;
2859 if (pCB->lastBoundPipeline) {
2860 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2861 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002862 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002863 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002864 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002865 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002866 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002867 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002868 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002869}
2870
Chia-I Wuc278df82015-07-07 11:50:03 +08002871VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2872{
2873 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2874 if (pCB) {
2875 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002876 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wuc278df82015-07-07 11:50:03 +08002877 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2878 } else {
2879 updateCBTracking(cmdBuffer);
2880 addCmd(pCB, CMD_NEXTSUBPASS);
2881 pCB->activeSubpass++;
2882 if (pCB->lastBoundPipeline) {
2883 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2884 }
2885 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2886 }
2887 }
2888}
2889
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002890VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002891{
2892 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2893 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002894 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002895 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 +08002896 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06002897 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002898 updateCBTracking(cmdBuffer);
2899 addCmd(pCB, CMD_ENDRENDERPASS);
2900 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08002901 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002902 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2903 }
2904 }
2905}
2906
2907VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2908{
2909 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2910 if (pCB) {
2911 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002912 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 +08002913 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2914 } else {
2915 updateCBTracking(cmdBuffer);
2916 addCmd(pCB, CMD_EXECUTECOMMANDS);
2917 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002918 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002919 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002920}
2921
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002922VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2923 VkInstance instance,
2924 VkFlags msgFlags,
2925 const PFN_vkDbgMsgCallback pfnMsgCallback,
2926 void* pUserData,
2927 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002928{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002929 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002930 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2931 if (VK_SUCCESS == res) {
2932 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2933 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2934 }
2935 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002936}
2937
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06002938VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2939 VkInstance instance,
2940 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002941{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002942 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06002943 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2944 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2945 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2946 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002947}
2948
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002949VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002950{
2951 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002952 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2953 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002954 // TODO : cmdBuffer should be srcObj
2955 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 -06002956 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002957 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002958 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002959 updateCBTracking(cmdBuffer);
2960 addCmd(pCB, CMD_DBGMARKERBEGIN);
2961 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002962 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002963}
2964
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002965VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002966{
2967 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002968 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2969 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002970 // TODO : cmdBuffer should be srcObj
2971 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 -06002972 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002973 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002974 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002975 updateCBTracking(cmdBuffer);
2976 addCmd(pCB, CMD_DBGMARKEREND);
2977 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06002978 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2979}
2980
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002981//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2982//{
2983// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2984// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2985// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2986// "Attempt to use DbgSetObjectTag but extension disabled!");
2987// return VK_ERROR_UNAVAILABLE;
2988// }
2989// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2990//}
2991//
2992//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2993//{
2994// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2995// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2996// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2997// "Attempt to use DbgSetObjectName but extension disabled!");
2998// return VK_ERROR_UNAVAILABLE;
2999// }
3000// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3001//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003002
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003003VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003004{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003005 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003006 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003007
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003008 /* loader uses this to force layer initialization; device object is wrapped */
3009 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003010 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003011 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003012 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003013 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003014 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003015 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003016 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003017 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003018 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003019 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003020 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003021 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003022 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003023 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003024 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003025 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003026 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003027 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003028 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003029 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003030 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003031 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003032 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003033 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003034 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003035 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003036 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003037 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003038 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003039 if (!strcmp(funcName, "vkDestroyAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003040 return (PFN_vkVoidFunction) vkDestroyAttachmentView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003041 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003042 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003043 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003044 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003045 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003046 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003047 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003048 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003049 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003050 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003051 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003052 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003053 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003054 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003055 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003056 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003057 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003058 return (PFN_vkVoidFunction) vkDestroyDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003059 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003060 return (PFN_vkVoidFunction) vkDestroyDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003061 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003062 return (PFN_vkVoidFunction) vkDestroyDynamicDepthStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003063 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003064 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003065 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003066 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003067 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003068 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003069 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003070 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003071 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003072 return (PFN_vkVoidFunction) vkCreateImageView;
Tobin Ehlis44c757d2015-07-10 12:15:19 -06003073 if (!strcmp(funcName, "vkCreateAttachmentView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003074 return (PFN_vkVoidFunction) vkCreateAttachmentView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003075 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003076 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003077 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003078 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003079 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003080 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003081 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003082 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003083 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003084 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003085 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003086 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003087 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003088 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003089 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003090 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003091 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003092 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003093 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003094 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003095 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003096 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003097 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003098 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003099 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003100 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003101 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003102 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003103 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003104 return (PFN_vkVoidFunction) vkCreateDynamicRasterState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003105 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003106 return (PFN_vkVoidFunction) vkCreateDynamicColorBlendState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003107 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003108 return (PFN_vkVoidFunction) vkCreateDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003109 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003110 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003111 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003112 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003113 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003114 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003115 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003116 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003117 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003118 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003119 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003120 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003121 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003122 return (PFN_vkVoidFunction) vkCmdBindDynamicRasterState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003123 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003124 return (PFN_vkVoidFunction) vkCmdBindDynamicColorBlendState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003125 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003126 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003127 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003128 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003129 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003130 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003131 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003132 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003133 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003134 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003135 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003136 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003137 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003138 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003139 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003140 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003141 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003142 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003143 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003144 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003145 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003146 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003147 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003148 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003149 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003150 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003151 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003152 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003153 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003154 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003155 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003156 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003157 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003158 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003159 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003160 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003161 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003162 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003163 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003164 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003165 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003166 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003167 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003168 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003169 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003170 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003171 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003172 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003173 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003174 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003175 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003176 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003177 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003178 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003179 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003180 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003181 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003182 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003183 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003184 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003185 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003186 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003187 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003188 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003189 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003190 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003191 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003192 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003193
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003194 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3195 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003196 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003197 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003198 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003199 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003200 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003201// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3202// return (void*) vkDbgSetObjectTag;
3203// if (!strcmp(funcName, "vkDbgSetObjectName"))
3204// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003205 }
3206 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003207 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003208 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003209 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003210 }
3211}
3212
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003213VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003214{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003215 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003216 if (instance == NULL)
3217 return NULL;
3218
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003219 /* loader uses this to force layer initialization; instance object is wrapped */
3220 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003221 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003222 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003223 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003224 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003226 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003228 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003230 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003232 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003234 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003236
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003237 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3238 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003239 if (fptr)
3240 return fptr;
3241
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003242 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003243 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003244 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003245 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003246 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003247 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003248}