blob: cbf96c1f7e80c83ead2bd45f231539f553d20425 [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;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060065unordered_map<uint64_t, VkImageViewCreateInfo> viewMap;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060066unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
67unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicVpStateMap;
Cody Northrope4bc6942015-08-26 10:01:32 -060068unordered_map<uint64_t, VkDynamicLineWidthStateCreateInfo> dynamicLineWidthStateMap;
69unordered_map<uint64_t, VkDynamicDepthBiasStateCreateInfo> dynamicDepthBiasStateMap;
70unordered_map<uint64_t, VkDynamicBlendStateCreateInfo> dynamicBlendStateMap;
71unordered_map<uint64_t, VkDynamicDepthBoundsStateCreateInfo> dynamicDepthBoundsStateMap;
Cody Northrop2605cb02015-08-18 15:21:16 -060072unordered_map<uint64_t, std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo>> dynamicStencilStateMap;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060073unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
74unordered_map<uint64_t, POOL_NODE*> poolMap;
75unordered_map<uint64_t, SET_NODE*> setMap;
76unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060077// Map for layout chains
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060078unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
79unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
80unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060081
Jon Ashburn6f8cd632015-06-01 09:37:38 -060082struct devExts {
83 bool debug_marker_enabled;
84};
85
Jon Ashburn6f8cd632015-06-01 09:37:38 -060086static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060087
Tobin Ehlis63bb9482015-03-17 16:24:32 -060088static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060089
Tobin Ehlis63bb9482015-03-17 16:24:32 -060090// TODO : This can be much smarter, using separate locks for separate global data
91static int globalLockInitialized = 0;
92static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060093#define MAX_TID 513
94static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
95static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060096
97template layer_data *get_my_data_ptr<layer_data>(
98 void *data_key,
99 std::unordered_map<void *, layer_data *> &data_map);
100
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600101debug_report_data *mdd(void* object)
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600102{
103 dispatch_key key = get_dispatch_key(object);
104 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
105#if DISPATCH_MAP_DEBUG
106 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
107#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600108 return my_data->report_data;
109}
110
111debug_report_data *mid(VkInstance object)
112{
113 dispatch_key key = get_dispatch_key(object);
Tobin Ehlis8354e022015-09-01 11:46:36 -0600114 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600115#if DISPATCH_MAP_DEBUG
116 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
117#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600118 return my_data->report_data;
119}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600120// Map actual TID to an index value and return that index
121// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
122static uint32_t getTIDIndex() {
123 loader_platform_thread_id tid = loader_platform_get_thread_id();
124 for (uint32_t i = 0; i < g_maxTID; i++) {
125 if (tid == g_tidMapping[i])
126 return i;
127 }
128 // Don't yet have mapping, set it and return newly set index
129 uint32_t retVal = (uint32_t) g_maxTID;
130 g_tidMapping[g_maxTID++] = tid;
131 assert(g_maxTID < MAX_TID);
132 return retVal;
133}
134// Return a string representation of CMD_TYPE enum
135static string cmdTypeToString(CMD_TYPE cmd)
136{
137 switch (cmd)
138 {
139 case CMD_BINDPIPELINE:
140 return "CMD_BINDPIPELINE";
141 case CMD_BINDPIPELINEDELTA:
142 return "CMD_BINDPIPELINEDELTA";
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600143 case CMD_BINDDYNAMICVIEWPORTSTATE:
144 return "CMD_BINDDYNAMICVIEWPORTSTATE";
Cody Northrope4bc6942015-08-26 10:01:32 -0600145 case CMD_BINDDYNAMICLINEWIDTHSTATE:
146 return "CMD_BINDDYNAMICLINEWIDTHSTATE";
147 case CMD_BINDDYNAMICDEPTHBIASSTATE:
148 return "CMD_BINDDYNAMICDEPTHBIASSTATE";
149 case CMD_BINDDYNAMICBLENDSTATE:
150 return "CMD_BINDDYNAMICBLENDSTATE";
151 case CMD_BINDDYNAMICDEPTHBOUNDSSTATE:
152 return "CMD_BINDDYNAMICDEPTHBOUNDSSTATE";
Cody Northrop2605cb02015-08-18 15:21:16 -0600153 case CMD_BINDDYNAMICSTENCILSTATE:
154 return "CMD_BINDDYNAMICSTENCILSTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600155 case CMD_BINDDESCRIPTORSETS:
156 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600157 case CMD_BINDINDEXBUFFER:
158 return "CMD_BINDINDEXBUFFER";
159 case CMD_BINDVERTEXBUFFER:
160 return "CMD_BINDVERTEXBUFFER";
161 case CMD_DRAW:
162 return "CMD_DRAW";
163 case CMD_DRAWINDEXED:
164 return "CMD_DRAWINDEXED";
165 case CMD_DRAWINDIRECT:
166 return "CMD_DRAWINDIRECT";
167 case CMD_DRAWINDEXEDINDIRECT:
168 return "CMD_DRAWINDEXEDINDIRECT";
169 case CMD_DISPATCH:
170 return "CMD_DISPATCH";
171 case CMD_DISPATCHINDIRECT:
172 return "CMD_DISPATCHINDIRECT";
173 case CMD_COPYBUFFER:
174 return "CMD_COPYBUFFER";
175 case CMD_COPYIMAGE:
176 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600177 case CMD_BLITIMAGE:
178 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600179 case CMD_COPYBUFFERTOIMAGE:
180 return "CMD_COPYBUFFERTOIMAGE";
181 case CMD_COPYIMAGETOBUFFER:
182 return "CMD_COPYIMAGETOBUFFER";
183 case CMD_CLONEIMAGEDATA:
184 return "CMD_CLONEIMAGEDATA";
185 case CMD_UPDATEBUFFER:
186 return "CMD_UPDATEBUFFER";
187 case CMD_FILLBUFFER:
188 return "CMD_FILLBUFFER";
189 case CMD_CLEARCOLORIMAGE:
190 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600191 case CMD_CLEARCOLORATTACHMENT:
192 return "CMD_CLEARCOLORATTACHMENT";
193 case CMD_CLEARDEPTHSTENCILIMAGE:
194 return "CMD_CLEARDEPTHSTENCILIMAGE";
195 case CMD_CLEARDEPTHSTENCILATTACHMENT:
196 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600197 case CMD_RESOLVEIMAGE:
198 return "CMD_RESOLVEIMAGE";
199 case CMD_SETEVENT:
200 return "CMD_SETEVENT";
201 case CMD_RESETEVENT:
202 return "CMD_RESETEVENT";
203 case CMD_WAITEVENTS:
204 return "CMD_WAITEVENTS";
205 case CMD_PIPELINEBARRIER:
206 return "CMD_PIPELINEBARRIER";
207 case CMD_BEGINQUERY:
208 return "CMD_BEGINQUERY";
209 case CMD_ENDQUERY:
210 return "CMD_ENDQUERY";
211 case CMD_RESETQUERYPOOL:
212 return "CMD_RESETQUERYPOOL";
213 case CMD_WRITETIMESTAMP:
214 return "CMD_WRITETIMESTAMP";
215 case CMD_INITATOMICCOUNTERS:
216 return "CMD_INITATOMICCOUNTERS";
217 case CMD_LOADATOMICCOUNTERS:
218 return "CMD_LOADATOMICCOUNTERS";
219 case CMD_SAVEATOMICCOUNTERS:
220 return "CMD_SAVEATOMICCOUNTERS";
221 case CMD_BEGINRENDERPASS:
222 return "CMD_BEGINRENDERPASS";
223 case CMD_ENDRENDERPASS:
224 return "CMD_ENDRENDERPASS";
225 case CMD_DBGMARKERBEGIN:
226 return "CMD_DBGMARKERBEGIN";
227 case CMD_DBGMARKEREND:
228 return "CMD_DBGMARKEREND";
229 default:
230 return "UNKNOWN";
231 }
232}
233// Block of code at start here for managing/tracking Pipeline state that this layer cares about
234// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600235#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600236#define MAX_SLOTS 2048
237#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
238
239static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
240
241// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
242// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
243// to that same cmd buffer by separate thread are not changing state from underneath us
244// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600245static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600246// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600247static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
248static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600249// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600250static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
251static PIPELINE_NODE* g_lastBoundPipeline = NULL;
252static uint64_t g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {0};
Dana Jansens4a3e0862015-07-30 13:22:15 -0700253static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600254#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
255
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600256//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600257
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600258// Free all allocated nodes for Dynamic State objs
Tobin Ehliseaf28662015-04-08 10:58:37 -0600259static void deleteDynamicState()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600260{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600261 for (auto ii=dynamicVpStateMap.begin(); ii!=dynamicVpStateMap.end(); ++ii) {
262 delete[] (*ii).second.pScissors;
263 delete[] (*ii).second.pViewports;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600264 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600265 dynamicVpStateMap.clear();
Cody Northrope4bc6942015-08-26 10:01:32 -0600266 dynamicLineWidthStateMap.clear();
267 dynamicDepthBiasStateMap.clear();
268 dynamicBlendStateMap.clear();
269 dynamicDepthBoundsStateMap.clear();
Cody Northrop2605cb02015-08-18 15:21:16 -0600270 dynamicStencilStateMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600271}
272// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600273static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600274{
David Pinedof5997ab2015-04-27 16:36:17 -0600275 if (sampleMap.size() <= 0)
276 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600277 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600278 delete (*ii).second;
279 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600280 sampleMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600282static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600283{
284 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600285 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600286 loader_platform_thread_unlock_mutex(&globalLock);
287 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600288 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600289 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600290 return &imageMap[view.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600291 }
292}
293// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600294static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600295{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600296 if (imageMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -0600297 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600298 imageMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600299}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600300static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301{
302 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600303 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600304 loader_platform_thread_unlock_mutex(&globalLock);
305 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600306 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600307 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600308 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600309 }
310}
311// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600312static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600313{
David Pinedof5997ab2015-04-27 16:36:17 -0600314 if (bufferMap.size() <= 0)
315 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600316 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600317 delete (*ii).second;
318 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600319 bufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600320}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600321static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600322// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600323static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600324{
325 g_lastCmdBuffer[getTIDIndex()] = cb;
326 GLOBAL_CB_NODE* pCB = getCBNode(cb);
327 loader_platform_thread_lock_mutex(&globalLock);
328 g_lastGlobalCB = pCB;
329 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
330 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
331 if (g_pLastTouchedCB[i] == pCB) {
332 loader_platform_thread_unlock_mutex(&globalLock);
333 return;
334 }
335 }
336 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
337 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
338 loader_platform_thread_unlock_mutex(&globalLock);
339}
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600340static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600341{
342 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
343 if (pCB->drawCount[i])
344 return VK_TRUE;
345 }
346 return VK_FALSE;
347}
Tobin Ehlis97866202015-06-10 12:57:07 -0600348// Check object status for selected flag state
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600349static 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 -0600350{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600351 // If non-zero enable mask is present, check it against status but if enable_mask
352 // is 0 then no enable required so we should always just check status
353 if ((!enable_mask) || (enable_mask & pNode->status)) {
354 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600355 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600356 return log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -0600357 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->cmdBuffer), fail_msg);
Tobin Ehlis97866202015-06-10 12:57:07 -0600358 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600359 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600360 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600361}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600362// For given dynamic state handle and type, return CreateInfo for that Dynamic State
363static void* getDynamicStateCreateInfo(const uint64_t handle, const DYNAMIC_STATE_BIND_POINT type)
364{
365 switch (type) {
366 case VK_STATE_BIND_POINT_VIEWPORT:
367 return (void*)&dynamicVpStateMap[handle];
Cody Northrope4bc6942015-08-26 10:01:32 -0600368 case VK_STATE_BIND_POINT_LINE_WIDTH:
369 return (void*)&dynamicLineWidthStateMap[handle];
370 case VK_STATE_BIND_POINT_DEPTH_BIAS:
371 return (void*)&dynamicDepthBiasStateMap[handle];
372 case VK_STATE_BIND_POINT_BLEND:
373 return (void*)&dynamicBlendStateMap[handle];
374 case VK_STATE_BIND_POINT_DEPTH_BOUNDS:
375 return (void*)&dynamicDepthBoundsStateMap[handle];
Cody Northrop2605cb02015-08-18 15:21:16 -0600376 case VK_STATE_BIND_POINT_STENCIL:
377 return (void*)&dynamicStencilStateMap[handle];
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600378 default:
379 return NULL;
380 }
381}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600382// Print the last bound dynamic state
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600383static VkBool32 printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600384{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600385 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600386 GLOBAL_CB_NODE* pCB = getCBNode(cb);
387 if (pCB) {
388 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600389 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Mark Lobodzinski563d1bb2015-08-11 15:44:15 -0600390 if (pCB->lastBoundDynamicState[i]) {
391 void* pDynStateCI = getDynamicStateCreateInfo(pCB->lastBoundDynamicState[i], (DYNAMIC_STATE_BIND_POINT)i);
392 if (pDynStateCI) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600393 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
Mark Lobodzinski563d1bb2015-08-11 15:44:15 -0600394 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600395 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
Mark Lobodzinski563d1bb2015-08-11 15:44:15 -0600396 dynamic_display(pDynStateCI, " ").c_str());
397 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600398 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Mark Lobodzinski563d1bb2015-08-11 15:44:15 -0600399 "No dynamic state of type %s bound", string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str());
400 }
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600401 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600402 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600403 "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 -0600404 }
405 }
406 loader_platform_thread_unlock_mutex(&globalLock);
407 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600408 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600409}
410// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600412{
413 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600414 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600415 loader_platform_thread_unlock_mutex(&globalLock);
416 return NULL;
417 }
418 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600419 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600420}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600421// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600422static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
423 VkBool32 result;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600424 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");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600425 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_LINE_WIDTH_BOUND, CBSTATUS_LINE_WIDTH_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_LINE_WIDTH_NOT_BOUND, "Line width object not bound to this command buffer");
426 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_DEPTH_BIAS_BOUND, CBSTATUS_DEPTH_BIAS_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_BIAS_NOT_BOUND, "Depth bias object not bound to this command buffer");
427 result |= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_BLEND_BOUND, CBSTATUS_BLEND_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_BLEND_NOT_BOUND, "Blend object not bound to this command buffer");
428 result |= validate_status(pCB, CBSTATUS_DEPTH_WRITE_ENABLE, CBSTATUS_DEPTH_BOUNDS_BOUND, CBSTATUS_DEPTH_BOUNDS_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, "Depth bounds object not bound to this command buffer");
429 result |= validate_status(pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_BOUND, CBSTATUS_STENCIL_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Stencil object not bound to this command buffer");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600430 if (indexedDraw)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600431 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");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600432 return result;
433}
434// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600435static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600436 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600437 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600438 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
439 // Now complete other state checks
Tobin Ehlis12ab7dc2015-09-09 13:31:01 -0600440 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
441 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
442 // We should have that check separately and then gate this check based on that check
443 if (pPipe && (pCB->lastBoundPipelineLayout) && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600444 result = VK_FALSE;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600445 result |= 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 -0600446 "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 -0600447 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600448 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600449 result |= 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 -0600450 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
451 }
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600452 // Verify Vtx binding
453 if (MAX_BINDING != pCB->lastVtxBinding) {
454 if (pCB->lastVtxBinding >= pPipe->vtxBindingCount) {
455 if (0 == pPipe->vtxBindingCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600456 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600457 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600458 }
459 else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600460 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600461 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipe->vtxBindingCount - 1));
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600462 }
463 }
464 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600465 return result;
466}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600467// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600468static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600469{
470 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600471 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600472 loader_platform_thread_unlock_mutex(&globalLock);
473 return NULL;
474 }
475 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600476 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600477}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600478// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600479static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600480{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600481 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisde63c532015-06-18 15:59:33 -0600482 // VS is required
483 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600484 skipCall |= 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 -0600485 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600486 }
487 // Either both or neither TC/TE shaders should be defined
488 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
489 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600490 skipCall |= 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 -0600491 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600492 }
493 // Compute shaders should be specified independent of Gfx shaders
494 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
495 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
496 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
497 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600498 skipCall |= 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 -0600499 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600500 }
501 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
502 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
503 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
504 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600505 skipCall |= 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 -0600506 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600507 }
508 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
509 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600510 skipCall |= 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 -0600511 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600512 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600513 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -0600514}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600515// Init the pipeline mapping info based on pipeline create info LL tree
516// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600517static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600518{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600519 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
520 if (pBasePipeline) {
521 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600522 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600523 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
524 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600525 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600526 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600527 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600528
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600529 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600530 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600531 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600532
533 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
534 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
535
536 switch (pPSSCI->stage) {
537 case VK_SHADER_STAGE_VERTEX:
538 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
539 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600540 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600541 case VK_SHADER_STAGE_TESS_CONTROL:
542 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
543 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600544 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600545 case VK_SHADER_STAGE_TESS_EVALUATION:
546 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
547 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600548 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600549 case VK_SHADER_STAGE_GEOMETRY:
550 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
551 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600552 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600553 case VK_SHADER_STAGE_FRAGMENT:
554 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
555 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600556 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600557 case VK_SHADER_STAGE_COMPUTE:
558 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
559 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600560 break;
561 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600562 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600563 break;
564 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600565 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600566
567 if (pCreateInfo->pVertexInputState != NULL) {
568 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
569 // Copy embedded ptrs
570 pVICI = pCreateInfo->pVertexInputState;
571 pPipeline->vtxBindingCount = pVICI->bindingCount;
572 if (pPipeline->vtxBindingCount) {
573 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
574 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
575 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
576 }
577 pPipeline->vtxAttributeCount = pVICI->attributeCount;
578 if (pPipeline->vtxAttributeCount) {
579 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
580 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
581 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
582 }
583 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
584 }
Tony Barboure307f582015-07-10 15:29:03 -0600585 if (pCreateInfo->pInputAssemblyState != NULL) {
586 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
587 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600588 }
Tony Barboure307f582015-07-10 15:29:03 -0600589 if (pCreateInfo->pTessellationState != NULL) {
590 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
591 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600592 }
Tony Barboure307f582015-07-10 15:29:03 -0600593 if (pCreateInfo->pViewportState != NULL) {
594 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
595 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600596 }
Tony Barboure307f582015-07-10 15:29:03 -0600597 if (pCreateInfo->pRasterState != NULL) {
598 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
599 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600600 }
Tony Barboure307f582015-07-10 15:29:03 -0600601 if (pCreateInfo->pMultisampleState != NULL) {
602 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
603 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600604 }
Tony Barboure307f582015-07-10 15:29:03 -0600605 if (pCreateInfo->pColorBlendState != NULL) {
606 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600607 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600608 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600609 pPipeline->attachmentCount = pCBCI->attachmentCount;
610 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600611 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
612 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600613 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
614 }
Tony Barboure307f582015-07-10 15:29:03 -0600615 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600616 }
Tony Barboure307f582015-07-10 15:29:03 -0600617 if (pCreateInfo->pDepthStencilState != NULL) {
618 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
619 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600620 }
621
622 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
623 if (pCreateInfo->stageCount != 0) {
624 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
625 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
626 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
627 }
628
Tobin Ehlisde63c532015-06-18 15:59:33 -0600629 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600630}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600631
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600632// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600633static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600634{
David Pinedof5997ab2015-04-27 16:36:17 -0600635 if (pipelineMap.size() <= 0)
636 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600637 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600638 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
639 delete[] (*ii).second->graphicsPipelineCI.pStages;
640 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600641 if ((*ii).second->pVertexBindingDescriptions) {
642 delete[] (*ii).second->pVertexBindingDescriptions;
643 }
644 if ((*ii).second->pVertexAttributeDescriptions) {
645 delete[] (*ii).second->pVertexAttributeDescriptions;
646 }
647 if ((*ii).second->pAttachments) {
648 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600649 }
650 delete (*ii).second;
651 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600652 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600653}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600654// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600655static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600656{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600657 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600658 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
659 return pPipe->msStateCI.rasterSamples;
660 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600661 return 1;
662}
663// Validate state related to the PSO
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600664static VkBool32 validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600665{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600666 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600667 // Verify that any MSAA request in PSO matches sample# in bound FB
668 uint32_t psoNumSamples = getNumSamples(pipeline);
669 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600670 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800671 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
672 int subpassNumSamples = 0;
673 uint32_t i;
674
675 for (i = 0; i < pSD->colorCount; i++) {
676 uint32_t samples;
677
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600678 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800679 continue;
680
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600681 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800682 if (subpassNumSamples == 0) {
683 subpassNumSamples = samples;
684 } else if (subpassNumSamples != samples) {
685 subpassNumSamples = -1;
686 break;
687 }
688 }
689 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
690 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
691 if (subpassNumSamples == 0)
692 subpassNumSamples = samples;
693 else if (subpassNumSamples != samples)
694 subpassNumSamples = -1;
695 }
696
697 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600698 return log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600699 "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 -0600700 }
701 } else {
702 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
703 // Verify and flag error as appropriate
704 }
705 // TODO : Add more checks here
706 } else {
707 // TODO : Validate non-gfx pipeline updates
708 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600709 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600710}
711
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600712// Block of code at start here specifically for managing/tracking DSs
713
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600714// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600715static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600716{
717 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600718 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600719 loader_platform_thread_unlock_mutex(&globalLock);
720 return NULL;
721 }
722 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600723 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600724}
725// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600726static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600727{
728 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600729 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600730 loader_platform_thread_unlock_mutex(&globalLock);
731 return NULL;
732 }
733 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600734 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600735}
736
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600737static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600738 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600739 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600740 loader_platform_thread_unlock_mutex(&globalLock);
741 return NULL;
742 }
743 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600744 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600745}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600746// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600747static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600748{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600749 switch (pUpdateStruct->sType)
750 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800751 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
752 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600753 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600754 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600755 return 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 -0600756 "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 -0600757 }
758}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600759// For given update struct, return binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600760static VkBool32 getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* binding)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600761{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600762 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600763 switch (pUpdateStruct->sType)
764 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800765 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600766 *binding = ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
767 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800768 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600769 *binding = ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
770 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600771 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600772 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600773 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600774 *binding = 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600775 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600776 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600777}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600778// Set arrayIndex for given update struct in the last parameter
779// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
780static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* arrayIndex)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600781{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600782 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600783 switch (pUpdateStruct->sType)
784 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800785 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600786 *arrayIndex = ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
787 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800788 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600789 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600790 *arrayIndex = ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
791 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600792 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600793 skipCall |= 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 -0600794 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600795 *arrayIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600796 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600797 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600798}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600799// Set count for given update struct in the last parameter
800// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
801static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* count)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600802{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600803 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600804 switch (pUpdateStruct->sType)
805 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800806 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600807 *count = ((VkWriteDescriptorSet*)pUpdateStruct)->count;
808 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800809 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600810 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600811 *count = ((VkCopyDescriptorSet*)pUpdateStruct)->count;
812 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600813 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600814 skipCall |= 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 -0600815 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600816 *count = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600817 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600818 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600819}
820// For given Layout Node and binding, return index where that binding begins
821static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
822{
823 uint32_t offsetIndex = 0;
824 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800825 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600826 }
827 return offsetIndex;
828}
829// For given layout node and binding, return last index that is updated
830static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
831{
832 uint32_t offsetIndex = 0;
833 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800834 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600835 }
836 return offsetIndex-1;
837}
838// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600839static VkBool32 getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* startIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600840{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600841 uint32_t binding = 0, arrayIndex = 0;
842 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
843 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
844 if (VK_FALSE == skipCall)
845 *startIndex = getBindingStartIndex(pLayout, binding)+arrayIndex;
846 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600847}
848// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600849static VkBool32 getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* endIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600850{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600851 uint32_t binding = 0, arrayIndex = 0, count = 0;
852 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
853 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
854 skipCall |= getUpdateCount(device, pUpdateStruct, &count);
855 if (VK_FALSE == skipCall)
856 *endIndex = getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
857 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600858}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600859// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600860static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600861{
862 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600863 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600864 VkDescriptorType actualType;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600865 uint32_t i = 0, startIndex = 0, endIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600866 switch (pUpdateStruct->sType)
867 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800868 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
869 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600870 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800871 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
872 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600873 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600874 break;
875 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600876 skipCall |= 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 -0600877 "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 -0600878 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600879 skipCall |= getUpdateStartIndex(device, pLayout, pUpdateStruct, &startIndex);
880 skipCall |= getUpdateEndIndex(device, pLayout, pUpdateStruct, &endIndex);
881 if (VK_FALSE == skipCall) {
882 for (i = startIndex; i <= endIndex; i++) {
883 if (pLayout->pTypes[i] != actualType)
884 return VK_TRUE;
885 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600886 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600887 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600888}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600889// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600890// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600891// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600892static VkBool32 shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600893{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600894 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800895 VkWriteDescriptorSet* pWDS = NULL;
896 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600897 size_t array_size = 0;
898 size_t base_array_size = 0;
899 size_t total_array_size = 0;
900 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600901 switch (pUpdate->sType)
902 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800903 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
904 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600905 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800906 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
907 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
908 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
909 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600910 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800911 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
912 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600913 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800914 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600915 break;
916 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600917 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
918 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
919 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600920 }
921 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600922 (*pNewNode)->pNext = NULL;
923 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600924}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800925// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600926static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600927{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800928 const VkWriteDescriptorSet *pWDS = NULL;
929 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600930 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800931
932 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
933 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
934 else
935 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
936
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600937 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600938 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600939 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600940 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600941 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600942 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800943 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600944 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800945 g_lastBoundDescriptorSet = pSet->set;
946 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600947 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600948 // First verify valid update struct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600949 if ((skipCall = validUpdateStruct(device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600950 break;
951 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600952 // Make sure that binding is within bounds
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600953 uint32_t binding = 0, endIndex = 0;
954 skipCall |= getUpdateBinding(device, pUpdate, &binding);
955 if (pLayout->createInfo.count < binding) {
956 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
957 "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600958 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600959 // Next verify that update falls within size of given binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600960 skipCall |= getUpdateBinding(device, pUpdate, &binding);
961 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
962 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tony Barbour29b12062015-07-13 13:37:24 -0600963 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600964 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600965 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600966 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
967 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), binding, DSstr.c_str());
Tobin Ehlise42007c2015-06-19 13:00:59 -0600968 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600969 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600970 if ((skipCall = validateUpdateType(device, pLayout, pUpdate)) == VK_TRUE) {
971 skipCall |= 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 -0600972 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600973 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600974 // Save the update info
975 // TODO : Info message that update successful
976 // Create new update struct for this set's shadow copy
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600977 GENERIC_HEADER* pNewNode = NULL;
978 skipCall |= shadowUpdateNode(device, pUpdate, &pNewNode);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600979 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600980 skipCall |= 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 -0600981 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlise42007c2015-06-19 13:00:59 -0600982 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600983 // Insert shadow node into LL of updates for this set
984 pNewNode->pNext = pSet->pUpdateStructs;
985 pSet->pUpdateStructs = pNewNode;
986 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600987 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
988 uint32_t startIndex;
989 skipCall |= getUpdateStartIndex(device, pLayout, pUpdate, &startIndex);
990 for (uint32_t j = startIndex; j <= endIndex; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600991 assert(j<pSet->descriptorCount);
992 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600993 }
994 }
995 }
996 }
997 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600998 }
999 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001000 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001001}
1002// Free the shadowed update node for this Set
1003// NOTE : Calls to this function should be wrapped in mutex
1004static void freeShadowUpdateTree(SET_NODE* pSet)
1005{
1006 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
1007 pSet->pUpdateStructs = NULL;
1008 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
1009 // Clear the descriptor mappings as they will now be invalid
1010 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
1011 while(pShadowUpdate) {
1012 pFreeUpdate = pShadowUpdate;
1013 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
1014 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001015 VkWriteDescriptorSet * pWDS = NULL;
1016 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017 void** ppToFree = NULL;
1018 switch (pFreeUpdate->sType)
1019 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001020 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1021 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
1022 if (pWDS->pDescriptors)
1023 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001024 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001025 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001026 break;
1027 default:
1028 assert(0);
1029 break;
1030 }
Tobin Ehliseaf28662015-04-08 10:58:37 -06001031 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001032 }
1033}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001034// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001035// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001036static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001037{
David Pinedof5997ab2015-04-27 16:36:17 -06001038 if (poolMap.size() <= 0)
1039 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001040 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001041 SET_NODE* pSet = (*ii).second->pSets;
1042 SET_NODE* pFreeSet = pSet;
1043 while (pSet) {
1044 pFreeSet = pSet;
1045 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001046 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001047 // Free Update shadow struct tree
1048 freeShadowUpdateTree(pFreeSet);
1049 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001050 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001051 }
1052 delete pFreeSet;
1053 }
1054 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001055 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001056 }
1057 delete (*ii).second;
1058 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001059 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001060}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001061// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001062// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001063static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001064{
David Pinedof5997ab2015-04-27 16:36:17 -06001065 if (layoutMap.size() <= 0)
1066 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001067 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001068 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001069 if (pLayout->createInfo.pBinding) {
1070 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1071 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1072 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1073 }
1074 delete[] pLayout->createInfo.pBinding;
1075 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001076 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001077 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001078 }
1079 delete pLayout;
1080 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001081 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001082}
1083// Currently clearing a set is removing all previous updates to that set
1084// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001085static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001086{
1087 SET_NODE* pSet = getSetNode(set);
1088 if (!pSet) {
1089 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001090 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001091 loader_platform_thread_lock_mutex(&globalLock);
1092 freeShadowUpdateTree(pSet);
1093 loader_platform_thread_unlock_mutex(&globalLock);
1094 }
1095}
1096
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001097static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001098{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001099 POOL_NODE* pPool = getPoolNode(pool);
1100 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001101 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1102 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001103 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001104 // For every set off of this pool, clear it
1105 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001106 while (pSet) {
1107 clearDescriptorSet(pSet->set);
1108 }
1109 }
1110}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001111// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001112static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001113{
1114 loader_platform_thread_lock_mutex(&globalLock);
1115 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1116 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001117 // TODO : How to pass cb as srcObj here?
1118 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001119 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001120 return NULL;
1121 }
1122 loader_platform_thread_unlock_mutex(&globalLock);
1123 return cmdBufferMap[cb];
1124}
1125// Free all CB Nodes
1126// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001127static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001128{
David Pinedof5997ab2015-04-27 16:36:17 -06001129 if (cmdBufferMap.size() <= 0)
1130 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001131 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001132 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1133 while (!cmd_node_list.empty()) {
1134 CMD_NODE* cmd_node = cmd_node_list.back();
1135 delete cmd_node;
1136 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001137 }
1138 delete (*ii).second;
1139 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001140 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001141}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001142static VkBool32 report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
Tobin Ehlise42007c2015-06-19 13:00:59 -06001143{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001144 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001145 return 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 -06001146 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1147}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001148static VkBool32 addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001149{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001150 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001151 CMD_NODE* pCmd = new CMD_NODE;
1152 if (pCmd) {
1153 // init cmd node and append to end of cmd LL
1154 memset(pCmd, 0, sizeof(CMD_NODE));
1155 pCmd->cmdNumber = ++pCB->numCmds;
1156 pCmd->type = cmd;
1157 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001158 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001159 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001160 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001161 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001162 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001163 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001164}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001165static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001166{
1167 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1168 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001169 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1170 while (!cmd_list.empty()) {
1171 delete cmd_list.back();
1172 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001173 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001174 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001175 // Reset CB state (need to save createInfo)
1176 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001177 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1178 pCB->cmdBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001179 pCB->createInfo = saveCBCI;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001180 pCB->lastVtxBinding = MAX_BINDING;
1181 }
1182}
Tobin Ehlis97866202015-06-10 12:57:07 -06001183// Set PSO-related status bits for CB
1184static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1185{
1186 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1187 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1188 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1189 }
1190 }
1191 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06001192 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1193 }
1194
1195 if (pPipe->dsStateCI.stencilTestEnable) {
1196 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001197 }
1198}
1199// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001200static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001201 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1202 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
Cody Northrope4bc6942015-08-26 10:01:32 -06001203 } else if (stateBindPoint == VK_STATE_BIND_POINT_LINE_WIDTH) {
1204 pNode->status |= CBSTATUS_LINE_WIDTH_BOUND;
1205 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BIAS) {
1206 pNode->status |= CBSTATUS_DEPTH_BIAS_BOUND;
1207 } else if (stateBindPoint == VK_STATE_BIND_POINT_BLEND) {
1208 pNode->status |= CBSTATUS_BLEND_BOUND;
1209 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BOUNDS) {
1210 pNode->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
Cody Northrop2605cb02015-08-18 15:21:16 -06001211 } else if (stateBindPoint == VK_STATE_BIND_POINT_STENCIL) {
1212 pNode->status |= CBSTATUS_STENCIL_BOUND;
Tobin Ehlis97866202015-06-10 12:57:07 -06001213 }
1214}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001215// Print the last bound Gfx Pipeline
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001216static VkBool32 printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001217{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001218 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001219 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1220 if (pCB) {
1221 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1222 if (!pPipeTrav) {
1223 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001224 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001225 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001226 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001227 }
1228 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001229 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001230}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001231// Print details of DS config to stdout
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001232static VkBool32 printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001233{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001234 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001235 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.
1236 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001237 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001238 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001239 POOL_NODE* pPool = getPoolNode(pSet->pool);
1240 // Print out pool details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001241 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001242 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001243 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001244 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001245 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001246 // Print out set details
1247 char prefix[10];
1248 uint32_t index = 0;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001249 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001250 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001251 LAYOUT_NODE* pLayout = pSet->pLayout;
1252 // Print layout details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001253 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001254 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001255 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001256 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001257 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001258 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001259 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001260 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1261 if (pUpdate) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001262 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001263 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001264 sprintf(prefix, " [UC] ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001265 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001266 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001267 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001268 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001269 if (0 != pSet->descriptorCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001270 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001271 "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 -06001272 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001273 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001274 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001275 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001276 }
1277 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001278 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001279}
1280
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001281static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001282{
1283 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001284 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001285 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001286 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001287 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001288 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1289 // TODO : Need to pass cb as srcObj here
1290 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 -06001291 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001292 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001293 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001294 // Nothing to print
1295 }
1296}
1297
1298
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001299static VkBool32 synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001300{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001301 VkBool32 skipCall = VK_FALSE;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001302 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001303 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001304 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001305 skipCall |= printDSConfig(cb);
1306 skipCall |= printPipeline(cb);
1307 skipCall |= printDynamicState(cb);
1308 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001309}
1310
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001311static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001312{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001313 uint32_t report_flags = 0;
1314 uint32_t debug_action = 0;
1315 FILE *log_output = NULL;
1316 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001317 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001318 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1319 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001320
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001321 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001322 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001323 option_str = getLayerOption("DrawStateLogFilename");
1324 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001325 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001326 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001327 }
Tobin Ehlisaf14e9f2015-09-01 11:59:36 -06001328 if (log_output == NULL) {
1329 if (option_str)
1330 cout << endl << "DrawState ERROR: Bad output filename specified: " << option_str << ". Writing to STDOUT instead" << endl << endl;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001331 log_output = stdout;
Tobin Ehlisaf14e9f2015-09-01 11:59:36 -06001332 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001333
1334 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 -06001335 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001336
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001337 if (!globalLockInitialized)
1338 {
1339 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001340 // suggestion is to call this during vkCreateInstance(), and then we
1341 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001342 // that the layer have per-instance locks. We need to come back and
1343 // address this soon.
1344 loader_platform_thread_create_mutex(&globalLock);
1345 globalLockInitialized = 1;
1346 }
1347}
1348
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001349VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1350{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001351 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001352 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1353
1354 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001355 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1356 my_data->report_data = debug_report_create_instance(
1357 pTable,
1358 *pInstance,
1359 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001360 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001361
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001362 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001363 }
1364 return result;
1365}
1366
Jon Ashburne0fa2282015-05-20 09:00:28 -06001367/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001368VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Jon Ashburne0fa2282015-05-20 09:00:28 -06001369{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001370 dispatch_key key = get_dispatch_key(instance);
1371 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001372 pTable->DestroyInstance(instance);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001373
1374 // Clean up logging callback, if any
1375 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1376 if (my_data->logging_callback) {
1377 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1378 }
1379
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001380 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001381 layer_data_map.erase(pTable);
1382
1383 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001384}
1385
Jon Ashburnf0615e22015-05-25 14:11:37 -06001386static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1387{
Tony Barbour29b12062015-07-13 13:37:24 -06001388 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001389 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001390 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001391
1392 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001393 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001394 /* Found a matching extension name, mark it enabled and init dispatch table*/
1395 initDebugMarkerTable(device);
1396 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001397 }
1398
1399 }
1400}
1401
Tony Barbour8205d902015-04-16 15:59:00 -06001402VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001403{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001404 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1405 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001406 if (result == VK_SUCCESS) {
1407 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1408 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1409 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1410 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001411 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001412 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001413 return result;
1414}
1415
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001416VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001417{
1418 // Free all the memory
1419 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001420 deletePipelines();
1421 deleteSamplers();
1422 deleteImages();
1423 deleteBuffers();
1424 deleteCmdBuffers();
1425 deleteDynamicState();
1426 deletePools();
1427 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001428 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001429
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001430 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001431 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001432 pDisp->DestroyDevice(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001433 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001434 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001435 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001436}
1437
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001438static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001439 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001440 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001441 VK_API_VERSION,
1442 VK_MAKE_VERSION(0, 1, 0),
1443 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001444 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001445};
1446
Tony Barbour426b9052015-06-24 16:06:58 -06001447VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001448 const char *pLayerName,
1449 uint32_t *pCount,
1450 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001451{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001452 /* DrawState does not have any global extensions */
1453 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1454}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001455
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001456VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1457 uint32_t *pCount,
1458 VkLayerProperties* pProperties)
1459{
1460 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1461 ds_global_layers,
1462 pCount, pProperties);
1463}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001464
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001465static const VkExtensionProperties ds_device_extensions[] = {
1466 {
1467 DEBUG_MARKER_EXTENSION_NAME,
1468 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001469 }
1470};
1471
1472static const VkLayerProperties ds_device_layers[] = {
1473 {
1474 "DrawState",
1475 VK_API_VERSION,
1476 VK_MAKE_VERSION(0, 1, 0),
1477 "Validation layer: DrawState",
1478 }
1479};
1480
1481VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1482 VkPhysicalDevice physicalDevice,
1483 const char* pLayerName,
1484 uint32_t* pCount,
1485 VkExtensionProperties* pProperties)
1486{
1487 /* Mem tracker does not have any physical device extensions */
1488 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1489 pCount, pProperties);
1490}
1491
1492VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1493 VkPhysicalDevice physicalDevice,
1494 uint32_t* pCount,
1495 VkLayerProperties* pProperties)
1496{
1497 /* Mem tracker's physical device layers are the same as global */
1498 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1499 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001500}
1501
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001502VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001503{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001504 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001505 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001506 for (uint32_t i=0; i < cmdBufferCount; i++) {
1507 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001508 pCB = getCBNode(pCmdBuffers[i]);
1509 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001510 pCB->submitCount++; // increment submit count
1511 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001512 skipCall |= log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CMD_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001513 "CB %#" PRIxLEAST64 " was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.", reinterpret_cast<uint64_t>(pCB->cmdBuffer), pCB->submitCount);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001514 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001515 if (CB_UPDATE_COMPLETE != pCB->state) {
1516 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001517 // TODO : How to pass cb as srcObj?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001518 skipCall |= log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001519 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlise90b1712015-05-27 14:30:06 -06001520 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001521 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001522 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001523 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001524 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001525 if (VK_FALSE == skipCall)
1526 return get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
1527 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001528}
1529
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001530VK_LAYER_EXPORT void VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001531{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001532 get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001533 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001534}
1535
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001536VK_LAYER_EXPORT void VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001537{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001538 get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001539 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001540}
1541
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001542VK_LAYER_EXPORT void VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001543{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001544 get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001545 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001546}
1547
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001548VK_LAYER_EXPORT void VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001549{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001550 get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001551 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001552}
1553
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001554VK_LAYER_EXPORT void VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001555{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001556 get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001557 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001558}
1559
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001560VK_LAYER_EXPORT void VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001561{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001562 get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001563 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001564}
1565
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001566VK_LAYER_EXPORT void VKAPI vkDestroyImage(VkDevice device, VkImage image)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001567{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001568 get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001569 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001570}
1571
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001572VK_LAYER_EXPORT void VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001573{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001574 get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001575 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001576}
1577
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001578VK_LAYER_EXPORT void VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001579{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001580 get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001581 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001582}
1583
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001584VK_LAYER_EXPORT void VKAPI vkDestroyShader(VkDevice device, VkShader shader)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001585{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001586 get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001587 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001588}
1589
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001590VK_LAYER_EXPORT void VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001591{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001592 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001593 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001594}
1595
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001596VK_LAYER_EXPORT void VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001597{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001598 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001599 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001600}
1601
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001602VK_LAYER_EXPORT void VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001603{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001604 get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001605 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001606}
1607
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001608VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001609{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001610 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001611 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001612}
1613
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001614VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001615{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001616 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001617 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001618}
1619
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001620VK_LAYER_EXPORT void VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001621{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001622 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001623 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001624}
1625
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001626VK_LAYER_EXPORT void VKAPI vkDestroyDynamicLineWidthState(VkDevice device, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001627{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001628 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicLineWidthState(device, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06001629 // TODO : Clean up any internal data structures using this obj.
Cody Northropf5bd2252015-08-17 11:10:49 -06001630}
1631
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001632VK_LAYER_EXPORT void VKAPI vkDestroyDynamicDepthBiasState(VkDevice device, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001633{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001634 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBiasState(device, dynamicDepthBiasState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001635 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001636}
1637
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001638VK_LAYER_EXPORT void VKAPI vkDestroyDynamicBlendState(VkDevice device, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001639{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001640 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicBlendState(device, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001641 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001642}
1643
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001644VK_LAYER_EXPORT void VKAPI vkDestroyDynamicDepthBoundsState(VkDevice device, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001645{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001646 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBoundsState(device, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06001647 // TODO : Clean up any internal data structures using this obj.
Cody Northrop2605cb02015-08-18 15:21:16 -06001648}
1649
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001650VK_LAYER_EXPORT void VKAPI vkDestroyDynamicStencilState(VkDevice device, VkDynamicStencilState dynamicStencilState)
Cody Northrop2605cb02015-08-18 15:21:16 -06001651{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001652 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicStencilState(device, dynamicStencilState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001653 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001654}
1655
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001656VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001657{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001658 get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001659 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001660}
1661
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001662VK_LAYER_EXPORT void VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001663{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001664 get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001665 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001666}
1667
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001668VK_LAYER_EXPORT void VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001669{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001670 get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001671 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001672}
1673
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001674VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001675{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001676 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001677 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001678 loader_platform_thread_lock_mutex(&globalLock);
1679 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1680 pNewNode->buffer = *pView;
1681 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001682 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683 loader_platform_thread_unlock_mutex(&globalLock);
1684 }
1685 return result;
1686}
1687
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001688VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001689{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001690 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001691 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001692 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001693 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001694 loader_platform_thread_unlock_mutex(&globalLock);
1695 }
1696 return result;
1697}
1698
Jon Ashburn0d60d272015-07-09 15:02:25 -06001699//TODO handle pipeline caches
1700VkResult VKAPI vkCreatePipelineCache(
1701 VkDevice device,
1702 const VkPipelineCacheCreateInfo* pCreateInfo,
1703 VkPipelineCache* pPipelineCache)
1704{
1705 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1706 return result;
1707}
1708
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001709void VKAPI vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06001710 VkDevice device,
1711 VkPipelineCache pipelineCache)
1712{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001713 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001714}
1715
1716size_t VKAPI vkGetPipelineCacheSize(
1717 VkDevice device,
1718 VkPipelineCache pipelineCache)
1719{
1720 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1721 return size;
1722}
1723
1724VkResult VKAPI vkGetPipelineCacheData(
1725 VkDevice device,
1726 VkPipelineCache pipelineCache,
1727 void* pData)
1728{
1729 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1730 return result;
1731}
1732
1733VkResult VKAPI vkMergePipelineCaches(
1734 VkDevice device,
1735 VkPipelineCache destCache,
1736 uint32_t srcCacheCount,
1737 const VkPipelineCache* pSrcCaches)
1738{
1739 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1740 return result;
1741}
1742
1743VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001744{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001745 VkResult result = VK_SUCCESS;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001746 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001747 // The order of operations here is a little convoluted but gets the job done
1748 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1749 // 2. Create state is then validated (which uses flags setup during shadowing)
1750 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1751 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001752 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001753 VkBool32 skipCall = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001754 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001755 if (VK_FALSE == skipCall) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001756 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001757 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1758 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001759 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001760 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001761 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001762 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001763 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001764 if (pPipeNode) {
1765 // If we allocated a pipeNode, need to clean it up here
1766 delete[] pPipeNode->pVertexBindingDescriptions;
1767 delete[] pPipeNode->pVertexAttributeDescriptions;
1768 delete[] pPipeNode->pAttachments;
1769 delete pPipeNode;
1770 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001771 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001772 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001773 return result;
1774}
1775
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001776VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001777{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001778 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001779 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001780 loader_platform_thread_lock_mutex(&globalLock);
1781 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1782 pNewNode->sampler = *pSampler;
1783 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001784 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785 loader_platform_thread_unlock_mutex(&globalLock);
1786 }
1787 return result;
1788}
1789
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001790VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001791{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001792 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001793 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001794 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1795 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001796 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1797 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
1798 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799 }
1800 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001801 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1802 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1803 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001805 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001806 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001807 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001808 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001809 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1810 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001811 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001812 }
1813 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001814 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001815 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001816 uint32_t j = 0;
1817 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001818 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001819 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001821 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001822 }
1823 }
1824 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001826 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1827 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001828 // Put new node at Head of global Layer list
1829 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001830 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001831 loader_platform_thread_unlock_mutex(&globalLock);
1832 }
1833 return result;
1834}
1835
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001836VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001837{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001838 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001839 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001840 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001841 }
1842 return result;
1843}
1844
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001845VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001846{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001847 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001849 // Insert this pool into Global Pool LL at head
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001850 if (log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1851 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle))
1852 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001854 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001855 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001856 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1857 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()"))
1858 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001859 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001860 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001861 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1862 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001863 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001864 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1865 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001866 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1867 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001868 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001869 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001870 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001871 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001872 }
1873 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001874 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001875 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001876 }
1877 return result;
1878}
1879
Mike Stroyan230e6252015-04-17 12:36:38 -06001880VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001882 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001883 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001884 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001885 }
1886 return result;
1887}
1888
Cody Northropc8aa4a52015-08-03 12:47:29 -06001889VK_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 -06001890{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001891 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1892 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001893 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1894 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001895 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1896 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001897 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001898 if (count == 0) {
1899 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1900 "AllocDescriptorSets called with 0 count");
1901 }
1902 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001903 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1904 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001905 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001906 SET_NODE* pNewNode = new SET_NODE;
1907 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001908 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1909 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()"))
1910 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001911 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001912 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001913 // Insert set at head of Set LL for this pool
1914 pNewNode->pNext = pPoolNode->pSets;
1915 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001916 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1917 if (NULL == pLayout) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001918 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1919 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle))
1920 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001921 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001922 pNewNode->pLayout = pLayout;
1923 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001924 pNewNode->set = pDescriptorSets[i];
1925 pNewNode->setUsage = setUsage;
1926 pNewNode->descriptorCount = pLayout->endIndex + 1;
1927 if (pNewNode->descriptorCount) {
1928 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1929 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1930 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1931 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001932 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001933 }
1934 }
1935 }
1936 }
1937 return result;
1938}
1939
Tony Barbourb857d312015-07-10 10:50:45 -06001940VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1941{
1942 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1943 // TODO : Clean up any internal data structures using this obj.
1944 return result;
1945}
1946
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001947VK_LAYER_EXPORT void VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001948{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001949 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when both updates return VK_FALSE
1950 if (!dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1951 !dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001952 get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001953 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001954}
1955
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001956VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001957{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001958 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001959 VkDynamicViewportStateCreateInfo local_ci;
1960 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1961 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1962 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1963 loader_platform_thread_lock_mutex(&globalLock);
1964 dynamicVpStateMap[pState->handle] = local_ci;
1965 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001966 return result;
1967}
1968
Cody Northrope4bc6942015-08-26 10:01:32 -06001969VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicLineWidthState(VkDevice device, const VkDynamicLineWidthStateCreateInfo* pCreateInfo, VkDynamicLineWidthState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001970{
Cody Northrope4bc6942015-08-26 10:01:32 -06001971 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicLineWidthState(device, pCreateInfo, pState);
1972 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_LINE_WIDTH);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001973 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001974 dynamicLineWidthStateMap[pState->handle] = *pCreateInfo;
Cody Northropf5bd2252015-08-17 11:10:49 -06001975 loader_platform_thread_unlock_mutex(&globalLock);
1976 return result;
1977}
1978
Cody Northrope4bc6942015-08-26 10:01:32 -06001979VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBiasState(VkDevice device, const VkDynamicDepthBiasStateCreateInfo* pCreateInfo, VkDynamicDepthBiasState* pState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001980{
Cody Northrope4bc6942015-08-26 10:01:32 -06001981 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBiasState(device, pCreateInfo, pState);
1982 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BIAS);
Cody Northropf5bd2252015-08-17 11:10:49 -06001983 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001984 dynamicDepthBiasStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001985 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001986 return result;
1987}
1988
Cody Northrope4bc6942015-08-26 10:01:32 -06001989VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicBlendState(VkDevice device, const VkDynamicBlendStateCreateInfo* pCreateInfo, VkDynamicBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001990{
Cody Northrope4bc6942015-08-26 10:01:32 -06001991 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicBlendState(device, pCreateInfo, pState);
1992 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_BLEND);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001993 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001994 dynamicBlendStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001995 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001996 return result;
1997}
1998
Cody Northrope4bc6942015-08-26 10:01:32 -06001999VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBoundsState(VkDevice device, const VkDynamicDepthBoundsStateCreateInfo* pCreateInfo, VkDynamicDepthBoundsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002000{
Cody Northrope4bc6942015-08-26 10:01:32 -06002001 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBoundsState(device, pCreateInfo, pState);
2002 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BOUNDS);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002003 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002004 dynamicDepthBoundsStateMap[pState->handle] = *pCreateInfo;
Cody Northrop2605cb02015-08-18 15:21:16 -06002005 loader_platform_thread_unlock_mutex(&globalLock);
2006 return result;
2007}
2008
2009VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicStencilState(VkDevice device, const VkDynamicStencilStateCreateInfo* pCreateInfoFront, const VkDynamicStencilStateCreateInfo* pCreateInfoBack, VkDynamicStencilState* pState)
2010{
2011 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicStencilState(device, pCreateInfoFront, pCreateInfoBack, pState);
2012 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_STENCIL);
2013 loader_platform_thread_lock_mutex(&globalLock);
2014
2015 // Bug 14406 - If back is NULL or equal to front, then single sided.
2016 // To support NULL case, simply track front twice
2017 const VkDynamicStencilStateCreateInfo* pLocalCreateInfoBack = (pCreateInfoBack == NULL) ? pCreateInfoFront : pCreateInfoBack;
2018
2019 std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo> infos(*pCreateInfoFront, *pLocalCreateInfoBack);
2020 dynamicStencilStateMap[pState->handle] = infos;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002021 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002022 return result;
2023}
2024
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002025VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002026{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002027 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002028 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002029 loader_platform_thread_lock_mutex(&globalLock);
2030 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2031 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2032 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002033 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002034 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002035 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002036 cmdBufferMap[*pCmdBuffer] = pCB;
2037 loader_platform_thread_unlock_mutex(&globalLock);
2038 updateCBTracking(*pCmdBuffer);
2039 }
2040 return result;
2041}
2042
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002043VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002044{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002045 VkBool32 skipCall = false;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002046 // Validate command buffer level
2047 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2048 if (pCB) {
2049 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
2050 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2051 // These should be NULL for a Primary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002052 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002053 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2054 }
2055 } else {
2056 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2057 // These should NOT be null for an Secondary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002058 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002059 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2060 }
2061 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002062 pCB->beginInfo = *pBeginInfo;
2063 } else {
2064 // TODO : Need to pass cmdBuffer as objType here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002065 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002066 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002067 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002068 if (skipCall) {
2069 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06002070 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002071 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002072 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002073 if (CB_NEW != pCB->state)
2074 resetCB(cmdBuffer);
2075 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002076 updateCBTracking(cmdBuffer);
2077 }
2078 return result;
2079}
2080
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002081VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002082{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002083 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06002084 VkResult result = VK_SUCCESS;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002085 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06002086 /* TODO: preference is to always call API function after reporting any validation errors */
Tobin Ehlise42007c2015-06-19 13:00:59 -06002087 if (pCB) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002088 if (pCB->state != CB_UPDATE_ACTIVE) {
2089 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002090 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002091 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002092 if (VK_FALSE == skipCall) {
2093 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2094 if (VK_SUCCESS == result) {
2095 updateCBTracking(cmdBuffer);
2096 pCB->state = CB_UPDATE_COMPLETE;
2097 // Reset CB status flags
2098 pCB->status = 0;
2099 printCB(cmdBuffer);
2100 }
2101 } else {
2102 result = VK_ERROR_VALIDATION_FAILED;
2103 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002104 return result;
2105}
2106
Cody Northropf02f9f82015-07-09 18:08:05 -06002107VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002108{
Cody Northropf02f9f82015-07-09 18:08:05 -06002109 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002110 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002111 resetCB(cmdBuffer);
2112 updateCBTracking(cmdBuffer);
2113 }
2114 return result;
2115}
2116
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002117VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002118{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002119 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002120 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2121 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002122 if (pCB->state == CB_UPDATE_ACTIVE) {
2123 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002124 skipCall |= addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002125 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002126 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002127 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002128 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002129 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002130 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002131 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002132 PIPELINE_NODE* pPN = getPipeline(pipeline);
2133 if (pPN) {
2134 pCB->lastBoundPipeline = pipeline;
2135 loader_platform_thread_lock_mutex(&globalLock);
2136 set_cb_pso_status(pCB, pPN);
2137 g_lastBoundPipeline = pPN;
2138 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002139 skipCall |= validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002140 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002141 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002142 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002143 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002144 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002145 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002146 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002147 }
2148 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002149 if (VK_FALSE == skipCall)
2150 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002151}
2152
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002153VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002154{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002155 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002156 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2157 if (pCB) {
2158 if (pCB->state == CB_UPDATE_ACTIVE) {
2159 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002160 skipCall |= addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002161 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002162 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002163 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002164 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002165 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002166 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2167 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002168 skipCall |= 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 -06002169 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002170 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002171 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2172 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002173 }
2174 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002175 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002176 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002177 }
2178 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002179 if (VK_FALSE == skipCall)
2180 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002181}
Cody Northrope4bc6942015-08-26 10:01:32 -06002182VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(VkCmdBuffer cmdBuffer, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002183{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002184 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002185 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2186 if (pCB) {
2187 if (pCB->state == CB_UPDATE_ACTIVE) {
2188 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002189 skipCall |= addCmd(pCB, CMD_BINDDYNAMICLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002190 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002191 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002192 "Incorrect call to vkCmdBindDynamicLineWidthState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002193 }
2194 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002195 pCB->status |= CBSTATUS_LINE_WIDTH_BOUND;
2196 if (dynamicLineWidthStateMap.find(dynamicLineWidthState.handle) == dynamicLineWidthStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002197 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_LINE_WIDTH_STATE, dynamicLineWidthState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002198 "Unable to find VkDynamicLineWidthState object %#" PRIxLEAST64 ", was it ever created?", dynamicLineWidthState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002199 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002200 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
2201 g_lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002202 }
2203 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002204 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002205 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002206 }
2207 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002208 if (VK_FALSE == skipCall)
2209 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicLineWidthState(cmdBuffer, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06002210}
Cody Northrope4bc6942015-08-26 10:01:32 -06002211VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(VkCmdBuffer cmdBuffer, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06002212{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002213 VkBool32 skipCall = VK_FALSE;
Cody Northropf5bd2252015-08-17 11:10:49 -06002214 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2215 if (pCB) {
2216 if (pCB->state == CB_UPDATE_ACTIVE) {
2217 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002218 skipCall |= addCmd(pCB, CMD_BINDDYNAMICDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002219 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002220 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002221 "Incorrect call to vkCmdBindDynamicDepthBiasState() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002222 }
2223 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002224 pCB->status |= CBSTATUS_DEPTH_BIAS_BOUND;
2225 if (dynamicDepthBiasStateMap.find(dynamicDepthBiasState.handle) == dynamicDepthBiasStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002226 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_DEPTH_BIAS_STATE, dynamicDepthBiasState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002227 "Unable to find VkDynamicDepthBiasState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBiasState.handle);
Cody Northropf5bd2252015-08-17 11:10:49 -06002228 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002229 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
2230 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
Cody Northropf5bd2252015-08-17 11:10:49 -06002231 }
2232 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northropf5bd2252015-08-17 11:10:49 -06002233 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002234 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBiasState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002235 }
2236 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002237 if (VK_FALSE == skipCall)
2238 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBiasState(cmdBuffer, dynamicDepthBiasState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002239}
Cody Northrope4bc6942015-08-26 10:01:32 -06002240VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicBlendState(VkCmdBuffer cmdBuffer, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002241{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002242 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002243 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2244 if (pCB) {
2245 if (pCB->state == CB_UPDATE_ACTIVE) {
2246 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002247 skipCall |= addCmd(pCB, CMD_BINDDYNAMICBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002248 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002249 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002250 "Incorrect call to vkCmdBindDynamicBlendState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002251 }
2252 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002253 pCB->status |= CBSTATUS_BLEND_BOUND;
2254 if (dynamicBlendStateMap.find(dynamicBlendState.handle) == dynamicBlendStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002255 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_BLEND_STATE, dynamicBlendState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002256 "Unable to find VkDynamicBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicBlendState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002257 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002258 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
2259 g_lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002260 }
2261 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002262 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002263 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicBlendState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002264 }
2265 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002266 if (VK_FALSE == skipCall)
2267 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicBlendState(cmdBuffer, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002268}
Cody Northrope4bc6942015-08-26 10:01:32 -06002269VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(VkCmdBuffer cmdBuffer, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002270{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002271 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002272 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2273 if (pCB) {
2274 if (pCB->state == CB_UPDATE_ACTIVE) {
2275 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002276 skipCall |= addCmd(pCB, CMD_BINDDYNAMICDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002277 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002278 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002279 "Incorrect call to vkCmdBindDynamicDepthBoundsState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002280 }
2281 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002282 pCB->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
2283 if (dynamicDepthBoundsStateMap.find(dynamicDepthBoundsState.handle) == dynamicDepthBoundsStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002284 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_DEPTH_BOUNDS_STATE, dynamicDepthBoundsState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Cody Northrope4bc6942015-08-26 10:01:32 -06002285 "Unable to find VkDynamicDepthBoundsState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBoundsState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002286 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002287 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
2288 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002289 }
2290 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002291 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002292 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBoundsState()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002293 }
2294 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002295 if (VK_FALSE == skipCall)
2296 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBoundsState(cmdBuffer, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06002297}
2298VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStencilState(VkCmdBuffer cmdBuffer, VkDynamicStencilState dynamicStencilState)
2299{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002300 VkBool32 skipCall = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -06002301 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2302 if (pCB) {
2303 if (pCB->state == CB_UPDATE_ACTIVE) {
2304 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002305 skipCall |= addCmd(pCB, CMD_BINDDYNAMICSTENCILSTATE);
Cody Northrop2605cb02015-08-18 15:21:16 -06002306 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002307 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrop2605cb02015-08-18 15:21:16 -06002308 "Incorrect call to vkCmdBindDynamicStencilState() without an active RenderPass.");
2309 }
2310 loader_platform_thread_lock_mutex(&globalLock);
2311 pCB->status |= CBSTATUS_STENCIL_BOUND;
2312 if (dynamicStencilStateMap.find(dynamicStencilState.handle) == dynamicStencilStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002313 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_STENCIL_STATE, dynamicStencilState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Cody Northrop2605cb02015-08-18 15:21:16 -06002314 "Unable to find VkDynamicStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicStencilState.handle);
2315 } else {
2316 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2317 g_lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2318 }
2319 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop2605cb02015-08-18 15:21:16 -06002320 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002321 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicStencilState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002322 }
2323 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002324 if (VK_FALSE == skipCall)
2325 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStencilState(cmdBuffer, dynamicStencilState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002326}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002327VK_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 -06002328{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002329 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002330 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2331 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002332 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002333 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002334 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002335 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002336 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002337 skipCall |= 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 -06002338 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002339 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002340 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002341 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2342 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002343 loader_platform_thread_lock_mutex(&globalLock);
2344 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002345 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002346 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2347 g_lastBoundDescriptorSet = pDescriptorSets[i];
2348 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002349 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002350 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002351 if (!pSet->pUpdateStructs)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002352 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002353 "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 -06002354 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002355 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002356 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002357 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002358 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002359 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002360 skipCall |= addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002361 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002362 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002363 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002364 }
2365 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002366 if (VK_FALSE == skipCall)
2367 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 -06002368}
2369
Tony Barbour8205d902015-04-16 15:59:00 -06002370VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002371{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002372 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002373 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2374 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002375 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002376 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002377 skipCall |= 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 -06002378 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2379 } else {
2380 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2381 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002382 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002383 skipCall |= addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002384 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002385 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002386 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002387 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002388 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002389 if (VK_FALSE == skipCall)
2390 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002391}
2392
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002393VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2394 VkCmdBuffer cmdBuffer,
2395 uint32_t startBinding,
2396 uint32_t bindingCount,
2397 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002398 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002399{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002400 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002401 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2402 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002403 if (pCB->state == CB_UPDATE_ACTIVE) {
2404 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002405 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002406 skipCall |= 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 -06002407 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2408 } else {
2409 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002410 updateCBTracking(cmdBuffer);
2411 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002412 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002413 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002414 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002415 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002416 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002417 if (VK_FALSE == skipCall)
2418 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002419}
2420
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002421VK_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 -06002422{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002423 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002424 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2425 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002426 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002427 pCB->drawCount[DRAW]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002428 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002429 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002430 skipCall |= 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 -06002431 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002432 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2433 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002434 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002435 skipCall |= addCmd(pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002436 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002437 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002438 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002439 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002440 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002441 if (VK_FALSE == skipCall)
2442 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443}
2444
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002445VK_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 -06002446{
2447 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002448 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002449 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002450 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002451 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002452 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002453 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002454 skipCall |= 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 -06002455 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002456 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2457 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002458 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002459 skipCall |= addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002460 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002461 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002462 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002463 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002464 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002465 if (VK_FALSE == skipCall)
2466 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467}
2468
Tony Barbour8205d902015-04-16 15:59:00 -06002469VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470{
2471 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002472 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002473 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002474 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002475 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002476 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002477 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002478 skipCall |= 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 -06002479 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002480 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2481 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002482 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002483 skipCall |= addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002484 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002485 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002486 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002487 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002488 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002489 if (VK_FALSE == skipCall)
2490 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002491}
2492
Tony Barbour8205d902015-04-16 15:59:00 -06002493VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002494{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002495 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002496 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2497 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002498 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002499 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002500 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002501 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002502 skipCall |= 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 -06002503 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002504 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2505 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002506 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002507 skipCall |= addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002508 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002509 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002510 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002511 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002512 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002513 if (VK_FALSE == skipCall)
2514 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002515}
2516
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002517VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002518{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002519 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002520 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2521 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002522 if (pCB->state == CB_UPDATE_ACTIVE) {
2523 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002524 skipCall |= addCmd(pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002525 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002526 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002527 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002528 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002529 if (VK_FALSE == skipCall)
2530 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531}
2532
Tony Barbour8205d902015-04-16 15:59:00 -06002533VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002534{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002535 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002536 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2537 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002538 if (pCB->state == CB_UPDATE_ACTIVE) {
2539 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002540 skipCall |= addCmd(pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002541 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002542 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002543 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002544 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002545 if (VK_FALSE == skipCall)
2546 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002547}
2548
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002549VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002550{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002551 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002552 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2553 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002554 if (pCB->state == CB_UPDATE_ACTIVE) {
2555 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002556 skipCall |= addCmd(pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002557 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002558 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002559 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002560 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002561 if (VK_FALSE == skipCall)
2562 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002563}
2564
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002565VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2566 VkImage srcImage,
2567 VkImageLayout srcImageLayout,
2568 VkImage destImage,
2569 VkImageLayout destImageLayout,
2570 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002571{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002572 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002573 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2574 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002575 if (pCB->state == CB_UPDATE_ACTIVE) {
2576 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002577 skipCall |= addCmd(pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002578 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002579 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002580 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002581 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002582 if (VK_FALSE == skipCall)
2583 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002584}
2585
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002586VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2587 VkImage srcImage, VkImageLayout srcImageLayout,
2588 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002589 uint32_t regionCount, const VkImageBlit* pRegions,
2590 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002591{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002592 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002593 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2594 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002595 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002596 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002597 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002598 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002599 } else {
2600 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002601 skipCall |= addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002602 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002603 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002604 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002605 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002606 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002607 if (VK_FALSE == skipCall)
2608 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002609}
2610
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002611VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2612 VkBuffer srcBuffer,
2613 VkImage destImage, VkImageLayout destImageLayout,
2614 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002615{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002616 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002617 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2618 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002619 if (pCB->state == CB_UPDATE_ACTIVE) {
2620 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002621 skipCall |= addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002622 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002623 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002624 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002626 if (VK_FALSE == skipCall)
2627 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002628}
2629
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002630VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2631 VkImage srcImage, VkImageLayout srcImageLayout,
2632 VkBuffer destBuffer,
2633 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002634{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002635 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002636 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2637 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002638 if (pCB->state == CB_UPDATE_ACTIVE) {
2639 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002640 skipCall |= addCmd(pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002641 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002642 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002643 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002644 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002645 if (VK_FALSE == skipCall)
2646 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002647}
2648
Tony Barbour8205d902015-04-16 15:59:00 -06002649VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002650{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002651 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002652 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2653 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002654 if (pCB->state == CB_UPDATE_ACTIVE) {
2655 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002656 skipCall |= addCmd(pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002657 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002658 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002659 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002660 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002661 if (VK_FALSE == skipCall)
2662 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663}
2664
Tony Barbour8205d902015-04-16 15:59:00 -06002665VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002666{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002667 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002668 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);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002672 skipCall |= addCmd(pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002673 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002674 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002675 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002676 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002677 if (VK_FALSE == skipCall)
2678 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002679}
2680
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002681VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2682 VkCmdBuffer cmdBuffer,
2683 uint32_t colorAttachment,
2684 VkImageLayout imageLayout,
2685 const VkClearColorValue* pColor,
2686 uint32_t rectCount,
2687 const VkRect3D* pRects)
2688{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002689 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002690 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2691 if (pCB) {
2692 if (pCB->state == CB_UPDATE_ACTIVE) {
2693 // Warn if this is issued prior to Draw Cmd
2694 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002695 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002696 skipCall |= 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 -06002697 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002698 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002699 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002700 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002701 skipCall |= 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 -06002702 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2703 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2704 } else {
2705 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002706 skipCall |= addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002707 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002708 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002709 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002710 }
2711 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002712 if (VK_FALSE == skipCall)
2713 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002714}
2715
2716VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2717 VkCmdBuffer cmdBuffer,
2718 VkImageAspectFlags imageAspectMask,
2719 VkImageLayout imageLayout,
2720 float depth,
2721 uint32_t stencil,
2722 uint32_t rectCount,
2723 const VkRect3D* pRects)
2724{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002725 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002726 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2727 if (pCB) {
2728 if (pCB->state == CB_UPDATE_ACTIVE) {
2729 // Warn if this is issued prior to Draw Cmd
2730 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002731 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002732 skipCall |= 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 -06002733 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002734 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002735 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002736 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002737 skipCall |= 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 -06002738 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2739 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2740 } else {
2741 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002742 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002743 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002744 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002745 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002746 }
2747 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002748 if (VK_FALSE == skipCall)
2749 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002750}
2751
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002752VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2753 VkCmdBuffer cmdBuffer,
2754 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002755 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002756 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002757{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002758 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002759 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2760 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002761 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002762 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002763 skipCall |= 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 -06002764 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2765 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2766 } else {
2767 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002768 skipCall |= addCmd(pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002769 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002770 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002771 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002772 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002773 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002774 if (VK_FALSE == skipCall)
2775 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002776}
2777
Chris Forbes2951d7d2015-06-22 17:21:59 +12002778VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002779 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002780 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002781 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002782{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002783 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002784 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2785 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002786 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002787 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002788 skipCall |= 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 -06002789 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2790 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2791 } else {
2792 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002793 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002794 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002795 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002796 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002797 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002798 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002799 if (VK_FALSE == skipCall)
2800 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002801}
2802
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002803VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2804 VkImage srcImage, VkImageLayout srcImageLayout,
2805 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002806 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002807{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002808 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002809 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2810 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002811 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002812 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002813 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002814 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002815 } else {
2816 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002817 skipCall |= addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002818 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002819 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002820 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002821 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002822 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002823 if (VK_FALSE == skipCall)
2824 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002825}
2826
Tony Barbourc2e987e2015-06-29 16:20:35 -06002827VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002828{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002829 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002830 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2831 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002832 if (pCB->state == CB_UPDATE_ACTIVE) {
2833 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002834 skipCall |= addCmd(pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002835 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002836 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002837 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002838 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002839 if (VK_FALSE == skipCall)
2840 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002841}
2842
Tony Barbourc2e987e2015-06-29 16:20:35 -06002843VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002844{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002845 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002846 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2847 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002848 if (pCB->state == CB_UPDATE_ACTIVE) {
2849 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002850 skipCall |= addCmd(pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002851 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002852 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002853 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002854 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002855 if (VK_FALSE == skipCall)
2856 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002857}
2858
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002859VK_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 -06002860{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002861 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002862 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2863 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002864 if (pCB->state == CB_UPDATE_ACTIVE) {
2865 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002866 skipCall |= addCmd(pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002867 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002868 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002869 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002870 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002871 if (VK_FALSE == skipCall)
2872 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002873}
2874
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002875VK_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 -06002876{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002877 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002878 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2879 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002880 if (pCB->state == CB_UPDATE_ACTIVE) {
2881 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002882 skipCall |= addCmd(pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002883 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002884 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002885 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002886 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002887 if (VK_FALSE == skipCall)
2888 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002889}
2890
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002891VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002892{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002893 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002894 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2895 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002896 if (pCB->state == CB_UPDATE_ACTIVE) {
2897 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002898 skipCall |= addCmd(pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002899 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002900 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002901 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002902 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002903 if (VK_FALSE == skipCall)
2904 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002905}
2906
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002907VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002908{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002909 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002910 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2911 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002912 if (pCB->state == CB_UPDATE_ACTIVE) {
2913 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002914 skipCall |= addCmd(pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002915 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002916 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002917 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002918 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002919 if (VK_FALSE == skipCall)
2920 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002921}
2922
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002923VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002924{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002925 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002926 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2927 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002928 if (pCB->state == CB_UPDATE_ACTIVE) {
2929 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002930 skipCall |= addCmd(pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002931 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002932 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002933 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002934 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002935 if (VK_FALSE == skipCall)
2936 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002937}
2938
Tony Barbour8205d902015-04-16 15:59:00 -06002939VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002940{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002941 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002942 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2943 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002944 if (pCB->state == CB_UPDATE_ACTIVE) {
2945 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002946 skipCall |= addCmd(pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002947 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002948 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002949 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002950 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002951 if (VK_FALSE == skipCall)
2952 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002953}
2954
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002955VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002956{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002957 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002958 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002959 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002960 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002961 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002962 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2963 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002964 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002965 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002966 }
2967 return result;
2968}
2969
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002970VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002971{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002972 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002973 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002974 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002975 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002976 if (pCreateInfo->pAttachments) {
2977 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2978 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002979 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002980 if (pCreateInfo->pSubpasses) {
2981 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2982 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2983
2984 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2985 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2986 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002987 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002988 subpass->preserveCount;
2989 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2990
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002991 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002992 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002993 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002994 attachments += subpass->inputCount;
2995
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002996 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002997 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002998 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002999 attachments += subpass->colorCount;
3000
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003001 if (subpass->pResolveAttachments) {
3002 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003003 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003004 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003005 attachments += subpass->colorCount;
3006 }
3007
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003008 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003009 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003010 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003011 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06003012 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003013 if (pCreateInfo->pDependencies) {
3014 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
3015 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06003016 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003017 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06003018 }
3019 return result;
3020}
3021
Chia-I Wuc278df82015-07-07 11:50:03 +08003022VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003023{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003024 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003025 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3026 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003027 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003028 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003029 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003030 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06003031 } else {
3032 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003033 skipCall |= addCmd(pCB, CMD_BEGINRENDERPASS);
Tobin Ehlise4076782015-06-24 15:53:07 -06003034 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003035 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06003036 pCB->framebuffer = pRenderPassBegin->framebuffer;
3037 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003038 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06003039 }
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003040 }
Tobin Ehlise4076782015-06-24 15:53:07 -06003041 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003042 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003043 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06003044 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003045 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003046 if (VK_FALSE == skipCall)
3047 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003048}
3049
Chia-I Wuc278df82015-07-07 11:50:03 +08003050VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
3051{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003052 VkBool32 skipCall = VK_FALSE;
Chia-I Wuc278df82015-07-07 11:50:03 +08003053 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3054 if (pCB) {
3055 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003056 skipCall |= 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 +08003057 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
3058 } else {
3059 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003060 skipCall |= addCmd(pCB, CMD_NEXTSUBPASS);
Chia-I Wuc278df82015-07-07 11:50:03 +08003061 pCB->activeSubpass++;
3062 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003063 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08003064 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003065 }
3066 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003067 if (VK_FALSE == skipCall)
3068 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08003069}
3070
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003071VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003072{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003073 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003074 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3075 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003076 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003077 skipCall |= 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 +08003078 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06003079 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003080 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003081 skipCall |= addCmd(pCB, CMD_ENDRENDERPASS);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003082 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08003083 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003084 }
3085 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003086 if (VK_FALSE == skipCall)
3087 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003088}
3089
3090VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3091{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003092 VkBool32 skipCall = VK_FALSE;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003093 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3094 if (pCB) {
3095 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003096 skipCall |= 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 +08003097 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
3098 } else {
3099 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003100 skipCall |= addCmd(pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003101 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003102 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003103 if (VK_FALSE == skipCall)
3104 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003105}
3106
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003107VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3108 VkInstance instance,
3109 VkFlags msgFlags,
3110 const PFN_vkDbgMsgCallback pfnMsgCallback,
3111 void* pUserData,
3112 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003113{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003114 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003115 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3116 if (VK_SUCCESS == res) {
3117 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3118 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3119 }
3120 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003121}
3122
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003123VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3124 VkInstance instance,
3125 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003126{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003127 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003128 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3129 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3130 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3131 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003132}
3133
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003134VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003135{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003136 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003137 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003138 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3139 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003140 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003141 skipCall |= 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 -06003142 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003143 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003144 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003145 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003146 skipCall |= addCmd(pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003147 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003148 if (VK_FALSE == skipCall)
3149 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003150}
3151
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003152VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003153{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003154 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003155 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003156 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3157 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003158 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003159 skipCall |= 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 -06003160 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003161 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003162 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003163 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003164 skipCall |= addCmd(pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003165 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003166 if (VK_FALSE == skipCall)
3167 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003168}
3169
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003170//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3171//{
3172// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3173// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3174// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3175// "Attempt to use DbgSetObjectTag but extension disabled!");
3176// return VK_ERROR_UNAVAILABLE;
3177// }
3178// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3179//}
3180//
3181//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3182//{
3183// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3184// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3185// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3186// "Attempt to use DbgSetObjectName but extension disabled!");
3187// return VK_ERROR_UNAVAILABLE;
3188// }
3189// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3190//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003191
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003192VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003193{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003194 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003195 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003196
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003197 /* loader uses this to force layer initialization; device object is wrapped */
3198 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003199 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003200 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003201 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003202 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003204 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003206 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003208 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003209 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003210 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003211 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003212 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003213 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003214 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003215 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003216 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003217 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003218 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003219 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003220 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003221 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003222 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003223 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003224 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003226 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003228 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003230 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003232 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003234 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003236 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003238 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003240 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003242 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003243 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003244 if (!strcmp(funcName, "vkDestroyDynamicLineWidthState"))
3245 return (PFN_vkVoidFunction) vkDestroyDynamicLineWidthState;
3246 if (!strcmp(funcName, "vkDestroyDynamicDepthBiasState"))
3247 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBiasState;
3248 if (!strcmp(funcName, "vkDestroyDynamicBlendState"))
3249 return (PFN_vkVoidFunction) vkDestroyDynamicBlendState;
3250 if (!strcmp(funcName, "vkDestroyDynamicDepthBoundsState"))
3251 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003252 if (!strcmp(funcName, "vkDestroyDynamicStencilState"))
3253 return (PFN_vkVoidFunction) vkDestroyDynamicStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003254 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003256 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003258 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003260 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003262 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003264 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003265 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003266 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003267 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003268 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003269 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003270 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003271 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003272 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003273 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003274 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003276 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003278 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003280 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003282 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003284 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003286 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003287 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003288 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003289 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003290 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003291 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003292 if (!strcmp(funcName, "vkCreateDynamicLineWidthState"))
3293 return (PFN_vkVoidFunction) vkCreateDynamicLineWidthState;
3294 if (!strcmp(funcName, "vkCreateDynamicDepthBiasState"))
3295 return (PFN_vkVoidFunction) vkCreateDynamicDepthBiasState;
3296 if (!strcmp(funcName, "vkCreateDynamicBlendState"))
3297 return (PFN_vkVoidFunction) vkCreateDynamicBlendState;
3298 if (!strcmp(funcName, "vkCreateDynamicDepthBoundsState"))
3299 return (PFN_vkVoidFunction) vkCreateDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003300 if (!strcmp(funcName, "vkCreateDynamicStencilState"))
3301 return (PFN_vkVoidFunction) vkCreateDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003302 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003303 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003304 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003305 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003306 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003307 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003308 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003309 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003310 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003311 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003312 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003313 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003314 if (!strcmp(funcName, "vkCmdBindDynamicLineWidthState"))
3315 return (PFN_vkVoidFunction) vkCmdBindDynamicLineWidthState;
3316 if (!strcmp(funcName, "vkCmdBindDynamicDepthBiasState"))
3317 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBiasState;
3318 if (!strcmp(funcName, "vkCmdBindDynamicBlendState"))
3319 return (PFN_vkVoidFunction) vkCmdBindDynamicBlendState;
3320 if (!strcmp(funcName, "vkCmdBindDynamicDepthBoundsState"))
3321 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003322 if (!strcmp(funcName, "vkCmdBindDynamicStencilState"))
3323 return (PFN_vkVoidFunction) vkCmdBindDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003324 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003325 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003326 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003327 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003328 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003329 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003330 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003331 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003332 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003333 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003334 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003335 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003336 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003337 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003338 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003339 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003340 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003341 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003342 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003343 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003344 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003345 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003346 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003347 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003348 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003349 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003350 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003351 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003352 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003353 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003354 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003355 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003356 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003357 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003358 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003359 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003360 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003361 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003362 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003363 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003364 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003365 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003366 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003367 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003368 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003369 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003370 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003371 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003372 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003373 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003374 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003375 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003376 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003377 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003378 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003379 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003380 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003381 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003382 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003383 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003384 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003385 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003386 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003387 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003388 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003389 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003390
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003391 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3392 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003393 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003394 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003395 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003396 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003397 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003398// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3399// return (void*) vkDbgSetObjectTag;
3400// if (!strcmp(funcName, "vkDbgSetObjectName"))
3401// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003402 }
3403 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003404 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003405 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003406 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003407 }
3408}
3409
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003410VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003411{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003412 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003413 if (instance == NULL)
3414 return NULL;
3415
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003416 /* loader uses this to force layer initialization; instance object is wrapped */
3417 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003418 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003419 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003420 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003421 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003422 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003423 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003424 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003425 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003426 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003427 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003428 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003429 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003430 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003431 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003432 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003433
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003434 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3435 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003436 if (fptr)
3437 return fptr;
3438
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003439 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003440 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003441 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003442 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003443 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003444 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003445}