blob: cf101b73e408e72109425bfbd03d8010f60f9b29 [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 }
Tobin Ehlis20693172015-09-17 08:46:18 -0600508 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) {
509 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) {
510 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 Ehlis20693172015-09-17 08:46:18 -0600512 }
513 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
514 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
515 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology used with patchControlPoints value %u."
516 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
517 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600518 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600519 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -0600520}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600521// Init the pipeline mapping info based on pipeline create info LL tree
522// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600523static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600524{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600525 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
526 if (pBasePipeline) {
527 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600528 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600529 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
530 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600531 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600532 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600533 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600534
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600535 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600536 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600537 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600538
539 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
540 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
541
542 switch (pPSSCI->stage) {
543 case VK_SHADER_STAGE_VERTEX:
544 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
545 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600546 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600547 case VK_SHADER_STAGE_TESS_CONTROL:
548 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
549 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600550 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600551 case VK_SHADER_STAGE_TESS_EVALUATION:
552 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
553 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600554 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600555 case VK_SHADER_STAGE_GEOMETRY:
556 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
557 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600558 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600559 case VK_SHADER_STAGE_FRAGMENT:
560 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
561 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600562 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600563 case VK_SHADER_STAGE_COMPUTE:
564 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
565 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600566 break;
567 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600568 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600569 break;
570 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600571 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600572
573 if (pCreateInfo->pVertexInputState != NULL) {
574 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
575 // Copy embedded ptrs
576 pVICI = pCreateInfo->pVertexInputState;
577 pPipeline->vtxBindingCount = pVICI->bindingCount;
578 if (pPipeline->vtxBindingCount) {
579 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
580 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
581 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
582 }
583 pPipeline->vtxAttributeCount = pVICI->attributeCount;
584 if (pPipeline->vtxAttributeCount) {
585 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
586 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
587 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
588 }
589 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
590 }
Tony Barboure307f582015-07-10 15:29:03 -0600591 if (pCreateInfo->pInputAssemblyState != NULL) {
592 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
593 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600594 }
Tony Barboure307f582015-07-10 15:29:03 -0600595 if (pCreateInfo->pTessellationState != NULL) {
596 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
597 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600598 }
Tony Barboure307f582015-07-10 15:29:03 -0600599 if (pCreateInfo->pViewportState != NULL) {
600 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
601 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600602 }
Tony Barboure307f582015-07-10 15:29:03 -0600603 if (pCreateInfo->pRasterState != NULL) {
604 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
605 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600606 }
Tony Barboure307f582015-07-10 15:29:03 -0600607 if (pCreateInfo->pMultisampleState != NULL) {
608 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
609 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600610 }
Tony Barboure307f582015-07-10 15:29:03 -0600611 if (pCreateInfo->pColorBlendState != NULL) {
612 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600613 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600614 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600615 pPipeline->attachmentCount = pCBCI->attachmentCount;
616 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600617 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
618 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600619 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
620 }
Tony Barboure307f582015-07-10 15:29:03 -0600621 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600622 }
Tony Barboure307f582015-07-10 15:29:03 -0600623 if (pCreateInfo->pDepthStencilState != NULL) {
624 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
625 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600626 }
627
628 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
629 if (pCreateInfo->stageCount != 0) {
630 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
631 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
632 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
633 }
634
Tobin Ehlisde63c532015-06-18 15:59:33 -0600635 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600636}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600637
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600638// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600639static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600640{
David Pinedof5997ab2015-04-27 16:36:17 -0600641 if (pipelineMap.size() <= 0)
642 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600643 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600644 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
645 delete[] (*ii).second->graphicsPipelineCI.pStages;
646 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600647 if ((*ii).second->pVertexBindingDescriptions) {
648 delete[] (*ii).second->pVertexBindingDescriptions;
649 }
650 if ((*ii).second->pVertexAttributeDescriptions) {
651 delete[] (*ii).second->pVertexAttributeDescriptions;
652 }
653 if ((*ii).second->pAttachments) {
654 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600655 }
656 delete (*ii).second;
657 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600658 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600659}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600660// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600661static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600662{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600663 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600664 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
665 return pPipe->msStateCI.rasterSamples;
666 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600667 return 1;
668}
669// Validate state related to the PSO
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600670static VkBool32 validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600671{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600672 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600673 // Verify that any MSAA request in PSO matches sample# in bound FB
674 uint32_t psoNumSamples = getNumSamples(pipeline);
675 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600676 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800677 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
678 int subpassNumSamples = 0;
679 uint32_t i;
680
681 for (i = 0; i < pSD->colorCount; i++) {
682 uint32_t samples;
683
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600684 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800685 continue;
686
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600687 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800688 if (subpassNumSamples == 0) {
689 subpassNumSamples = samples;
690 } else if (subpassNumSamples != samples) {
691 subpassNumSamples = -1;
692 break;
693 }
694 }
695 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
696 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
697 if (subpassNumSamples == 0)
698 subpassNumSamples = samples;
699 else if (subpassNumSamples != samples)
700 subpassNumSamples = -1;
701 }
702
703 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600704 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 -0600705 "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 -0600706 }
707 } else {
708 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
709 // Verify and flag error as appropriate
710 }
711 // TODO : Add more checks here
712 } else {
713 // TODO : Validate non-gfx pipeline updates
714 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600715 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600716}
717
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600718// Block of code at start here specifically for managing/tracking DSs
719
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600720// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600721static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600722{
723 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600724 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600725 loader_platform_thread_unlock_mutex(&globalLock);
726 return NULL;
727 }
728 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600729 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600730}
731// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600732static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600733{
734 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600735 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600736 loader_platform_thread_unlock_mutex(&globalLock);
737 return NULL;
738 }
739 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600740 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600741}
742
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600743static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600744 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600745 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600746 loader_platform_thread_unlock_mutex(&globalLock);
747 return NULL;
748 }
749 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600750 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600751}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600752// 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 -0600753static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600754{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600755 switch (pUpdateStruct->sType)
756 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800757 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
758 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600759 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600760 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600761 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 -0600762 "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 -0600763 }
764}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600765// For given update struct, return binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600766static VkBool32 getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* binding)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600767{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600768 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600769 switch (pUpdateStruct->sType)
770 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800771 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600772 *binding = ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
773 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800774 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600775 *binding = ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
776 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600777 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600778 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 -0600779 "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 -0600780 *binding = 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600781 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600782 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600783}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600784// Set arrayIndex for given update struct in the last parameter
785// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
786static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* arrayIndex)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600787{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600788 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600789 switch (pUpdateStruct->sType)
790 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800791 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600792 *arrayIndex = ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
793 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800794 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600795 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600796 *arrayIndex = ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
797 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600798 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600799 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 -0600800 "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 -0600801 *arrayIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600802 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600803 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600804}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600805// Set count for given update struct in the last parameter
806// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
807static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* count)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600808{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600809 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600810 switch (pUpdateStruct->sType)
811 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800812 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600813 *count = ((VkWriteDescriptorSet*)pUpdateStruct)->count;
814 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800815 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600816 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600817 *count = ((VkCopyDescriptorSet*)pUpdateStruct)->count;
818 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600819 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600820 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 -0600821 "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 -0600822 *count = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600823 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600824 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600825}
826// For given Layout Node and binding, return index where that binding begins
827static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
828{
829 uint32_t offsetIndex = 0;
830 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800831 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600832 }
833 return offsetIndex;
834}
835// For given layout node and binding, return last index that is updated
836static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
837{
838 uint32_t offsetIndex = 0;
839 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800840 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600841 }
842 return offsetIndex-1;
843}
844// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600845static VkBool32 getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* startIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600846{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600847 uint32_t binding = 0, arrayIndex = 0;
848 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
849 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
850 if (VK_FALSE == skipCall)
851 *startIndex = getBindingStartIndex(pLayout, binding)+arrayIndex;
852 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600853}
854// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600855static VkBool32 getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* endIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600856{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600857 uint32_t binding = 0, arrayIndex = 0, count = 0;
858 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
859 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
860 skipCall |= getUpdateCount(device, pUpdateStruct, &count);
861 if (VK_FALSE == skipCall)
862 *endIndex = getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
863 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600864}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600865// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600866static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600867{
868 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600869 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600870 VkDescriptorType actualType;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600871 uint32_t i = 0, startIndex = 0, endIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600872 switch (pUpdateStruct->sType)
873 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800874 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
875 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600876 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800877 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
878 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600879 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880 break;
881 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600882 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 -0600883 "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 -0600884 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600885 skipCall |= getUpdateStartIndex(device, pLayout, pUpdateStruct, &startIndex);
886 skipCall |= getUpdateEndIndex(device, pLayout, pUpdateStruct, &endIndex);
887 if (VK_FALSE == skipCall) {
888 for (i = startIndex; i <= endIndex; i++) {
889 if (pLayout->pTypes[i] != actualType)
890 return VK_TRUE;
891 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600892 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600893 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600894}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600895// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600896// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600897// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600898static VkBool32 shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600899{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600900 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800901 VkWriteDescriptorSet* pWDS = NULL;
902 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600903 size_t array_size = 0;
904 size_t base_array_size = 0;
905 size_t total_array_size = 0;
906 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600907 switch (pUpdate->sType)
908 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800909 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
910 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600911 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800912 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
913 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
914 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
915 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600916 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800917 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
918 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600919 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800920 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600921 break;
922 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600923 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
924 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
925 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600926 }
927 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600928 (*pNewNode)->pNext = NULL;
929 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600930}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800931// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600932static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600933{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800934 const VkWriteDescriptorSet *pWDS = NULL;
935 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600936 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800937
938 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
939 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
940 else
941 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
942
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600943 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600944 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600945 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600946 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600947 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600948 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800949 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600950 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800951 g_lastBoundDescriptorSet = pSet->set;
952 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600953 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600954 // First verify valid update struct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600955 if ((skipCall = validUpdateStruct(device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600956 break;
957 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600958 // Make sure that binding is within bounds
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600959 uint32_t binding = 0, endIndex = 0;
960 skipCall |= getUpdateBinding(device, pUpdate, &binding);
961 if (pLayout->createInfo.count < binding) {
962 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
963 "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 -0600964 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600965 // Next verify that update falls within size of given binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600966 skipCall |= getUpdateBinding(device, pUpdate, &binding);
967 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
968 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tony Barbour29b12062015-07-13 13:37:24 -0600969 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600970 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600971 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600972 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",
973 "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 -0600974 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600975 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600976 if ((skipCall = validateUpdateType(device, pLayout, pUpdate)) == VK_TRUE) {
977 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 -0600978 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600979 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600980 // Save the update info
981 // TODO : Info message that update successful
982 // Create new update struct for this set's shadow copy
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600983 GENERIC_HEADER* pNewNode = NULL;
984 skipCall |= shadowUpdateNode(device, pUpdate, &pNewNode);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600985 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600986 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 -0600987 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlise42007c2015-06-19 13:00:59 -0600988 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600989 // Insert shadow node into LL of updates for this set
990 pNewNode->pNext = pSet->pUpdateStructs;
991 pSet->pUpdateStructs = pNewNode;
992 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600993 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
994 uint32_t startIndex;
995 skipCall |= getUpdateStartIndex(device, pLayout, pUpdate, &startIndex);
996 for (uint32_t j = startIndex; j <= endIndex; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600997 assert(j<pSet->descriptorCount);
998 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600999 }
1000 }
1001 }
1002 }
1003 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001004 }
1005 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001006 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001007}
1008// Free the shadowed update node for this Set
1009// NOTE : Calls to this function should be wrapped in mutex
1010static void freeShadowUpdateTree(SET_NODE* pSet)
1011{
1012 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
1013 pSet->pUpdateStructs = NULL;
1014 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
1015 // Clear the descriptor mappings as they will now be invalid
1016 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
1017 while(pShadowUpdate) {
1018 pFreeUpdate = pShadowUpdate;
1019 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
1020 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001021 VkWriteDescriptorSet * pWDS = NULL;
1022 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023 void** ppToFree = NULL;
1024 switch (pFreeUpdate->sType)
1025 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001026 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
1027 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
1028 if (pWDS->pDescriptors)
1029 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001030 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001031 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001032 break;
1033 default:
1034 assert(0);
1035 break;
1036 }
Tobin Ehliseaf28662015-04-08 10:58:37 -06001037 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001038 }
1039}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001040// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001041// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001042static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001043{
David Pinedof5997ab2015-04-27 16:36:17 -06001044 if (poolMap.size() <= 0)
1045 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001046 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001047 SET_NODE* pSet = (*ii).second->pSets;
1048 SET_NODE* pFreeSet = pSet;
1049 while (pSet) {
1050 pFreeSet = pSet;
1051 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001052 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001053 // Free Update shadow struct tree
1054 freeShadowUpdateTree(pFreeSet);
1055 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001056 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001057 }
1058 delete pFreeSet;
1059 }
1060 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001061 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001062 }
1063 delete (*ii).second;
1064 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001065 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001066}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001067// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001068// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001069static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001070{
David Pinedof5997ab2015-04-27 16:36:17 -06001071 if (layoutMap.size() <= 0)
1072 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001073 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001074 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001075 if (pLayout->createInfo.pBinding) {
1076 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1077 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1078 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1079 }
1080 delete[] pLayout->createInfo.pBinding;
1081 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001082 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001083 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001084 }
1085 delete pLayout;
1086 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001087 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001088}
1089// Currently clearing a set is removing all previous updates to that set
1090// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001091static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001092{
1093 SET_NODE* pSet = getSetNode(set);
1094 if (!pSet) {
1095 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001096 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001097 loader_platform_thread_lock_mutex(&globalLock);
1098 freeShadowUpdateTree(pSet);
1099 loader_platform_thread_unlock_mutex(&globalLock);
1100 }
1101}
1102
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001103static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001104{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001105 POOL_NODE* pPool = getPoolNode(pool);
1106 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001107 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1108 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001109 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001110 // For every set off of this pool, clear it
1111 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001112 while (pSet) {
1113 clearDescriptorSet(pSet->set);
1114 }
1115 }
1116}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001117// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001119{
1120 loader_platform_thread_lock_mutex(&globalLock);
1121 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1122 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001123 // TODO : How to pass cb as srcObj here?
1124 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 -06001125 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001126 return NULL;
1127 }
1128 loader_platform_thread_unlock_mutex(&globalLock);
1129 return cmdBufferMap[cb];
1130}
1131// Free all CB Nodes
1132// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001133static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001134{
David Pinedof5997ab2015-04-27 16:36:17 -06001135 if (cmdBufferMap.size() <= 0)
1136 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001137 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001138 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1139 while (!cmd_node_list.empty()) {
1140 CMD_NODE* cmd_node = cmd_node_list.back();
1141 delete cmd_node;
1142 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001143 }
1144 delete (*ii).second;
1145 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001146 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001147}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001148static VkBool32 report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
Tobin Ehlise42007c2015-06-19 13:00:59 -06001149{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001150 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001151 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 -06001152 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1153}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001154static VkBool32 addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001155{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001156 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001157 CMD_NODE* pCmd = new CMD_NODE;
1158 if (pCmd) {
1159 // init cmd node and append to end of cmd LL
1160 memset(pCmd, 0, sizeof(CMD_NODE));
1161 pCmd->cmdNumber = ++pCB->numCmds;
1162 pCmd->type = cmd;
1163 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001164 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001165 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001166 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 -06001167 "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 -06001168 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001169 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001170}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001171static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001172{
1173 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1174 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001175 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1176 while (!cmd_list.empty()) {
1177 delete cmd_list.back();
1178 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001179 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001180 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001181 // Reset CB state (need to save createInfo)
1182 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001183 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1184 pCB->cmdBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001185 pCB->createInfo = saveCBCI;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001186 pCB->lastVtxBinding = MAX_BINDING;
1187 }
1188}
Tobin Ehlis97866202015-06-10 12:57:07 -06001189// Set PSO-related status bits for CB
1190static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1191{
1192 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1193 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1194 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1195 }
1196 }
1197 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06001198 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1199 }
1200
1201 if (pPipe->dsStateCI.stencilTestEnable) {
1202 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001203 }
1204}
1205// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001206static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001207 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1208 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
Cody Northrope4bc6942015-08-26 10:01:32 -06001209 } else if (stateBindPoint == VK_STATE_BIND_POINT_LINE_WIDTH) {
1210 pNode->status |= CBSTATUS_LINE_WIDTH_BOUND;
1211 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BIAS) {
1212 pNode->status |= CBSTATUS_DEPTH_BIAS_BOUND;
1213 } else if (stateBindPoint == VK_STATE_BIND_POINT_BLEND) {
1214 pNode->status |= CBSTATUS_BLEND_BOUND;
1215 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BOUNDS) {
1216 pNode->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
Cody Northrop2605cb02015-08-18 15:21:16 -06001217 } else if (stateBindPoint == VK_STATE_BIND_POINT_STENCIL) {
1218 pNode->status |= CBSTATUS_STENCIL_BOUND;
Tobin Ehlis97866202015-06-10 12:57:07 -06001219 }
1220}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001221// Print the last bound Gfx Pipeline
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001222static VkBool32 printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001223{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001224 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001225 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1226 if (pCB) {
1227 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1228 if (!pPipeTrav) {
1229 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001230 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001231 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001232 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001233 }
1234 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001235 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001236}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001237// Print details of DS config to stdout
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001238static VkBool32 printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001239{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001240 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001241 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.
1242 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001243 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001244 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001245 POOL_NODE* pPool = getPoolNode(pSet->pool);
1246 // Print out pool details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001247 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001248 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001249 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001250 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001251 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001252 // Print out set details
1253 char prefix[10];
1254 uint32_t index = 0;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001255 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001256 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001257 LAYOUT_NODE* pLayout = pSet->pLayout;
1258 // Print layout details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001259 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001260 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001261 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001262 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001263 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001264 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001265 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001266 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1267 if (pUpdate) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001268 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001269 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001270 sprintf(prefix, " [UC] ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001271 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001272 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001273 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001274 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001275 if (0 != pSet->descriptorCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001276 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001277 "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 -06001278 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001279 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001280 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001281 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001282 }
1283 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001284 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001285}
1286
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001287static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001288{
1289 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001290 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001291 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001292 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001293 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001294 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1295 // TODO : Need to pass cb as srcObj here
1296 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 -06001297 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001298 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001299 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001300 // Nothing to print
1301 }
1302}
1303
1304
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001305static VkBool32 synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001306{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001307 VkBool32 skipCall = VK_FALSE;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001308 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001309 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001310 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001311 skipCall |= printDSConfig(cb);
1312 skipCall |= printPipeline(cb);
1313 skipCall |= printDynamicState(cb);
1314 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001315}
1316
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001317static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001318{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001319 uint32_t report_flags = 0;
1320 uint32_t debug_action = 0;
1321 FILE *log_output = NULL;
1322 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001323 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001324 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1325 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001326
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001327 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001328 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001329 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06001330 log_output = getLayerLogOutput(option_str, "DrawState");
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001331 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 -06001332 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001333
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001334 if (!globalLockInitialized)
1335 {
1336 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001337 // suggestion is to call this during vkCreateInstance(), and then we
1338 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001339 // that the layer have per-instance locks. We need to come back and
1340 // address this soon.
1341 loader_platform_thread_create_mutex(&globalLock);
1342 globalLockInitialized = 1;
1343 }
1344}
1345
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001346VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1347{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001348 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001349 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1350
1351 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001352 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1353 my_data->report_data = debug_report_create_instance(
1354 pTable,
1355 *pInstance,
1356 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001357 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001358
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001359 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001360 }
1361 return result;
1362}
1363
Jon Ashburne0fa2282015-05-20 09:00:28 -06001364/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001365VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Jon Ashburne0fa2282015-05-20 09:00:28 -06001366{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001367 dispatch_key key = get_dispatch_key(instance);
1368 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001369 pTable->DestroyInstance(instance);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001370
1371 // Clean up logging callback, if any
1372 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1373 if (my_data->logging_callback) {
1374 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1375 }
1376
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001377 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001378 layer_data_map.erase(pTable);
1379
1380 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001381}
1382
Jon Ashburnf0615e22015-05-25 14:11:37 -06001383static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1384{
Tony Barbour29b12062015-07-13 13:37:24 -06001385 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001386 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001387 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001388
1389 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001390 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001391 /* Found a matching extension name, mark it enabled and init dispatch table*/
1392 initDebugMarkerTable(device);
1393 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001394 }
1395
1396 }
1397}
1398
Tony Barbour8205d902015-04-16 15:59:00 -06001399VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001400{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001401 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1402 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001403 if (result == VK_SUCCESS) {
1404 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1405 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1406 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1407 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001408 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001409 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001410 return result;
1411}
1412
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001413VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001414{
1415 // Free all the memory
1416 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001417 deletePipelines();
1418 deleteSamplers();
1419 deleteImages();
1420 deleteBuffers();
1421 deleteCmdBuffers();
1422 deleteDynamicState();
1423 deletePools();
1424 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001425 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001426
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001427 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001428 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001429 pDisp->DestroyDevice(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001430 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001431 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001432 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001433}
1434
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001435static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001436 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001437 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001438 VK_API_VERSION,
1439 VK_MAKE_VERSION(0, 1, 0),
1440 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001441 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001442};
1443
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001444VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001445 const char *pLayerName,
1446 uint32_t *pCount,
1447 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001448{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001449 /* DrawState does not have any global extensions */
1450 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1451}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001452
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001453VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001454 uint32_t *pCount,
1455 VkLayerProperties* pProperties)
1456{
1457 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1458 ds_global_layers,
1459 pCount, pProperties);
1460}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001461
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001462static const VkExtensionProperties ds_device_extensions[] = {
1463 {
1464 DEBUG_MARKER_EXTENSION_NAME,
1465 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001466 }
1467};
1468
1469static const VkLayerProperties ds_device_layers[] = {
1470 {
1471 "DrawState",
1472 VK_API_VERSION,
1473 VK_MAKE_VERSION(0, 1, 0),
1474 "Validation layer: DrawState",
1475 }
1476};
1477
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001478VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001479 VkPhysicalDevice physicalDevice,
1480 const char* pLayerName,
1481 uint32_t* pCount,
1482 VkExtensionProperties* pProperties)
1483{
1484 /* Mem tracker does not have any physical device extensions */
1485 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1486 pCount, pProperties);
1487}
1488
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001489VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001490 VkPhysicalDevice physicalDevice,
1491 uint32_t* pCount,
1492 VkLayerProperties* pProperties)
1493{
1494 /* Mem tracker's physical device layers are the same as global */
1495 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1496 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001497}
1498
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001499VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001500{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001501 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001502 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001503 for (uint32_t i=0; i < cmdBufferCount; i++) {
1504 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001505 pCB = getCBNode(pCmdBuffers[i]);
1506 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001507 pCB->submitCount++; // increment submit count
1508 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
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_CMD_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001510 "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 -06001511 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001512 if (CB_UPDATE_COMPLETE != pCB->state) {
1513 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001514 // TODO : How to pass cb as srcObj?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001515 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 -06001516 "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 -06001517 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001518 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001519 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001520 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001521 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001522 if (VK_FALSE == skipCall)
1523 return get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
1524 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001525}
1526
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001527VK_LAYER_EXPORT void VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001528{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001529 get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
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 vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
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)->DestroySemaphore(device, semaphore);
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 vkDestroyEvent(VkDevice device, VkEvent event)
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)->DestroyEvent(device, event);
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 vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
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)->DestroyQueryPool(device, queryPool);
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 vkDestroyBuffer(VkDevice device, VkBuffer buffer)
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)->DestroyBuffer(device, buffer);
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 vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
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)->DestroyBufferView(device, bufferView);
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 vkDestroyImage(VkDevice device, VkImage image)
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)->DestroyImage(device, image);
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 vkDestroyImageView(VkDevice device, VkImageView imageView)
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)->DestroyImageView(device, imageView);
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 vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
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)->DestroyShaderModule(device, shaderModule);
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 vkDestroyShader(VkDevice device, VkShader shader)
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)->DestroyShader(device, shader);
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 vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
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)->DestroyPipeline(device, pipeline);
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 vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
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)->DestroyPipelineLayout(device, pipelineLayout);
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 vkDestroySampler(VkDevice device, VkSampler sampler)
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)->DestroySampler(device, sampler);
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 vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
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)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
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 vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
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)->DestroyDescriptorPool(device, descriptorPool);
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 vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
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)->DestroyDynamicViewportState(device, dynamicViewportState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001620 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001621}
1622
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001623VK_LAYER_EXPORT void VKAPI vkDestroyDynamicLineWidthState(VkDevice device, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001624{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001625 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicLineWidthState(device, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06001626 // TODO : Clean up any internal data structures using this obj.
Cody Northropf5bd2252015-08-17 11:10:49 -06001627}
1628
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001629VK_LAYER_EXPORT void VKAPI vkDestroyDynamicDepthBiasState(VkDevice device, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001630{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001631 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBiasState(device, dynamicDepthBiasState);
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 vkDestroyDynamicBlendState(VkDevice device, VkDynamicBlendState dynamicBlendState)
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)->DestroyDynamicBlendState(device, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001638 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001639}
1640
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001641VK_LAYER_EXPORT void VKAPI vkDestroyDynamicDepthBoundsState(VkDevice device, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001642{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001643 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBoundsState(device, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06001644 // TODO : Clean up any internal data structures using this obj.
Cody Northrop2605cb02015-08-18 15:21:16 -06001645}
1646
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001647VK_LAYER_EXPORT void VKAPI vkDestroyDynamicStencilState(VkDevice device, VkDynamicStencilState dynamicStencilState)
Cody Northrop2605cb02015-08-18 15:21:16 -06001648{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001649 get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicStencilState(device, dynamicStencilState);
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 vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
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)->DestroyCommandBuffer(device, commandBuffer);
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 vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
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)->DestroyFramebuffer(device, framebuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001662 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001663}
1664
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001665VK_LAYER_EXPORT void VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001666{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001667 get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001668 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001669}
1670
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001671VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001672{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001673 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001674 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001675 loader_platform_thread_lock_mutex(&globalLock);
1676 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1677 pNewNode->buffer = *pView;
1678 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001679 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001680 loader_platform_thread_unlock_mutex(&globalLock);
1681 }
1682 return result;
1683}
1684
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001685VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001686{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001687 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001688 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001689 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001690 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001691 loader_platform_thread_unlock_mutex(&globalLock);
1692 }
1693 return result;
1694}
1695
Jon Ashburn0d60d272015-07-09 15:02:25 -06001696//TODO handle pipeline caches
1697VkResult VKAPI vkCreatePipelineCache(
1698 VkDevice device,
1699 const VkPipelineCacheCreateInfo* pCreateInfo,
1700 VkPipelineCache* pPipelineCache)
1701{
1702 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1703 return result;
1704}
1705
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001706void VKAPI vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06001707 VkDevice device,
1708 VkPipelineCache pipelineCache)
1709{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001710 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001711}
1712
1713size_t VKAPI vkGetPipelineCacheSize(
1714 VkDevice device,
1715 VkPipelineCache pipelineCache)
1716{
1717 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1718 return size;
1719}
1720
1721VkResult VKAPI vkGetPipelineCacheData(
1722 VkDevice device,
1723 VkPipelineCache pipelineCache,
1724 void* pData)
1725{
1726 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1727 return result;
1728}
1729
1730VkResult VKAPI vkMergePipelineCaches(
1731 VkDevice device,
1732 VkPipelineCache destCache,
1733 uint32_t srcCacheCount,
1734 const VkPipelineCache* pSrcCaches)
1735{
1736 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1737 return result;
1738}
1739
1740VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001741{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001742 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06001743 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06001744 // The order of operations here is a little convoluted but gets the job done
1745 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1746 // 2. Create state is then validated (which uses flags setup during shadowing)
1747 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06001748 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06001749 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
1750 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise48be202015-09-16 10:33:53 -06001751 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001752 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001753 for (i=0; i<count; i++) {
1754 pPipeNode[i] = initPipeline(&pCreateInfos[i], NULL);
1755 skipCall |= verifyPipelineCreateState(device, pPipeNode[i]);
1756 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001757 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001758 if (VK_FALSE == skipCall) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001759 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001760 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001761 for (i=0; i<count; i++) {
1762 pPipeNode[i]->pipeline = pPipelines[i];
1763 pipelineMap[pPipeNode[i]->pipeline.handle] = pPipeNode[i];
1764 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001765 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001766 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06001767 for (i=0; i<count; i++) {
1768 if (pPipeNode[i]) {
1769 // If we allocated a pipeNode, need to clean it up here
1770 delete[] pPipeNode[i]->pVertexBindingDescriptions;
1771 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
1772 delete[] pPipeNode[i]->pAttachments;
1773 delete pPipeNode[i];
1774 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001775 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001776 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001777 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001778 return result;
1779}
1780
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001781VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001782{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001783 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001784 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785 loader_platform_thread_lock_mutex(&globalLock);
1786 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1787 pNewNode->sampler = *pSampler;
1788 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001789 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001790 loader_platform_thread_unlock_mutex(&globalLock);
1791 }
1792 return result;
1793}
1794
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001795VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001796{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001797 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001798 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1800 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001801 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1802 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
1803 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804 }
1805 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001806 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1807 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1808 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001809 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001810 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001811 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001812 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001813 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001814 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1815 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001816 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001817 }
1818 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001819 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001821 uint32_t j = 0;
1822 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001823 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001824 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001826 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001827 }
1828 }
1829 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001830 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001831 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1832 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001833 // Put new node at Head of global Layer list
1834 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001835 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001836 loader_platform_thread_unlock_mutex(&globalLock);
1837 }
1838 return result;
1839}
1840
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001841VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001842{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001843 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001844 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001845 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001846 }
1847 return result;
1848}
1849
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001850VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001851{
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001852 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001853 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001854 // Insert this pool into Global Pool LL at head
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001855 if (log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1856 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle))
1857 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001858 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001859 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001860 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001861 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1862 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()"))
1863 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001864 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001865 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001866 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1867 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001869 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1870 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1872 }
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001873 pNewNode->poolUsage = pCreateInfo->poolUsage;
1874 pNewNode->maxSets = pCreateInfo->maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001875 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001876 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001877 }
1878 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001879 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001880 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881 }
1882 return result;
1883}
1884
Mike Stroyan230e6252015-04-17 12:36:38 -06001885VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001886{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001887 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001888 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001889 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001890 }
1891 return result;
1892}
1893
Cody Northropc8aa4a52015-08-03 12:47:29 -06001894VK_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 -06001895{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001896 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1897 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001898 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1899 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001900 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1901 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001902 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001903 if (count == 0) {
1904 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1905 "AllocDescriptorSets called with 0 count");
1906 }
1907 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001908 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1909 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001910 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001911 SET_NODE* pNewNode = new SET_NODE;
1912 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001913 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1914 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()"))
1915 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001916 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001917 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001918 // Insert set at head of Set LL for this pool
1919 pNewNode->pNext = pPoolNode->pSets;
1920 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001921 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1922 if (NULL == pLayout) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001923 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1924 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle))
1925 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001926 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001927 pNewNode->pLayout = pLayout;
1928 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001929 pNewNode->set = pDescriptorSets[i];
1930 pNewNode->setUsage = setUsage;
1931 pNewNode->descriptorCount = pLayout->endIndex + 1;
1932 if (pNewNode->descriptorCount) {
1933 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1934 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1935 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1936 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001937 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001938 }
1939 }
1940 }
1941 }
1942 return result;
1943}
1944
Tony Barbourb857d312015-07-10 10:50:45 -06001945VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1946{
1947 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1948 // TODO : Clean up any internal data structures using this obj.
1949 return result;
1950}
1951
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001952VK_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 -06001953{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001954 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when both updates return VK_FALSE
1955 if (!dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1956 !dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001957 get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001958 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001959}
1960
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001961VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001962{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001963 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001964 VkDynamicViewportStateCreateInfo local_ci;
1965 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1966 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1967 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1968 loader_platform_thread_lock_mutex(&globalLock);
1969 dynamicVpStateMap[pState->handle] = local_ci;
1970 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001971 return result;
1972}
1973
Cody Northrope4bc6942015-08-26 10:01:32 -06001974VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicLineWidthState(VkDevice device, const VkDynamicLineWidthStateCreateInfo* pCreateInfo, VkDynamicLineWidthState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975{
Cody Northrope4bc6942015-08-26 10:01:32 -06001976 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicLineWidthState(device, pCreateInfo, pState);
1977 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_LINE_WIDTH);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001978 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001979 dynamicLineWidthStateMap[pState->handle] = *pCreateInfo;
Cody Northropf5bd2252015-08-17 11:10:49 -06001980 loader_platform_thread_unlock_mutex(&globalLock);
1981 return result;
1982}
1983
Cody Northrope4bc6942015-08-26 10:01:32 -06001984VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBiasState(VkDevice device, const VkDynamicDepthBiasStateCreateInfo* pCreateInfo, VkDynamicDepthBiasState* pState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001985{
Cody Northrope4bc6942015-08-26 10:01:32 -06001986 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBiasState(device, pCreateInfo, pState);
1987 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BIAS);
Cody Northropf5bd2252015-08-17 11:10:49 -06001988 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001989 dynamicDepthBiasStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001990 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001991 return result;
1992}
1993
Cody Northrope4bc6942015-08-26 10:01:32 -06001994VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicBlendState(VkDevice device, const VkDynamicBlendStateCreateInfo* pCreateInfo, VkDynamicBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001995{
Cody Northrope4bc6942015-08-26 10:01:32 -06001996 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicBlendState(device, pCreateInfo, pState);
1997 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_BLEND);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001998 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001999 dynamicBlendStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002000 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002001 return result;
2002}
2003
Cody Northrope4bc6942015-08-26 10:01:32 -06002004VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBoundsState(VkDevice device, const VkDynamicDepthBoundsStateCreateInfo* pCreateInfo, VkDynamicDepthBoundsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002005{
Cody Northrope4bc6942015-08-26 10:01:32 -06002006 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBoundsState(device, pCreateInfo, pState);
2007 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BOUNDS);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002008 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002009 dynamicDepthBoundsStateMap[pState->handle] = *pCreateInfo;
Cody Northrop2605cb02015-08-18 15:21:16 -06002010 loader_platform_thread_unlock_mutex(&globalLock);
2011 return result;
2012}
2013
2014VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicStencilState(VkDevice device, const VkDynamicStencilStateCreateInfo* pCreateInfoFront, const VkDynamicStencilStateCreateInfo* pCreateInfoBack, VkDynamicStencilState* pState)
2015{
2016 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicStencilState(device, pCreateInfoFront, pCreateInfoBack, pState);
2017 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_STENCIL);
2018 loader_platform_thread_lock_mutex(&globalLock);
2019
2020 // Bug 14406 - If back is NULL or equal to front, then single sided.
2021 // To support NULL case, simply track front twice
2022 const VkDynamicStencilStateCreateInfo* pLocalCreateInfoBack = (pCreateInfoBack == NULL) ? pCreateInfoFront : pCreateInfoBack;
2023
2024 std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo> infos(*pCreateInfoFront, *pLocalCreateInfoBack);
2025 dynamicStencilStateMap[pState->handle] = infos;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002026 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002027 return result;
2028}
2029
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002030VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002031{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002032 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002033 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002034 loader_platform_thread_lock_mutex(&globalLock);
2035 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2036 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2037 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002038 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002039 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002040 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002041 cmdBufferMap[*pCmdBuffer] = pCB;
2042 loader_platform_thread_unlock_mutex(&globalLock);
2043 updateCBTracking(*pCmdBuffer);
2044 }
2045 return result;
2046}
2047
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002048VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002049{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002050 VkBool32 skipCall = false;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002051 // Validate command buffer level
2052 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2053 if (pCB) {
2054 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
2055 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2056 // These should be NULL for a Primary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002057 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 -06002058 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2059 }
2060 } else {
2061 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2062 // These should NOT be null for an Secondary CB
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_BEGIN_CB_INVALID_STATE, "DS",
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002064 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2065 }
2066 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002067 pCB->beginInfo = *pBeginInfo;
2068 } else {
2069 // TODO : Need to pass cmdBuffer as objType here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002070 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 -06002071 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002072 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002073 if (skipCall) {
2074 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06002075 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002076 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002077 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002078 if (CB_NEW != pCB->state)
2079 resetCB(cmdBuffer);
2080 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002081 updateCBTracking(cmdBuffer);
2082 }
2083 return result;
2084}
2085
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002086VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002087{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002088 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06002089 VkResult result = VK_SUCCESS;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002090 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06002091 /* TODO: preference is to always call API function after reporting any validation errors */
Tobin Ehlise42007c2015-06-19 13:00:59 -06002092 if (pCB) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002093 if (pCB->state != CB_UPDATE_ACTIVE) {
2094 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002095 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002096 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002097 if (VK_FALSE == skipCall) {
2098 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2099 if (VK_SUCCESS == result) {
2100 updateCBTracking(cmdBuffer);
2101 pCB->state = CB_UPDATE_COMPLETE;
2102 // Reset CB status flags
2103 pCB->status = 0;
2104 printCB(cmdBuffer);
2105 }
2106 } else {
2107 result = VK_ERROR_VALIDATION_FAILED;
2108 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002109 return result;
2110}
2111
Cody Northropf02f9f82015-07-09 18:08:05 -06002112VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002113{
Cody Northropf02f9f82015-07-09 18:08:05 -06002114 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002115 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002116 resetCB(cmdBuffer);
2117 updateCBTracking(cmdBuffer);
2118 }
2119 return result;
2120}
2121
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002122VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002123{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002124 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002125 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2126 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002127 if (pCB->state == CB_UPDATE_ACTIVE) {
2128 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002129 skipCall |= addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002130 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002131 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 -06002132 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002133 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002134 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 -06002135 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002136 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002137 PIPELINE_NODE* pPN = getPipeline(pipeline);
2138 if (pPN) {
2139 pCB->lastBoundPipeline = pipeline;
2140 loader_platform_thread_lock_mutex(&globalLock);
2141 set_cb_pso_status(pCB, pPN);
2142 g_lastBoundPipeline = pPN;
2143 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002144 skipCall |= validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002145 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002146 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 -06002147 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002148 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002149 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002150 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002151 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002152 }
2153 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002154 if (VK_FALSE == skipCall)
2155 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002156}
2157
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002158VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002159{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002160 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002161 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2162 if (pCB) {
2163 if (pCB->state == CB_UPDATE_ACTIVE) {
2164 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002165 skipCall |= addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002166 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002167 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 -06002168 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002169 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002170 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002171 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2172 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002173 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 -06002174 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002175 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002176 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2177 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002178 }
2179 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002180 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002181 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002182 }
2183 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002184 if (VK_FALSE == skipCall)
2185 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002186}
Cody Northrope4bc6942015-08-26 10:01:32 -06002187VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(VkCmdBuffer cmdBuffer, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002188{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002189 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002190 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2191 if (pCB) {
2192 if (pCB->state == CB_UPDATE_ACTIVE) {
2193 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002194 skipCall |= addCmd(pCB, CMD_BINDDYNAMICLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002195 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002196 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 -06002197 "Incorrect call to vkCmdBindDynamicLineWidthState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002198 }
2199 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002200 pCB->status |= CBSTATUS_LINE_WIDTH_BOUND;
2201 if (dynamicLineWidthStateMap.find(dynamicLineWidthState.handle) == dynamicLineWidthStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002202 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 -06002203 "Unable to find VkDynamicLineWidthState object %#" PRIxLEAST64 ", was it ever created?", dynamicLineWidthState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002204 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002205 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
2206 g_lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002207 }
2208 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002209 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002210 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002211 }
2212 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002213 if (VK_FALSE == skipCall)
2214 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicLineWidthState(cmdBuffer, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06002215}
Cody Northrope4bc6942015-08-26 10:01:32 -06002216VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(VkCmdBuffer cmdBuffer, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06002217{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002218 VkBool32 skipCall = VK_FALSE;
Cody Northropf5bd2252015-08-17 11:10:49 -06002219 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2220 if (pCB) {
2221 if (pCB->state == CB_UPDATE_ACTIVE) {
2222 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002223 skipCall |= addCmd(pCB, CMD_BINDDYNAMICDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002224 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002225 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 -06002226 "Incorrect call to vkCmdBindDynamicDepthBiasState() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002227 }
2228 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002229 pCB->status |= CBSTATUS_DEPTH_BIAS_BOUND;
2230 if (dynamicDepthBiasStateMap.find(dynamicDepthBiasState.handle) == dynamicDepthBiasStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002231 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 -06002232 "Unable to find VkDynamicDepthBiasState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBiasState.handle);
Cody Northropf5bd2252015-08-17 11:10:49 -06002233 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002234 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
2235 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
Cody Northropf5bd2252015-08-17 11:10:49 -06002236 }
2237 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northropf5bd2252015-08-17 11:10:49 -06002238 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002239 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBiasState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002240 }
2241 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002242 if (VK_FALSE == skipCall)
2243 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBiasState(cmdBuffer, dynamicDepthBiasState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002244}
Cody Northrope4bc6942015-08-26 10:01:32 -06002245VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicBlendState(VkCmdBuffer cmdBuffer, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002246{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002247 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002248 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2249 if (pCB) {
2250 if (pCB->state == CB_UPDATE_ACTIVE) {
2251 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002252 skipCall |= addCmd(pCB, CMD_BINDDYNAMICBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002253 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002254 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 -06002255 "Incorrect call to vkCmdBindDynamicBlendState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002256 }
2257 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002258 pCB->status |= CBSTATUS_BLEND_BOUND;
2259 if (dynamicBlendStateMap.find(dynamicBlendState.handle) == dynamicBlendStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002260 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 -06002261 "Unable to find VkDynamicBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicBlendState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002262 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002263 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
2264 g_lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002265 }
2266 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002267 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002268 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicBlendState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002269 }
2270 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002271 if (VK_FALSE == skipCall)
2272 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicBlendState(cmdBuffer, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002273}
Cody Northrope4bc6942015-08-26 10:01:32 -06002274VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(VkCmdBuffer cmdBuffer, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002275{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002276 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002277 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2278 if (pCB) {
2279 if (pCB->state == CB_UPDATE_ACTIVE) {
2280 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002281 skipCall |= addCmd(pCB, CMD_BINDDYNAMICDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002282 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002283 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 -06002284 "Incorrect call to vkCmdBindDynamicDepthBoundsState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002285 }
2286 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002287 pCB->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
2288 if (dynamicDepthBoundsStateMap.find(dynamicDepthBoundsState.handle) == dynamicDepthBoundsStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002289 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 -06002290 "Unable to find VkDynamicDepthBoundsState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBoundsState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002291 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002292 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
2293 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002294 }
2295 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002296 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002297 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBoundsState()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002298 }
2299 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002300 if (VK_FALSE == skipCall)
2301 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBoundsState(cmdBuffer, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06002302}
2303VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStencilState(VkCmdBuffer cmdBuffer, VkDynamicStencilState dynamicStencilState)
2304{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002305 VkBool32 skipCall = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -06002306 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2307 if (pCB) {
2308 if (pCB->state == CB_UPDATE_ACTIVE) {
2309 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002310 skipCall |= addCmd(pCB, CMD_BINDDYNAMICSTENCILSTATE);
Cody Northrop2605cb02015-08-18 15:21:16 -06002311 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002312 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 -06002313 "Incorrect call to vkCmdBindDynamicStencilState() without an active RenderPass.");
2314 }
2315 loader_platform_thread_lock_mutex(&globalLock);
2316 pCB->status |= CBSTATUS_STENCIL_BOUND;
2317 if (dynamicStencilStateMap.find(dynamicStencilState.handle) == dynamicStencilStateMap.end()) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002318 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 -06002319 "Unable to find VkDynamicStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicStencilState.handle);
2320 } else {
2321 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2322 g_lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2323 }
2324 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop2605cb02015-08-18 15:21:16 -06002325 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002326 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicStencilState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002327 }
2328 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002329 if (VK_FALSE == skipCall)
2330 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStencilState(cmdBuffer, dynamicStencilState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002331}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002332VK_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 -06002333{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002334 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002335 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2336 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002337 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002338 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002339 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 -06002340 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002341 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002342 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 -06002343 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002344 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002345 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002346 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2347 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002348 loader_platform_thread_lock_mutex(&globalLock);
2349 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002350 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002351 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2352 g_lastBoundDescriptorSet = pDescriptorSets[i];
2353 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002354 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 -06002355 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002356 if (!pSet->pUpdateStructs)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002357 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 -06002358 "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 -06002359 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002360 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 -06002361 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002362 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002363 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002364 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002365 skipCall |= addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002366 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002367 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002368 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002369 }
2370 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002371 if (VK_FALSE == skipCall)
2372 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 -06002373}
2374
Tony Barbour8205d902015-04-16 15:59:00 -06002375VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002376{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002377 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002378 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2379 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002380 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002381 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002382 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 -06002383 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002384 }
2385 VkDeviceSize offset_align = 0;
2386 switch (indexType) {
2387 case VK_INDEX_TYPE_UINT16:
2388 offset_align = 2;
2389 break;
2390 case VK_INDEX_TYPE_UINT32:
2391 offset_align = 4;
2392 break;
2393 default:
2394 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
2395 break;
2396 }
2397 if (!offset_align || (offset % offset_align)) {
2398 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
2399 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06002400 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002401 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002402 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002403 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002404 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
2405 updateCBTracking(cmdBuffer);
2406 skipCall |= addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002407 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002408 if (VK_FALSE == skipCall)
2409 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002410}
2411
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002412VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2413 VkCmdBuffer cmdBuffer,
2414 uint32_t startBinding,
2415 uint32_t bindingCount,
2416 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002417 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002418{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002419 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002420 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2421 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002422 if (pCB->state == CB_UPDATE_ACTIVE) {
2423 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002424 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002425 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 -06002426 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2427 } else {
2428 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002429 updateCBTracking(cmdBuffer);
2430 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002431 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002432 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002433 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002434 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002435 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002436 if (VK_FALSE == skipCall)
2437 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002438}
2439
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002440VK_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 -06002441{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002442 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002443 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2444 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002445 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002446 pCB->drawCount[DRAW]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002447 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002448 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002449 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 -06002450 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002451 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2452 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002453 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002454 skipCall |= addCmd(pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002455 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002456 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002457 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002458 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002459 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002460 if (VK_FALSE == skipCall)
2461 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002462}
2463
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002464VK_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 -06002465{
2466 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002467 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002468 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002469 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002470 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002471 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002472 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002473 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 -06002474 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002475 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2476 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002477 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002478 skipCall |= addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002479 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002480 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002481 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002482 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002483 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002484 if (VK_FALSE == skipCall)
2485 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002486}
2487
Tony Barbour8205d902015-04-16 15:59:00 -06002488VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002489{
2490 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002491 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002492 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002493 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002494 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002495 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002496 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002497 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 -06002498 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002499 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2500 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002501 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002502 skipCall |= addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002503 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002504 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002505 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002506 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002507 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002508 if (VK_FALSE == skipCall)
2509 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002510}
2511
Tony Barbour8205d902015-04-16 15:59:00 -06002512VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002514 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002515 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2516 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002517 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002518 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002519 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002520 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002521 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 -06002522 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002523 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2524 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002525 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002526 skipCall |= addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002527 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002528 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002529 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002530 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002531 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002532 if (VK_FALSE == skipCall)
2533 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002534}
2535
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002536VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002537{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002538 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002539 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2540 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002541 if (pCB->state == CB_UPDATE_ACTIVE) {
2542 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002543 skipCall |= addCmd(pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002544 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002545 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002546 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002547 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002548 if (VK_FALSE == skipCall)
2549 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002550}
2551
Tony Barbour8205d902015-04-16 15:59:00 -06002552VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002553{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002554 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002555 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2556 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002557 if (pCB->state == CB_UPDATE_ACTIVE) {
2558 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002559 skipCall |= addCmd(pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002560 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002561 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002562 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002563 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002564 if (VK_FALSE == skipCall)
2565 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002566}
2567
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002568VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* 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_COPYBUFFER);
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)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002582}
2583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002584VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2585 VkImage srcImage,
2586 VkImageLayout srcImageLayout,
2587 VkImage destImage,
2588 VkImageLayout destImageLayout,
2589 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002590{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002591 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002592 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2593 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002594 if (pCB->state == CB_UPDATE_ACTIVE) {
2595 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002596 skipCall |= addCmd(pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002597 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002598 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002599 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002600 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002601 if (VK_FALSE == skipCall)
2602 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002603}
2604
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002605VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2606 VkImage srcImage, VkImageLayout srcImageLayout,
2607 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002608 uint32_t regionCount, const VkImageBlit* pRegions,
2609 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002610{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002611 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002612 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2613 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002614 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002615 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002616 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 -06002617 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002618 } else {
2619 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002620 skipCall |= addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002621 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002622 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002623 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002624 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002625 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002626 if (VK_FALSE == skipCall)
2627 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 -06002628}
2629
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002630VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2631 VkBuffer srcBuffer,
2632 VkImage destImage, VkImageLayout destImageLayout,
2633 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002634{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002635 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002636 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2637 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002638 if (pCB->state == CB_UPDATE_ACTIVE) {
2639 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002640 skipCall |= addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002641 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002642 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002643 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002644 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002645 if (VK_FALSE == skipCall)
2646 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002647}
2648
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002649VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2650 VkImage srcImage, VkImageLayout srcImageLayout,
2651 VkBuffer destBuffer,
2652 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002653{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002654 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002655 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2656 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002657 if (pCB->state == CB_UPDATE_ACTIVE) {
2658 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002659 skipCall |= addCmd(pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002660 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002661 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002662 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002663 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002664 if (VK_FALSE == skipCall)
2665 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002666}
2667
Tony Barbour8205d902015-04-16 15:59:00 -06002668VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002669{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002670 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002671 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2672 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002673 if (pCB->state == CB_UPDATE_ACTIVE) {
2674 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002675 skipCall |= addCmd(pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002676 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002677 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002678 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002679 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002680 if (VK_FALSE == skipCall)
2681 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002682}
2683
Tony Barbour8205d902015-04-16 15:59:00 -06002684VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002685{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002686 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002687 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2688 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002689 if (pCB->state == CB_UPDATE_ACTIVE) {
2690 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002691 skipCall |= addCmd(pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002692 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002693 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002694 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002695 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002696 if (VK_FALSE == skipCall)
2697 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002698}
2699
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002700VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2701 VkCmdBuffer cmdBuffer,
2702 uint32_t colorAttachment,
2703 VkImageLayout imageLayout,
2704 const VkClearColorValue* pColor,
2705 uint32_t rectCount,
2706 const VkRect3D* pRects)
2707{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002708 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002709 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2710 if (pCB) {
2711 if (pCB->state == CB_UPDATE_ACTIVE) {
2712 // Warn if this is issued prior to Draw Cmd
2713 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002714 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002715 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 -06002716 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002717 " 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 -06002718 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002719 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002720 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 -06002721 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2722 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2723 } else {
2724 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002725 skipCall |= addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002726 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002727 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002728 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002729 }
2730 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002731 if (VK_FALSE == skipCall)
2732 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002733}
2734
2735VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2736 VkCmdBuffer cmdBuffer,
2737 VkImageAspectFlags imageAspectMask,
2738 VkImageLayout imageLayout,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002739 const VkClearDepthStencilValue* pDepthStencil,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002740 uint32_t rectCount,
2741 const VkRect3D* pRects)
2742{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002743 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002744 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2745 if (pCB) {
2746 if (pCB->state == CB_UPDATE_ACTIVE) {
2747 // Warn if this is issued prior to Draw Cmd
2748 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002749 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002750 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 -06002751 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002752 " 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 -06002753 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002754 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002755 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 -06002756 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2757 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2758 } else {
2759 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002760 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002761 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002762 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002763 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002764 }
2765 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002766 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002767 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, pDepthStencil, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002768}
2769
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002770VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2771 VkCmdBuffer cmdBuffer,
2772 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002773 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002774 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002775{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002776 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002777 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2778 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002779 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002780 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002781 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 -06002782 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2783 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2784 } else {
2785 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002786 skipCall |= addCmd(pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002787 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002788 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002789 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002790 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002791 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002792 if (VK_FALSE == skipCall)
2793 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002794}
2795
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002796VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(
2797 VkCmdBuffer cmdBuffer,
2798 VkImage image, VkImageLayout imageLayout,
2799 const VkClearDepthStencilValue *pDepthStencil,
2800 uint32_t rangeCount,
2801 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002802{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002803 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002804 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2805 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002806 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002807 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002808 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 -06002809 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2810 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2811 } else {
2812 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002813 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002814 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002815 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002816 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002817 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002818 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002819 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002820 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002821}
2822
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002823VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2824 VkImage srcImage, VkImageLayout srcImageLayout,
2825 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002826 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002827{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002828 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002829 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2830 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002831 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002832 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002833 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 -06002834 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002835 } else {
2836 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002837 skipCall |= addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002838 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002839 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002840 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002841 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002842 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002843 if (VK_FALSE == skipCall)
2844 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002845}
2846
Tony Barbourc2e987e2015-06-29 16:20:35 -06002847VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002848{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002849 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002850 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2851 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002852 if (pCB->state == CB_UPDATE_ACTIVE) {
2853 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002854 skipCall |= addCmd(pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002855 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002856 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002857 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002858 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002859 if (VK_FALSE == skipCall)
2860 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002861}
2862
Tony Barbourc2e987e2015-06-29 16:20:35 -06002863VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002864{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002865 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002866 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2867 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002868 if (pCB->state == CB_UPDATE_ACTIVE) {
2869 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002870 skipCall |= addCmd(pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002871 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002872 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002873 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002874 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002875 if (VK_FALSE == skipCall)
2876 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002877}
2878
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002879VK_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 -06002880{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002881 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002882 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2883 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002884 if (pCB->state == CB_UPDATE_ACTIVE) {
2885 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002886 skipCall |= addCmd(pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002887 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002888 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002889 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002890 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002891 if (VK_FALSE == skipCall)
2892 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002893}
2894
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002895VK_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 -06002896{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002897 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002898 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2899 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002900 if (pCB->state == CB_UPDATE_ACTIVE) {
2901 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002902 skipCall |= addCmd(pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002903 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002904 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002905 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002906 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002907 if (VK_FALSE == skipCall)
2908 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002909}
2910
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002911VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002912{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002913 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002914 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2915 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002916 if (pCB->state == CB_UPDATE_ACTIVE) {
2917 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002918 skipCall |= addCmd(pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002919 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002920 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002921 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002922 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002923 if (VK_FALSE == skipCall)
2924 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002925}
2926
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002927VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002928{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002929 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002930 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2931 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002932 if (pCB->state == CB_UPDATE_ACTIVE) {
2933 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002934 skipCall |= addCmd(pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002935 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002936 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002937 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002938 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002939 if (VK_FALSE == skipCall)
2940 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002941}
2942
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002943VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002944{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002945 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002946 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2947 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002948 if (pCB->state == CB_UPDATE_ACTIVE) {
2949 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002950 skipCall |= addCmd(pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002951 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002952 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002953 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002954 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002955 if (VK_FALSE == skipCall)
2956 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002957}
2958
Tony Barbour8205d902015-04-16 15:59:00 -06002959VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002960{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002961 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002962 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2963 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002964 if (pCB->state == CB_UPDATE_ACTIVE) {
2965 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002966 skipCall |= addCmd(pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002967 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002968 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002969 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002970 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002971 if (VK_FALSE == skipCall)
2972 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002973}
2974
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002975VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002976{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002977 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002978 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002979 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002980 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002981 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002982 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2983 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002984 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002985 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002986 }
2987 return result;
2988}
2989
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002990VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002991{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002992 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002993 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002994 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002995 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002996 if (pCreateInfo->pAttachments) {
2997 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2998 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002999 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003000 if (pCreateInfo->pSubpasses) {
3001 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
3002 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
3003
3004 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
3005 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
3006 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003007 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08003008 subpass->preserveCount;
3009 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
3010
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003011 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003012 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003013 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003014 attachments += subpass->inputCount;
3015
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003016 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003017 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003018 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003019 attachments += subpass->colorCount;
3020
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003021 if (subpass->pResolveAttachments) {
3022 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003023 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003024 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003025 attachments += subpass->colorCount;
3026 }
3027
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003028 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08003029 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06003030 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08003031 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06003032 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003033 if (pCreateInfo->pDependencies) {
3034 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
3035 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06003036 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003037 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06003038 }
3039 return result;
3040}
3041
Chia-I Wuc278df82015-07-07 11:50:03 +08003042VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003043{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003044 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003045 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3046 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003047 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003048 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003049 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 -06003050 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06003051 } else {
3052 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003053 skipCall |= addCmd(pCB, CMD_BEGINRENDERPASS);
Tobin Ehlise4076782015-06-24 15:53:07 -06003054 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003055 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06003056 pCB->framebuffer = pRenderPassBegin->framebuffer;
3057 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003058 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06003059 }
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003060 }
Tobin Ehlise4076782015-06-24 15:53:07 -06003061 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003062 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 -06003063 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06003064 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003065 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003066 if (VK_FALSE == skipCall)
3067 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003068}
3069
Chia-I Wuc278df82015-07-07 11:50:03 +08003070VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
3071{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003072 VkBool32 skipCall = VK_FALSE;
Chia-I Wuc278df82015-07-07 11:50:03 +08003073 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3074 if (pCB) {
3075 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003076 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 +08003077 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
3078 } else {
3079 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003080 skipCall |= addCmd(pCB, CMD_NEXTSUBPASS);
Chia-I Wuc278df82015-07-07 11:50:03 +08003081 pCB->activeSubpass++;
3082 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003083 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08003084 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003085 }
3086 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003087 if (VK_FALSE == skipCall)
3088 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08003089}
3090
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003091VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003092{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003093 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003094 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3095 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003096 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003097 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 +08003098 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06003099 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003100 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003101 skipCall |= addCmd(pCB, CMD_ENDRENDERPASS);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003102 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08003103 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003104 }
3105 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003106 if (VK_FALSE == skipCall)
3107 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003108}
3109
3110VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3111{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003112 VkBool32 skipCall = VK_FALSE;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003113 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3114 if (pCB) {
3115 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003116 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 +08003117 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
3118 } else {
3119 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003120 skipCall |= addCmd(pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003121 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003122 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003123 if (VK_FALSE == skipCall)
3124 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003125}
3126
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003127VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3128 VkInstance instance,
3129 VkFlags msgFlags,
3130 const PFN_vkDbgMsgCallback pfnMsgCallback,
3131 void* pUserData,
3132 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003133{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003134 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003135 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3136 if (VK_SUCCESS == res) {
3137 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3138 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3139 }
3140 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003141}
3142
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003143VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3144 VkInstance instance,
3145 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003146{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003147 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003148 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3149 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3150 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3151 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003152}
3153
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003154VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003155{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003156 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003157 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003158 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3159 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003160 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003161 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 -06003162 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003163 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003164 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003165 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003166 skipCall |= addCmd(pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003167 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003168 if (VK_FALSE == skipCall)
3169 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003170}
3171
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003172VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003173{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003174 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003175 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003176 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3177 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003178 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003179 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 -06003180 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003181 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003182 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003183 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003184 skipCall |= addCmd(pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003185 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003186 if (VK_FALSE == skipCall)
3187 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003188}
3189
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003190//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3191//{
3192// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3193// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3194// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3195// "Attempt to use DbgSetObjectTag but extension disabled!");
3196// return VK_ERROR_UNAVAILABLE;
3197// }
3198// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3199//}
3200//
3201//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3202//{
3203// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3204// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3205// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3206// "Attempt to use DbgSetObjectName but extension disabled!");
3207// return VK_ERROR_UNAVAILABLE;
3208// }
3209// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3210//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003211
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003212VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003213{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003214 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003215 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003216
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003217 /* loader uses this to force layer initialization; device object is wrapped */
3218 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003219 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003220 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003221 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003222 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003223 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003224 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003226 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003228 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003230 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003232 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003234 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003236 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003238 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003240 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003242 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003243 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003244 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003245 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003246 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003247 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003248 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003249 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003250 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003251 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003252 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003253 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003254 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003256 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003258 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003260 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003262 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003264 if (!strcmp(funcName, "vkDestroyDynamicLineWidthState"))
3265 return (PFN_vkVoidFunction) vkDestroyDynamicLineWidthState;
3266 if (!strcmp(funcName, "vkDestroyDynamicDepthBiasState"))
3267 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBiasState;
3268 if (!strcmp(funcName, "vkDestroyDynamicBlendState"))
3269 return (PFN_vkVoidFunction) vkDestroyDynamicBlendState;
3270 if (!strcmp(funcName, "vkDestroyDynamicDepthBoundsState"))
3271 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003272 if (!strcmp(funcName, "vkDestroyDynamicStencilState"))
3273 return (PFN_vkVoidFunction) vkDestroyDynamicStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003274 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003276 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003278 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003280 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003282 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003284 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003286 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003287 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003288 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003289 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003290 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003291 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003292 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003293 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003294 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003295 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003296 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003297 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003298 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003299 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003300 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003301 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003302 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003303 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003304 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003305 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003306 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003307 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003308 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003309 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003310 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003311 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003312 if (!strcmp(funcName, "vkCreateDynamicLineWidthState"))
3313 return (PFN_vkVoidFunction) vkCreateDynamicLineWidthState;
3314 if (!strcmp(funcName, "vkCreateDynamicDepthBiasState"))
3315 return (PFN_vkVoidFunction) vkCreateDynamicDepthBiasState;
3316 if (!strcmp(funcName, "vkCreateDynamicBlendState"))
3317 return (PFN_vkVoidFunction) vkCreateDynamicBlendState;
3318 if (!strcmp(funcName, "vkCreateDynamicDepthBoundsState"))
3319 return (PFN_vkVoidFunction) vkCreateDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003320 if (!strcmp(funcName, "vkCreateDynamicStencilState"))
3321 return (PFN_vkVoidFunction) vkCreateDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003322 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003323 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003324 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003325 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003326 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003327 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003328 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003329 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003330 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003331 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003332 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003333 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003334 if (!strcmp(funcName, "vkCmdBindDynamicLineWidthState"))
3335 return (PFN_vkVoidFunction) vkCmdBindDynamicLineWidthState;
3336 if (!strcmp(funcName, "vkCmdBindDynamicDepthBiasState"))
3337 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBiasState;
3338 if (!strcmp(funcName, "vkCmdBindDynamicBlendState"))
3339 return (PFN_vkVoidFunction) vkCmdBindDynamicBlendState;
3340 if (!strcmp(funcName, "vkCmdBindDynamicDepthBoundsState"))
3341 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003342 if (!strcmp(funcName, "vkCmdBindDynamicStencilState"))
3343 return (PFN_vkVoidFunction) vkCmdBindDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003344 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003345 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003346 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003347 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003348 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003349 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003350 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003351 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003352 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003353 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003354 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003355 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003356 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003357 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003358 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003359 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003360 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003361 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003362 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003363 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003364 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003365 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003366 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003367 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003368 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003369 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003370 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003371 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003372 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003373 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003374 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003375 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003376 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003377 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003378 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003379 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003380 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003381 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003382 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003383 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003384 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003385 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003386 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003387 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003388 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003389 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003390 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003391 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003392 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003393 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003394 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003395 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003396 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003397 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003398 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003399 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003400 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003401 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003402 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003403 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003404 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003405 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003406 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003407 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003408 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003409 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003410
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003411 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3412 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003413 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003414 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003415 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003416 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003417 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003418// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3419// return (void*) vkDbgSetObjectTag;
3420// if (!strcmp(funcName, "vkDbgSetObjectName"))
3421// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003422 }
3423 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003424 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003425 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003426 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003427 }
3428}
3429
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003430VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003431{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003432 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003433 if (instance == NULL)
3434 return NULL;
3435
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003436 /* loader uses this to force layer initialization; instance object is wrapped */
3437 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003438 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003439 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003440 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003441 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003442 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003443 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003444 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06003445 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
3446 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
3447 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
3448 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
3449 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
3450 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
3451 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
3452 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003453
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003454 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3455 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003456 if (fptr)
3457 return fptr;
3458
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003459 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003460 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003461 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003462 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003463 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003464 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003465}