blob: a831869a7e9dc3ce810b4f88d67114a45d1d51cc [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");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06001324 log_output = getLayerLogOutput(option_str, "DrawState");
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001325 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 -06001326 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001327
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001328 if (!globalLockInitialized)
1329 {
1330 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001331 // suggestion is to call this during vkCreateInstance(), and then we
1332 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001333 // that the layer have per-instance locks. We need to come back and
1334 // address this soon.
1335 loader_platform_thread_create_mutex(&globalLock);
1336 globalLockInitialized = 1;
1337 }
1338}
1339
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001340VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1341{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001342 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001343 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1344
1345 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001346 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1347 my_data->report_data = debug_report_create_instance(
1348 pTable,
1349 *pInstance,
1350 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001351 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001352
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001353 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001354 }
1355 return result;
1356}
1357
Jon Ashburne0fa2282015-05-20 09:00:28 -06001358/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001359VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Jon Ashburne0fa2282015-05-20 09:00:28 -06001360{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001361 dispatch_key key = get_dispatch_key(instance);
1362 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001363 pTable->DestroyInstance(instance);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001364
1365 // Clean up logging callback, if any
1366 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1367 if (my_data->logging_callback) {
1368 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1369 }
1370
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001371 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001372 layer_data_map.erase(pTable);
1373
1374 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001375}
1376
Jon Ashburnf0615e22015-05-25 14:11:37 -06001377static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1378{
Tony Barbour29b12062015-07-13 13:37:24 -06001379 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001380 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001381 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001382
1383 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001384 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001385 /* Found a matching extension name, mark it enabled and init dispatch table*/
1386 initDebugMarkerTable(device);
1387 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001388 }
1389
1390 }
1391}
1392
Tony Barbour8205d902015-04-16 15:59:00 -06001393VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001394{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001395 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1396 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001397 if (result == VK_SUCCESS) {
1398 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1399 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1400 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1401 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001402 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001403 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001404 return result;
1405}
1406
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001407VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001408{
1409 // Free all the memory
1410 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001411 deletePipelines();
1412 deleteSamplers();
1413 deleteImages();
1414 deleteBuffers();
1415 deleteCmdBuffers();
1416 deleteDynamicState();
1417 deletePools();
1418 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001419 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001420
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001421 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001422 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001423 pDisp->DestroyDevice(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001424 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001425 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001426 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001427}
1428
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001429static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001430 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001431 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001432 VK_API_VERSION,
1433 VK_MAKE_VERSION(0, 1, 0),
1434 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001435 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001436};
1437
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001438VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001439 const char *pLayerName,
1440 uint32_t *pCount,
1441 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001442{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001443 /* DrawState does not have any global extensions */
1444 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1445}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001446
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001447VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001448 uint32_t *pCount,
1449 VkLayerProperties* pProperties)
1450{
1451 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1452 ds_global_layers,
1453 pCount, pProperties);
1454}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001455
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001456static const VkExtensionProperties ds_device_extensions[] = {
1457 {
1458 DEBUG_MARKER_EXTENSION_NAME,
1459 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001460 }
1461};
1462
1463static const VkLayerProperties ds_device_layers[] = {
1464 {
1465 "DrawState",
1466 VK_API_VERSION,
1467 VK_MAKE_VERSION(0, 1, 0),
1468 "Validation layer: DrawState",
1469 }
1470};
1471
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001472VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001473 VkPhysicalDevice physicalDevice,
1474 const char* pLayerName,
1475 uint32_t* pCount,
1476 VkExtensionProperties* pProperties)
1477{
1478 /* Mem tracker does not have any physical device extensions */
1479 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1480 pCount, pProperties);
1481}
1482
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001483VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001484 VkPhysicalDevice physicalDevice,
1485 uint32_t* pCount,
1486 VkLayerProperties* pProperties)
1487{
1488 /* Mem tracker's physical device layers are the same as global */
1489 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1490 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001491}
1492
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001493VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001494{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001495 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001496 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001497 for (uint32_t i=0; i < cmdBufferCount; i++) {
1498 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001499 pCB = getCBNode(pCmdBuffers[i]);
1500 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001501 pCB->submitCount++; // increment submit count
1502 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001503 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 -06001504 "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 -06001505 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001506 if (CB_UPDATE_COMPLETE != pCB->state) {
1507 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001508 // TODO : How to pass cb as srcObj?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001509 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 -06001510 "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 -06001511 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001512 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001513 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001514 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001515 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001516 if (VK_FALSE == skipCall)
1517 return get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
1518 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001519}
1520
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001521VK_LAYER_EXPORT void VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001522{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001523 get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001524 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001525}
1526
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001527VK_LAYER_EXPORT void VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001528{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001529 get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001530 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001531}
1532
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001533VK_LAYER_EXPORT void VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001534{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001535 get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001536 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001537}
1538
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001539VK_LAYER_EXPORT void VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001540{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001541 get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001542 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001543}
1544
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001545VK_LAYER_EXPORT void VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001546{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001547 get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001548 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001549}
1550
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001551VK_LAYER_EXPORT void VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001552{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001553 get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001554 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001555}
1556
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001557VK_LAYER_EXPORT void VKAPI vkDestroyImage(VkDevice device, VkImage image)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001558{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001559 get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001560 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001561}
1562
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001563VK_LAYER_EXPORT void VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001564{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001565 get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001566 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001567}
1568
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001569VK_LAYER_EXPORT void VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001570{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001571 get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001572 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001573}
1574
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001575VK_LAYER_EXPORT void VKAPI vkDestroyShader(VkDevice device, VkShader shader)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001576{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001577 get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001578 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001579}
1580
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001581VK_LAYER_EXPORT void VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001582{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001583 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001584 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001585}
1586
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001587VK_LAYER_EXPORT void VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001588{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001589 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001590 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001591}
1592
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001593VK_LAYER_EXPORT void VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001594{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001595 get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001596 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001597}
1598
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001599VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001600{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001601 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001602 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001603}
1604
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001605VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001606{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001607 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001608 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001609}
1610
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001611VK_LAYER_EXPORT void VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001612{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001613 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001614 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001615}
1616
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001617VK_LAYER_EXPORT void VKAPI vkDestroyDynamicLineWidthState(VkDevice device, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001618{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001619 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicLineWidthState(device, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06001620 // TODO : Clean up any internal data structures using this obj.
Cody Northropf5bd2252015-08-17 11:10:49 -06001621}
1622
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001623VK_LAYER_EXPORT void VKAPI vkDestroyDynamicDepthBiasState(VkDevice device, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001624{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001625 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBiasState(device, dynamicDepthBiasState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001626 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001627}
1628
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001629VK_LAYER_EXPORT void VKAPI vkDestroyDynamicBlendState(VkDevice device, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001630{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001631 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicBlendState(device, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001632 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001633}
1634
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001635VK_LAYER_EXPORT void VKAPI vkDestroyDynamicDepthBoundsState(VkDevice device, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001636{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001637 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBoundsState(device, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06001638 // TODO : Clean up any internal data structures using this obj.
Cody Northrop2605cb02015-08-18 15:21:16 -06001639}
1640
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001641VK_LAYER_EXPORT void VKAPI vkDestroyDynamicStencilState(VkDevice device, VkDynamicStencilState dynamicStencilState)
Cody Northrop2605cb02015-08-18 15:21:16 -06001642{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001643 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicStencilState(device, dynamicStencilState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001644 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001645}
1646
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001647VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001648{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001649 get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001650 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001651}
1652
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001653VK_LAYER_EXPORT void VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001654{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001655 get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001656 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001657}
1658
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001659VK_LAYER_EXPORT void VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001660{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001661 get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001662 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001663}
1664
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001665VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001666{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001667 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001668 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001669 loader_platform_thread_lock_mutex(&globalLock);
1670 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1671 pNewNode->buffer = *pView;
1672 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001673 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674 loader_platform_thread_unlock_mutex(&globalLock);
1675 }
1676 return result;
1677}
1678
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001679VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001680{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001681 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001682 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001684 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001685 loader_platform_thread_unlock_mutex(&globalLock);
1686 }
1687 return result;
1688}
1689
Jon Ashburn0d60d272015-07-09 15:02:25 -06001690//TODO handle pipeline caches
1691VkResult VKAPI vkCreatePipelineCache(
1692 VkDevice device,
1693 const VkPipelineCacheCreateInfo* pCreateInfo,
1694 VkPipelineCache* pPipelineCache)
1695{
1696 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1697 return result;
1698}
1699
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001700void VKAPI vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06001701 VkDevice device,
1702 VkPipelineCache pipelineCache)
1703{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001704 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001705}
1706
1707size_t VKAPI vkGetPipelineCacheSize(
1708 VkDevice device,
1709 VkPipelineCache pipelineCache)
1710{
1711 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1712 return size;
1713}
1714
1715VkResult VKAPI vkGetPipelineCacheData(
1716 VkDevice device,
1717 VkPipelineCache pipelineCache,
1718 void* pData)
1719{
1720 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1721 return result;
1722}
1723
1724VkResult VKAPI vkMergePipelineCaches(
1725 VkDevice device,
1726 VkPipelineCache destCache,
1727 uint32_t srcCacheCount,
1728 const VkPipelineCache* pSrcCaches)
1729{
1730 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1731 return result;
1732}
1733
1734VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001735{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001736 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06001737 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06001738 // The order of operations here is a little convoluted but gets the job done
1739 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1740 // 2. Create state is then validated (which uses flags setup during shadowing)
1741 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06001742 VkBool32 skipCall = VK_FALSE;
1743 PIPELINE_NODE* pPipeNode[count] = {};
1744 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001745 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001746 for (i=0; i<count; i++) {
1747 pPipeNode[i] = initPipeline(&pCreateInfos[i], NULL);
1748 skipCall |= verifyPipelineCreateState(device, pPipeNode[i]);
1749 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001750 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001751 if (VK_FALSE == skipCall) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001752 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001753 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001754 for (i=0; i<count; i++) {
1755 pPipeNode[i]->pipeline = pPipelines[i];
1756 pipelineMap[pPipeNode[i]->pipeline.handle] = pPipeNode[i];
1757 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001758 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001759 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06001760 for (i=0; i<count; i++) {
1761 if (pPipeNode[i]) {
1762 // If we allocated a pipeNode, need to clean it up here
1763 delete[] pPipeNode[i]->pVertexBindingDescriptions;
1764 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
1765 delete[] pPipeNode[i]->pAttachments;
1766 delete pPipeNode[i];
1767 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001768 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001769 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001770 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001771 return result;
1772}
1773
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001774VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001775{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001776 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001778 loader_platform_thread_lock_mutex(&globalLock);
1779 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1780 pNewNode->sampler = *pSampler;
1781 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001782 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001783 loader_platform_thread_unlock_mutex(&globalLock);
1784 }
1785 return result;
1786}
1787
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001788VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001789{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001790 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001791 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001792 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1793 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001794 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1795 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
1796 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001797 }
1798 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001799 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1800 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1801 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001802 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001803 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001804 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001805 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001806 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001807 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1808 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001809 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001810 }
1811 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001812 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001813 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001814 uint32_t j = 0;
1815 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001816 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001817 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001818 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001819 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 }
1821 }
1822 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001823 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001824 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1825 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001826 // Put new node at Head of global Layer list
1827 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001828 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001829 loader_platform_thread_unlock_mutex(&globalLock);
1830 }
1831 return result;
1832}
1833
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001834VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001836 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001837 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001838 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001839 }
1840 return result;
1841}
1842
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001843VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001845 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001846 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001847 // Insert this pool into Global Pool LL at head
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001848 if (log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1849 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle))
1850 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001851 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001852 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001854 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1855 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()"))
1856 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001857 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001858 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001859 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1860 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001861 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001862 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1863 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001864 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1865 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001866 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001867 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001868 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001869 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001870 }
1871 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001872 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001873 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001874 }
1875 return result;
1876}
1877
Mike Stroyan230e6252015-04-17 12:36:38 -06001878VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001879{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001880 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001881 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001882 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001883 }
1884 return result;
1885}
1886
Cody Northropc8aa4a52015-08-03 12:47:29 -06001887VK_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 -06001888{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001889 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1890 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001891 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1892 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001893 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1894 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001895 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001896 if (count == 0) {
1897 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1898 "AllocDescriptorSets called with 0 count");
1899 }
1900 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001901 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1902 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001903 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001904 SET_NODE* pNewNode = new SET_NODE;
1905 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001906 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1907 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()"))
1908 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001909 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001910 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001911 // Insert set at head of Set LL for this pool
1912 pNewNode->pNext = pPoolNode->pSets;
1913 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001914 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1915 if (NULL == pLayout) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001916 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1917 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle))
1918 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001919 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001920 pNewNode->pLayout = pLayout;
1921 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001922 pNewNode->set = pDescriptorSets[i];
1923 pNewNode->setUsage = setUsage;
1924 pNewNode->descriptorCount = pLayout->endIndex + 1;
1925 if (pNewNode->descriptorCount) {
1926 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1927 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1928 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1929 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001930 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001931 }
1932 }
1933 }
1934 }
1935 return result;
1936}
1937
Tony Barbourb857d312015-07-10 10:50:45 -06001938VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1939{
1940 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1941 // TODO : Clean up any internal data structures using this obj.
1942 return result;
1943}
1944
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001945VK_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 -06001946{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001947 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when both updates return VK_FALSE
1948 if (!dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1949 !dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001950 get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001951 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001952}
1953
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001954VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001955{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001956 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001957 VkDynamicViewportStateCreateInfo local_ci;
1958 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1959 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1960 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1961 loader_platform_thread_lock_mutex(&globalLock);
1962 dynamicVpStateMap[pState->handle] = local_ci;
1963 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001964 return result;
1965}
1966
Cody Northrope4bc6942015-08-26 10:01:32 -06001967VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicLineWidthState(VkDevice device, const VkDynamicLineWidthStateCreateInfo* pCreateInfo, VkDynamicLineWidthState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001968{
Cody Northrope4bc6942015-08-26 10:01:32 -06001969 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicLineWidthState(device, pCreateInfo, pState);
1970 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_LINE_WIDTH);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001971 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001972 dynamicLineWidthStateMap[pState->handle] = *pCreateInfo;
Cody Northropf5bd2252015-08-17 11:10:49 -06001973 loader_platform_thread_unlock_mutex(&globalLock);
1974 return result;
1975}
1976
Cody Northrope4bc6942015-08-26 10:01:32 -06001977VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBiasState(VkDevice device, const VkDynamicDepthBiasStateCreateInfo* pCreateInfo, VkDynamicDepthBiasState* pState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001978{
Cody Northrope4bc6942015-08-26 10:01:32 -06001979 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBiasState(device, pCreateInfo, pState);
1980 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BIAS);
Cody Northropf5bd2252015-08-17 11:10:49 -06001981 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001982 dynamicDepthBiasStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001983 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001984 return result;
1985}
1986
Cody Northrope4bc6942015-08-26 10:01:32 -06001987VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicBlendState(VkDevice device, const VkDynamicBlendStateCreateInfo* pCreateInfo, VkDynamicBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001988{
Cody Northrope4bc6942015-08-26 10:01:32 -06001989 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicBlendState(device, pCreateInfo, pState);
1990 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_BLEND);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001991 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001992 dynamicBlendStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001993 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001994 return result;
1995}
1996
Cody Northrope4bc6942015-08-26 10:01:32 -06001997VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBoundsState(VkDevice device, const VkDynamicDepthBoundsStateCreateInfo* pCreateInfo, VkDynamicDepthBoundsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001998{
Cody Northrope4bc6942015-08-26 10:01:32 -06001999 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBoundsState(device, pCreateInfo, pState);
2000 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BOUNDS);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002001 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002002 dynamicDepthBoundsStateMap[pState->handle] = *pCreateInfo;
Cody Northrop2605cb02015-08-18 15:21:16 -06002003 loader_platform_thread_unlock_mutex(&globalLock);
2004 return result;
2005}
2006
2007VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicStencilState(VkDevice device, const VkDynamicStencilStateCreateInfo* pCreateInfoFront, const VkDynamicStencilStateCreateInfo* pCreateInfoBack, VkDynamicStencilState* pState)
2008{
2009 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicStencilState(device, pCreateInfoFront, pCreateInfoBack, pState);
2010 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_STENCIL);
2011 loader_platform_thread_lock_mutex(&globalLock);
2012
2013 // Bug 14406 - If back is NULL or equal to front, then single sided.
2014 // To support NULL case, simply track front twice
2015 const VkDynamicStencilStateCreateInfo* pLocalCreateInfoBack = (pCreateInfoBack == NULL) ? pCreateInfoFront : pCreateInfoBack;
2016
2017 std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo> infos(*pCreateInfoFront, *pLocalCreateInfoBack);
2018 dynamicStencilStateMap[pState->handle] = infos;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002019 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002020 return result;
2021}
2022
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002023VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002024{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002025 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002026 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002027 loader_platform_thread_lock_mutex(&globalLock);
2028 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2029 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2030 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002031 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002032 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002033 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002034 cmdBufferMap[*pCmdBuffer] = pCB;
2035 loader_platform_thread_unlock_mutex(&globalLock);
2036 updateCBTracking(*pCmdBuffer);
2037 }
2038 return result;
2039}
2040
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002041VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002043 VkBool32 skipCall = false;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002044 // Validate command buffer level
2045 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2046 if (pCB) {
2047 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
2048 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2049 // These should be NULL for a Primary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002050 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 -06002051 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2052 }
2053 } else {
2054 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2055 // These should NOT be null for an Secondary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002056 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 -06002057 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2058 }
2059 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002060 pCB->beginInfo = *pBeginInfo;
2061 } else {
2062 // TODO : Need to pass cmdBuffer as objType here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002063 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 -06002064 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002065 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002066 if (skipCall) {
2067 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06002068 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002069 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002070 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002071 if (CB_NEW != pCB->state)
2072 resetCB(cmdBuffer);
2073 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002074 updateCBTracking(cmdBuffer);
2075 }
2076 return result;
2077}
2078
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002079VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002080{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002081 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06002082 VkResult result = VK_SUCCESS;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002083 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06002084 /* TODO: preference is to always call API function after reporting any validation errors */
Tobin Ehlise42007c2015-06-19 13:00:59 -06002085 if (pCB) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002086 if (pCB->state != CB_UPDATE_ACTIVE) {
2087 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002088 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002089 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002090 if (VK_FALSE == skipCall) {
2091 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2092 if (VK_SUCCESS == result) {
2093 updateCBTracking(cmdBuffer);
2094 pCB->state = CB_UPDATE_COMPLETE;
2095 // Reset CB status flags
2096 pCB->status = 0;
2097 printCB(cmdBuffer);
2098 }
2099 } else {
2100 result = VK_ERROR_VALIDATION_FAILED;
2101 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002102 return result;
2103}
2104
Cody Northropf02f9f82015-07-09 18:08:05 -06002105VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002106{
Cody Northropf02f9f82015-07-09 18:08:05 -06002107 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002108 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002109 resetCB(cmdBuffer);
2110 updateCBTracking(cmdBuffer);
2111 }
2112 return result;
2113}
2114
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002115VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002116{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002117 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002118 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2119 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002120 if (pCB->state == CB_UPDATE_ACTIVE) {
2121 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002122 skipCall |= addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002123 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002124 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 -06002125 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002126 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002127 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 -06002128 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002129 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002130 PIPELINE_NODE* pPN = getPipeline(pipeline);
2131 if (pPN) {
2132 pCB->lastBoundPipeline = pipeline;
2133 loader_platform_thread_lock_mutex(&globalLock);
2134 set_cb_pso_status(pCB, pPN);
2135 g_lastBoundPipeline = pPN;
2136 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002137 skipCall |= validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002138 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002139 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 -06002140 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002141 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002142 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002143 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002144 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002145 }
2146 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002147 if (VK_FALSE == skipCall)
2148 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002149}
2150
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002151VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002152{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002153 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002154 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2155 if (pCB) {
2156 if (pCB->state == CB_UPDATE_ACTIVE) {
2157 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002158 skipCall |= addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002159 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002160 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 -06002161 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002162 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002163 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002164 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2165 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002166 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 -06002167 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002168 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002169 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2170 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002171 }
2172 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002173 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002174 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002175 }
2176 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002177 if (VK_FALSE == skipCall)
2178 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002179}
Cody Northrope4bc6942015-08-26 10:01:32 -06002180VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(VkCmdBuffer cmdBuffer, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002181{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002182 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002183 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2184 if (pCB) {
2185 if (pCB->state == CB_UPDATE_ACTIVE) {
2186 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002187 skipCall |= addCmd(pCB, CMD_BINDDYNAMICLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002188 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002189 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 -06002190 "Incorrect call to vkCmdBindDynamicLineWidthState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002191 }
2192 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002193 pCB->status |= CBSTATUS_LINE_WIDTH_BOUND;
2194 if (dynamicLineWidthStateMap.find(dynamicLineWidthState.handle) == dynamicLineWidthStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002195 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 -06002196 "Unable to find VkDynamicLineWidthState object %#" PRIxLEAST64 ", was it ever created?", dynamicLineWidthState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002197 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002198 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
2199 g_lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002200 }
2201 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002202 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002203 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002204 }
2205 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002206 if (VK_FALSE == skipCall)
2207 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicLineWidthState(cmdBuffer, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06002208}
Cody Northrope4bc6942015-08-26 10:01:32 -06002209VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(VkCmdBuffer cmdBuffer, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06002210{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002211 VkBool32 skipCall = VK_FALSE;
Cody Northropf5bd2252015-08-17 11:10:49 -06002212 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2213 if (pCB) {
2214 if (pCB->state == CB_UPDATE_ACTIVE) {
2215 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002216 skipCall |= addCmd(pCB, CMD_BINDDYNAMICDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002217 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002218 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 -06002219 "Incorrect call to vkCmdBindDynamicDepthBiasState() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002220 }
2221 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002222 pCB->status |= CBSTATUS_DEPTH_BIAS_BOUND;
2223 if (dynamicDepthBiasStateMap.find(dynamicDepthBiasState.handle) == dynamicDepthBiasStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002224 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 -06002225 "Unable to find VkDynamicDepthBiasState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBiasState.handle);
Cody Northropf5bd2252015-08-17 11:10:49 -06002226 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002227 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
2228 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
Cody Northropf5bd2252015-08-17 11:10:49 -06002229 }
2230 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northropf5bd2252015-08-17 11:10:49 -06002231 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002232 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBiasState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002233 }
2234 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002235 if (VK_FALSE == skipCall)
2236 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBiasState(cmdBuffer, dynamicDepthBiasState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002237}
Cody Northrope4bc6942015-08-26 10:01:32 -06002238VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicBlendState(VkCmdBuffer cmdBuffer, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002239{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002240 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002241 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2242 if (pCB) {
2243 if (pCB->state == CB_UPDATE_ACTIVE) {
2244 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002245 skipCall |= addCmd(pCB, CMD_BINDDYNAMICBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002246 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002247 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 -06002248 "Incorrect call to vkCmdBindDynamicBlendState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002249 }
2250 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002251 pCB->status |= CBSTATUS_BLEND_BOUND;
2252 if (dynamicBlendStateMap.find(dynamicBlendState.handle) == dynamicBlendStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002253 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 -06002254 "Unable to find VkDynamicBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicBlendState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002255 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002256 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
2257 g_lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002258 }
2259 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002260 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002261 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicBlendState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002262 }
2263 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002264 if (VK_FALSE == skipCall)
2265 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicBlendState(cmdBuffer, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002266}
Cody Northrope4bc6942015-08-26 10:01:32 -06002267VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(VkCmdBuffer cmdBuffer, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002268{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002269 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002270 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2271 if (pCB) {
2272 if (pCB->state == CB_UPDATE_ACTIVE) {
2273 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002274 skipCall |= addCmd(pCB, CMD_BINDDYNAMICDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002275 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002276 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 -06002277 "Incorrect call to vkCmdBindDynamicDepthBoundsState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002278 }
2279 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002280 pCB->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
2281 if (dynamicDepthBoundsStateMap.find(dynamicDepthBoundsState.handle) == dynamicDepthBoundsStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002282 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 -06002283 "Unable to find VkDynamicDepthBoundsState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBoundsState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002284 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002285 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
2286 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002287 }
2288 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002289 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002290 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBoundsState()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002291 }
2292 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002293 if (VK_FALSE == skipCall)
2294 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBoundsState(cmdBuffer, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06002295}
2296VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStencilState(VkCmdBuffer cmdBuffer, VkDynamicStencilState dynamicStencilState)
2297{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002298 VkBool32 skipCall = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -06002299 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2300 if (pCB) {
2301 if (pCB->state == CB_UPDATE_ACTIVE) {
2302 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002303 skipCall |= addCmd(pCB, CMD_BINDDYNAMICSTENCILSTATE);
Cody Northrop2605cb02015-08-18 15:21:16 -06002304 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002305 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 -06002306 "Incorrect call to vkCmdBindDynamicStencilState() without an active RenderPass.");
2307 }
2308 loader_platform_thread_lock_mutex(&globalLock);
2309 pCB->status |= CBSTATUS_STENCIL_BOUND;
2310 if (dynamicStencilStateMap.find(dynamicStencilState.handle) == dynamicStencilStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002311 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 -06002312 "Unable to find VkDynamicStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicStencilState.handle);
2313 } else {
2314 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2315 g_lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2316 }
2317 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop2605cb02015-08-18 15:21:16 -06002318 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002319 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicStencilState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002320 }
2321 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002322 if (VK_FALSE == skipCall)
2323 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStencilState(cmdBuffer, dynamicStencilState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002324}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002325VK_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 -06002326{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002327 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002328 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2329 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002330 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002331 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002332 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 -06002333 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002334 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002335 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 -06002336 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002337 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002338 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002339 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2340 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002341 loader_platform_thread_lock_mutex(&globalLock);
2342 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002343 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002344 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2345 g_lastBoundDescriptorSet = pDescriptorSets[i];
2346 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002347 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 -06002348 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002349 if (!pSet->pUpdateStructs)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002350 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 -06002351 "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 -06002352 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002353 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 -06002354 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002355 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002356 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002357 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002358 skipCall |= addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002360 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002361 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362 }
2363 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002364 if (VK_FALSE == skipCall)
2365 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 -06002366}
2367
Tony Barbour8205d902015-04-16 15:59:00 -06002368VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002369{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002370 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002371 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2372 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002373 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002374 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002375 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 -06002376 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2377 } else {
2378 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2379 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002380 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002381 skipCall |= addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002382 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002383 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002384 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002385 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002386 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002387 if (VK_FALSE == skipCall)
2388 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002389}
2390
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002391VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2392 VkCmdBuffer cmdBuffer,
2393 uint32_t startBinding,
2394 uint32_t bindingCount,
2395 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002396 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002397{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002398 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002399 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2400 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002401 if (pCB->state == CB_UPDATE_ACTIVE) {
2402 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002403 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002404 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 -06002405 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2406 } else {
2407 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002408 updateCBTracking(cmdBuffer);
2409 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002410 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002411 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002412 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002413 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002414 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002415 if (VK_FALSE == skipCall)
2416 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002417}
2418
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002419VK_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 -06002420{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002421 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002422 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2423 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002424 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002425 pCB->drawCount[DRAW]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002426 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002427 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002428 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 -06002429 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002430 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2431 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002432 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002433 skipCall |= addCmd(pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002434 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002435 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002436 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002437 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002438 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002439 if (VK_FALSE == skipCall)
2440 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002441}
2442
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002443VK_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 -06002444{
2445 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002446 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002448 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002449 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002450 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002451 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002452 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 -06002453 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002454 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2455 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002456 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002457 skipCall |= addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002458 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002459 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002460 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002461 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002462 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002463 if (VK_FALSE == skipCall)
2464 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002465}
2466
Tony Barbour8205d902015-04-16 15:59:00 -06002467VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002468{
2469 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002470 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002471 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002472 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002473 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002474 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002475 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002476 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 -06002477 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002478 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2479 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002480 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002481 skipCall |= addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002482 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002483 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002484 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002485 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002486 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002487 if (VK_FALSE == skipCall)
2488 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002489}
2490
Tony Barbour8205d902015-04-16 15:59:00 -06002491VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002492{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002493 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002494 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2495 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002496 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002497 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002498 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002499 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002500 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 -06002501 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002502 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2503 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002504 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002505 skipCall |= addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002506 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002507 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002508 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002509 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002510 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002511 if (VK_FALSE == skipCall)
2512 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513}
2514
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002515VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002516{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002517 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002518 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2519 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002520 if (pCB->state == CB_UPDATE_ACTIVE) {
2521 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002522 skipCall |= addCmd(pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002523 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002524 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002525 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002526 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002527 if (VK_FALSE == skipCall)
2528 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002529}
2530
Tony Barbour8205d902015-04-16 15:59:00 -06002531VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002532{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002533 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002534 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2535 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002536 if (pCB->state == CB_UPDATE_ACTIVE) {
2537 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002538 skipCall |= addCmd(pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002539 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002540 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002541 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002542 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002543 if (VK_FALSE == skipCall)
2544 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002545}
2546
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002547VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002548{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002549 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002550 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2551 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002552 if (pCB->state == CB_UPDATE_ACTIVE) {
2553 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002554 skipCall |= addCmd(pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002555 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002556 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002557 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002558 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002559 if (VK_FALSE == skipCall)
2560 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002561}
2562
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002563VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2564 VkImage srcImage,
2565 VkImageLayout srcImageLayout,
2566 VkImage destImage,
2567 VkImageLayout destImageLayout,
2568 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002569{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002570 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002571 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2572 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002573 if (pCB->state == CB_UPDATE_ACTIVE) {
2574 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002575 skipCall |= addCmd(pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002576 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002577 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002578 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002579 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002580 if (VK_FALSE == skipCall)
2581 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002582}
2583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002584VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2585 VkImage srcImage, VkImageLayout srcImageLayout,
2586 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002587 uint32_t regionCount, const VkImageBlit* pRegions,
2588 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002589{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002590 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002591 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2592 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002593 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002594 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002595 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 -06002596 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002597 } else {
2598 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002599 skipCall |= addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002600 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002601 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002602 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002603 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002604 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002605 if (VK_FALSE == skipCall)
2606 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 -06002607}
2608
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002609VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2610 VkBuffer srcBuffer,
2611 VkImage destImage, VkImageLayout destImageLayout,
2612 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002613{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002614 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002615 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2616 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002617 if (pCB->state == CB_UPDATE_ACTIVE) {
2618 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002619 skipCall |= addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002620 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002621 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002622 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002623 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002624 if (VK_FALSE == skipCall)
2625 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002626}
2627
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002628VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2629 VkImage srcImage, VkImageLayout srcImageLayout,
2630 VkBuffer destBuffer,
2631 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002632{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002633 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002634 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2635 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002636 if (pCB->state == CB_UPDATE_ACTIVE) {
2637 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002638 skipCall |= addCmd(pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002639 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002640 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002641 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002642 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002643 if (VK_FALSE == skipCall)
2644 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002645}
2646
Tony Barbour8205d902015-04-16 15:59:00 -06002647VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002648{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002649 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002650 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2651 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002652 if (pCB->state == CB_UPDATE_ACTIVE) {
2653 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002654 skipCall |= addCmd(pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002655 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002656 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002657 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002658 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002659 if (VK_FALSE == skipCall)
2660 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002661}
2662
Tony Barbour8205d902015-04-16 15:59:00 -06002663VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002664{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002665 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002666 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2667 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002668 if (pCB->state == CB_UPDATE_ACTIVE) {
2669 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002670 skipCall |= addCmd(pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002671 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002672 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002673 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002674 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002675 if (VK_FALSE == skipCall)
2676 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002677}
2678
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002679VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2680 VkCmdBuffer cmdBuffer,
2681 uint32_t colorAttachment,
2682 VkImageLayout imageLayout,
2683 const VkClearColorValue* pColor,
2684 uint32_t rectCount,
2685 const VkRect3D* pRects)
2686{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002687 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002688 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2689 if (pCB) {
2690 if (pCB->state == CB_UPDATE_ACTIVE) {
2691 // Warn if this is issued prior to Draw Cmd
2692 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002693 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002694 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 -06002695 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002696 " 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 -06002697 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002698 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002699 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 -06002700 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2701 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2702 } else {
2703 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002704 skipCall |= addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002705 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002706 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002707 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002708 }
2709 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002710 if (VK_FALSE == skipCall)
2711 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002712}
2713
2714VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2715 VkCmdBuffer cmdBuffer,
2716 VkImageAspectFlags imageAspectMask,
2717 VkImageLayout imageLayout,
2718 float depth,
2719 uint32_t stencil,
2720 uint32_t rectCount,
2721 const VkRect3D* pRects)
2722{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002723 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002724 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2725 if (pCB) {
2726 if (pCB->state == CB_UPDATE_ACTIVE) {
2727 // Warn if this is issued prior to Draw Cmd
2728 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002729 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002730 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 -06002731 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002732 " 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 -06002733 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002734 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002735 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 -06002736 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2737 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2738 } else {
2739 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002740 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002741 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002742 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002743 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002744 }
2745 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002746 if (VK_FALSE == skipCall)
2747 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002748}
2749
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002750VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2751 VkCmdBuffer cmdBuffer,
2752 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002753 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002754 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002755{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002756 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002757 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2758 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002759 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002760 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002761 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 -06002762 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2763 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2764 } else {
2765 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002766 skipCall |= addCmd(pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002767 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002768 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002769 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002770 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002771 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002772 if (VK_FALSE == skipCall)
2773 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002774}
2775
Chris Forbes2951d7d2015-06-22 17:21:59 +12002776VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002777 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002778 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002779 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002780{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002781 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002782 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2783 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002784 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002785 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002786 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 -06002787 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2788 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2789 } else {
2790 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002791 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002792 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002793 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002794 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002795 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002796 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002797 if (VK_FALSE == skipCall)
2798 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002799}
2800
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002801VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2802 VkImage srcImage, VkImageLayout srcImageLayout,
2803 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002804 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002805{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002806 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002807 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2808 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002809 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002810 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002811 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 -06002812 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002813 } else {
2814 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002815 skipCall |= addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002816 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002817 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002818 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002819 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002820 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002821 if (VK_FALSE == skipCall)
2822 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002823}
2824
Tony Barbourc2e987e2015-06-29 16:20:35 -06002825VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002826{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002827 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002828 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2829 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002830 if (pCB->state == CB_UPDATE_ACTIVE) {
2831 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002832 skipCall |= addCmd(pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002833 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002834 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002835 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002836 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002837 if (VK_FALSE == skipCall)
2838 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002839}
2840
Tony Barbourc2e987e2015-06-29 16:20:35 -06002841VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002842{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002843 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002844 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2845 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002846 if (pCB->state == CB_UPDATE_ACTIVE) {
2847 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002848 skipCall |= addCmd(pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002849 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002850 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002851 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002852 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002853 if (VK_FALSE == skipCall)
2854 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002855}
2856
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002857VK_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 -06002858{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002859 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002860 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2861 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002862 if (pCB->state == CB_UPDATE_ACTIVE) {
2863 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002864 skipCall |= addCmd(pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002865 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002866 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002867 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002868 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002869 if (VK_FALSE == skipCall)
2870 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002871}
2872
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002873VK_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 -06002874{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002875 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002876 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2877 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002878 if (pCB->state == CB_UPDATE_ACTIVE) {
2879 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002880 skipCall |= addCmd(pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002881 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002882 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002883 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002884 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002885 if (VK_FALSE == skipCall)
2886 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002887}
2888
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002889VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002890{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002891 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002892 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2893 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002894 if (pCB->state == CB_UPDATE_ACTIVE) {
2895 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002896 skipCall |= addCmd(pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002897 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002898 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002899 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002900 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002901 if (VK_FALSE == skipCall)
2902 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002903}
2904
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002905VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002906{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002907 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002908 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2909 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002910 if (pCB->state == CB_UPDATE_ACTIVE) {
2911 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002912 skipCall |= addCmd(pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002913 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002914 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002915 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002916 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002917 if (VK_FALSE == skipCall)
2918 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002919}
2920
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002921VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002922{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002923 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002924 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2925 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002926 if (pCB->state == CB_UPDATE_ACTIVE) {
2927 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002928 skipCall |= addCmd(pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002929 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002930 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002931 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002932 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002933 if (VK_FALSE == skipCall)
2934 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002935}
2936
Tony Barbour8205d902015-04-16 15:59:00 -06002937VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002938{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002939 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002940 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2941 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002942 if (pCB->state == CB_UPDATE_ACTIVE) {
2943 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002944 skipCall |= addCmd(pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002945 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002946 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002947 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002948 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002949 if (VK_FALSE == skipCall)
2950 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002951}
2952
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002953VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002954{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002955 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002956 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002957 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002958 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002959 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002960 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2961 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002962 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002963 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002964 }
2965 return result;
2966}
2967
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002968VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002969{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002970 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002971 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002972 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002973 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002974 if (pCreateInfo->pAttachments) {
2975 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2976 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002977 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002978 if (pCreateInfo->pSubpasses) {
2979 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2980 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2981
2982 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2983 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2984 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002985 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002986 subpass->preserveCount;
2987 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2988
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002989 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002990 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002991 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002992 attachments += subpass->inputCount;
2993
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002994 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002995 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002996 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002997 attachments += subpass->colorCount;
2998
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002999 if (subpass->pResolveAttachments) {
3000 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003001 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003002 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003003 attachments += subpass->colorCount;
3004 }
3005
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003006 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003007 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003008 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003009 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06003010 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003011 if (pCreateInfo->pDependencies) {
3012 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
3013 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06003014 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003015 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06003016 }
3017 return result;
3018}
3019
Chia-I Wuc278df82015-07-07 11:50:03 +08003020VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003021{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003022 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003023 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3024 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003025 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003026 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003027 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 -06003028 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06003029 } else {
3030 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003031 skipCall |= addCmd(pCB, CMD_BEGINRENDERPASS);
Tobin Ehlise4076782015-06-24 15:53:07 -06003032 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003033 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06003034 pCB->framebuffer = pRenderPassBegin->framebuffer;
3035 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003036 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06003037 }
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003038 }
Tobin Ehlise4076782015-06-24 15:53:07 -06003039 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003040 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 -06003041 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06003042 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003043 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003044 if (VK_FALSE == skipCall)
3045 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003046}
3047
Chia-I Wuc278df82015-07-07 11:50:03 +08003048VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
3049{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003050 VkBool32 skipCall = VK_FALSE;
Chia-I Wuc278df82015-07-07 11:50:03 +08003051 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3052 if (pCB) {
3053 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003054 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 +08003055 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
3056 } else {
3057 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003058 skipCall |= addCmd(pCB, CMD_NEXTSUBPASS);
Chia-I Wuc278df82015-07-07 11:50:03 +08003059 pCB->activeSubpass++;
3060 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003061 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08003062 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003063 }
3064 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003065 if (VK_FALSE == skipCall)
3066 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08003067}
3068
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003069VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003070{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003071 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003072 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3073 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003074 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003075 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 +08003076 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06003077 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003078 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003079 skipCall |= addCmd(pCB, CMD_ENDRENDERPASS);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003080 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08003081 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003082 }
3083 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003084 if (VK_FALSE == skipCall)
3085 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003086}
3087
3088VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3089{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003090 VkBool32 skipCall = VK_FALSE;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003091 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3092 if (pCB) {
3093 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003094 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 +08003095 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
3096 } else {
3097 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003098 skipCall |= addCmd(pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003099 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003100 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003101 if (VK_FALSE == skipCall)
3102 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003103}
3104
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003105VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3106 VkInstance instance,
3107 VkFlags msgFlags,
3108 const PFN_vkDbgMsgCallback pfnMsgCallback,
3109 void* pUserData,
3110 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003111{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003112 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003113 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3114 if (VK_SUCCESS == res) {
3115 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3116 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3117 }
3118 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003119}
3120
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003121VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3122 VkInstance instance,
3123 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003124{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003125 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003126 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3127 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3128 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3129 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003130}
3131
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003132VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003133{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003134 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003135 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003136 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3137 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003138 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003139 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 -06003140 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003141 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003142 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003143 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003144 skipCall |= addCmd(pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003145 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003146 if (VK_FALSE == skipCall)
3147 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003148}
3149
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003150VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003151{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003152 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003153 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003154 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3155 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003156 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003157 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 -06003158 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003159 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003160 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003161 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003162 skipCall |= addCmd(pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003163 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003164 if (VK_FALSE == skipCall)
3165 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003166}
3167
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003168//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3169//{
3170// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3171// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3172// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3173// "Attempt to use DbgSetObjectTag but extension disabled!");
3174// return VK_ERROR_UNAVAILABLE;
3175// }
3176// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3177//}
3178//
3179//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3180//{
3181// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3182// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3183// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3184// "Attempt to use DbgSetObjectName but extension disabled!");
3185// return VK_ERROR_UNAVAILABLE;
3186// }
3187// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3188//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003189
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003190VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003191{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003192 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003193 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003194
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003195 /* loader uses this to force layer initialization; device object is wrapped */
3196 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003197 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003198 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003199 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003200 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003201 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003202 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003204 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003206 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003208 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003209 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003210 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003211 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003212 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003213 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003214 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003215 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003216 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003217 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003218 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003219 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003220 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003221 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003222 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003223 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003224 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003226 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003228 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003230 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003232 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003234 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003236 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003238 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003240 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003242 if (!strcmp(funcName, "vkDestroyDynamicLineWidthState"))
3243 return (PFN_vkVoidFunction) vkDestroyDynamicLineWidthState;
3244 if (!strcmp(funcName, "vkDestroyDynamicDepthBiasState"))
3245 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBiasState;
3246 if (!strcmp(funcName, "vkDestroyDynamicBlendState"))
3247 return (PFN_vkVoidFunction) vkDestroyDynamicBlendState;
3248 if (!strcmp(funcName, "vkDestroyDynamicDepthBoundsState"))
3249 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003250 if (!strcmp(funcName, "vkDestroyDynamicStencilState"))
3251 return (PFN_vkVoidFunction) vkDestroyDynamicStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003252 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003253 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003254 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003256 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003258 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003260 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003262 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003264 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003265 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003266 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003267 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003268 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003269 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003270 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003271 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003272 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003273 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003274 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003276 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003278 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003280 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003282 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003284 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003286 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003287 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003288 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003289 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003290 if (!strcmp(funcName, "vkCreateDynamicLineWidthState"))
3291 return (PFN_vkVoidFunction) vkCreateDynamicLineWidthState;
3292 if (!strcmp(funcName, "vkCreateDynamicDepthBiasState"))
3293 return (PFN_vkVoidFunction) vkCreateDynamicDepthBiasState;
3294 if (!strcmp(funcName, "vkCreateDynamicBlendState"))
3295 return (PFN_vkVoidFunction) vkCreateDynamicBlendState;
3296 if (!strcmp(funcName, "vkCreateDynamicDepthBoundsState"))
3297 return (PFN_vkVoidFunction) vkCreateDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003298 if (!strcmp(funcName, "vkCreateDynamicStencilState"))
3299 return (PFN_vkVoidFunction) vkCreateDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003300 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003301 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003302 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003303 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003304 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003305 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003306 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003307 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003308 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003309 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003310 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003311 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003312 if (!strcmp(funcName, "vkCmdBindDynamicLineWidthState"))
3313 return (PFN_vkVoidFunction) vkCmdBindDynamicLineWidthState;
3314 if (!strcmp(funcName, "vkCmdBindDynamicDepthBiasState"))
3315 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBiasState;
3316 if (!strcmp(funcName, "vkCmdBindDynamicBlendState"))
3317 return (PFN_vkVoidFunction) vkCmdBindDynamicBlendState;
3318 if (!strcmp(funcName, "vkCmdBindDynamicDepthBoundsState"))
3319 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003320 if (!strcmp(funcName, "vkCmdBindDynamicStencilState"))
3321 return (PFN_vkVoidFunction) vkCmdBindDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003322 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003323 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003324 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003325 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003326 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003327 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003328 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003329 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003330 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003331 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003332 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003333 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003334 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003335 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003336 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003337 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003338 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003339 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003340 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003341 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003342 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003343 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003344 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003345 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003346 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003347 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003348 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003349 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003350 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003351 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003352 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003353 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003354 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003355 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003356 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003357 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003358 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003359 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003360 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003361 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003362 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003363 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003364 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003365 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003366 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003367 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003368 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003369 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003370 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003371 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003372 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003373 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003374 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003375 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003376 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003377 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003378 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003379 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003380 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003381 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003382 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003383 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003384 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003385 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003386 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003387 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003388
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003389 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3390 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003391 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003392 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003393 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003394 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003395 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003396// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3397// return (void*) vkDbgSetObjectTag;
3398// if (!strcmp(funcName, "vkDbgSetObjectName"))
3399// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003400 }
3401 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003402 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003403 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003404 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003405 }
3406}
3407
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003408VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003409{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003410 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003411 if (instance == NULL)
3412 return NULL;
3413
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003414 /* loader uses this to force layer initialization; instance object is wrapped */
3415 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003416 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003417 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003418 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003419 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003420 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003421 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003422 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06003423 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
3424 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
3425 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
3426 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
3427 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
3428 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
3429 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
3430 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003431
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003432 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3433 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003434 if (fptr)
3435 return fptr;
3436
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003437 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003438 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003439 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003440 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003441 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003442 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003443}