blob: 02f2e10877b368fd08ea5ea326b43fe19401578d [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 Ehlise4076782015-06-24 15:53:07 -0600439 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600440 result = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600441 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 -0600442 "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 -0600443 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600444 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600445 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 -0600446 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
447 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600448 return result;
449}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600450// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600451static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600452{
453 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600454 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600455 loader_platform_thread_unlock_mutex(&globalLock);
456 return NULL;
457 }
458 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600459 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600460}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600461// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600462static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600463{
464 // VS is required
465 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600466 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 -0600467 "Invalid Pipeline CreateInfo State: Vtx Shader required");
468 return VK_FALSE;
469 }
470 // Either both or neither TC/TE shaders should be defined
471 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
472 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600473 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 -0600474 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
475 return VK_FALSE;
476 }
477 // Compute shaders should be specified independent of Gfx shaders
478 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
479 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
480 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
481 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600482 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 -0600483 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
484 return VK_FALSE;
485 }
486 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
487 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
488 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
489 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600490 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600491 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
492 return VK_FALSE;
493 }
494 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
495 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600496 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 -0600497 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
498 return VK_FALSE;
499 }
500 return VK_TRUE;
501}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600502// Init the pipeline mapping info based on pipeline create info LL tree
503// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600504static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600505{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600506 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
507 if (pBasePipeline) {
508 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600509 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600510 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
511 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600512 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600513 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600514 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600515
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600516 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600517 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600518 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600519
520 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
521 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
522
523 switch (pPSSCI->stage) {
524 case VK_SHADER_STAGE_VERTEX:
525 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
526 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600527 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600528 case VK_SHADER_STAGE_TESS_CONTROL:
529 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
530 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600531 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600532 case VK_SHADER_STAGE_TESS_EVALUATION:
533 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
534 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600535 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600536 case VK_SHADER_STAGE_GEOMETRY:
537 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
538 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600539 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600540 case VK_SHADER_STAGE_FRAGMENT:
541 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
542 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600543 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600544 case VK_SHADER_STAGE_COMPUTE:
545 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
546 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600547 break;
548 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600549 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600550 break;
551 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600552 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600553
554 if (pCreateInfo->pVertexInputState != NULL) {
555 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
556 // Copy embedded ptrs
557 pVICI = pCreateInfo->pVertexInputState;
558 pPipeline->vtxBindingCount = pVICI->bindingCount;
559 if (pPipeline->vtxBindingCount) {
560 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
561 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
562 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
563 }
564 pPipeline->vtxAttributeCount = pVICI->attributeCount;
565 if (pPipeline->vtxAttributeCount) {
566 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
567 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
568 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
569 }
570 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
571 }
Tony Barboure307f582015-07-10 15:29:03 -0600572 if (pCreateInfo->pInputAssemblyState != NULL) {
573 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
574 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600575 }
Tony Barboure307f582015-07-10 15:29:03 -0600576 if (pCreateInfo->pTessellationState != NULL) {
577 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
578 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600579 }
Tony Barboure307f582015-07-10 15:29:03 -0600580 if (pCreateInfo->pViewportState != NULL) {
581 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
582 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600583 }
Tony Barboure307f582015-07-10 15:29:03 -0600584 if (pCreateInfo->pRasterState != NULL) {
585 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
586 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600587 }
Tony Barboure307f582015-07-10 15:29:03 -0600588 if (pCreateInfo->pMultisampleState != NULL) {
589 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
590 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600591 }
Tony Barboure307f582015-07-10 15:29:03 -0600592 if (pCreateInfo->pColorBlendState != NULL) {
593 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600594 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600595 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600596 pPipeline->attachmentCount = pCBCI->attachmentCount;
597 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600598 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
599 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600600 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
601 }
Tony Barboure307f582015-07-10 15:29:03 -0600602 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600603 }
Tony Barboure307f582015-07-10 15:29:03 -0600604 if (pCreateInfo->pDepthStencilState != NULL) {
605 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
606 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600607 }
608
609 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
610 if (pCreateInfo->stageCount != 0) {
611 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
612 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
613 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
614 }
615
Tobin Ehlisde63c532015-06-18 15:59:33 -0600616 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600617}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600618
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600619// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600620static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600621{
David Pinedof5997ab2015-04-27 16:36:17 -0600622 if (pipelineMap.size() <= 0)
623 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600624 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600625 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
626 delete[] (*ii).second->graphicsPipelineCI.pStages;
627 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600628 if ((*ii).second->pVertexBindingDescriptions) {
629 delete[] (*ii).second->pVertexBindingDescriptions;
630 }
631 if ((*ii).second->pVertexAttributeDescriptions) {
632 delete[] (*ii).second->pVertexAttributeDescriptions;
633 }
634 if ((*ii).second->pAttachments) {
635 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600636 }
637 delete (*ii).second;
638 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600639 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600640}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600641// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600642static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600643{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600644 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600645 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
646 return pPipe->msStateCI.rasterSamples;
647 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600648 return 1;
649}
650// Validate state related to the PSO
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600651static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600652{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600653 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600654 // Verify that any MSAA request in PSO matches sample# in bound FB
655 uint32_t psoNumSamples = getNumSamples(pipeline);
656 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600657 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800658 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
659 int subpassNumSamples = 0;
660 uint32_t i;
661
662 for (i = 0; i < pSD->colorCount; i++) {
663 uint32_t samples;
664
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600665 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800666 continue;
667
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600668 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800669 if (subpassNumSamples == 0) {
670 subpassNumSamples = samples;
671 } else if (subpassNumSamples != samples) {
672 subpassNumSamples = -1;
673 break;
674 }
675 }
676 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
677 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
678 if (subpassNumSamples == 0)
679 subpassNumSamples = samples;
680 else if (subpassNumSamples != samples)
681 subpassNumSamples = -1;
682 }
683
684 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600685 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
686 "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 -0600687 }
688 } else {
689 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
690 // Verify and flag error as appropriate
691 }
692 // TODO : Add more checks here
693 } else {
694 // TODO : Validate non-gfx pipeline updates
695 }
696}
697
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600698// Block of code at start here specifically for managing/tracking DSs
699
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600700// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600701static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600702{
703 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600704 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600705 loader_platform_thread_unlock_mutex(&globalLock);
706 return NULL;
707 }
708 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600709 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600710}
711// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600712static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600713{
714 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600715 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600716 loader_platform_thread_unlock_mutex(&globalLock);
717 return NULL;
718 }
719 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600720 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600721}
722
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600723static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600724 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600725 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600726 loader_platform_thread_unlock_mutex(&globalLock);
727 return NULL;
728 }
729 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600730 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600731}
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600732// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600733static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600734{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600735 switch (pUpdateStruct->sType)
736 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800737 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
738 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600739 return 1;
740 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600741 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 -0600742 "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 -0600743 return 0;
744 }
745}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600746// For given update struct, return binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600747static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600748{
749 switch (pUpdateStruct->sType)
750 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800751 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
752 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
753 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
754 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600755 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600756 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 -0600757 "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 -0600758 return 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600759 }
760}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600761// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600762static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600763{
764 switch (pUpdateStruct->sType)
765 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800766 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
767 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
768 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600769 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800770 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600771 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600772 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600773 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600774 return 0;
775 }
776}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600777// Return count for given update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600778static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600779{
780 switch (pUpdateStruct->sType)
781 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800782 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
783 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
784 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600785 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800786 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600787 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600788 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 -0600789 "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 -0600790 return 0;
791 }
792}
793// For given Layout Node and binding, return index where that binding begins
794static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
795{
796 uint32_t offsetIndex = 0;
797 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800798 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600799 }
800 return offsetIndex;
801}
802// For given layout node and binding, return last index that is updated
803static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
804{
805 uint32_t offsetIndex = 0;
806 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800807 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600808 }
809 return offsetIndex-1;
810}
811// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600812static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600813{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600814 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600815}
816// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlisde63c532015-06-18 15:59:33 -0600817static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600818{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600819 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600820}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600821// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600822static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600823{
824 // First get actual type of update
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600825 VkDescriptorType actualType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600826 uint32_t i = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600827 switch (pUpdateStruct->sType)
828 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800829 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
830 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600831 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800832 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
833 /* no need to validate */
834 return 1;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600835 break;
836 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600837 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 -0600838 "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 -0600839 return 0;
840 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600841 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600842 if (pLayout->pTypes[i] != actualType)
843 return 0;
844 }
845 return 1;
846}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600847// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
848// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
849// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600850static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600851{
852 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800853 VkWriteDescriptorSet* pWDS = NULL;
854 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600855 size_t array_size = 0;
856 size_t base_array_size = 0;
857 size_t total_array_size = 0;
858 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600859 switch (pUpdate->sType)
860 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800861 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
862 pWDS = new VkWriteDescriptorSet;
863 pNewNode = (GENERIC_HEADER*)pWDS;
864 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
865 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
866 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
867 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600868 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800869 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
870 pCDS = new VkCopyDescriptorSet;
871 pUpdate = (GENERIC_HEADER*)pCDS;
872 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600873 break;
874 default:
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600875 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 -0600876 "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 -0600877 return NULL;
878 }
879 // Make sure that pNext for the end of shadow copy is NULL
880 pNewNode->pNext = NULL;
881 return pNewNode;
882}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800883// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600884static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600885{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800886 const VkWriteDescriptorSet *pWDS = NULL;
887 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600888 VkBool32 result = 1;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800889
890 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
891 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
892 else
893 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
894
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600895 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600896 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600897 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600898 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600899 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600900 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800901 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600902 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800903 g_lastBoundDescriptorSet = pSet->set;
904 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600905 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600906 // First verify valid update struct
Tobin Ehlisde63c532015-06-18 15:59:33 -0600907 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600908 result = 0;
909 break;
910 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600911 // Make sure that binding is within bounds
Tobin Ehlisde63c532015-06-18 15:59:33 -0600912 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600913 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 -0600914 "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 -0600915 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600916 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600917 // Next verify that update falls within size of given binding
Tobin Ehlisde63c532015-06-18 15:59:33 -0600918 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour29b12062015-07-13 13:37:24 -0600919 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600920 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600921 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600922 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 -0600923 "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 -0600924 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600925 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600926 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlisde63c532015-06-18 15:59:33 -0600927 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600928 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 -0600929 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600930 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600931 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600932 // Save the update info
933 // TODO : Info message that update successful
934 // Create new update struct for this set's shadow copy
Tobin Ehlisde63c532015-06-18 15:59:33 -0600935 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600936 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600937 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 -0600938 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600939 result = 0;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600940 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600941 // Insert shadow node into LL of updates for this set
942 pNewNode->pNext = pSet->pUpdateStructs;
943 pSet->pUpdateStructs = pNewNode;
944 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlisde63c532015-06-18 15:59:33 -0600945 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600946 assert(j<pSet->descriptorCount);
947 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600948 }
949 }
950 }
951 }
952 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600953 }
954 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600955 return result;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600956}
957// Free the shadowed update node for this Set
958// NOTE : Calls to this function should be wrapped in mutex
959static void freeShadowUpdateTree(SET_NODE* pSet)
960{
961 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
962 pSet->pUpdateStructs = NULL;
963 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
964 // Clear the descriptor mappings as they will now be invalid
965 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
966 while(pShadowUpdate) {
967 pFreeUpdate = pShadowUpdate;
968 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
969 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800970 VkWriteDescriptorSet * pWDS = NULL;
971 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600972 void** ppToFree = NULL;
973 switch (pFreeUpdate->sType)
974 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800975 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
976 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
977 if (pWDS->pDescriptors)
978 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600979 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800980 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600981 break;
982 default:
983 assert(0);
984 break;
985 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600986 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600987 }
988}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600989// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600990// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600991static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600992{
David Pinedof5997ab2015-04-27 16:36:17 -0600993 if (poolMap.size() <= 0)
994 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600995 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600996 SET_NODE* pSet = (*ii).second->pSets;
997 SET_NODE* pFreeSet = pSet;
998 while (pSet) {
999 pFreeSet = pSet;
1000 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001001 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001002 // Free Update shadow struct tree
1003 freeShadowUpdateTree(pFreeSet);
1004 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001005 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001006 }
1007 delete pFreeSet;
1008 }
1009 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001010 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001011 }
1012 delete (*ii).second;
1013 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001014 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001015}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001016// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001018static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019{
David Pinedof5997ab2015-04-27 16:36:17 -06001020 if (layoutMap.size() <= 0)
1021 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001022 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001024 if (pLayout->createInfo.pBinding) {
1025 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1026 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1027 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1028 }
1029 delete[] pLayout->createInfo.pBinding;
1030 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001031 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001032 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001033 }
1034 delete pLayout;
1035 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001036 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001037}
1038// Currently clearing a set is removing all previous updates to that set
1039// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001040static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001041{
1042 SET_NODE* pSet = getSetNode(set);
1043 if (!pSet) {
1044 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001045 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001046 loader_platform_thread_lock_mutex(&globalLock);
1047 freeShadowUpdateTree(pSet);
1048 loader_platform_thread_unlock_mutex(&globalLock);
1049 }
1050}
1051
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001052static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001053{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001054 POOL_NODE* pPool = getPoolNode(pool);
1055 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001056 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1057 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001058 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001059 // For every set off of this pool, clear it
1060 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001061 while (pSet) {
1062 clearDescriptorSet(pSet->set);
1063 }
1064 }
1065}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001066// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001067static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001068{
1069 loader_platform_thread_lock_mutex(&globalLock);
1070 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1071 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001072 // TODO : How to pass cb as srcObj here?
1073 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 -06001074 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001075 return NULL;
1076 }
1077 loader_platform_thread_unlock_mutex(&globalLock);
1078 return cmdBufferMap[cb];
1079}
1080// Free all CB Nodes
1081// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001082static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001083{
David Pinedof5997ab2015-04-27 16:36:17 -06001084 if (cmdBufferMap.size() <= 0)
1085 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001086 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001087 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1088 while (!cmd_node_list.empty()) {
1089 CMD_NODE* cmd_node = cmd_node_list.back();
1090 delete cmd_node;
1091 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001092 }
1093 delete (*ii).second;
1094 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001095 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001096}
Tobin Ehlise42007c2015-06-19 13:00:59 -06001097static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1098{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001099 // TODO : How to pass cb as srcObj here?
1100 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 -06001101 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1102}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001103static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1104{
1105 CMD_NODE* pCmd = new CMD_NODE;
1106 if (pCmd) {
1107 // init cmd node and append to end of cmd LL
1108 memset(pCmd, 0, sizeof(CMD_NODE));
1109 pCmd->cmdNumber = ++pCB->numCmds;
1110 pCmd->type = cmd;
1111 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001112 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001113 // TODO : How to pass cb as srcObj here?
1114 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 -06001115 "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 -06001116 }
1117}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001119{
1120 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1121 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001122 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1123 while (!cmd_list.empty()) {
1124 delete cmd_list.back();
1125 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001126 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001127 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001128 // Reset CB state (need to save createInfo)
1129 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001130 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1131 pCB->cmdBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001132 pCB->createInfo = saveCBCI;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001133 pCB->lastVtxBinding = MAX_BINDING;
1134 }
1135}
Tobin Ehlis97866202015-06-10 12:57:07 -06001136// Set PSO-related status bits for CB
1137static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1138{
1139 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1140 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1141 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1142 }
1143 }
1144 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06001145 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1146 }
1147
1148 if (pPipe->dsStateCI.stencilTestEnable) {
1149 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001150 }
1151}
1152// Set dyn-state related status bits for an object node
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001153static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlis97866202015-06-10 12:57:07 -06001154 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1155 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
Cody Northrope4bc6942015-08-26 10:01:32 -06001156 } else if (stateBindPoint == VK_STATE_BIND_POINT_LINE_WIDTH) {
1157 pNode->status |= CBSTATUS_LINE_WIDTH_BOUND;
1158 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BIAS) {
1159 pNode->status |= CBSTATUS_DEPTH_BIAS_BOUND;
1160 } else if (stateBindPoint == VK_STATE_BIND_POINT_BLEND) {
1161 pNode->status |= CBSTATUS_BLEND_BOUND;
1162 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BOUNDS) {
1163 pNode->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
Cody Northrop2605cb02015-08-18 15:21:16 -06001164 } else if (stateBindPoint == VK_STATE_BIND_POINT_STENCIL) {
1165 pNode->status |= CBSTATUS_STENCIL_BOUND;
Tobin Ehlis97866202015-06-10 12:57:07 -06001166 }
1167}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001168// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001169static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001170{
1171 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1172 if (pCB) {
1173 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1174 if (!pPipeTrav) {
1175 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001176 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001177 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001178 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001179 }
1180 }
1181}
Tobin Ehlise90b1712015-05-27 14:30:06 -06001182// Verify bound Pipeline State Object
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001183static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001184{
1185 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1186 if (pCB && pCB->lastBoundPipeline) {
1187 // First verify that we have a Node for bound pipeline
1188 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001189 if (!pPipeTrav) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001190 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1191 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001192 return false;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001193 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001194 // Verify Vtx binding
1195 if (MAX_BINDING != pCB->lastVtxBinding) {
1196 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1197 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001198 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 -06001199 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001200 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001201 }
1202 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001203 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 -06001204 "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 -06001205 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001206 }
1207 }
1208 else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001209 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001210 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001211 }
1212 }
1213 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001214 return true;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001215 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06001216 return false;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001217}
1218// Print details of DS config to stdout
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001219static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001220{
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001221 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.
1222 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001223 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001224 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001225 POOL_NODE* pPool = getPoolNode(pSet->pool);
1226 // Print out pool details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001227 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1228 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001229 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001230 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001231 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001232 // Print out set details
1233 char prefix[10];
1234 uint32_t index = 0;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001235 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1236 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001237 LAYOUT_NODE* pLayout = pSet->pLayout;
1238 // Print layout details
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001239 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1240 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001241 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001242 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001243 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001244 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001245 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001246 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1247 if (pUpdate) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001248 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1249 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001250 sprintf(prefix, " [UC] ");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001251 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001252 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001253 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001254 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001255 if (0 != pSet->descriptorCount) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001256 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1257 "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 -06001258 } else {
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 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001261 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001262 }
1263 }
1264}
1265
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001266static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001267{
1268 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001269 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001270 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001271 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001272 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001273 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1274 // TODO : Need to pass cb as srcObj here
1275 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 -06001276 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001277 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001278 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001279 // Nothing to print
1280 }
1281}
1282
1283
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001284static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001285{
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001286 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
1287 return;
1288 }
Mark Lobodzinskifdb20cf2015-08-07 17:11:09 -06001289 printDSConfig(cb);
1290 printPipeline(cb);
1291 printDynamicState(cb);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001292}
1293
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001294static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001295{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001296 uint32_t report_flags = 0;
1297 uint32_t debug_action = 0;
1298 FILE *log_output = NULL;
1299 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001300 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001301 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1302 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001303
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001304 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001305 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001306 option_str = getLayerOption("DrawStateLogFilename");
1307 if (option_str)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001308 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001309 log_output = fopen(option_str, "w");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001310 }
Tobin Ehlisaf14e9f2015-09-01 11:59:36 -06001311 if (log_output == NULL) {
1312 if (option_str)
1313 cout << endl << "DrawState ERROR: Bad output filename specified: " << option_str << ". Writing to STDOUT instead" << endl << endl;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001314 log_output = stdout;
Tobin Ehlisaf14e9f2015-09-01 11:59:36 -06001315 }
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001316
1317 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 -06001318 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001319
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001320 if (!globalLockInitialized)
1321 {
1322 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001323 // suggestion is to call this during vkCreateInstance(), and then we
1324 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001325 // that the layer have per-instance locks. We need to come back and
1326 // address this soon.
1327 loader_platform_thread_create_mutex(&globalLock);
1328 globalLockInitialized = 1;
1329 }
1330}
1331
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001332VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1333{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001334 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001335 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1336
1337 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001338 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1339 my_data->report_data = debug_report_create_instance(
1340 pTable,
1341 *pInstance,
1342 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001343 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001344
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001345 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001346 }
1347 return result;
1348}
1349
Jon Ashburne0fa2282015-05-20 09:00:28 -06001350/* hook DestroyInstance to remove tableInstanceMap entry */
1351VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1352{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001353 dispatch_key key = get_dispatch_key(instance);
1354 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1355 VkResult res = pTable->DestroyInstance(instance);
1356
1357 // Clean up logging callback, if any
1358 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1359 if (my_data->logging_callback) {
1360 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1361 }
1362
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001363 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001364 layer_data_map.erase(pTable);
1365
1366 draw_state_instance_table_map.erase(key);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001367 return res;
1368}
1369
Jon Ashburnf0615e22015-05-25 14:11:37 -06001370static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1371{
Tony Barbour29b12062015-07-13 13:37:24 -06001372 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001373 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001374 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001375
1376 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001377 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001378 /* Found a matching extension name, mark it enabled and init dispatch table*/
1379 initDebugMarkerTable(device);
1380 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001381 }
1382
1383 }
1384}
1385
Tony Barbour8205d902015-04-16 15:59:00 -06001386VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001387{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001388 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1389 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001390 if (result == VK_SUCCESS) {
1391 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1392 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1393 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1394 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001395 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001396 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001397 return result;
1398}
1399
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001400VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001401{
1402 // Free all the memory
1403 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001404 deletePipelines();
1405 deleteSamplers();
1406 deleteImages();
1407 deleteBuffers();
1408 deleteCmdBuffers();
1409 deleteDynamicState();
1410 deletePools();
1411 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001412 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001413
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001414 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001415 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1416 VkResult result = pDisp->DestroyDevice(device);
1417 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001418 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001419 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001420 return result;
1421}
1422
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001423static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001424 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001425 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001426 VK_API_VERSION,
1427 VK_MAKE_VERSION(0, 1, 0),
1428 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001429 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001430};
1431
Tony Barbour426b9052015-06-24 16:06:58 -06001432VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001433 const char *pLayerName,
1434 uint32_t *pCount,
1435 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001436{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001437 /* DrawState does not have any global extensions */
1438 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1439}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001440
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001441VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1442 uint32_t *pCount,
1443 VkLayerProperties* pProperties)
1444{
1445 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1446 ds_global_layers,
1447 pCount, pProperties);
1448}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001449
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001450static const VkExtensionProperties ds_device_extensions[] = {
1451 {
1452 DEBUG_MARKER_EXTENSION_NAME,
1453 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001454 }
1455};
1456
1457static const VkLayerProperties ds_device_layers[] = {
1458 {
1459 "DrawState",
1460 VK_API_VERSION,
1461 VK_MAKE_VERSION(0, 1, 0),
1462 "Validation layer: DrawState",
1463 }
1464};
1465
1466VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1467 VkPhysicalDevice physicalDevice,
1468 const char* pLayerName,
1469 uint32_t* pCount,
1470 VkExtensionProperties* pProperties)
1471{
1472 /* Mem tracker does not have any physical device extensions */
1473 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1474 pCount, pProperties);
1475}
1476
1477VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1478 VkPhysicalDevice physicalDevice,
1479 uint32_t* pCount,
1480 VkLayerProperties* pProperties)
1481{
1482 /* Mem tracker's physical device layers are the same as global */
1483 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1484 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001485}
1486
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001487VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001488{
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001489 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001490 for (uint32_t i=0; i < cmdBufferCount; i++) {
1491 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001492 pCB = getCBNode(pCmdBuffers[i]);
1493 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001494 pCB->submitCount++; // increment submit count
1495 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
1496 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 -06001497 "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 -06001498 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001499 if (CB_UPDATE_COMPLETE != pCB->state) {
1500 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001501 // TODO : How to pass cb as srcObj?
1502 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 -06001503 "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 -06001504 loader_platform_thread_unlock_mutex(&globalLock);
1505 return VK_ERROR_UNKNOWN;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001506 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001507 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001508 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001509
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001510 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001511 return result;
1512}
1513
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001514VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001515{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001516 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1517 // TODO : Clean up any internal data structures using this obj.
1518 return result;
1519}
1520
1521VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1522{
1523 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1524 // TODO : Clean up any internal data structures using this obj.
1525 return result;
1526}
1527
1528VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1529{
1530 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1531 // TODO : Clean up any internal data structures using this obj.
1532 return result;
1533}
1534
1535VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1536{
1537 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1538 // TODO : Clean up any internal data structures using this obj.
1539 return result;
1540}
1541
1542VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1543{
1544 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1545 // TODO : Clean up any internal data structures using this obj.
1546 return result;
1547}
1548
1549VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1550{
1551 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1552 // TODO : Clean up any internal data structures using this obj.
1553 return result;
1554}
1555
1556VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1557{
1558 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1559 // TODO : Clean up any internal data structures using this obj.
1560 return result;
1561}
1562
1563VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1564{
1565 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1566 // TODO : Clean up any internal data structures using this obj.
1567 return result;
1568}
1569
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001570VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1571{
1572 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1573 // TODO : Clean up any internal data structures using this obj.
1574 return result;
1575}
1576
1577VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1578{
1579 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1580 // TODO : Clean up any internal data structures using this obj.
1581 return result;
1582}
1583
1584VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1585{
1586 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1587 // TODO : Clean up any internal data structures using this obj.
1588 return result;
1589}
1590
1591VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1592{
1593 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1594 // TODO : Clean up any internal data structures using this obj.
1595 return result;
1596}
1597
1598VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1599{
1600 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1601 // TODO : Clean up any internal data structures using this obj.
1602 return result;
1603}
1604
1605VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1606{
1607 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1608 // TODO : Clean up any internal data structures using this obj.
1609 return result;
1610}
1611
1612VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1613{
1614 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1615 // TODO : Clean up any internal data structures using this obj.
1616 return result;
1617}
1618
1619VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1620{
1621 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1622 // TODO : Clean up any internal data structures using this obj.
1623 return result;
1624}
1625
Cody Northrope4bc6942015-08-26 10:01:32 -06001626VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicLineWidthState(VkDevice device, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001627{
Cody Northrope4bc6942015-08-26 10:01:32 -06001628 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicLineWidthState(device, dynamicLineWidthState);
Cody Northropf5bd2252015-08-17 11:10:49 -06001629 // TODO : Clean up any internal data structures using this obj.
1630 return result;
1631}
1632
Cody Northrope4bc6942015-08-26 10:01:32 -06001633VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthBiasState(VkDevice device, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001634{
Cody Northrope4bc6942015-08-26 10:01:32 -06001635 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBiasState(device, dynamicDepthBiasState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001636 // TODO : Clean up any internal data structures using this obj.
1637 return result;
1638}
1639
Cody Northrope4bc6942015-08-26 10:01:32 -06001640VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicBlendState(VkDevice device, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001641{
Cody Northrope4bc6942015-08-26 10:01:32 -06001642 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicBlendState(device, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001643 // TODO : Clean up any internal data structures using this obj.
1644 return result;
1645}
1646
Cody Northrope4bc6942015-08-26 10:01:32 -06001647VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthBoundsState(VkDevice device, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001648{
Cody Northrope4bc6942015-08-26 10:01:32 -06001649 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBoundsState(device, dynamicDepthBoundsState);
Cody Northrop2605cb02015-08-18 15:21:16 -06001650 // TODO : Clean up any internal data structures using this obj.
1651 return result;
1652}
1653
1654VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicStencilState(VkDevice device, VkDynamicStencilState dynamicStencilState)
1655{
1656 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicStencilState(device, dynamicStencilState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001657 // TODO : Clean up any internal data structures using this obj.
1658 return result;
1659}
1660
1661VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1662{
1663 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1664 // TODO : Clean up any internal data structures using this obj.
1665 return result;
1666}
1667
1668VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1669{
1670 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1671 // TODO : Clean up any internal data structures using this obj.
1672 return result;
1673}
1674
1675VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1676{
1677 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1678 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679 return result;
1680}
1681
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001682VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001683{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001684 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001685 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001686 loader_platform_thread_lock_mutex(&globalLock);
1687 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1688 pNewNode->buffer = *pView;
1689 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001690 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001691 loader_platform_thread_unlock_mutex(&globalLock);
1692 }
1693 return result;
1694}
1695
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001696VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001697{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001698 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001699 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001700 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001701 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001702 loader_platform_thread_unlock_mutex(&globalLock);
1703 }
1704 return result;
1705}
1706
Jon Ashburn0d60d272015-07-09 15:02:25 -06001707//TODO handle pipeline caches
1708VkResult VKAPI vkCreatePipelineCache(
1709 VkDevice device,
1710 const VkPipelineCacheCreateInfo* pCreateInfo,
1711 VkPipelineCache* pPipelineCache)
1712{
1713 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1714 return result;
1715}
1716
1717VkResult VKAPI vkDestroyPipelineCache(
1718 VkDevice device,
1719 VkPipelineCache pipelineCache)
1720{
1721 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1722 return result;
1723}
1724
1725size_t VKAPI vkGetPipelineCacheSize(
1726 VkDevice device,
1727 VkPipelineCache pipelineCache)
1728{
1729 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1730 return size;
1731}
1732
1733VkResult VKAPI vkGetPipelineCacheData(
1734 VkDevice device,
1735 VkPipelineCache pipelineCache,
1736 void* pData)
1737{
1738 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1739 return result;
1740}
1741
1742VkResult VKAPI vkMergePipelineCaches(
1743 VkDevice device,
1744 VkPipelineCache destCache,
1745 uint32_t srcCacheCount,
1746 const VkPipelineCache* pSrcCaches)
1747{
1748 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1749 return result;
1750}
1751
1752VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001753{
Tobin Ehlisde63c532015-06-18 15:59:33 -06001754 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburn0d60d272015-07-09 15:02:25 -06001755 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlisde63c532015-06-18 15:59:33 -06001756 // The order of operations here is a little convoluted but gets the job done
1757 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1758 // 2. Create state is then validated (which uses flags setup during shadowing)
1759 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1760 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001761 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06001762 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001763 loader_platform_thread_unlock_mutex(&globalLock);
1764 if (VK_TRUE == valid) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001765 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001766 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1767 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001768 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001769 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001770 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001771 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001772 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -06001773 if (pPipeNode) {
1774 // If we allocated a pipeNode, need to clean it up here
1775 delete[] pPipeNode->pVertexBindingDescriptions;
1776 delete[] pPipeNode->pVertexAttributeDescriptions;
1777 delete[] pPipeNode->pAttachments;
1778 delete pPipeNode;
1779 }
1780 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001781 return result;
1782}
1783
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001784VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001785{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001786 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001787 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001788 loader_platform_thread_lock_mutex(&globalLock);
1789 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1790 pNewNode->sampler = *pSampler;
1791 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001792 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001793 loader_platform_thread_unlock_mutex(&globalLock);
1794 }
1795 return result;
1796}
1797
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001798VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001800 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001801 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001802 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1803 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001804 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 -06001805 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001806 }
1807 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001808 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1809 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1810 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001811 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001812 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001813 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001814 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001815 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001816 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1817 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001818 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001819 }
1820 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001821 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001822 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001823 uint32_t j = 0;
1824 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001825 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001826 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001827 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001828 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001829 }
1830 }
1831 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001832 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001833 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1834 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835 // Put new node at Head of global Layer list
1836 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001837 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001838 loader_platform_thread_unlock_mutex(&globalLock);
1839 }
1840 return result;
1841}
1842
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001843VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001845 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001846 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001847 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001848 }
1849 return result;
1850}
1851
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001852VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001853{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001854 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001855 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001856 // Insert this pool into Global Pool LL at head
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001857 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1858 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001859 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001860 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001861 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001862 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 -06001863 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001864 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001865 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001866 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1867 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001868 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001869 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1870 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1872 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001873 pNewNode->poolUsage = poolUsage;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001874 pNewNode->maxSets = maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001875 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001876 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001877 }
1878 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001879 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001880 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001881 }
1882 return result;
1883}
1884
Mike Stroyan230e6252015-04-17 12:36:38 -06001885VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001886{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001887 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001888 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001889 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001890 }
1891 return result;
1892}
1893
Cody Northropc8aa4a52015-08-03 12:47:29 -06001894VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001895{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001896 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1897 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001898 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1899 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001900 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1901 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001902 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001903 if (count == 0) {
1904 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1905 "AllocDescriptorSets called with 0 count");
1906 }
1907 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001908 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1909 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001910 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001911 SET_NODE* pNewNode = new SET_NODE;
1912 if (NULL == pNewNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001913 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 -06001914 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001915 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001916 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001917 // Insert set at head of Set LL for this pool
1918 pNewNode->pNext = pPoolNode->pSets;
1919 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001920 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1921 if (NULL == pLayout) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001922 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1923 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001924 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001925 pNewNode->pLayout = pLayout;
1926 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001927 pNewNode->set = pDescriptorSets[i];
1928 pNewNode->setUsage = setUsage;
1929 pNewNode->descriptorCount = pLayout->endIndex + 1;
1930 if (pNewNode->descriptorCount) {
1931 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1932 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1933 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1934 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001935 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001936 }
1937 }
1938 }
1939 }
1940 return result;
1941}
1942
Tony Barbourb857d312015-07-10 10:50:45 -06001943VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1944{
1945 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1946 // TODO : Clean up any internal data structures using this obj.
1947 return result;
1948}
1949
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08001950VK_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 -06001951{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001952 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1953 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001954 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001955 }
1956 return VK_ERROR_UNKNOWN;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001957}
1958
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001959VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001960{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001961 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001962 VkDynamicViewportStateCreateInfo local_ci;
1963 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1964 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1965 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1966 loader_platform_thread_lock_mutex(&globalLock);
1967 dynamicVpStateMap[pState->handle] = local_ci;
1968 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001969 return result;
1970}
1971
Cody Northrope4bc6942015-08-26 10:01:32 -06001972VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicLineWidthState(VkDevice device, const VkDynamicLineWidthStateCreateInfo* pCreateInfo, VkDynamicLineWidthState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001973{
Cody Northrope4bc6942015-08-26 10:01:32 -06001974 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicLineWidthState(device, pCreateInfo, pState);
1975 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_LINE_WIDTH);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001976 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001977 dynamicLineWidthStateMap[pState->handle] = *pCreateInfo;
Cody Northropf5bd2252015-08-17 11:10:49 -06001978 loader_platform_thread_unlock_mutex(&globalLock);
1979 return result;
1980}
1981
Cody Northrope4bc6942015-08-26 10:01:32 -06001982VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBiasState(VkDevice device, const VkDynamicDepthBiasStateCreateInfo* pCreateInfo, VkDynamicDepthBiasState* pState)
Cody Northropf5bd2252015-08-17 11:10:49 -06001983{
Cody Northrope4bc6942015-08-26 10:01:32 -06001984 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBiasState(device, pCreateInfo, pState);
1985 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BIAS);
Cody Northropf5bd2252015-08-17 11:10:49 -06001986 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001987 dynamicDepthBiasStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001988 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001989 return result;
1990}
1991
Cody Northrope4bc6942015-08-26 10:01:32 -06001992VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicBlendState(VkDevice device, const VkDynamicBlendStateCreateInfo* pCreateInfo, VkDynamicBlendState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001993{
Cody Northrope4bc6942015-08-26 10:01:32 -06001994 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicBlendState(device, pCreateInfo, pState);
1995 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_BLEND);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001996 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06001997 dynamicBlendStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001998 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001999 return result;
2000}
2001
Cody Northrope4bc6942015-08-26 10:01:32 -06002002VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBoundsState(VkDevice device, const VkDynamicDepthBoundsStateCreateInfo* pCreateInfo, VkDynamicDepthBoundsState* pState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002003{
Cody Northrope4bc6942015-08-26 10:01:32 -06002004 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBoundsState(device, pCreateInfo, pState);
2005 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BOUNDS);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002006 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002007 dynamicDepthBoundsStateMap[pState->handle] = *pCreateInfo;
Cody Northrop2605cb02015-08-18 15:21:16 -06002008 loader_platform_thread_unlock_mutex(&globalLock);
2009 return result;
2010}
2011
2012VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicStencilState(VkDevice device, const VkDynamicStencilStateCreateInfo* pCreateInfoFront, const VkDynamicStencilStateCreateInfo* pCreateInfoBack, VkDynamicStencilState* pState)
2013{
2014 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicStencilState(device, pCreateInfoFront, pCreateInfoBack, pState);
2015 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_STENCIL);
2016 loader_platform_thread_lock_mutex(&globalLock);
2017
2018 // Bug 14406 - If back is NULL or equal to front, then single sided.
2019 // To support NULL case, simply track front twice
2020 const VkDynamicStencilStateCreateInfo* pLocalCreateInfoBack = (pCreateInfoBack == NULL) ? pCreateInfoFront : pCreateInfoBack;
2021
2022 std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo> infos(*pCreateInfoFront, *pLocalCreateInfoBack);
2023 dynamicStencilStateMap[pState->handle] = infos;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002024 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002025 return result;
2026}
2027
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002028VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002029{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002030 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002031 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002032 loader_platform_thread_lock_mutex(&globalLock);
2033 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2034 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2035 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002036 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002037 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002038 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002039 cmdBufferMap[*pCmdBuffer] = pCB;
2040 loader_platform_thread_unlock_mutex(&globalLock);
2041 updateCBTracking(*pCmdBuffer);
2042 }
2043 return result;
2044}
2045
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002046VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002047{
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002048 // Validate command buffer level
2049 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2050 if (pCB) {
2051 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
2052 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2053 // These should be NULL for a Primary CB
2054 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2055 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2056 }
2057 } else {
2058 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2059 // These should NOT be null for an Secondary CB
2060 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2061 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2062 }
2063 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002064 pCB->beginInfo = *pBeginInfo;
2065 } else {
2066 // TODO : Need to pass cmdBuffer as objType here
2067 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
2068 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06002069 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002070 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002071 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06002072 if (CB_NEW != pCB->state)
2073 resetCB(cmdBuffer);
2074 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002075 updateCBTracking(cmdBuffer);
2076 }
2077 return result;
2078}
2079
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002080VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002081{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002082 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2083 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2084 if (pCB) {
2085 if (pCB->state == CB_UPDATE_ACTIVE) {
2086 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2087 if (VK_SUCCESS == result) {
2088 updateCBTracking(cmdBuffer);
2089 pCB->state = CB_UPDATE_COMPLETE;
2090 // Reset CB status flags
2091 pCB->status = 0;
2092 printCB(cmdBuffer);
2093 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002094 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002095 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002096 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002097 }
2098 return result;
2099}
2100
Cody Northropf02f9f82015-07-09 18:08:05 -06002101VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002102{
Cody Northropf02f9f82015-07-09 18:08:05 -06002103 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002104 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002105 resetCB(cmdBuffer);
2106 updateCBTracking(cmdBuffer);
2107 }
2108 return result;
2109}
2110
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002111VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002112{
2113 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2114 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002115 if (pCB->state == CB_UPDATE_ACTIVE) {
2116 updateCBTracking(cmdBuffer);
2117 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06002118 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002119 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2120 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002121 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == 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_NO_ACTIVE_RENDERPASS, "DS",
2123 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002124 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002125 PIPELINE_NODE* pPN = getPipeline(pipeline);
2126 if (pPN) {
2127 pCB->lastBoundPipeline = pipeline;
2128 loader_platform_thread_lock_mutex(&globalLock);
2129 set_cb_pso_status(pCB, pPN);
2130 g_lastBoundPipeline = pPN;
2131 loader_platform_thread_unlock_mutex(&globalLock);
2132 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2133 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2134 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002135 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2136 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002137 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002138 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002139 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002140 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002141 }
2142 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002143}
2144
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002145VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002146{
Tobin Ehlise42007c2015-06-19 13:00:59 -06002147 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2148 if (pCB) {
2149 if (pCB->state == CB_UPDATE_ACTIVE) {
2150 updateCBTracking(cmdBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002151 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002152 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002153 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2154 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002155 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002156 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002157 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2158 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barbour2a199c12015-07-09 17:31:46 -06002159 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 -06002160 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002161 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002162 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2163 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002164 }
2165 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002166 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002167 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002168 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002169 }
2170 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002171}
Cody Northrope4bc6942015-08-26 10:01:32 -06002172VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(VkCmdBuffer cmdBuffer, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002173{
2174 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2175 if (pCB) {
2176 if (pCB->state == CB_UPDATE_ACTIVE) {
2177 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002178 addCmd(pCB, CMD_BINDDYNAMICLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002179 if (!pCB->activeRenderPass) {
2180 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 -06002181 "Incorrect call to vkCmdBindDynamicLineWidthState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002182 }
2183 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002184 pCB->status |= CBSTATUS_LINE_WIDTH_BOUND;
2185 if (dynamicLineWidthStateMap.find(dynamicLineWidthState.handle) == dynamicLineWidthStateMap.end()) {
2186 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",
2187 "Unable to find VkDynamicLineWidthState object %#" PRIxLEAST64 ", was it ever created?", dynamicLineWidthState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002188 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002189 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
2190 g_lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002191 }
2192 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002193 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicLineWidthState(cmdBuffer, dynamicLineWidthState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002194 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002195 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002196 }
2197 }
2198}
Cody Northrope4bc6942015-08-26 10:01:32 -06002199VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(VkCmdBuffer cmdBuffer, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northropf5bd2252015-08-17 11:10:49 -06002200{
2201 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2202 if (pCB) {
2203 if (pCB->state == CB_UPDATE_ACTIVE) {
2204 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002205 addCmd(pCB, CMD_BINDDYNAMICDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002206 if (!pCB->activeRenderPass) {
2207 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 -06002208 "Incorrect call to vkCmdBindDynamicDepthBiasState() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002209 }
2210 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002211 pCB->status |= CBSTATUS_DEPTH_BIAS_BOUND;
2212 if (dynamicDepthBiasStateMap.find(dynamicDepthBiasState.handle) == dynamicDepthBiasStateMap.end()) {
2213 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",
2214 "Unable to find VkDynamicDepthBiasState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBiasState.handle);
Cody Northropf5bd2252015-08-17 11:10:49 -06002215 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002216 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
2217 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
Cody Northropf5bd2252015-08-17 11:10:49 -06002218 }
2219 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002220 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBiasState(cmdBuffer, dynamicDepthBiasState);
Cody Northropf5bd2252015-08-17 11:10:49 -06002221 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002222 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBiasState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002223 }
2224 }
2225}
Cody Northrope4bc6942015-08-26 10:01:32 -06002226VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicBlendState(VkCmdBuffer cmdBuffer, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002227{
2228 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2229 if (pCB) {
2230 if (pCB->state == CB_UPDATE_ACTIVE) {
2231 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002232 addCmd(pCB, CMD_BINDDYNAMICBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002233 if (!pCB->activeRenderPass) {
2234 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 -06002235 "Incorrect call to vkCmdBindDynamicBlendState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002236 }
2237 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002238 pCB->status |= CBSTATUS_BLEND_BOUND;
2239 if (dynamicBlendStateMap.find(dynamicBlendState.handle) == dynamicBlendStateMap.end()) {
2240 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_BLEND_STATE, dynamicBlendState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
2241 "Unable to find VkDynamicBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicBlendState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002242 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002243 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
2244 g_lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002245 }
2246 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002247 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicBlendState(cmdBuffer, dynamicBlendState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002248 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002249 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicBlendState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002250 }
2251 }
2252}
Cody Northrope4bc6942015-08-26 10:01:32 -06002253VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(VkCmdBuffer cmdBuffer, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002254{
2255 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2256 if (pCB) {
2257 if (pCB->state == CB_UPDATE_ACTIVE) {
2258 updateCBTracking(cmdBuffer);
Cody Northrope4bc6942015-08-26 10:01:32 -06002259 addCmd(pCB, CMD_BINDDYNAMICDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002260 if (!pCB->activeRenderPass) {
2261 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 -06002262 "Incorrect call to vkCmdBindDynamicDepthBoundsState() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002263 }
2264 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002265 pCB->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
2266 if (dynamicDepthBoundsStateMap.find(dynamicDepthBoundsState.handle) == dynamicDepthBoundsStateMap.end()) {
2267 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",
2268 "Unable to find VkDynamicDepthBoundsState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBoundsState.handle);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002269 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002270 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
2271 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002272 }
2273 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope4bc6942015-08-26 10:01:32 -06002274 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBoundsState(cmdBuffer, dynamicDepthBoundsState);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002275 } else {
Cody Northrope4bc6942015-08-26 10:01:32 -06002276 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBoundsState()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002277 }
2278 }
2279}
2280VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStencilState(VkCmdBuffer cmdBuffer, VkDynamicStencilState dynamicStencilState)
2281{
2282 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2283 if (pCB) {
2284 if (pCB->state == CB_UPDATE_ACTIVE) {
2285 updateCBTracking(cmdBuffer);
2286 addCmd(pCB, CMD_BINDDYNAMICSTENCILSTATE);
2287 if (!pCB->activeRenderPass) {
2288 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2289 "Incorrect call to vkCmdBindDynamicStencilState() without an active RenderPass.");
2290 }
2291 loader_platform_thread_lock_mutex(&globalLock);
2292 pCB->status |= CBSTATUS_STENCIL_BOUND;
2293 if (dynamicStencilStateMap.find(dynamicStencilState.handle) == dynamicStencilStateMap.end()) {
2294 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_STENCIL_STATE, dynamicStencilState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
2295 "Unable to find VkDynamicStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicStencilState.handle);
2296 } else {
2297 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2298 g_lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2299 }
2300 loader_platform_thread_unlock_mutex(&globalLock);
2301 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStencilState(cmdBuffer, dynamicStencilState);
2302 } else {
2303 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicStencilState()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002304 }
2305 }
2306}
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002307VK_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 -06002308{
2309 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2310 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002311 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002312 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002313 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2314 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002315 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == 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_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06002317 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2318 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002319 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002320 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2321 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002322 loader_platform_thread_lock_mutex(&globalLock);
2323 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002324 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002325 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2326 g_lastBoundDescriptorSet = pDescriptorSets[i];
2327 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002328 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2329 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002330 if (!pSet->pUpdateStructs)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002331 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2332 "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 -06002333 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002334 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2335 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002336 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002337 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002338 updateCBTracking(cmdBuffer);
2339 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis9bde5922015-06-22 18:00:14 -06002340 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 -06002341 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002342 } else {
2343 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002344 }
2345 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002346}
2347
Tony Barbour8205d902015-04-16 15:59:00 -06002348VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002349{
2350 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2351 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002352 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002353 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002354 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 -06002355 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2356 } else {
2357 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2358 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis59db5712015-07-13 13:14:24 -06002359 updateCBTracking(cmdBuffer);
2360 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002361 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2362 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002363 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002364 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2365 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002366 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002367}
2368
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002369VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2370 VkCmdBuffer cmdBuffer,
2371 uint32_t startBinding,
2372 uint32_t bindingCount,
2373 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002374 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002375{
2376 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2377 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002378 if (pCB->state == CB_UPDATE_ACTIVE) {
2379 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002380 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002381 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 -06002382 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2383 } else {
2384 pCB->lastVtxBinding = startBinding + bindingCount -1;
2385 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002386 updateCBTracking(cmdBuffer);
2387 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise4076782015-06-24 15:53:07 -06002388 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2389 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002390 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002391 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002392 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002393 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002394 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002395}
2396
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002397VK_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 -06002398{
2399 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002400 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002401 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002402 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002403 pCB->drawCount[DRAW]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002404 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002405 // TODO : Need to pass cmdBuffer as srcObj here
2406 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 -06002407 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2408 synchAndPrintDSConfig(cmdBuffer);
2409 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002410 updateCBTracking(cmdBuffer);
2411 addCmd(pCB, CMD_DRAW);
2412 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002413 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002414 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002415 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2416 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002417 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002418}
2419
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002420VK_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 -06002421{
2422 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002423 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002424 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002425 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002426 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002427 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002428 // TODO : Need to pass cmdBuffer as srcObj here
2429 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 -06002430 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2431 synchAndPrintDSConfig(cmdBuffer);
2432 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002433 updateCBTracking(cmdBuffer);
2434 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002435 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2436 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002437 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002438 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2439 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002440 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002441}
2442
Tony Barbour8205d902015-04-16 15:59:00 -06002443VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002444{
2445 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002446 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002448 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002449 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002450 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002451 // TODO : Need to pass cmdBuffer as srcObj here
2452 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002453 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2454 synchAndPrintDSConfig(cmdBuffer);
2455 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002456 updateCBTracking(cmdBuffer);
2457 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002458 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2459 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002460 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002461 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2462 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002463 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002464}
2465
Tony Barbour8205d902015-04-16 15:59:00 -06002466VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002467{
2468 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -06002469 VkBool32 valid = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002470 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002471 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002472 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002473 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002474 // TODO : Need to pass cmdBuffer as srcObj here
2475 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 -06002476 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2477 synchAndPrintDSConfig(cmdBuffer);
2478 if (valid) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002479 updateCBTracking(cmdBuffer);
2480 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2481 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002482 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002483 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002484 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2485 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002486 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002487}
2488
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002489VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002490{
2491 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2492 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002493 if (pCB->state == CB_UPDATE_ACTIVE) {
2494 updateCBTracking(cmdBuffer);
2495 addCmd(pCB, CMD_DISPATCH);
2496 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002497 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002498 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2499 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002500 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002501}
2502
Tony Barbour8205d902015-04-16 15:59:00 -06002503VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002504{
2505 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2506 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002507 if (pCB->state == CB_UPDATE_ACTIVE) {
2508 updateCBTracking(cmdBuffer);
2509 addCmd(pCB, CMD_DISPATCHINDIRECT);
2510 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002511 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002512 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2513 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002514 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002515}
2516
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002517VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002518{
2519 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2520 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002521 if (pCB->state == CB_UPDATE_ACTIVE) {
2522 updateCBTracking(cmdBuffer);
2523 addCmd(pCB, CMD_COPYBUFFER);
2524 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002525 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002526 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2527 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002528 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002529}
2530
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002531VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2532 VkImage srcImage,
2533 VkImageLayout srcImageLayout,
2534 VkImage destImage,
2535 VkImageLayout destImageLayout,
2536 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002537{
2538 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2539 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002540 if (pCB->state == CB_UPDATE_ACTIVE) {
2541 updateCBTracking(cmdBuffer);
2542 addCmd(pCB, CMD_COPYIMAGE);
2543 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002544 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002545 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2546 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002547 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002548}
2549
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002550VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2551 VkImage srcImage, VkImageLayout srcImageLayout,
2552 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002553 uint32_t regionCount, const VkImageBlit* pRegions,
2554 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002555{
2556 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2557 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002558 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002559 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002560 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2561 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002562 } else {
2563 updateCBTracking(cmdBuffer);
2564 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002565 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 -06002566 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002567 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002568 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2569 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002570 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002571}
2572
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002573VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2574 VkBuffer srcBuffer,
2575 VkImage destImage, VkImageLayout destImageLayout,
2576 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002577{
2578 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2579 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002580 if (pCB->state == CB_UPDATE_ACTIVE) {
2581 updateCBTracking(cmdBuffer);
2582 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2583 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002584 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002585 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2586 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002587 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002588}
2589
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002590VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2591 VkImage srcImage, VkImageLayout srcImageLayout,
2592 VkBuffer destBuffer,
2593 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002594{
2595 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2596 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002597 if (pCB->state == CB_UPDATE_ACTIVE) {
2598 updateCBTracking(cmdBuffer);
2599 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2600 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002601 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002602 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2603 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002604 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002605}
2606
Tony Barbour8205d902015-04-16 15:59:00 -06002607VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002608{
2609 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2610 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002611 if (pCB->state == CB_UPDATE_ACTIVE) {
2612 updateCBTracking(cmdBuffer);
2613 addCmd(pCB, CMD_UPDATEBUFFER);
2614 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002615 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002616 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2617 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002618 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002619}
2620
Tony Barbour8205d902015-04-16 15:59:00 -06002621VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002622{
2623 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2624 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002625 if (pCB->state == CB_UPDATE_ACTIVE) {
2626 updateCBTracking(cmdBuffer);
2627 addCmd(pCB, CMD_FILLBUFFER);
2628 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002629 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002630 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2631 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002632 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002633}
2634
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002635VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2636 VkCmdBuffer cmdBuffer,
2637 uint32_t colorAttachment,
2638 VkImageLayout imageLayout,
2639 const VkClearColorValue* pColor,
2640 uint32_t rectCount,
2641 const VkRect3D* pRects)
2642{
2643 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2644 if (pCB) {
2645 if (pCB->state == CB_UPDATE_ACTIVE) {
2646 // Warn if this is issued prior to Draw Cmd
2647 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002648 // TODO : cmdBuffer should be srcObj
2649 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 -06002650 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002651 " 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 -06002652 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002653 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002654 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 -06002655 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2656 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2657 } else {
2658 updateCBTracking(cmdBuffer);
2659 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2660 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2661 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002662 } else {
2663 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2664 }
2665 }
2666}
2667
2668VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2669 VkCmdBuffer cmdBuffer,
2670 VkImageAspectFlags imageAspectMask,
2671 VkImageLayout imageLayout,
2672 float depth,
2673 uint32_t stencil,
2674 uint32_t rectCount,
2675 const VkRect3D* pRects)
2676{
2677 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2678 if (pCB) {
2679 if (pCB->state == CB_UPDATE_ACTIVE) {
2680 // Warn if this is issued prior to Draw Cmd
2681 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002682 // TODO : cmdBuffer should be srcObj
2683 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 -06002684 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002685 " 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 -06002686 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002687 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002688 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 -06002689 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2690 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2691 } else {
2692 updateCBTracking(cmdBuffer);
2693 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2694 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2695 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002696 } else {
2697 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2698 }
2699 }
2700}
2701
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002702VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2703 VkCmdBuffer cmdBuffer,
2704 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002705 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002706 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002707{
2708 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2709 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002710 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002711 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002712 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 -06002713 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2714 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2715 } else {
2716 updateCBTracking(cmdBuffer);
2717 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2718 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2719 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002720 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002721 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2722 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002723 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002724}
2725
Chris Forbes2951d7d2015-06-22 17:21:59 +12002726VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002727 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002728 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002729 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002730{
2731 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2732 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002733 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002734 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002735 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 -06002736 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2737 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2738 } else {
2739 updateCBTracking(cmdBuffer);
2740 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2741 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2742 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002743 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002744 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2745 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002746 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002747}
2748
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002749VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2750 VkImage srcImage, VkImageLayout srcImageLayout,
2751 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002752 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002753{
2754 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2755 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002756 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002757 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002758 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2759 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002760 } else {
2761 updateCBTracking(cmdBuffer);
2762 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002763 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002764 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002765 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002766 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2767 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002768 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002769}
2770
Tony Barbourc2e987e2015-06-29 16:20:35 -06002771VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002772{
2773 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2774 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002775 if (pCB->state == CB_UPDATE_ACTIVE) {
2776 updateCBTracking(cmdBuffer);
2777 addCmd(pCB, CMD_SETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002778 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002779 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002780 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2781 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002782 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002783}
2784
Tony Barbourc2e987e2015-06-29 16:20:35 -06002785VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002786{
2787 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2788 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002789 if (pCB->state == CB_UPDATE_ACTIVE) {
2790 updateCBTracking(cmdBuffer);
2791 addCmd(pCB, CMD_RESETEVENT);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002792 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002793 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002794 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2795 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002796 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002797}
2798
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002799VK_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 -06002800{
2801 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2802 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002803 if (pCB->state == CB_UPDATE_ACTIVE) {
2804 updateCBTracking(cmdBuffer);
2805 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbourc2e987e2015-06-29 16:20:35 -06002806 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002807 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002808 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2809 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002810 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002811}
2812
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002813VK_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 -06002814{
2815 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2816 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002817 if (pCB->state == CB_UPDATE_ACTIVE) {
2818 updateCBTracking(cmdBuffer);
2819 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter73a21d32015-07-12 13:20:05 -06002820 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002821 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002822 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2823 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002824 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002825}
2826
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002827VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002828{
2829 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2830 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002831 if (pCB->state == CB_UPDATE_ACTIVE) {
2832 updateCBTracking(cmdBuffer);
2833 addCmd(pCB, CMD_BEGINQUERY);
2834 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002835 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002836 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2837 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002838 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002839}
2840
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002841VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002842{
2843 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2844 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002845 if (pCB->state == CB_UPDATE_ACTIVE) {
2846 updateCBTracking(cmdBuffer);
2847 addCmd(pCB, CMD_ENDQUERY);
2848 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002849 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002850 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2851 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002852 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002853}
2854
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002855VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856{
2857 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2858 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002859 if (pCB->state == CB_UPDATE_ACTIVE) {
2860 updateCBTracking(cmdBuffer);
2861 addCmd(pCB, CMD_RESETQUERYPOOL);
2862 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002863 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002864 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2865 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002866 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002867}
2868
Tony Barbour8205d902015-04-16 15:59:00 -06002869VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002870{
2871 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2872 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002873 if (pCB->state == CB_UPDATE_ACTIVE) {
2874 updateCBTracking(cmdBuffer);
2875 addCmd(pCB, CMD_WRITETIMESTAMP);
2876 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002877 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002878 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2879 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002880 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002881}
2882
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002883VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002884{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002885 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002886 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002887 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002888 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002889 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002890 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2891 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002892 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002893 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002894 }
2895 return result;
2896}
2897
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002898VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002899{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002900 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002901 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002902 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002903 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002904 if (pCreateInfo->pAttachments) {
2905 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2906 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002907 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002908 if (pCreateInfo->pSubpasses) {
2909 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2910 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2911
2912 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2913 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2914 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002915 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002916 subpass->preserveCount;
2917 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2918
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002919 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002920 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002921 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002922 attachments += subpass->inputCount;
2923
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002924 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002925 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002926 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002927 attachments += subpass->colorCount;
2928
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002929 if (subpass->pResolveAttachments) {
2930 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002931 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002932 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002933 attachments += subpass->colorCount;
2934 }
2935
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002936 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002937 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002938 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002939 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002940 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002941 if (pCreateInfo->pDependencies) {
2942 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2943 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002944 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002945 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002946 }
2947 return result;
2948}
2949
Chia-I Wuc278df82015-07-07 11:50:03 +08002950VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002951{
2952 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2953 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002954 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002955 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002956 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2957 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002958 } else {
2959 updateCBTracking(cmdBuffer);
2960 addCmd(pCB, CMD_BEGINRENDERPASS);
2961 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002962 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002963 pCB->framebuffer = pRenderPassBegin->framebuffer;
2964 if (pCB->lastBoundPipeline) {
2965 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2966 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002967 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002968 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002969 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002970 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002971 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002972 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002973 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002974}
2975
Chia-I Wuc278df82015-07-07 11:50:03 +08002976VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2977{
2978 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2979 if (pCB) {
2980 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002981 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 +08002982 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2983 } else {
2984 updateCBTracking(cmdBuffer);
2985 addCmd(pCB, CMD_NEXTSUBPASS);
2986 pCB->activeSubpass++;
2987 if (pCB->lastBoundPipeline) {
2988 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2989 }
2990 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2991 }
2992 }
2993}
2994
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002995VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002996{
2997 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2998 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002999 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003000 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 +08003001 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06003002 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003003 updateCBTracking(cmdBuffer);
3004 addCmd(pCB, CMD_ENDRENDERPASS);
3005 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08003006 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003007 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
3008 }
3009 }
3010}
3011
3012VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3013{
3014 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3015 if (pCB) {
3016 if (!pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003017 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 +08003018 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
3019 } else {
3020 updateCBTracking(cmdBuffer);
3021 addCmd(pCB, CMD_EXECUTECOMMANDS);
3022 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003023 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003024 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003025}
3026
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003027VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3028 VkInstance instance,
3029 VkFlags msgFlags,
3030 const PFN_vkDbgMsgCallback pfnMsgCallback,
3031 void* pUserData,
3032 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003033{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003034 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003035 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3036 if (VK_SUCCESS == res) {
3037 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3038 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3039 }
3040 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003041}
3042
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003043VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3044 VkInstance instance,
3045 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003046{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003047 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003048 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3049 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3050 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3051 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003052}
3053
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003054VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003055{
3056 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003057 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3058 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003059 // TODO : cmdBuffer should be srcObj
3060 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 -06003061 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003062 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003063 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003064 updateCBTracking(cmdBuffer);
3065 addCmd(pCB, CMD_DBGMARKERBEGIN);
3066 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003067 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003068}
3069
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003070VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003071{
3072 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003073 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3074 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003075 // TODO : cmdBuffer should be srcObj
3076 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 -06003077 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003078 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003079 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003080 updateCBTracking(cmdBuffer);
3081 addCmd(pCB, CMD_DBGMARKEREND);
3082 }
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003083 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
3084}
3085
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003086//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3087//{
3088// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3089// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3090// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3091// "Attempt to use DbgSetObjectTag but extension disabled!");
3092// return VK_ERROR_UNAVAILABLE;
3093// }
3094// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3095//}
3096//
3097//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3098//{
3099// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3100// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3101// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3102// "Attempt to use DbgSetObjectName but extension disabled!");
3103// return VK_ERROR_UNAVAILABLE;
3104// }
3105// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3106//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003107
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003108VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003109{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003110 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003111 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003112
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003113 /* loader uses this to force layer initialization; device object is wrapped */
3114 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003115 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003116 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003117 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003118 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003120 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003122 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003124 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003126 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003128 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003130 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003132 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003134 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003136 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003138 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003140 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003142 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003143 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003144 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003145 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003146 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003147 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003148 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003150 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003152 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003154 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003156 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003158 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003160 if (!strcmp(funcName, "vkDestroyDynamicLineWidthState"))
3161 return (PFN_vkVoidFunction) vkDestroyDynamicLineWidthState;
3162 if (!strcmp(funcName, "vkDestroyDynamicDepthBiasState"))
3163 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBiasState;
3164 if (!strcmp(funcName, "vkDestroyDynamicBlendState"))
3165 return (PFN_vkVoidFunction) vkDestroyDynamicBlendState;
3166 if (!strcmp(funcName, "vkDestroyDynamicDepthBoundsState"))
3167 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003168 if (!strcmp(funcName, "vkDestroyDynamicStencilState"))
3169 return (PFN_vkVoidFunction) vkDestroyDynamicStencilState;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003170 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003172 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003173 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003174 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003175 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003176 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003177 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003178 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003179 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003180 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003181 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003182 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003183 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003184 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003185 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003186 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003187 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003188 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003189 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003190 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003191 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003192 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003193 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003194 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003195 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003196 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003197 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003198 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003199 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003200 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003201 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003202 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003204 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003206 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003208 if (!strcmp(funcName, "vkCreateDynamicLineWidthState"))
3209 return (PFN_vkVoidFunction) vkCreateDynamicLineWidthState;
3210 if (!strcmp(funcName, "vkCreateDynamicDepthBiasState"))
3211 return (PFN_vkVoidFunction) vkCreateDynamicDepthBiasState;
3212 if (!strcmp(funcName, "vkCreateDynamicBlendState"))
3213 return (PFN_vkVoidFunction) vkCreateDynamicBlendState;
3214 if (!strcmp(funcName, "vkCreateDynamicDepthBoundsState"))
3215 return (PFN_vkVoidFunction) vkCreateDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003216 if (!strcmp(funcName, "vkCreateDynamicStencilState"))
3217 return (PFN_vkVoidFunction) vkCreateDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003218 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003219 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003220 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003221 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003222 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003223 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003224 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003226 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003228 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Cody Northrope4bc6942015-08-26 10:01:32 -06003230 if (!strcmp(funcName, "vkCmdBindDynamicLineWidthState"))
3231 return (PFN_vkVoidFunction) vkCmdBindDynamicLineWidthState;
3232 if (!strcmp(funcName, "vkCmdBindDynamicDepthBiasState"))
3233 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBiasState;
3234 if (!strcmp(funcName, "vkCmdBindDynamicBlendState"))
3235 return (PFN_vkVoidFunction) vkCmdBindDynamicBlendState;
3236 if (!strcmp(funcName, "vkCmdBindDynamicDepthBoundsState"))
3237 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBoundsState;
Cody Northrop2605cb02015-08-18 15:21:16 -06003238 if (!strcmp(funcName, "vkCmdBindDynamicStencilState"))
3239 return (PFN_vkVoidFunction) vkCmdBindDynamicStencilState;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003240 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003242 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003243 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003244 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003245 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003246 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003247 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003248 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003249 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003250 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003251 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003252 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003253 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003254 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003256 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003258 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003260 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003262 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003264 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003265 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003266 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003267 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003268 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003269 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003270 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003271 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003272 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003273 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003274 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003276 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003278 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003280 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003282 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003284 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003286 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003287 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003288 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003289 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003290 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003291 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003292 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003293 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003294 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003295 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003296 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003297 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003298 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003299 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003300 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003301 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003302 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003303 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003304 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003305 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003306
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003307 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3308 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003309 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003310 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003311 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003312 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003313 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003314// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3315// return (void*) vkDbgSetObjectTag;
3316// if (!strcmp(funcName, "vkDbgSetObjectName"))
3317// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003318 }
3319 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003320 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003321 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003322 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003323 }
3324}
3325
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003326VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003327{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003328 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003329 if (instance == NULL)
3330 return NULL;
3331
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003332 /* loader uses this to force layer initialization; instance object is wrapped */
3333 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003334 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003335 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003336 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003337 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003338 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003339 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003340 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003341 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003342 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003343 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003344 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06003345 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003346 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour426b9052015-06-24 16:06:58 -06003347 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003348 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003349
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003350 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3351 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003352 if (fptr)
3353 return fptr;
3354
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003355 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003356 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003357 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003358 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003359 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003360 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003361}