blob: d97578a777fcb9c362b63dc4b7592752cef6aedf [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
356 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 Ehlisc6c3d6d2015-06-22 17:20:50 -0600358 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600359 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600360 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600361 return VK_TRUE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600362}
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600363// For given dynamic state handle and type, return CreateInfo for that Dynamic State
364static void* getDynamicStateCreateInfo(const uint64_t handle, const DYNAMIC_STATE_BIND_POINT type)
365{
366 switch (type) {
367 case VK_STATE_BIND_POINT_VIEWPORT:
368 return (void*)&dynamicVpStateMap[handle];
Cody Northrope4bc6942015-08-26 10:01:32 -0600369 case VK_STATE_BIND_POINT_LINE_WIDTH:
370 return (void*)&dynamicLineWidthStateMap[handle];
371 case VK_STATE_BIND_POINT_DEPTH_BIAS:
372 return (void*)&dynamicDepthBiasStateMap[handle];
373 case VK_STATE_BIND_POINT_BLEND:
374 return (void*)&dynamicBlendStateMap[handle];
375 case VK_STATE_BIND_POINT_DEPTH_BOUNDS:
376 return (void*)&dynamicDepthBoundsStateMap[handle];
Cody Northrop2605cb02015-08-18 15:21:16 -0600377 case VK_STATE_BIND_POINT_STENCIL:
378 return (void*)&dynamicStencilStateMap[handle];
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600379 default:
380 return NULL;
381 }
382}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600383// Print the last bound dynamic state
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600384static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600385{
386 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) {
393 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
394 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
395 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
396 dynamic_display(pDynStateCI, " ").c_str());
397 } else {
398 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
399 "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 Ehlis1dce5f12015-07-07 10:42:20 -0600402 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
403 "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 Ehlis63bb9482015-03-17 16:24:32 -0600408}
409// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600410static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600411{
412 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600413 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600414 loader_platform_thread_unlock_mutex(&globalLock);
415 return NULL;
416 }
417 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600418 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600419}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600420// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600421static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
422 VkBool32 result;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600423 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");
Cody Northrope4bc6942015-08-26 10:01:32 -0600424 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");
425 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");
426 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");
427 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");
Cody Northrop2605cb02015-08-18 15:21:16 -0600428 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 -0600429 if (indexedDraw)
430 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");
431 return result;
432}
433// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600434static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600435 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600436 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600437 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
438 // Now complete other state checks
Tobin Ehlis12ab7dc2015-09-09 13:31:01 -0600439 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
440 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
441 // We should have that check separately and then gate this check based on that check
442 if (pPipe && (pCB->lastBoundPipelineLayout) && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600443 result = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600444 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 -0600445 "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 -0600446 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600447 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600448 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 -0600449 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
450 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600451 return result;
452}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600453// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600454static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600455{
456 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600457 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600458 loader_platform_thread_unlock_mutex(&globalLock);
459 return NULL;
460 }
461 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600462 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600463}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600464// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600465static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600466{
467 // VS is required
468 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600469 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 -0600470 "Invalid Pipeline CreateInfo State: Vtx Shader required");
471 return VK_FALSE;
472 }
473 // Either both or neither TC/TE shaders should be defined
474 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
475 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600476 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600477 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
478 return VK_FALSE;
479 }
480 // Compute shaders should be specified independent of Gfx shaders
481 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
482 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
483 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
484 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600485 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 -0600486 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
487 return VK_FALSE;
488 }
489 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
490 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
491 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
492 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600493 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 -0600494 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
495 return VK_FALSE;
496 }
497 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
498 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600499 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 -0600500 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
501 return VK_FALSE;
502 }
503 return VK_TRUE;
504}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600505// Init the pipeline mapping info based on pipeline create info LL tree
506// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600507static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600508{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600509 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
510 if (pBasePipeline) {
511 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600512 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600513 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
514 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600515 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600516 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600517 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600518
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600519 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600520 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600521 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600522
523 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
524 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
525
526 switch (pPSSCI->stage) {
527 case VK_SHADER_STAGE_VERTEX:
528 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
529 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600530 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600531 case VK_SHADER_STAGE_TESS_CONTROL:
532 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
533 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600534 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600535 case VK_SHADER_STAGE_TESS_EVALUATION:
536 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
537 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600538 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600539 case VK_SHADER_STAGE_GEOMETRY:
540 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
541 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600542 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600543 case VK_SHADER_STAGE_FRAGMENT:
544 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
545 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600546 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600547 case VK_SHADER_STAGE_COMPUTE:
548 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
549 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600550 break;
551 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600552 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600553 break;
554 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600555 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600556
557 if (pCreateInfo->pVertexInputState != NULL) {
558 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
559 // Copy embedded ptrs
560 pVICI = pCreateInfo->pVertexInputState;
561 pPipeline->vtxBindingCount = pVICI->bindingCount;
562 if (pPipeline->vtxBindingCount) {
563 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
564 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
565 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
566 }
567 pPipeline->vtxAttributeCount = pVICI->attributeCount;
568 if (pPipeline->vtxAttributeCount) {
569 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
570 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
571 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
572 }
573 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
574 }
Tony Barboure307f582015-07-10 15:29:03 -0600575 if (pCreateInfo->pInputAssemblyState != NULL) {
576 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
577 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600578 }
Tony Barboure307f582015-07-10 15:29:03 -0600579 if (pCreateInfo->pTessellationState != NULL) {
580 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
581 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600582 }
Tony Barboure307f582015-07-10 15:29:03 -0600583 if (pCreateInfo->pViewportState != NULL) {
584 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
585 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600586 }
Tony Barboure307f582015-07-10 15:29:03 -0600587 if (pCreateInfo->pRasterState != NULL) {
588 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
589 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600590 }
Tony Barboure307f582015-07-10 15:29:03 -0600591 if (pCreateInfo->pMultisampleState != NULL) {
592 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
593 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600594 }
Tony Barboure307f582015-07-10 15:29:03 -0600595 if (pCreateInfo->pColorBlendState != NULL) {
596 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600597 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600598 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600599 pPipeline->attachmentCount = pCBCI->attachmentCount;
600 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600601 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
602 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600603 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
604 }
Tony Barboure307f582015-07-10 15:29:03 -0600605 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600606 }
Tony Barboure307f582015-07-10 15:29:03 -0600607 if (pCreateInfo->pDepthStencilState != NULL) {
608 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
609 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600610 }
611
612 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
613 if (pCreateInfo->stageCount != 0) {
614 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
615 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
616 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
617 }
618
Tobin Ehlisde63c532015-06-18 15:59:33 -0600619 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600620}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600621
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600622// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600623static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600624{
David Pinedof5997ab2015-04-27 16:36:17 -0600625 if (pipelineMap.size() <= 0)
626 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600627 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600628 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
629 delete[] (*ii).second->graphicsPipelineCI.pStages;
630 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600631 if ((*ii).second->pVertexBindingDescriptions) {
632 delete[] (*ii).second->pVertexBindingDescriptions;
633 }
634 if ((*ii).second->pVertexAttributeDescriptions) {
635 delete[] (*ii).second->pVertexAttributeDescriptions;
636 }
637 if ((*ii).second->pAttachments) {
638 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600639 }
640 delete (*ii).second;
641 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600642 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600643}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600644// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600645static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600646{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600647 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600648 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
649 return pPipe->msStateCI.rasterSamples;
650 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600651 return 1;
652}
653// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600654static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600655{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600656 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600657 // Verify that any MSAA request in PSO matches sample# in bound FB
658 uint32_t psoNumSamples = getNumSamples(pipeline);
659 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600660 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800661 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
662 int subpassNumSamples = 0;
663 uint32_t i;
664
665 for (i = 0; i < pSD->colorCount; i++) {
666 uint32_t samples;
667
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600668 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800669 continue;
670
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600671 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800672 if (subpassNumSamples == 0) {
673 subpassNumSamples = samples;
674 } else if (subpassNumSamples != samples) {
675 subpassNumSamples = -1;
676 break;
677 }
678 }
679 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
680 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
681 if (subpassNumSamples == 0)
682 subpassNumSamples = samples;
683 else if (subpassNumSamples != samples)
684 subpassNumSamples = -1;
685 }
686
687 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600688 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
689 "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 -0600690 }
691 } else {
692 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
693 // Verify and flag error as appropriate
694 }
695 // TODO : Add more checks here
696 } else {
697 // TODO : Validate non-gfx pipeline updates
698 }
699}
700
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600701// Block of code at start here specifically for managing/tracking DSs
702
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600703// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600704static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600705{
706 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600707 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600708 loader_platform_thread_unlock_mutex(&globalLock);
709 return NULL;
710 }
711 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600712 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600713}
714// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600715static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600716{
717 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600718 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600719 loader_platform_thread_unlock_mutex(&globalLock);
720 return NULL;
721 }
722 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600723 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600724}
725
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600726static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600727 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600728 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600729 loader_platform_thread_unlock_mutex(&globalLock);
730 return NULL;
731 }
732 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600733 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600734}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600735// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600736static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600737{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600738 switch (pUpdateStruct->sType)
739 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800740 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
741 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600742 return 1;
743 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600744 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 -0600745 "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 -0600746 return 0;
747 }
748}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600749// For given update struct, return binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600750static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600751{
752 switch (pUpdateStruct->sType)
753 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800754 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
755 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
756 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
757 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600758 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600759 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 -0600760 "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 -0600761 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600762 }
763}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600764// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600765static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600766{
767 switch (pUpdateStruct->sType)
768 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800769 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
770 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
771 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600772 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800773 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600774 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600775 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 -0600776 "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 -0600777 return 0;
778 }
779}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600780// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600781static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600782{
783 switch (pUpdateStruct->sType)
784 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800785 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
786 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
787 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600788 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800789 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600790 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600791 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 -0600792 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600793 return 0;
794 }
795}
796// For given Layout Node and binding, return index where that binding begins
797static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
798{
799 uint32_t offsetIndex = 0;
800 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800801 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600802 }
803 return offsetIndex;
804}
805// For given layout node and binding, return last index that is updated
806static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
807{
808 uint32_t offsetIndex = 0;
809 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800810 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600811 }
812 return offsetIndex-1;
813}
814// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600815static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600816{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600817 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600818}
819// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600820static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600821{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600822 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600823}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600824// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600825static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600826{
827 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600828 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600830 switch (pUpdateStruct->sType)
831 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800832 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
833 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600834 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800835 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
836 /* no need to validate */
837 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600838 break;
839 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600840 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 -0600841 "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 -0600842 return 0;
843 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600844 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600845 if (pLayout->pTypes[i] != actualType)
846 return 0;
847 }
848 return 1;
849}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600850// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
851// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
852// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600853static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600854{
855 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800856 VkWriteDescriptorSet* pWDS = NULL;
857 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600858 size_t array_size = 0;
859 size_t base_array_size = 0;
860 size_t total_array_size = 0;
861 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600862 switch (pUpdate->sType)
863 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800864 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
865 pWDS = new VkWriteDescriptorSet;
866 pNewNode = (GENERIC_HEADER*)pWDS;
867 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
868 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
869 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
870 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600871 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800872 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
873 pCDS = new VkCopyDescriptorSet;
874 pUpdate = (GENERIC_HEADER*)pCDS;
875 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600876 break;
877 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600878 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 -0600879 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880 return NULL;
881 }
882 // Make sure that pNext for the end of shadow copy is NULL
883 pNewNode->pNext = NULL;
884 return pNewNode;
885}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800886// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600887static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600888{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800889 const VkWriteDescriptorSet *pWDS = NULL;
890 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600891 VkBool32 result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800892
893 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
894 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
895 else
896 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
897
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600898 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600899 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600900 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600901 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600902 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600903 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800904 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600905 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800906 g_lastBoundDescriptorSet = pSet->set;
907 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600908 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600909 // First verify valid update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600910 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600911 result = 0;
912 break;
913 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600914 // Make sure that binding is within bounds
Tobin Ehlisde63c532015-06-18 15:59:33 -0600915 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600916 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600917 "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, getUpdateBinding(device, pUpdate), string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600918 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600919 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600920 // Next verify that update falls within size of given binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600921 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour29b12062015-07-13 13:37:24 -0600922 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600923 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600924 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600925 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600926 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), getUpdateBinding(device, pUpdate), DSstr.c_str());
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600927 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600928 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600929 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlisde63c532015-06-18 15:59:33 -0600930 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600931 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 -0600932 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600933 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600934 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600935 // Save the update info
936 // TODO : Info message that update successful
937 // Create new update struct for this set's shadow copy
Tobin Ehlisde63c532015-06-18 15:59:33 -0600938 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600939 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600940 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 -0600941 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600942 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600943 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600944 // Insert shadow node into LL of updates for this set
945 pNewNode->pNext = pSet->pUpdateStructs;
946 pSet->pUpdateStructs = pNewNode;
947 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisde63c532015-06-18 15:59:33 -0600948 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600949 assert(j<pSet->descriptorCount);
950 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600951 }
952 }
953 }
954 }
955 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600956 }
957 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600958 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600959}
960// Free the shadowed update node for this Set
961// NOTE : Calls to this function should be wrapped in mutex
962static void freeShadowUpdateTree(SET_NODE* pSet)
963{
964 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
965 pSet->pUpdateStructs = NULL;
966 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
967 // Clear the descriptor mappings as they will now be invalid
968 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
969 while(pShadowUpdate) {
970 pFreeUpdate = pShadowUpdate;
971 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
972 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800973 VkWriteDescriptorSet * pWDS = NULL;
974 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600975 void** ppToFree = NULL;
976 switch (pFreeUpdate->sType)
977 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800978 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
979 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
980 if (pWDS->pDescriptors)
981 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600982 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800983 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600984 break;
985 default:
986 assert(0);
987 break;
988 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600989 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600990 }
991}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600992// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600993// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600994static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600995{
David Pinedof5997ab2015-04-27 16:36:17 -0600996 if (poolMap.size() <= 0)
997 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600998 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600999 SET_NODE* pSet = (*ii).second->pSets;
1000 SET_NODE* pFreeSet = pSet;
1001 while (pSet) {
1002 pFreeSet = pSet;
1003 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001004 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001005 // Free Update shadow struct tree
1006 freeShadowUpdateTree(pFreeSet);
1007 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001008 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001009 }
1010 delete pFreeSet;
1011 }
1012 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001013 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001014 }
1015 delete (*ii).second;
1016 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001017 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001018}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001019// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001020// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001021static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001022{
David Pinedof5997ab2015-04-27 16:36:17 -06001023 if (layoutMap.size() <= 0)
1024 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001025 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001026 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001027 if (pLayout->createInfo.pBinding) {
1028 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1029 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1030 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1031 }
1032 delete[] pLayout->createInfo.pBinding;
1033 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001034 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001035 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001036 }
1037 delete pLayout;
1038 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001039 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001040}
1041// Currently clearing a set is removing all previous updates to that set
1042// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001043static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001044{
1045 SET_NODE* pSet = getSetNode(set);
1046 if (!pSet) {
1047 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001048 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001049 loader_platform_thread_lock_mutex(&globalLock);
1050 freeShadowUpdateTree(pSet);
1051 loader_platform_thread_unlock_mutex(&globalLock);
1052 }
1053}
1054
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001055static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001056{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001057 POOL_NODE* pPool = getPoolNode(pool);
1058 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001059 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1060 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001061 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001062 // For every set off of this pool, clear it
1063 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001064 while (pSet) {
1065 clearDescriptorSet(pSet->set);
1066 }
1067 }
1068}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001069// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001070static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001071{
1072 loader_platform_thread_lock_mutex(&globalLock);
1073 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1074 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001075 // TODO : How to pass cb as srcObj here?
1076 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 -06001077 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001078 return NULL;
1079 }
1080 loader_platform_thread_unlock_mutex(&globalLock);
1081 return cmdBufferMap[cb];
1082}
1083// Free all CB Nodes
1084// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001085static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001086{
David Pinedof5997ab2015-04-27 16:36:17 -06001087 if (cmdBufferMap.size() <= 0)
1088 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001089 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001090 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1091 while (!cmd_node_list.empty()) {
1092 CMD_NODE* cmd_node = cmd_node_list.back();
1093 delete cmd_node;
1094 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001095 }
1096 delete (*ii).second;
1097 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001098 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001099}
Tobin Ehlise42007c2015-06-19 13:00:59 -06001100static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1101{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001102 // TODO : How to pass cb as srcObj here?
1103 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 -06001104 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1105}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001106static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1107{
1108 CMD_NODE* pCmd = new CMD_NODE;
1109 if (pCmd) {
1110 // init cmd node and append to end of cmd LL
1111 memset(pCmd, 0, sizeof(CMD_NODE));
1112 pCmd->cmdNumber = ++pCB->numCmds;
1113 pCmd->type = cmd;
1114 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001115 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001116 // TODO : How to pass cb as srcObj here?
1117 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 -06001118 "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 -06001119 }
1120}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001121static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001122{
1123 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1124 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001125 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1126 while (!cmd_list.empty()) {
1127 delete cmd_list.back();
1128 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001129 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001130 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001131 // Reset CB state (need to save createInfo)
1132 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001133 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1134 pCB->cmdBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001135 pCB->createInfo = saveCBCI;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001136 pCB->lastVtxBinding = MAX_BINDING;
1137 }
1138}
Tobin Ehlis97866202015-06-10 12:57:07 -06001139// Set PSO-related status bits for CB
1140static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1141{
1142 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1143 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1144 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1145 }
1146 }
1147 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06001148 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1149 }
1150
1151 if (pPipe->dsStateCI.stencilTestEnable) {
1152 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001153 }
1154}
1155// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001156static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001157 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1158 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
Cody Northrope4bc6942015-08-26 10:01:32 -06001159 } else if (stateBindPoint == VK_STATE_BIND_POINT_LINE_WIDTH) {
1160 pNode->status |= CBSTATUS_LINE_WIDTH_BOUND;
1161 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BIAS) {
1162 pNode->status |= CBSTATUS_DEPTH_BIAS_BOUND;
1163 } else if (stateBindPoint == VK_STATE_BIND_POINT_BLEND) {
1164 pNode->status |= CBSTATUS_BLEND_BOUND;
1165 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BOUNDS) {
1166 pNode->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
Cody Northrop2605cb02015-08-18 15:21:16 -06001167 } else if (stateBindPoint == VK_STATE_BIND_POINT_STENCIL) {
1168 pNode->status |= CBSTATUS_STENCIL_BOUND;
Tobin Ehlis97866202015-06-10 12:57:07 -06001169 }
1170}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001171// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001172static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001173{
1174 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1175 if (pCB) {
1176 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1177 if (!pPipeTrav) {
1178 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001179 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001180 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001181 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001182 }
1183 }
1184}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001185// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001186static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001187{
1188 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1189 if (pCB && pCB->lastBoundPipeline) {
1190 // First verify that we have a Node for bound pipeline
1191 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001192 if (!pPipeTrav) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001193 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1194 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001195 return false;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001196 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001197 // Verify Vtx binding
1198 if (MAX_BINDING != pCB->lastVtxBinding) {
1199 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1200 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001201 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001202 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001203 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001204 }
1205 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001206 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001207 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001208 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001209 }
1210 }
1211 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001212 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001213 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001214 }
1215 }
1216 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001217 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001218 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001219 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001220}
1221// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001222static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001223{
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001224 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.
1225 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001226 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001227 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001228 POOL_NODE* pPool = getPoolNode(pSet->pool);
1229 // Print out pool details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001230 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1231 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001232 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001233 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001234 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001235 // Print out set details
1236 char prefix[10];
1237 uint32_t index = 0;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001238 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1239 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001240 LAYOUT_NODE* pLayout = pSet->pLayout;
1241 // Print layout details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001242 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1243 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001244 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001245 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001246 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001247 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001248 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001249 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1250 if (pUpdate) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001251 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1252 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001253 sprintf(prefix, " [UC] ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001254 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001255 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001256 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001257 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001258 if (0 != pSet->descriptorCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001259 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1260 "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 -06001261 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001262 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1263 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001264 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001265 }
1266 }
1267}
1268
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001269static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001270{
1271 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001272 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001273 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001274 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001275 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001276 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1277 // TODO : Need to pass cb as srcObj here
1278 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 -06001279 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001280 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001281 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001282 // Nothing to print
1283 }
1284}
1285
1286
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001287static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001288{
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001289 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
1290 return;
1291 }
Mark Lobodzinskifdb20cf2015-08-07 17:11:09 -06001292 printDSConfig(cb);
1293 printPipeline(cb);
1294 printDynamicState(cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001295}
1296
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001297static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001298{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001299 uint32_t report_flags = 0;
1300 uint32_t debug_action = 0;
1301 FILE *log_output = NULL;
1302 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001303 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001304 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1305 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001306
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001307 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001308 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001309 option_str = getLayerOption("DrawStateLogFilename");
1310 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001311 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001312 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001313 }
Tobin Ehlisaf14e9f2015-09-01 11:59:36 -06001314 if (log_output == NULL) {
1315 if (option_str)
1316 cout << endl << "DrawState ERROR: Bad output filename specified: " << option_str << ". Writing to STDOUT instead" << endl << endl;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001317 log_output = stdout;
Tobin Ehlisaf14e9f2015-09-01 11:59:36 -06001318 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001319
1320 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 -06001321 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001322
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001323 if (!globalLockInitialized)
1324 {
1325 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001326 // suggestion is to call this during vkCreateInstance(), and then we
1327 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001328 // that the layer have per-instance locks. We need to come back and
1329 // address this soon.
1330 loader_platform_thread_create_mutex(&globalLock);
1331 globalLockInitialized = 1;
1332 }
1333}
1334
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001335VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1336{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001337 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001338 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1339
1340 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001341 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1342 my_data->report_data = debug_report_create_instance(
1343 pTable,
1344 *pInstance,
1345 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001346 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001347
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001348 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001349 }
1350 return result;
1351}
1352
Jon Ashburne0fa2282015-05-20 09:00:28 -06001353/* hook DestroyInstance to remove tableInstanceMap entry */
1354VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1355{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001356 dispatch_key key = get_dispatch_key(instance);
1357 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1358 VkResult res = pTable->DestroyInstance(instance);
1359
1360 // Clean up logging callback, if any
1361 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1362 if (my_data->logging_callback) {
1363 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1364 }
1365
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001366 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001367 layer_data_map.erase(pTable);
1368
1369 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001370 return res;
1371}
1372
Jon Ashburnf0615e22015-05-25 14:11:37 -06001373static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1374{
Tony Barbour29b12062015-07-13 13:37:24 -06001375 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001376 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001377 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001378
1379 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001380 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001381 /* Found a matching extension name, mark it enabled and init dispatch table*/
1382 initDebugMarkerTable(device);
1383 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001384 }
1385
1386 }
1387}
1388
Tony Barbour8205d902015-04-16 15:59:00 -06001389VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001390{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001391 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1392 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001393 if (result == VK_SUCCESS) {
1394 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1395 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1396 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1397 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001398 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001399 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001400 return result;
1401}
1402
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001403VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001404{
1405 // Free all the memory
1406 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001407 deletePipelines();
1408 deleteSamplers();
1409 deleteImages();
1410 deleteBuffers();
1411 deleteCmdBuffers();
1412 deleteDynamicState();
1413 deletePools();
1414 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001415 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001416
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001417 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001418 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1419 VkResult result = pDisp->DestroyDevice(device);
1420 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001421 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001422 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001423 return result;
1424}
1425
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001426static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001427 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001428 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001429 VK_API_VERSION,
1430 VK_MAKE_VERSION(0, 1, 0),
1431 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001432 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001433};
1434
Tony Barbour426b9052015-06-24 16:06:58 -06001435VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001436 const char *pLayerName,
1437 uint32_t *pCount,
1438 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001439{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001440 /* DrawState does not have any global extensions */
1441 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1442}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001443
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001444VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1445 uint32_t *pCount,
1446 VkLayerProperties* pProperties)
1447{
1448 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1449 ds_global_layers,
1450 pCount, pProperties);
1451}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001452
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001453static const VkExtensionProperties ds_device_extensions[] = {
1454 {
1455 DEBUG_MARKER_EXTENSION_NAME,
1456 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001457 }
1458};
1459
1460static const VkLayerProperties ds_device_layers[] = {
1461 {
1462 "DrawState",
1463 VK_API_VERSION,
1464 VK_MAKE_VERSION(0, 1, 0),
1465 "Validation layer: DrawState",
1466 }
1467};
1468
1469VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1470 VkPhysicalDevice physicalDevice,
1471 const char* pLayerName,
1472 uint32_t* pCount,
1473 VkExtensionProperties* pProperties)
1474{
1475 /* Mem tracker does not have any physical device extensions */
1476 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1477 pCount, pProperties);
1478}
1479
1480VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1481 VkPhysicalDevice physicalDevice,
1482 uint32_t* pCount,
1483 VkLayerProperties* pProperties)
1484{
1485 /* Mem tracker's physical device layers are the same as global */
1486 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1487 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001488}
1489
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001490VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001491{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001492 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001493 for (uint32_t i=0; i < cmdBufferCount; i++) {
1494 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001495 pCB = getCBNode(pCmdBuffers[i]);
1496 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001497 pCB->submitCount++; // increment submit count
1498 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
1499 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 -06001500 "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 -06001501 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001502 if (CB_UPDATE_COMPLETE != pCB->state) {
1503 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001504 // TODO : How to pass cb as srcObj?
1505 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 -06001506 "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 -06001507 loader_platform_thread_unlock_mutex(&globalLock);
1508 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001509 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001510 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001511 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001512
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001513 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001514 return result;
1515}
1516
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001517VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001518{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001519 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1520 // TODO : Clean up any internal data structures using this obj.
1521 return result;
1522}
1523
1524VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1525{
1526 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1527 // TODO : Clean up any internal data structures using this obj.
1528 return result;
1529}
1530
1531VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1532{
1533 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1534 // TODO : Clean up any internal data structures using this obj.
1535 return result;
1536}
1537
1538VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1539{
1540 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1541 // TODO : Clean up any internal data structures using this obj.
1542 return result;
1543}
1544
1545VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1546{
1547 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1548 // TODO : Clean up any internal data structures using this obj.
1549 return result;
1550}
1551
1552VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1553{
1554 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1555 // TODO : Clean up any internal data structures using this obj.
1556 return result;
1557}
1558
1559VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1560{
1561 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1562 // TODO : Clean up any internal data structures using this obj.
1563 return result;
1564}
1565
1566VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1567{
1568 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1569 // TODO : Clean up any internal data structures using this obj.
1570 return result;
1571}
1572
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001573VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1574{
1575 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1576 // TODO : Clean up any internal data structures using this obj.
1577 return result;
1578}
1579
1580VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1581{
1582 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1583 // TODO : Clean up any internal data structures using this obj.
1584 return result;
1585}
1586
1587VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1588{
1589 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1590 // TODO : Clean up any internal data structures using this obj.
1591 return result;
1592}
1593
1594VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1595{
1596 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1597 // TODO : Clean up any internal data structures using this obj.
1598 return result;
1599}
1600
1601VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1602{
1603 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1604 // TODO : Clean up any internal data structures using this obj.
1605 return result;
1606}
1607
1608VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1609{
1610 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1611 // TODO : Clean up any internal data structures using this obj.
1612 return result;
1613}
1614
1615VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1616{
1617 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1618 // TODO : Clean up any internal data structures using this obj.
1619 return result;
1620}
1621
1622VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1623{
1624 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1625 // TODO : Clean up any internal data structures using this obj.
1626 return result;
1627}
1628
Cody Northrope4bc6942015-08-26 10:01:32 -06001629VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicLineWidthState(VkDevice device, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001630{
Cody Northrope4bc6942015-08-26 10:01:32 -06001631 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicLineWidthState(device, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06001632 // TODO : Clean up any internal data structures using this obj.
1633 return result;
1634}
1635
Cody Northrope4bc6942015-08-26 10:01:32 -06001636VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthBiasState(VkDevice device, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001637{
Cody Northrope4bc6942015-08-26 10:01:32 -06001638 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBiasState(device, dynamicDepthBiasState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001639 // TODO : Clean up any internal data structures using this obj.
1640 return result;
1641}
1642
Cody Northrope4bc6942015-08-26 10:01:32 -06001643VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicBlendState(VkDevice device, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001644{
Cody Northrope4bc6942015-08-26 10:01:32 -06001645 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicBlendState(device, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001646 // TODO : Clean up any internal data structures using this obj.
1647 return result;
1648}
1649
Cody Northrope4bc6942015-08-26 10:01:32 -06001650VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthBoundsState(VkDevice device, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001651{
Cody Northrope4bc6942015-08-26 10:01:32 -06001652 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBoundsState(device, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06001653 // TODO : Clean up any internal data structures using this obj.
1654 return result;
1655}
1656
1657VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicStencilState(VkDevice device, VkDynamicStencilState dynamicStencilState)
1658{
1659 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicStencilState(device, dynamicStencilState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001660 // TODO : Clean up any internal data structures using this obj.
1661 return result;
1662}
1663
1664VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1665{
1666 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1667 // TODO : Clean up any internal data structures using this obj.
1668 return result;
1669}
1670
1671VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1672{
1673 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1674 // TODO : Clean up any internal data structures using this obj.
1675 return result;
1676}
1677
1678VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1679{
1680 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1681 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001682 return result;
1683}
1684
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001685VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* 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)->CreateBufferView(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);
1690 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1691 pNewNode->buffer = *pView;
1692 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001693 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001694 loader_platform_thread_unlock_mutex(&globalLock);
1695 }
1696 return result;
1697}
1698
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001699VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001700{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001701 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001702 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001703 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001704 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001705 loader_platform_thread_unlock_mutex(&globalLock);
1706 }
1707 return result;
1708}
1709
Jon Ashburn0d60d272015-07-09 15:02:25 -06001710//TODO handle pipeline caches
1711VkResult VKAPI vkCreatePipelineCache(
1712 VkDevice device,
1713 const VkPipelineCacheCreateInfo* pCreateInfo,
1714 VkPipelineCache* pPipelineCache)
1715{
1716 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1717 return result;
1718}
1719
1720VkResult VKAPI vkDestroyPipelineCache(
1721 VkDevice device,
1722 VkPipelineCache pipelineCache)
1723{
1724 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1725 return result;
1726}
1727
1728size_t VKAPI vkGetPipelineCacheSize(
1729 VkDevice device,
1730 VkPipelineCache pipelineCache)
1731{
1732 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1733 return size;
1734}
1735
1736VkResult VKAPI vkGetPipelineCacheData(
1737 VkDevice device,
1738 VkPipelineCache pipelineCache,
1739 void* pData)
1740{
1741 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1742 return result;
1743}
1744
1745VkResult VKAPI vkMergePipelineCaches(
1746 VkDevice device,
1747 VkPipelineCache destCache,
1748 uint32_t srcCacheCount,
1749 const VkPipelineCache* pSrcCaches)
1750{
1751 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1752 return result;
1753}
1754
1755VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001756{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001757 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001758 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001759 // The order of operations here is a little convoluted but gets the job done
1760 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1761 // 2. Create state is then validated (which uses flags setup during shadowing)
1762 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1763 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001764 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001765 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001766 loader_platform_thread_unlock_mutex(&globalLock);
1767 if (VK_TRUE == valid) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001768 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001769 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1770 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001771 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001772 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001773 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001774 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001775 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001776 if (pPipeNode) {
1777 // If we allocated a pipeNode, need to clean it up here
1778 delete[] pPipeNode->pVertexBindingDescriptions;
1779 delete[] pPipeNode->pVertexAttributeDescriptions;
1780 delete[] pPipeNode->pAttachments;
1781 delete pPipeNode;
1782 }
1783 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001784 return result;
1785}
1786
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001787VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001788{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001789 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001790 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001791 loader_platform_thread_lock_mutex(&globalLock);
1792 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1793 pNewNode->sampler = *pSampler;
1794 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001795 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001796 loader_platform_thread_unlock_mutex(&globalLock);
1797 }
1798 return result;
1799}
1800
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001801VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001802{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001803 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001804 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001805 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1806 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001807 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001808 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001809 }
1810 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001811 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1812 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1813 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001815 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001816 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001817 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001818 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001819 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1820 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001821 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001822 }
1823 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001824 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001825 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001826 uint32_t j = 0;
1827 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001828 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001829 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001830 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001831 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001832 }
1833 }
1834 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001836 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1837 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001838 // Put new node at Head of global Layer list
1839 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001840 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001841 loader_platform_thread_unlock_mutex(&globalLock);
1842 }
1843 return result;
1844}
1845
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001846VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001848 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001849 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001850 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001851 }
1852 return result;
1853}
1854
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001855VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001856{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001857 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001858 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001859 // Insert this pool into Global Pool LL at head
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001860 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1861 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001863 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001864 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001865 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001866 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001867 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001868 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001869 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1870 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001872 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1873 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001874 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1875 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001876 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001877 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001878 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001879 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001880 }
1881 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001882 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001883 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001884 }
1885 return result;
1886}
1887
Mike Stroyan230e6252015-04-17 12:36:38 -06001888VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001889{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001890 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001891 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001892 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001893 }
1894 return result;
1895}
1896
Cody Northropc8aa4a52015-08-03 12:47:29 -06001897VK_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 -06001898{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001899 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1900 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001901 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1902 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001903 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1904 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001905 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001906 if (count == 0) {
1907 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1908 "AllocDescriptorSets called with 0 count");
1909 }
1910 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001911 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1912 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001913 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001914 SET_NODE* pNewNode = new SET_NODE;
1915 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001916 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001917 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001918 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001919 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001920 // Insert set at head of Set LL for this pool
1921 pNewNode->pNext = pPoolNode->pSets;
1922 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001923 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1924 if (NULL == pLayout) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001925 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1926 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001927 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001928 pNewNode->pLayout = pLayout;
1929 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001930 pNewNode->set = pDescriptorSets[i];
1931 pNewNode->setUsage = setUsage;
1932 pNewNode->descriptorCount = pLayout->endIndex + 1;
1933 if (pNewNode->descriptorCount) {
1934 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1935 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1936 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1937 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001938 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001939 }
1940 }
1941 }
1942 }
1943 return result;
1944}
1945
Tony Barbourb857d312015-07-10 10:50:45 -06001946VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1947{
1948 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1949 // TODO : Clean up any internal data structures using this obj.
1950 return result;
1951}
1952
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001953VK_LAYER_EXPORT VkResult VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001954{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001955 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1956 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001957 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001958 }
1959 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001960}
1961
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001962VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001963{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001964 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001965 VkDynamicViewportStateCreateInfo local_ci;
1966 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1967 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1968 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1969 loader_platform_thread_lock_mutex(&globalLock);
1970 dynamicVpStateMap[pState->handle] = local_ci;
1971 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001972 return result;
1973}
1974
Cody Northrope4bc6942015-08-26 10:01:32 -06001975VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicLineWidthState(VkDevice device, const VkDynamicLineWidthStateCreateInfo* pCreateInfo, VkDynamicLineWidthState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001976{
Cody Northrope4bc6942015-08-26 10:01:32 -06001977 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicLineWidthState(device, pCreateInfo, pState);
1978 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_LINE_WIDTH);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001979 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001980 dynamicLineWidthStateMap[pState->handle] = *pCreateInfo;
Cody Northropf5bd2252015-08-17 11:10:49 -06001981 loader_platform_thread_unlock_mutex(&globalLock);
1982 return result;
1983}
1984
Cody Northrope4bc6942015-08-26 10:01:32 -06001985VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBiasState(VkDevice device, const VkDynamicDepthBiasStateCreateInfo* pCreateInfo, VkDynamicDepthBiasState* pState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001986{
Cody Northrope4bc6942015-08-26 10:01:32 -06001987 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBiasState(device, pCreateInfo, pState);
1988 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BIAS);
Cody Northropf5bd2252015-08-17 11:10:49 -06001989 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001990 dynamicDepthBiasStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001991 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001992 return result;
1993}
1994
Cody Northrope4bc6942015-08-26 10:01:32 -06001995VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicBlendState(VkDevice device, const VkDynamicBlendStateCreateInfo* pCreateInfo, VkDynamicBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001996{
Cody Northrope4bc6942015-08-26 10:01:32 -06001997 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicBlendState(device, pCreateInfo, pState);
1998 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_BLEND);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001999 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002000 dynamicBlendStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002001 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002002 return result;
2003}
2004
Cody Northrope4bc6942015-08-26 10:01:32 -06002005VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBoundsState(VkDevice device, const VkDynamicDepthBoundsStateCreateInfo* pCreateInfo, VkDynamicDepthBoundsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002006{
Cody Northrope4bc6942015-08-26 10:01:32 -06002007 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBoundsState(device, pCreateInfo, pState);
2008 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BOUNDS);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002009 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002010 dynamicDepthBoundsStateMap[pState->handle] = *pCreateInfo;
Cody Northrop2605cb02015-08-18 15:21:16 -06002011 loader_platform_thread_unlock_mutex(&globalLock);
2012 return result;
2013}
2014
2015VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicStencilState(VkDevice device, const VkDynamicStencilStateCreateInfo* pCreateInfoFront, const VkDynamicStencilStateCreateInfo* pCreateInfoBack, VkDynamicStencilState* pState)
2016{
2017 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicStencilState(device, pCreateInfoFront, pCreateInfoBack, pState);
2018 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_STENCIL);
2019 loader_platform_thread_lock_mutex(&globalLock);
2020
2021 // Bug 14406 - If back is NULL or equal to front, then single sided.
2022 // To support NULL case, simply track front twice
2023 const VkDynamicStencilStateCreateInfo* pLocalCreateInfoBack = (pCreateInfoBack == NULL) ? pCreateInfoFront : pCreateInfoBack;
2024
2025 std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo> infos(*pCreateInfoFront, *pLocalCreateInfoBack);
2026 dynamicStencilStateMap[pState->handle] = infos;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002027 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002028 return result;
2029}
2030
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002031VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002032{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002033 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002034 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002035 loader_platform_thread_lock_mutex(&globalLock);
2036 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2037 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2038 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002039 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002040 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002041 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002042 cmdBufferMap[*pCmdBuffer] = pCB;
2043 loader_platform_thread_unlock_mutex(&globalLock);
2044 updateCBTracking(*pCmdBuffer);
2045 }
2046 return result;
2047}
2048
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002049VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002050{
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
2057 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2058 "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
2063 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2064 "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
2070 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
2071 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002072 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002073 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002074 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002075 if (CB_NEW != pCB->state)
2076 resetCB(cmdBuffer);
2077 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002078 updateCBTracking(cmdBuffer);
2079 }
2080 return result;
2081}
2082
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002083VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002084{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002085 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2086 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2087 if (pCB) {
2088 if (pCB->state == CB_UPDATE_ACTIVE) {
2089 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2090 if (VK_SUCCESS == result) {
2091 updateCBTracking(cmdBuffer);
2092 pCB->state = CB_UPDATE_COMPLETE;
2093 // Reset CB status flags
2094 pCB->status = 0;
2095 printCB(cmdBuffer);
2096 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002097 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002098 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002099 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002100 }
2101 return result;
2102}
2103
Cody Northropf02f9f82015-07-09 18:08:05 -06002104VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002105{
Cody Northropf02f9f82015-07-09 18:08:05 -06002106 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002107 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002108 resetCB(cmdBuffer);
2109 updateCBTracking(cmdBuffer);
2110 }
2111 return result;
2112}
2113
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002114VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002115{
2116 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2117 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002118 if (pCB->state == CB_UPDATE_ACTIVE) {
2119 updateCBTracking(cmdBuffer);
2120 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002121 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002122 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2123 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002124 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002125 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2126 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002127 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002128 PIPELINE_NODE* pPN = getPipeline(pipeline);
2129 if (pPN) {
2130 pCB->lastBoundPipeline = pipeline;
2131 loader_platform_thread_lock_mutex(&globalLock);
2132 set_cb_pso_status(pCB, pPN);
2133 g_lastBoundPipeline = pPN;
2134 loader_platform_thread_unlock_mutex(&globalLock);
2135 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2136 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2137 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002138 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2139 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002140 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002141 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002142 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002143 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002144 }
2145 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002146}
2147
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002148VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002149{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002150 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2151 if (pCB) {
2152 if (pCB->state == CB_UPDATE_ACTIVE) {
2153 updateCBTracking(cmdBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002154 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002155 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002156 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2157 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002158 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002159 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002160 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2161 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002162 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 -06002163 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002164 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002165 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2166 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002167 }
2168 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002169 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002170 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002171 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002172 }
2173 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002174}
Cody Northrope4bc6942015-08-26 10:01:32 -06002175VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(VkCmdBuffer cmdBuffer, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002176{
2177 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2178 if (pCB) {
2179 if (pCB->state == CB_UPDATE_ACTIVE) {
2180 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002181 addCmd(pCB, CMD_BINDDYNAMICLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002182 if (!pCB->activeRenderPass) {
2183 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 -06002184 "Incorrect call to vkCmdBindDynamicLineWidthState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002185 }
2186 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002187 pCB->status |= CBSTATUS_LINE_WIDTH_BOUND;
2188 if (dynamicLineWidthStateMap.find(dynamicLineWidthState.handle) == dynamicLineWidthStateMap.end()) {
2189 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",
2190 "Unable to find VkDynamicLineWidthState object %#" PRIxLEAST64 ", was it ever created?", dynamicLineWidthState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002191 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002192 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
2193 g_lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002194 }
2195 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002196 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicLineWidthState(cmdBuffer, dynamicLineWidthState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002197 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002198 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002199 }
2200 }
2201}
Cody Northrope4bc6942015-08-26 10:01:32 -06002202VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(VkCmdBuffer cmdBuffer, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06002203{
2204 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2205 if (pCB) {
2206 if (pCB->state == CB_UPDATE_ACTIVE) {
2207 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002208 addCmd(pCB, CMD_BINDDYNAMICDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002209 if (!pCB->activeRenderPass) {
2210 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 -06002211 "Incorrect call to vkCmdBindDynamicDepthBiasState() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002212 }
2213 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002214 pCB->status |= CBSTATUS_DEPTH_BIAS_BOUND;
2215 if (dynamicDepthBiasStateMap.find(dynamicDepthBiasState.handle) == dynamicDepthBiasStateMap.end()) {
2216 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",
2217 "Unable to find VkDynamicDepthBiasState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBiasState.handle);
Cody Northropf5bd2252015-08-17 11:10:49 -06002218 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002219 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
2220 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
Cody Northropf5bd2252015-08-17 11:10:49 -06002221 }
2222 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002223 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBiasState(cmdBuffer, dynamicDepthBiasState);
Cody Northropf5bd2252015-08-17 11:10:49 -06002224 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002225 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBiasState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002226 }
2227 }
2228}
Cody Northrope4bc6942015-08-26 10:01:32 -06002229VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicBlendState(VkCmdBuffer cmdBuffer, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002230{
2231 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2232 if (pCB) {
2233 if (pCB->state == CB_UPDATE_ACTIVE) {
2234 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002235 addCmd(pCB, CMD_BINDDYNAMICBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002236 if (!pCB->activeRenderPass) {
2237 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 -06002238 "Incorrect call to vkCmdBindDynamicBlendState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002239 }
2240 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002241 pCB->status |= CBSTATUS_BLEND_BOUND;
2242 if (dynamicBlendStateMap.find(dynamicBlendState.handle) == dynamicBlendStateMap.end()) {
2243 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_BLEND_STATE, dynamicBlendState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
2244 "Unable to find VkDynamicBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicBlendState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002245 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002246 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
2247 g_lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002248 }
2249 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002250 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicBlendState(cmdBuffer, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002251 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002252 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicBlendState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002253 }
2254 }
2255}
Cody Northrope4bc6942015-08-26 10:01:32 -06002256VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(VkCmdBuffer cmdBuffer, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002257{
2258 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2259 if (pCB) {
2260 if (pCB->state == CB_UPDATE_ACTIVE) {
2261 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002262 addCmd(pCB, CMD_BINDDYNAMICDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002263 if (!pCB->activeRenderPass) {
2264 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 -06002265 "Incorrect call to vkCmdBindDynamicDepthBoundsState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002266 }
2267 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002268 pCB->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
2269 if (dynamicDepthBoundsStateMap.find(dynamicDepthBoundsState.handle) == dynamicDepthBoundsStateMap.end()) {
2270 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",
2271 "Unable to find VkDynamicDepthBoundsState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBoundsState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002272 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002273 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
2274 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002275 }
2276 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002277 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBoundsState(cmdBuffer, dynamicDepthBoundsState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002278 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002279 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBoundsState()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002280 }
2281 }
2282}
2283VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStencilState(VkCmdBuffer cmdBuffer, VkDynamicStencilState dynamicStencilState)
2284{
2285 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2286 if (pCB) {
2287 if (pCB->state == CB_UPDATE_ACTIVE) {
2288 updateCBTracking(cmdBuffer);
2289 addCmd(pCB, CMD_BINDDYNAMICSTENCILSTATE);
2290 if (!pCB->activeRenderPass) {
2291 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2292 "Incorrect call to vkCmdBindDynamicStencilState() without an active RenderPass.");
2293 }
2294 loader_platform_thread_lock_mutex(&globalLock);
2295 pCB->status |= CBSTATUS_STENCIL_BOUND;
2296 if (dynamicStencilStateMap.find(dynamicStencilState.handle) == dynamicStencilStateMap.end()) {
2297 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_STENCIL_STATE, dynamicStencilState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
2298 "Unable to find VkDynamicStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicStencilState.handle);
2299 } else {
2300 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2301 g_lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2302 }
2303 loader_platform_thread_unlock_mutex(&globalLock);
2304 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStencilState(cmdBuffer, dynamicStencilState);
2305 } else {
2306 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicStencilState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002307 }
2308 }
2309}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002310VK_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 -06002311{
2312 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2313 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002314 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002315 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002316 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2317 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002318 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002319 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 -06002320 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2321 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002322 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002323 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2324 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002325 loader_platform_thread_lock_mutex(&globalLock);
2326 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002327 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002328 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2329 g_lastBoundDescriptorSet = pDescriptorSets[i];
2330 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002331 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2332 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002333 if (!pSet->pUpdateStructs)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002334 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2335 "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 -06002336 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002337 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2338 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002339 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002340 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002341 updateCBTracking(cmdBuffer);
2342 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis9bde5922015-06-22 18:00:14 -06002343 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 -06002344 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002345 } else {
2346 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002347 }
2348 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002349}
2350
Tony Barbour8205d902015-04-16 15:59:00 -06002351VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002352{
2353 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2354 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002355 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002356 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002357 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 -06002358 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2359 } else {
2360 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2361 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002362 updateCBTracking(cmdBuffer);
2363 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002364 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2365 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002366 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002367 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2368 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002369 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002370}
2371
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002372VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2373 VkCmdBuffer cmdBuffer,
2374 uint32_t startBinding,
2375 uint32_t bindingCount,
2376 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002377 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002378{
2379 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2380 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002381 if (pCB->state == CB_UPDATE_ACTIVE) {
2382 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002383 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002384 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 -06002385 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2386 } else {
2387 pCB->lastVtxBinding = startBinding + bindingCount -1;
2388 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002389 updateCBTracking(cmdBuffer);
2390 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002391 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2392 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002393 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002394 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002395 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002396 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002397 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002398}
2399
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002400VK_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 -06002401{
2402 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002403 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002404 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002405 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002406 pCB->drawCount[DRAW]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002407 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002408 // TODO : Need to pass cmdBuffer as srcObj here
2409 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 -06002410 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2411 synchAndPrintDSConfig(cmdBuffer);
2412 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002413 updateCBTracking(cmdBuffer);
2414 addCmd(pCB, CMD_DRAW);
2415 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002416 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002417 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002418 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2419 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002420 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002421}
2422
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002423VK_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 -06002424{
2425 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002426 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002427 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002428 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002429 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002430 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002431 // TODO : Need to pass cmdBuffer as srcObj here
2432 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 -06002433 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2434 synchAndPrintDSConfig(cmdBuffer);
2435 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002436 updateCBTracking(cmdBuffer);
2437 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002438 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2439 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002440 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002441 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2442 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002443 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002444}
2445
Tony Barbour8205d902015-04-16 15:59:00 -06002446VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447{
2448 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002449 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002450 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002451 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002452 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002453 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002454 // TODO : Need to pass cmdBuffer as srcObj here
2455 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 -06002456 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2457 synchAndPrintDSConfig(cmdBuffer);
2458 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002459 updateCBTracking(cmdBuffer);
2460 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002461 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2462 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002463 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002464 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2465 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002466 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467}
2468
Tony Barbour8205d902015-04-16 15:59:00 -06002469VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470{
2471 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002472 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002473 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002474 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002475 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002476 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002477 // TODO : Need to pass cmdBuffer as srcObj here
2478 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002479 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2480 synchAndPrintDSConfig(cmdBuffer);
2481 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002482 updateCBTracking(cmdBuffer);
2483 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2484 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002485 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002486 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002487 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2488 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002489 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002490}
2491
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002492VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002493{
2494 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2495 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002496 if (pCB->state == CB_UPDATE_ACTIVE) {
2497 updateCBTracking(cmdBuffer);
2498 addCmd(pCB, CMD_DISPATCH);
2499 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002500 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002501 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2502 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002503 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002504}
2505
Tony Barbour8205d902015-04-16 15:59:00 -06002506VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002507{
2508 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2509 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002510 if (pCB->state == CB_UPDATE_ACTIVE) {
2511 updateCBTracking(cmdBuffer);
2512 addCmd(pCB, CMD_DISPATCHINDIRECT);
2513 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002514 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002515 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2516 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002517 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002518}
2519
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002520VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002521{
2522 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2523 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002524 if (pCB->state == CB_UPDATE_ACTIVE) {
2525 updateCBTracking(cmdBuffer);
2526 addCmd(pCB, CMD_COPYBUFFER);
2527 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002528 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002529 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2530 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002531 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002532}
2533
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002534VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2535 VkImage srcImage,
2536 VkImageLayout srcImageLayout,
2537 VkImage destImage,
2538 VkImageLayout destImageLayout,
2539 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002540{
2541 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2542 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002543 if (pCB->state == CB_UPDATE_ACTIVE) {
2544 updateCBTracking(cmdBuffer);
2545 addCmd(pCB, CMD_COPYIMAGE);
2546 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002547 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002548 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2549 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002550 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002551}
2552
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002553VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2554 VkImage srcImage, VkImageLayout srcImageLayout,
2555 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002556 uint32_t regionCount, const VkImageBlit* pRegions,
2557 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002558{
2559 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2560 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002561 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002562 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002563 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2564 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002565 } else {
2566 updateCBTracking(cmdBuffer);
2567 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002568 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002569 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002570 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002571 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2572 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002573 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002574}
2575
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002576VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2577 VkBuffer srcBuffer,
2578 VkImage destImage, VkImageLayout destImageLayout,
2579 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002580{
2581 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2582 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002583 if (pCB->state == CB_UPDATE_ACTIVE) {
2584 updateCBTracking(cmdBuffer);
2585 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2586 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002587 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002588 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2589 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002590 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002591}
2592
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002593VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2594 VkImage srcImage, VkImageLayout srcImageLayout,
2595 VkBuffer destBuffer,
2596 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002597{
2598 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2599 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002600 if (pCB->state == CB_UPDATE_ACTIVE) {
2601 updateCBTracking(cmdBuffer);
2602 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2603 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002604 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002605 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2606 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002607 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002608}
2609
Tony Barbour8205d902015-04-16 15:59:00 -06002610VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002611{
2612 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2613 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002614 if (pCB->state == CB_UPDATE_ACTIVE) {
2615 updateCBTracking(cmdBuffer);
2616 addCmd(pCB, CMD_UPDATEBUFFER);
2617 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002618 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002619 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2620 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002621 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002622}
2623
Tony Barbour8205d902015-04-16 15:59:00 -06002624VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002625{
2626 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2627 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002628 if (pCB->state == CB_UPDATE_ACTIVE) {
2629 updateCBTracking(cmdBuffer);
2630 addCmd(pCB, CMD_FILLBUFFER);
2631 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002632 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002633 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2634 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002635 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002636}
2637
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002638VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2639 VkCmdBuffer cmdBuffer,
2640 uint32_t colorAttachment,
2641 VkImageLayout imageLayout,
2642 const VkClearColorValue* pColor,
2643 uint32_t rectCount,
2644 const VkRect3D* pRects)
2645{
2646 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2647 if (pCB) {
2648 if (pCB->state == CB_UPDATE_ACTIVE) {
2649 // Warn if this is issued prior to Draw Cmd
2650 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002651 // TODO : cmdBuffer should be srcObj
2652 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 -06002653 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002654 " 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 -06002655 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002656 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002657 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 -06002658 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2659 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2660 } else {
2661 updateCBTracking(cmdBuffer);
2662 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2663 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2664 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002665 } else {
2666 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2667 }
2668 }
2669}
2670
2671VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2672 VkCmdBuffer cmdBuffer,
2673 VkImageAspectFlags imageAspectMask,
2674 VkImageLayout imageLayout,
2675 float depth,
2676 uint32_t stencil,
2677 uint32_t rectCount,
2678 const VkRect3D* pRects)
2679{
2680 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2681 if (pCB) {
2682 if (pCB->state == CB_UPDATE_ACTIVE) {
2683 // Warn if this is issued prior to Draw Cmd
2684 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002685 // TODO : cmdBuffer should be srcObj
2686 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 -06002687 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002688 " 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 -06002689 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002690 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002691 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 -06002692 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2693 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2694 } else {
2695 updateCBTracking(cmdBuffer);
2696 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2697 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2698 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002699 } else {
2700 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2701 }
2702 }
2703}
2704
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002705VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2706 VkCmdBuffer cmdBuffer,
2707 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002708 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002709 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002710{
2711 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2712 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002713 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002714 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002715 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 -06002716 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2717 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2718 } else {
2719 updateCBTracking(cmdBuffer);
2720 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2721 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2722 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002723 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002724 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2725 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002726 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002727}
2728
Chris Forbes2951d7d2015-06-22 17:21:59 +12002729VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002730 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002731 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002732 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002733{
2734 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2735 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002736 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002737 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002738 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 -06002739 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2740 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2741 } else {
2742 updateCBTracking(cmdBuffer);
2743 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2744 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2745 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002746 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002747 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2748 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002749 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002750}
2751
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002752VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2753 VkImage srcImage, VkImageLayout srcImageLayout,
2754 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002755 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002756{
2757 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2758 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002759 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002760 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002761 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2762 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002763 } else {
2764 updateCBTracking(cmdBuffer);
2765 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002766 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002767 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002768 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002769 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2770 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002771 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002772}
2773
Tony Barbourc2e987e2015-06-29 16:20:35 -06002774VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002775{
2776 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2777 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002778 if (pCB->state == CB_UPDATE_ACTIVE) {
2779 updateCBTracking(cmdBuffer);
2780 addCmd(pCB, CMD_SETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002781 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002782 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002783 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2784 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002785 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002786}
2787
Tony Barbourc2e987e2015-06-29 16:20:35 -06002788VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002789{
2790 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2791 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002792 if (pCB->state == CB_UPDATE_ACTIVE) {
2793 updateCBTracking(cmdBuffer);
2794 addCmd(pCB, CMD_RESETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002795 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002796 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002797 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2798 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002799 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002800}
2801
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002802VK_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 -06002803{
2804 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2805 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002806 if (pCB->state == CB_UPDATE_ACTIVE) {
2807 updateCBTracking(cmdBuffer);
2808 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002809 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002810 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002811 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2812 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002813 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002814}
2815
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002816VK_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 -06002817{
2818 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2819 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002820 if (pCB->state == CB_UPDATE_ACTIVE) {
2821 updateCBTracking(cmdBuffer);
2822 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter73a21d32015-07-12 13:20:05 -06002823 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002824 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002825 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2826 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002827 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002828}
2829
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002830VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002831{
2832 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2833 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002834 if (pCB->state == CB_UPDATE_ACTIVE) {
2835 updateCBTracking(cmdBuffer);
2836 addCmd(pCB, CMD_BEGINQUERY);
2837 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002838 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002839 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2840 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002841 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002842}
2843
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002844VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002845{
2846 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2847 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002848 if (pCB->state == CB_UPDATE_ACTIVE) {
2849 updateCBTracking(cmdBuffer);
2850 addCmd(pCB, CMD_ENDQUERY);
2851 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002852 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002853 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2854 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002855 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856}
2857
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002858VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002859{
2860 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2861 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002862 if (pCB->state == CB_UPDATE_ACTIVE) {
2863 updateCBTracking(cmdBuffer);
2864 addCmd(pCB, CMD_RESETQUERYPOOL);
2865 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002866 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002867 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2868 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002869 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002870}
2871
Tony Barbour8205d902015-04-16 15:59:00 -06002872VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002873{
2874 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2875 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002876 if (pCB->state == CB_UPDATE_ACTIVE) {
2877 updateCBTracking(cmdBuffer);
2878 addCmd(pCB, CMD_WRITETIMESTAMP);
2879 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002880 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002881 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2882 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002883 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002884}
2885
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002886VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002887{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002888 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002889 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002890 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002891 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002892 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002893 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2894 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002895 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002896 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002897 }
2898 return result;
2899}
2900
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002901VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002902{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002903 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002904 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002905 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002906 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002907 if (pCreateInfo->pAttachments) {
2908 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2909 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002910 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002911 if (pCreateInfo->pSubpasses) {
2912 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2913 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2914
2915 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2916 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2917 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002918 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002919 subpass->preserveCount;
2920 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2921
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002922 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002923 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002924 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002925 attachments += subpass->inputCount;
2926
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002927 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002928 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002929 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002930 attachments += subpass->colorCount;
2931
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002932 if (subpass->pResolveAttachments) {
2933 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002934 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002935 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002936 attachments += subpass->colorCount;
2937 }
2938
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002939 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002940 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002941 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002942 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002943 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002944 if (pCreateInfo->pDependencies) {
2945 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2946 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002947 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002948 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002949 }
2950 return result;
2951}
2952
Chia-I Wuc278df82015-07-07 11:50:03 +08002953VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002954{
2955 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2956 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002957 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002958 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002959 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2960 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002961 } else {
2962 updateCBTracking(cmdBuffer);
2963 addCmd(pCB, CMD_BEGINRENDERPASS);
2964 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002965 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002966 pCB->framebuffer = pRenderPassBegin->framebuffer;
2967 if (pCB->lastBoundPipeline) {
2968 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2969 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002970 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002971 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002972 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002973 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002974 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002975 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002976 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002977}
2978
Chia-I Wuc278df82015-07-07 11:50:03 +08002979VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2980{
2981 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2982 if (pCB) {
2983 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002984 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 +08002985 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2986 } else {
2987 updateCBTracking(cmdBuffer);
2988 addCmd(pCB, CMD_NEXTSUBPASS);
2989 pCB->activeSubpass++;
2990 if (pCB->lastBoundPipeline) {
2991 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2992 }
2993 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2994 }
2995 }
2996}
2997
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002998VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002999{
3000 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3001 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003002 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003003 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 +08003004 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06003005 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003006 updateCBTracking(cmdBuffer);
3007 addCmd(pCB, CMD_ENDRENDERPASS);
3008 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08003009 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003010 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
3011 }
3012 }
3013}
3014
3015VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3016{
3017 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3018 if (pCB) {
3019 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003020 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 +08003021 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
3022 } else {
3023 updateCBTracking(cmdBuffer);
3024 addCmd(pCB, CMD_EXECUTECOMMANDS);
3025 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003026 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003027 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003028}
3029
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003030VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3031 VkInstance instance,
3032 VkFlags msgFlags,
3033 const PFN_vkDbgMsgCallback pfnMsgCallback,
3034 void* pUserData,
3035 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003036{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003037 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003038 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3039 if (VK_SUCCESS == res) {
3040 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3041 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3042 }
3043 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003044}
3045
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003046VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3047 VkInstance instance,
3048 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003049{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003050 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003051 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3052 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3053 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3054 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003055}
3056
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003057VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003058{
3059 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003060 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3061 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003062 // TODO : cmdBuffer should be srcObj
3063 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 -06003064 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003065 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003066 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003067 updateCBTracking(cmdBuffer);
3068 addCmd(pCB, CMD_DBGMARKERBEGIN);
3069 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003070 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003071}
3072
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003073VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003074{
3075 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003076 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3077 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003078 // TODO : cmdBuffer should be srcObj
3079 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 -06003080 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003081 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003082 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003083 updateCBTracking(cmdBuffer);
3084 addCmd(pCB, CMD_DBGMARKEREND);
3085 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003086 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
3087}
3088
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003089//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3090//{
3091// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3092// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3093// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3094// "Attempt to use DbgSetObjectTag but extension disabled!");
3095// return VK_ERROR_UNAVAILABLE;
3096// }
3097// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3098//}
3099//
3100//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3101//{
3102// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3103// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3104// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3105// "Attempt to use DbgSetObjectName but extension disabled!");
3106// return VK_ERROR_UNAVAILABLE;
3107// }
3108// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3109//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003110
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003111VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003112{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003113 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003114 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003115
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003116 /* loader uses this to force layer initialization; device object is wrapped */
3117 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003118 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003120 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003121 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003122 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003123 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003124 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003125 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003126 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003127 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003128 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003129 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003130 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003131 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003132 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003133 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003134 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003135 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003136 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003137 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003138 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003139 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003140 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003141 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003142 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003143 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003144 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003145 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003146 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003147 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003148 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003149 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003150 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003151 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003152 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003153 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003154 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003155 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003156 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003157 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003158 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003159 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003160 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003161 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003162 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003163 if (!strcmp(funcName, "vkDestroyDynamicLineWidthState"))
3164 return (PFN_vkVoidFunction) vkDestroyDynamicLineWidthState;
3165 if (!strcmp(funcName, "vkDestroyDynamicDepthBiasState"))
3166 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBiasState;
3167 if (!strcmp(funcName, "vkDestroyDynamicBlendState"))
3168 return (PFN_vkVoidFunction) vkDestroyDynamicBlendState;
3169 if (!strcmp(funcName, "vkDestroyDynamicDepthBoundsState"))
3170 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003171 if (!strcmp(funcName, "vkDestroyDynamicStencilState"))
3172 return (PFN_vkVoidFunction) vkDestroyDynamicStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003173 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003174 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003175 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003176 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003177 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003178 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003179 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003180 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003181 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003182 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003183 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003184 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003185 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003186 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003187 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003188 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003189 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003190 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003191 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003192 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003193 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003194 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003195 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003196 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003197 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003198 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003199 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003200 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003201 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003202 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003203 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003204 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003205 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003206 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003207 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003208 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003209 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003210 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003211 if (!strcmp(funcName, "vkCreateDynamicLineWidthState"))
3212 return (PFN_vkVoidFunction) vkCreateDynamicLineWidthState;
3213 if (!strcmp(funcName, "vkCreateDynamicDepthBiasState"))
3214 return (PFN_vkVoidFunction) vkCreateDynamicDepthBiasState;
3215 if (!strcmp(funcName, "vkCreateDynamicBlendState"))
3216 return (PFN_vkVoidFunction) vkCreateDynamicBlendState;
3217 if (!strcmp(funcName, "vkCreateDynamicDepthBoundsState"))
3218 return (PFN_vkVoidFunction) vkCreateDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003219 if (!strcmp(funcName, "vkCreateDynamicStencilState"))
3220 return (PFN_vkVoidFunction) vkCreateDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003221 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003222 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003223 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003224 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003225 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003226 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003227 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003228 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003229 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003230 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003231 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003232 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003233 if (!strcmp(funcName, "vkCmdBindDynamicLineWidthState"))
3234 return (PFN_vkVoidFunction) vkCmdBindDynamicLineWidthState;
3235 if (!strcmp(funcName, "vkCmdBindDynamicDepthBiasState"))
3236 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBiasState;
3237 if (!strcmp(funcName, "vkCmdBindDynamicBlendState"))
3238 return (PFN_vkVoidFunction) vkCmdBindDynamicBlendState;
3239 if (!strcmp(funcName, "vkCmdBindDynamicDepthBoundsState"))
3240 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003241 if (!strcmp(funcName, "vkCmdBindDynamicStencilState"))
3242 return (PFN_vkVoidFunction) vkCmdBindDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003243 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003244 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003245 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003246 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003247 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003248 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003249 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003250 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003251 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003252 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003253 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003254 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003255 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003256 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003257 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003258 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003259 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003260 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003261 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003262 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003263 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003264 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003265 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003266 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003267 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003268 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003269 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003270 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003271 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003272 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003273 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003274 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003275 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003276 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003277 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003278 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003279 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003280 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003281 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003282 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003283 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003284 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003285 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003286 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003287 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003288 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003289 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003290 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003291 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003292 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003293 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003294 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003295 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003296 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003297 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003298 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003299 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003300 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003301 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003302 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003303 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003304 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003305 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003306 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003307 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003308 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003309
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003310 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3311 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003312 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003313 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003314 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003315 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003316 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003317// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3318// return (void*) vkDbgSetObjectTag;
3319// if (!strcmp(funcName, "vkDbgSetObjectName"))
3320// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003321 }
3322 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003323 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003324 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003325 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003326 }
3327}
3328
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003329VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003330{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003331 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003332 if (instance == NULL)
3333 return NULL;
3334
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003335 /* loader uses this to force layer initialization; instance object is wrapped */
3336 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003337 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003338 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003339 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003340 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003341 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003342 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003343 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003344 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003345 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003346 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003347 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003348 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003349 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003350 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003351 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003352
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003353 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3354 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003355 if (fptr)
3356 return fptr;
3357
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003358 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003359 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003360 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003361 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003362 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003363 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003364}