blob: 04bf39739fa470ec44b31f17fd4aad04b8b5a334 [file] [log] [blame]
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis10ae8c12015-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 Ehlisb835d1b2015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barbour18f71552015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060035#endif
Tony Barbour18f71552015-04-22 11:36:22 -060036#if defined(__GNUC__)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060037#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barbour18f71552015-04-22 11:36:22 -060038#endif
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060039#include "vk_struct_size_helper.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060040#include "draw_state.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060041#include "vk_layer_config.h"
Jon Ashburne68a9ff2015-05-25 14:11:37 -060042#include "vk_debug_marker_layer.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060043// The following is #included again to catch certain OS-specific functions
44// being used:
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Tobin Ehlisa0cb02e2015-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 Goeltzenleuchter7ad58c02015-07-06 22:31:52 -060051#include "vk_layer_extension_utils.h"
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060052
Tobin Ehlisc16c3e92015-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 Goeltzenleuchter3d0dfad2015-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 Ehlis60a9b4f2015-07-07 10:42:20 -060063unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
64unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -060065unordered_map<uint64_t, VkImageViewCreateInfo> viewMap;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -060066unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
67unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicVpStateMap;
Cody Northrop271ba752015-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 Northrop82485a82015-08-18 15:21:16 -060072unordered_map<uint64_t, std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo>> dynamicStencilStateMap;
Tobin Ehlis60a9b4f2015-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 Ehlis793ad302015-04-03 12:01:11 -060077// Map for layout chains
Tobin Ehlis60a9b4f2015-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 Ehlis10ae8c12015-03-17 16:24:32 -060081
Jon Ashburneab34492015-06-01 09:37:38 -060082struct devExts {
83 bool debug_marker_enabled;
84};
85
Jon Ashburneab34492015-06-01 09:37:38 -060086static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburn3950e1b2015-05-20 09:00:28 -060087
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060088static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060089
Tobin Ehlis10ae8c12015-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 Ehlis10ae8c12015-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 Ehlisa16e8922015-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 Ehlis60a9b4f2015-07-07 10:42:20 -0600101debug_report_data *mdd(void* object)
Tobin Ehlisa16e8922015-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 Ehlisa16e8922015-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 Ehlisbfbac252015-09-01 11:46:36 -0600114 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisa16e8922015-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 Ehlisa16e8922015-06-16 15:50:44 -0600118 return my_data->report_data;
119}
Tobin Ehlis10ae8c12015-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 Ehlis60a9b4f2015-07-07 10:42:20 -0600143 case CMD_BINDDYNAMICVIEWPORTSTATE:
144 return "CMD_BINDDYNAMICVIEWPORTSTATE";
Cody Northrop271ba752015-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 Northrop82485a82015-08-18 15:21:16 -0600153 case CMD_BINDDYNAMICSTENCILSTATE:
154 return "CMD_BINDDYNAMICSTENCILSTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600155 case CMD_BINDDESCRIPTORSETS:
156 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-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 Ehlis793ad302015-04-03 12:01:11 -0600177 case CMD_BLITIMAGE:
178 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-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 Ehlis53eddda2015-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 Ehlis10ae8c12015-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600235#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis10ae8c12015-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 Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600245static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600246// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600247static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
248static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600249// Track the last global DrawState of interest touched by any thread
Tobin Ehlis60a9b4f2015-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 Jansensc73ff982015-07-30 13:22:15 -0700253static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600254#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
255
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600256//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600257
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600258// Free all allocated nodes for Dynamic State objs
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600259static void deleteDynamicState()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600260{
Tobin Ehlis60a9b4f2015-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 Ehlis10ae8c12015-03-17 16:24:32 -0600264 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600265 dynamicVpStateMap.clear();
Cody Northrop271ba752015-08-26 10:01:32 -0600266 dynamicLineWidthStateMap.clear();
267 dynamicDepthBiasStateMap.clear();
268 dynamicBlendStateMap.clear();
269 dynamicDepthBoundsStateMap.clear();
Cody Northrop82485a82015-08-18 15:21:16 -0600270 dynamicStencilStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600271}
272// Free all sampler nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600273static void deleteSamplers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600274{
David Pinedod8f83d82015-04-27 16:36:17 -0600275 if (sampleMap.size() <= 0)
276 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600277 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600278 delete (*ii).second;
279 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600280 sampleMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600281}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600282static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600283{
284 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600285 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600286 loader_platform_thread_unlock_mutex(&globalLock);
287 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600288 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600289 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600290 return &imageMap[view.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600291 }
292}
293// Free all image nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600294static void deleteImages()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600295{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600296 if (imageMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -0600297 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600298 imageMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600299}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600300static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600301{
302 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600303 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600304 loader_platform_thread_unlock_mutex(&globalLock);
305 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600306 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600307 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600308 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600309 }
310}
311// Free all buffer nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600312static void deleteBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600313{
David Pinedod8f83d82015-04-27 16:36:17 -0600314 if (bufferMap.size() <= 0)
315 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600316 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600317 delete (*ii).second;
318 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600319 bufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600320}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600321static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600322// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600323static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-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 Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600340static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-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 Ehlise382c5a2015-06-10 12:57:07 -0600348// Check object status for selected flag state
Courtney Goeltzenleuchtercd2a0992015-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 Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600350{
Tobin Ehlis429b91d2015-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 Ehlis60a9b4f2015-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 Goeltzenleuchterdee721d2015-08-26 15:09:25 -0600357 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->cmdBuffer), fail_msg);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600358 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600359 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600360 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600361 return VK_TRUE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600362}
Tobin Ehlis60a9b4f2015-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 Northrop271ba752015-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 Northrop82485a82015-08-18 15:21:16 -0600377 case VK_STATE_BIND_POINT_STENCIL:
378 return (void*)&dynamicStencilStateMap[handle];
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600379 default:
380 return NULL;
381 }
382}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600383// Print the last bound dynamic state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600384static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600385{
386 GLOBAL_CB_NODE* pCB = getCBNode(cb);
387 if (pCB) {
388 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600389 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Mark Lobodzinski31422ee2015-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 Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600401 } else {
Tobin Ehlis60a9b4f2015-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 Ehlis10ae8c12015-03-17 16:24:32 -0600404 }
405 }
406 loader_platform_thread_unlock_mutex(&globalLock);
407 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600408}
409// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600410static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600411{
412 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600413 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600414 loader_platform_thread_unlock_mutex(&globalLock);
415 return NULL;
416 }
417 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600418 return pipelineMap[pipeline.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600419}
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600420// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600421static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
422 VkBool32 result;
Tobin Ehlis429b91d2015-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 Northrop271ba752015-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 Northrop82485a82015-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 Ehlis429b91d2015-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 Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600434static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600435 // First check flag states
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600436 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600437 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
438 // Now complete other state checks
Tobin Ehlise90e66d2015-09-09 13:31:01 -0600439 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
440 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
441 // We should have that check separately and then gate this check based on that check
442 if (pPipe && (pCB->lastBoundPipelineLayout) && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600443 result = VK_FALSE;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600444 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Mark Lobodzinski735e4b32015-08-04 10:54:43 -0600445 "Pipeline layout from last vkCmdBindDescriptorSets() (%#" PRIxLEAST64 ") does not match PSO Pipeline layout (%#" PRIxLEAST64 ") ", pCB->lastBoundPipelineLayout.handle, pPipe->graphicsPipelineCI.layout.handle);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600446 }
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -0600447 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600448 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -0600449 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
450 }
Tobin Ehlisf7bf4502015-09-09 15:12:35 -0600451 // Verify Vtx binding
452 if (MAX_BINDING != pCB->lastVtxBinding) {
453 if (pCB->lastVtxBinding >= pPipe->vtxBindingCount) {
454 if (0 == pPipe->vtxBindingCount) {
455 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
456 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
457 return false;
458 }
459 else {
460 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
461 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipe->vtxBindingCount - 1));
462 return false;
463 }
464 }
465 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600466 return result;
467}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600468// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600469static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600470{
471 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600472 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600473 loader_platform_thread_unlock_mutex(&globalLock);
474 return NULL;
475 }
476 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600477 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600478}
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600479// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600480static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600481{
482 // VS is required
483 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600484 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600485 "Invalid Pipeline CreateInfo State: Vtx Shader required");
486 return VK_FALSE;
487 }
488 // Either both or neither TC/TE shaders should be defined
489 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
490 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600491 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600492 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
493 return VK_FALSE;
494 }
495 // Compute shaders should be specified independent of Gfx shaders
496 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
497 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
498 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
499 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600500 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600501 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
502 return VK_FALSE;
503 }
504 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
505 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
506 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
507 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600508 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600509 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
510 return VK_FALSE;
511 }
512 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
513 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600514 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600515 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
516 return VK_FALSE;
517 }
518 return VK_TRUE;
519}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600520// Init the pipeline mapping info based on pipeline create info LL tree
521// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600522static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600523{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600524 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
525 if (pBasePipeline) {
526 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlis9c536442015-06-19 13:00:59 -0600527 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600528 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
529 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600530 // First init create info
Tobin Ehliseba312c2015-04-01 08:40:34 -0600531 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600532 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600533
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600534 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600535 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -0600536 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600537
538 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
539 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
540
541 switch (pPSSCI->stage) {
542 case VK_SHADER_STAGE_VERTEX:
543 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
544 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600545 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600546 case VK_SHADER_STAGE_TESS_CONTROL:
547 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
548 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600549 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600550 case VK_SHADER_STAGE_TESS_EVALUATION:
551 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
552 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600553 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600554 case VK_SHADER_STAGE_GEOMETRY:
555 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
556 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600557 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600558 case VK_SHADER_STAGE_FRAGMENT:
559 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
560 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600561 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600562 case VK_SHADER_STAGE_COMPUTE:
563 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
564 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600565 break;
566 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600567 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600568 break;
569 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600570 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600571
572 if (pCreateInfo->pVertexInputState != NULL) {
573 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
574 // Copy embedded ptrs
575 pVICI = pCreateInfo->pVertexInputState;
576 pPipeline->vtxBindingCount = pVICI->bindingCount;
577 if (pPipeline->vtxBindingCount) {
578 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
579 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
580 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
581 }
582 pPipeline->vtxAttributeCount = pVICI->attributeCount;
583 if (pPipeline->vtxAttributeCount) {
584 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
585 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
586 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
587 }
588 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
589 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600590 if (pCreateInfo->pInputAssemblyState != NULL) {
591 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
592 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600593 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600594 if (pCreateInfo->pTessellationState != NULL) {
595 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
596 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600597 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600598 if (pCreateInfo->pViewportState != NULL) {
599 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
600 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600601 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600602 if (pCreateInfo->pRasterState != NULL) {
603 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
604 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600605 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600606 if (pCreateInfo->pMultisampleState != NULL) {
607 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
608 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600609 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600610 if (pCreateInfo->pColorBlendState != NULL) {
611 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600612 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600613 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600614 pPipeline->attachmentCount = pCBCI->attachmentCount;
615 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600616 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
617 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600618 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
619 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600620 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600621 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600622 if (pCreateInfo->pDepthStencilState != NULL) {
623 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
624 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600625 }
626
627 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
628 if (pCreateInfo->stageCount != 0) {
629 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
630 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
631 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
632 }
633
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600634 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600635}
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600636
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600637// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600638static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600639{
David Pinedod8f83d82015-04-27 16:36:17 -0600640 if (pipelineMap.size() <= 0)
641 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600642 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600643 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
644 delete[] (*ii).second->graphicsPipelineCI.pStages;
645 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600646 if ((*ii).second->pVertexBindingDescriptions) {
647 delete[] (*ii).second->pVertexBindingDescriptions;
648 }
649 if ((*ii).second->pVertexAttributeDescriptions) {
650 delete[] (*ii).second->pVertexAttributeDescriptions;
651 }
652 if ((*ii).second->pAttachments) {
653 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600654 }
655 delete (*ii).second;
656 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600657 pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600658}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600659// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600660static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600661{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600662 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlis577188e2015-07-13 14:51:15 -0600663 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
664 return pPipe->msStateCI.rasterSamples;
665 }
Tobin Ehliseba312c2015-04-01 08:40:34 -0600666 return 1;
667}
668// Validate state related to the PSO
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600669static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600670{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600671 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600672 // Verify that any MSAA request in PSO matches sample# in bound FB
673 uint32_t psoNumSamples = getNumSamples(pipeline);
674 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600675 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wu08accc62015-07-07 11:50:03 +0800676 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
677 int subpassNumSamples = 0;
678 uint32_t i;
679
680 for (i = 0; i < pSD->colorCount; i++) {
681 uint32_t samples;
682
Cody Northropa505dda2015-08-04 11:16:41 -0600683 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +0800684 continue;
685
Cody Northropa505dda2015-08-04 11:16:41 -0600686 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu08accc62015-07-07 11:50:03 +0800687 if (subpassNumSamples == 0) {
688 subpassNumSamples = samples;
689 } else if (subpassNumSamples != samples) {
690 subpassNumSamples = -1;
691 break;
692 }
693 }
694 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
695 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
696 if (subpassNumSamples == 0)
697 subpassNumSamples = samples;
698 else if (subpassNumSamples != samples)
699 subpassNumSamples = -1;
700 }
701
702 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600703 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
704 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!", pipeline.handle, psoNumSamples, pCB->activeRenderPass.handle, subpassNumSamples);
Tobin Ehliseba312c2015-04-01 08:40:34 -0600705 }
706 } else {
707 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
708 // Verify and flag error as appropriate
709 }
710 // TODO : Add more checks here
711 } else {
712 // TODO : Validate non-gfx pipeline updates
713 }
714}
715
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600716// Block of code at start here specifically for managing/tracking DSs
717
Tobin Ehlis793ad302015-04-03 12:01:11 -0600718// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600719static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600720{
721 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600722 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600723 loader_platform_thread_unlock_mutex(&globalLock);
724 return NULL;
725 }
726 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600727 return poolMap[pool.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600728}
729// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600730static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600731{
732 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600733 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600734 loader_platform_thread_unlock_mutex(&globalLock);
735 return NULL;
736 }
737 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600738 return setMap[set.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600739}
740
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600741static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600742 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600743 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600744 loader_platform_thread_unlock_mutex(&globalLock);
745 return NULL;
746 }
747 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600748 return layoutMap[layout.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600749}
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600750// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600751static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600752{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600753 switch (pUpdateStruct->sType)
754 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800755 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
756 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600757 return 1;
758 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600759 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600760 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600761 return 0;
762 }
763}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600764// For given update struct, return binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600765static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600766{
767 switch (pUpdateStruct->sType)
768 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800769 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
770 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
771 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
772 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600773 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600774 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600775 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600776 return 0xFFFFFFFF;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600777 }
778}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600779// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600780static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600781{
782 switch (pUpdateStruct->sType)
783 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800784 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
785 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
786 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600787 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800788 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600789 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600790 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600791 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600792 return 0;
793 }
794}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600795// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600796static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600797{
798 switch (pUpdateStruct->sType)
799 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800800 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
801 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
802 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600803 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800804 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600805 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600806 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600807 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600808 return 0;
809 }
810}
811// For given Layout Node and binding, return index where that binding begins
812static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
813{
814 uint32_t offsetIndex = 0;
815 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800816 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600817 }
818 return offsetIndex;
819}
820// For given layout node and binding, return last index that is updated
821static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
822{
823 uint32_t offsetIndex = 0;
824 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800825 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600826 }
827 return offsetIndex-1;
828}
829// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600830static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600831{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600832 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlis793ad302015-04-03 12:01:11 -0600833}
834// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600835static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600836{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600837 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600838}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600839// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600840static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600841{
842 // First get actual type of update
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600843 VkDescriptorType actualType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600844 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600845 switch (pUpdateStruct->sType)
846 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800847 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
848 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600849 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800850 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
851 /* no need to validate */
852 return 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600853 break;
854 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600855 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600856 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600857 return 0;
858 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600859 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600860 if (pLayout->pTypes[i] != actualType)
861 return 0;
862 }
863 return 1;
864}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600865// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
866// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
867// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600868static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600869{
870 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800871 VkWriteDescriptorSet* pWDS = NULL;
872 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600873 size_t array_size = 0;
874 size_t base_array_size = 0;
875 size_t total_array_size = 0;
876 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600877 switch (pUpdate->sType)
878 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800879 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
880 pWDS = new VkWriteDescriptorSet;
881 pNewNode = (GENERIC_HEADER*)pWDS;
882 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
883 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
884 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
885 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600886 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800887 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
888 pCDS = new VkCopyDescriptorSet;
889 pUpdate = (GENERIC_HEADER*)pCDS;
890 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600891 break;
892 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600893 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600894 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600895 return NULL;
896 }
897 // Make sure that pNext for the end of shadow copy is NULL
898 pNewNode->pNext = NULL;
899 return pNewNode;
900}
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800901// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600902static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600903{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800904 const VkWriteDescriptorSet *pWDS = NULL;
905 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600906 VkBool32 result = 1;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800907
908 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
909 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
910 else
911 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
912
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600913 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600914 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600915 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600916 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600917 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600918 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800919 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600920 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800921 g_lastBoundDescriptorSet = pSet->set;
922 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600923 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600924 // First verify valid update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600925 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600926 result = 0;
927 break;
928 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600929 // Make sure that binding is within bounds
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600930 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600931 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600932 "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 Ehlis0174fed2015-05-28 12:10:17 -0600933 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600934 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600935 // Next verify that update falls within size of given binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600936 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour3b4732f2015-07-13 13:37:24 -0600937 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlis793ad302015-04-03 12:01:11 -0600938 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600939 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600940 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 Ehlis75283bf2015-06-18 15:59:33 -0600941 "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 Ehlis0174fed2015-05-28 12:10:17 -0600942 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600943 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600944 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600945 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600946 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600947 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600948 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600949 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600950 // Save the update info
951 // TODO : Info message that update successful
952 // Create new update struct for this set's shadow copy
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600953 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600954 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600955 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600956 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600957 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600958 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600959 // Insert shadow node into LL of updates for this set
960 pNewNode->pNext = pSet->pUpdateStructs;
961 pSet->pUpdateStructs = pNewNode;
962 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600963 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600964 assert(j<pSet->descriptorCount);
965 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600966 }
967 }
968 }
969 }
970 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600971 }
972 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600973 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600974}
975// Free the shadowed update node for this Set
976// NOTE : Calls to this function should be wrapped in mutex
977static void freeShadowUpdateTree(SET_NODE* pSet)
978{
979 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
980 pSet->pUpdateStructs = NULL;
981 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
982 // Clear the descriptor mappings as they will now be invalid
983 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
984 while(pShadowUpdate) {
985 pFreeUpdate = pShadowUpdate;
986 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
987 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800988 VkWriteDescriptorSet * pWDS = NULL;
989 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600990 void** ppToFree = NULL;
991 switch (pFreeUpdate->sType)
992 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800993 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
994 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
995 if (pWDS->pDescriptors)
996 delete[] pWDS->pDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600997 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800998 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600999 break;
1000 default:
1001 assert(0);
1002 break;
1003 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001004 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001005 }
1006}
Tobin Ehlis793ad302015-04-03 12:01:11 -06001007// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001008// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001009static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001010{
David Pinedod8f83d82015-04-27 16:36:17 -06001011 if (poolMap.size() <= 0)
1012 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001013 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001014 SET_NODE* pSet = (*ii).second->pSets;
1015 SET_NODE* pFreeSet = pSet;
1016 while (pSet) {
1017 pFreeSet = pSet;
1018 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001019 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001020 // Free Update shadow struct tree
1021 freeShadowUpdateTree(pFreeSet);
1022 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +12001023 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001024 }
1025 delete pFreeSet;
1026 }
1027 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes02038792015-06-04 10:49:27 +12001028 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001029 }
1030 delete (*ii).second;
1031 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001032 poolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001033}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001034// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001035// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001036static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001037{
David Pinedod8f83d82015-04-27 16:36:17 -06001038 if (layoutMap.size() <= 0)
1039 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001040 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001041 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001042 if (pLayout->createInfo.pBinding) {
1043 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1044 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1045 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1046 }
1047 delete[] pLayout->createInfo.pBinding;
1048 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001049 if (pLayout->pTypes) {
Chris Forbes02038792015-06-04 10:49:27 +12001050 delete[] pLayout->pTypes;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001051 }
1052 delete pLayout;
1053 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001054 layoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001055}
1056// Currently clearing a set is removing all previous updates to that set
1057// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001058static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001059{
1060 SET_NODE* pSet = getSetNode(set);
1061 if (!pSet) {
1062 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06001063 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001064 loader_platform_thread_lock_mutex(&globalLock);
1065 freeShadowUpdateTree(pSet);
1066 loader_platform_thread_unlock_mutex(&globalLock);
1067 }
1068}
1069
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001070static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001071{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001072 POOL_NODE* pPool = getPoolNode(pool);
1073 if (!pPool) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001074 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1075 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001076 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001077 // For every set off of this pool, clear it
1078 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001079 while (pSet) {
1080 clearDescriptorSet(pSet->set);
1081 }
1082 }
1083}
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001084// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001085static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001086{
1087 loader_platform_thread_lock_mutex(&globalLock);
1088 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1089 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001090 // TODO : How to pass cb as srcObj here?
1091 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001092 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001093 return NULL;
1094 }
1095 loader_platform_thread_unlock_mutex(&globalLock);
1096 return cmdBufferMap[cb];
1097}
1098// Free all CB Nodes
1099// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001100static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001101{
David Pinedod8f83d82015-04-27 16:36:17 -06001102 if (cmdBufferMap.size() <= 0)
1103 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001104 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06001105 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1106 while (!cmd_node_list.empty()) {
1107 CMD_NODE* cmd_node = cmd_node_list.back();
1108 delete cmd_node;
1109 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001110 }
1111 delete (*ii).second;
1112 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001113 cmdBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001114}
Tobin Ehlis9c536442015-06-19 13:00:59 -06001115static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1116{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001117 // TODO : How to pass cb as srcObj here?
1118 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_BEGIN_CMD_BUFFER, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06001119 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1120}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001121static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1122{
1123 CMD_NODE* pCmd = new CMD_NODE;
1124 if (pCmd) {
1125 // init cmd node and append to end of cmd LL
1126 memset(pCmd, 0, sizeof(CMD_NODE));
1127 pCmd->cmdNumber = ++pCB->numCmds;
1128 pCmd->type = cmd;
1129 pCB->pCmds.push_back(pCmd);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001130 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001131 // TODO : How to pass cb as srcObj here?
1132 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001133 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001134 }
1135}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001136static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001137{
1138 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1139 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001140 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1141 while (!cmd_list.empty()) {
1142 delete cmd_list.back();
1143 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001144 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001145 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001146 // Reset CB state (need to save createInfo)
1147 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001148 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1149 pCB->cmdBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001150 pCB->createInfo = saveCBCI;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001151 pCB->lastVtxBinding = MAX_BINDING;
1152 }
1153}
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001154// Set PSO-related status bits for CB
1155static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1156{
1157 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1158 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1159 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1160 }
1161 }
1162 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop82485a82015-08-18 15:21:16 -06001163 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1164 }
1165
1166 if (pPipe->dsStateCI.stencilTestEnable) {
1167 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001168 }
1169}
1170// Set dyn-state related status bits for an object node
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001171static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001172 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1173 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
Cody Northrop271ba752015-08-26 10:01:32 -06001174 } else if (stateBindPoint == VK_STATE_BIND_POINT_LINE_WIDTH) {
1175 pNode->status |= CBSTATUS_LINE_WIDTH_BOUND;
1176 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BIAS) {
1177 pNode->status |= CBSTATUS_DEPTH_BIAS_BOUND;
1178 } else if (stateBindPoint == VK_STATE_BIND_POINT_BLEND) {
1179 pNode->status |= CBSTATUS_BLEND_BOUND;
1180 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_BOUNDS) {
1181 pNode->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
Cody Northrop82485a82015-08-18 15:21:16 -06001182 } else if (stateBindPoint == VK_STATE_BIND_POINT_STENCIL) {
1183 pNode->status |= CBSTATUS_STENCIL_BOUND;
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001184 }
1185}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001186// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001187static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001188{
1189 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1190 if (pCB) {
1191 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1192 if (!pPipeTrav) {
1193 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06001194 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001195 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001196 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001197 }
1198 }
1199}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001200// Print details of DS config to stdout
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001201static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001202{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001203 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.
1204 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06001205 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001206 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001207 POOL_NODE* pPool = getPoolNode(pSet->pool);
1208 // Print out pool details
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001209 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1210 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001211 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001212 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001213 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001214 // Print out set details
1215 char prefix[10];
1216 uint32_t index = 0;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001217 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1218 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001219 LAYOUT_NODE* pLayout = pSet->pLayout;
1220 // Print layout details
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001221 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1222 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001223 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001224 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001225 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001226 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06001227 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001228 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1229 if (pUpdate) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001230 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1231 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001232 sprintf(prefix, " [UC] ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001233 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001234 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001235 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06001236 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001237 if (0 != pSet->descriptorCount) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001238 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1239 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", pSet->set.handle, pSet->descriptorCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001240 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001241 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1242 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001243 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001244 }
1245 }
1246}
1247
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001248static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001249{
1250 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001251 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001252 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001253 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001254 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001255 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1256 // TODO : Need to pass cb as srcObj here
1257 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001258 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001259 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06001260 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001261 // Nothing to print
1262 }
1263}
1264
1265
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001266static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001267{
Mike Stroyanba35e352015-08-12 17:11:28 -06001268 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
1269 return;
1270 }
Mark Lobodzinski3f41c7c2015-08-07 17:11:09 -06001271 printDSConfig(cb);
1272 printPipeline(cb);
1273 printDynamicState(cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001274}
1275
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001276static void init_draw_state(layer_data *my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001277{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001278 uint32_t report_flags = 0;
1279 uint32_t debug_action = 0;
1280 FILE *log_output = NULL;
1281 const char *option_str;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001282 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001283 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1284 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001285
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001286 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001287 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001288 option_str = getLayerOption("DrawStateLogFilename");
1289 if (option_str)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001290 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001291 log_output = fopen(option_str, "w");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001292 }
Tobin Ehlisb80b4252015-09-01 11:59:36 -06001293 if (log_output == NULL) {
1294 if (option_str)
1295 cout << endl << "DrawState ERROR: Bad output filename specified: " << option_str << ". Writing to STDOUT instead" << endl << endl;
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001296 log_output = stdout;
Tobin Ehlisb80b4252015-09-01 11:59:36 -06001297 }
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001298
1299 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001300 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001301
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001302 if (!globalLockInitialized)
1303 {
1304 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001305 // suggestion is to call this during vkCreateInstance(), and then we
1306 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001307 // that the layer have per-instance locks. We need to come back and
1308 // address this soon.
1309 loader_platform_thread_create_mutex(&globalLock);
1310 globalLockInitialized = 1;
1311 }
1312}
1313
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001314VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1315{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001316 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001317 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1318
1319 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001320 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1321 my_data->report_data = debug_report_create_instance(
1322 pTable,
1323 *pInstance,
1324 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001325 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001326
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001327 init_draw_state(my_data);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001328 }
1329 return result;
1330}
1331
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001332/* hook DestroyInstance to remove tableInstanceMap entry */
1333VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1334{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001335 dispatch_key key = get_dispatch_key(instance);
1336 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1337 VkResult res = pTable->DestroyInstance(instance);
1338
1339 // Clean up logging callback, if any
1340 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1341 if (my_data->logging_callback) {
1342 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1343 }
1344
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001345 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001346 layer_data_map.erase(pTable);
1347
1348 draw_state_instance_table_map.erase(key);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001349 return res;
1350}
1351
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001352static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1353{
Tony Barbour3b4732f2015-07-13 13:37:24 -06001354 uint32_t i;
Jon Ashburn747f2b62015-06-18 15:02:58 -06001355 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburneab34492015-06-01 09:37:38 -06001356 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001357
1358 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001359 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06001360 /* Found a matching extension name, mark it enabled and init dispatch table*/
1361 initDebugMarkerTable(device);
1362 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001363 }
1364
1365 }
1366}
1367
Tony Barbourd1c35722015-04-16 15:59:00 -06001368VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001369{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06001370 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1371 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001372 if (result == VK_SUCCESS) {
1373 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1374 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1375 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1376 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001377 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001378 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001379 return result;
1380}
1381
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001382VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001383{
1384 // Free all the memory
1385 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001386 deletePipelines();
1387 deleteSamplers();
1388 deleteImages();
1389 deleteBuffers();
1390 deleteCmdBuffers();
1391 deleteDynamicState();
1392 deletePools();
1393 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001394 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001395
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001396 dispatch_key key = get_dispatch_key(device);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001397 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1398 VkResult result = pDisp->DestroyDevice(device);
1399 deviceExtMap.erase(pDisp);
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001400 draw_state_device_table_map.erase(key);
Jon Ashburneab34492015-06-01 09:37:38 -06001401 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001402 return result;
1403}
1404
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001405static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001406 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001407 "DrawState",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001408 VK_API_VERSION,
1409 VK_MAKE_VERSION(0, 1, 0),
1410 "Validation layer: DrawState",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001411 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001412};
1413
Tony Barbour59a47322015-06-24 16:06:58 -06001414VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001415 const char *pLayerName,
1416 uint32_t *pCount,
1417 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001418{
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001419 /* DrawState does not have any global extensions */
1420 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1421}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001422
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001423VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1424 uint32_t *pCount,
1425 VkLayerProperties* pProperties)
1426{
1427 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1428 ds_global_layers,
1429 pCount, pProperties);
1430}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001431
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001432static const VkExtensionProperties ds_device_extensions[] = {
1433 {
1434 DEBUG_MARKER_EXTENSION_NAME,
1435 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001436 }
1437};
1438
1439static const VkLayerProperties ds_device_layers[] = {
1440 {
1441 "DrawState",
1442 VK_API_VERSION,
1443 VK_MAKE_VERSION(0, 1, 0),
1444 "Validation layer: DrawState",
1445 }
1446};
1447
1448VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1449 VkPhysicalDevice physicalDevice,
1450 const char* pLayerName,
1451 uint32_t* pCount,
1452 VkExtensionProperties* pProperties)
1453{
1454 /* Mem tracker does not have any physical device extensions */
1455 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1456 pCount, pProperties);
1457}
1458
1459VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1460 VkPhysicalDevice physicalDevice,
1461 uint32_t* pCount,
1462 VkLayerProperties* pProperties)
1463{
1464 /* Mem tracker's physical device layers are the same as global */
1465 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1466 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001467}
1468
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001469VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001470{
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001471 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001472 for (uint32_t i=0; i < cmdBufferCount; i++) {
1473 // Validate that cmd buffers have been updated
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001474 pCB = getCBNode(pCmdBuffers[i]);
1475 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001476 pCB->submitCount++; // increment submit count
1477 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
1478 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CMD_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001479 "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 Ehlis59278bf2015-08-18 07:10:58 -06001480 }
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001481 if (CB_UPDATE_COMPLETE != pCB->state) {
1482 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001483 // TODO : How to pass cb as srcObj?
1484 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06001485 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001486 loader_platform_thread_unlock_mutex(&globalLock);
1487 return VK_ERROR_UNKNOWN;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001488 }
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06001489 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001490 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001491
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001492 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001493 return result;
1494}
1495
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001496VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001497{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001498 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1499 // TODO : Clean up any internal data structures using this obj.
1500 return result;
1501}
1502
1503VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1504{
1505 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1506 // TODO : Clean up any internal data structures using this obj.
1507 return result;
1508}
1509
1510VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1511{
1512 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1513 // TODO : Clean up any internal data structures using this obj.
1514 return result;
1515}
1516
1517VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1518{
1519 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1520 // TODO : Clean up any internal data structures using this obj.
1521 return result;
1522}
1523
1524VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1525{
1526 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1527 // TODO : Clean up any internal data structures using this obj.
1528 return result;
1529}
1530
1531VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1532{
1533 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1534 // TODO : Clean up any internal data structures using this obj.
1535 return result;
1536}
1537
1538VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1539{
1540 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1541 // TODO : Clean up any internal data structures using this obj.
1542 return result;
1543}
1544
1545VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1546{
1547 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1548 // TODO : Clean up any internal data structures using this obj.
1549 return result;
1550}
1551
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001552VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1553{
1554 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1555 // TODO : Clean up any internal data structures using this obj.
1556 return result;
1557}
1558
1559VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1560{
1561 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1562 // TODO : Clean up any internal data structures using this obj.
1563 return result;
1564}
1565
1566VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1567{
1568 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1569 // TODO : Clean up any internal data structures using this obj.
1570 return result;
1571}
1572
1573VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1574{
1575 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1576 // TODO : Clean up any internal data structures using this obj.
1577 return result;
1578}
1579
1580VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1581{
1582 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1583 // TODO : Clean up any internal data structures using this obj.
1584 return result;
1585}
1586
1587VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1588{
1589 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1590 // TODO : Clean up any internal data structures using this obj.
1591 return result;
1592}
1593
1594VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1595{
1596 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1597 // TODO : Clean up any internal data structures using this obj.
1598 return result;
1599}
1600
1601VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1602{
1603 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1604 // TODO : Clean up any internal data structures using this obj.
1605 return result;
1606}
1607
Cody Northrop271ba752015-08-26 10:01:32 -06001608VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicLineWidthState(VkDevice device, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001609{
Cody Northrop271ba752015-08-26 10:01:32 -06001610 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicLineWidthState(device, dynamicLineWidthState);
Cody Northrop12365112015-08-17 11:10:49 -06001611 // TODO : Clean up any internal data structures using this obj.
1612 return result;
1613}
1614
Cody Northrop271ba752015-08-26 10:01:32 -06001615VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthBiasState(VkDevice device, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northrop12365112015-08-17 11:10:49 -06001616{
Cody Northrop271ba752015-08-26 10:01:32 -06001617 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBiasState(device, dynamicDepthBiasState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001618 // TODO : Clean up any internal data structures using this obj.
1619 return result;
1620}
1621
Cody Northrop271ba752015-08-26 10:01:32 -06001622VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicBlendState(VkDevice device, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001623{
Cody Northrop271ba752015-08-26 10:01:32 -06001624 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicBlendState(device, dynamicBlendState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001625 // TODO : Clean up any internal data structures using this obj.
1626 return result;
1627}
1628
Cody Northrop271ba752015-08-26 10:01:32 -06001629VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthBoundsState(VkDevice device, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001630{
Cody Northrop271ba752015-08-26 10:01:32 -06001631 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthBoundsState(device, dynamicDepthBoundsState);
Cody Northrop82485a82015-08-18 15:21:16 -06001632 // TODO : Clean up any internal data structures using this obj.
1633 return result;
1634}
1635
1636VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicStencilState(VkDevice device, VkDynamicStencilState dynamicStencilState)
1637{
1638 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicStencilState(device, dynamicStencilState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001639 // TODO : Clean up any internal data structures using this obj.
1640 return result;
1641}
1642
1643VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1644{
1645 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1646 // TODO : Clean up any internal data structures using this obj.
1647 return result;
1648}
1649
1650VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1651{
1652 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1653 // TODO : Clean up any internal data structures using this obj.
1654 return result;
1655}
1656
1657VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1658{
1659 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1660 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001661 return result;
1662}
1663
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001664VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001665{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001666 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001667 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001668 loader_platform_thread_lock_mutex(&globalLock);
1669 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1670 pNewNode->buffer = *pView;
1671 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001672 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001673 loader_platform_thread_unlock_mutex(&globalLock);
1674 }
1675 return result;
1676}
1677
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001678VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001679{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001680 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001681 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001682 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001683 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001684 loader_platform_thread_unlock_mutex(&globalLock);
1685 }
1686 return result;
1687}
1688
Jon Ashburnc669cc62015-07-09 15:02:25 -06001689//TODO handle pipeline caches
1690VkResult VKAPI vkCreatePipelineCache(
1691 VkDevice device,
1692 const VkPipelineCacheCreateInfo* pCreateInfo,
1693 VkPipelineCache* pPipelineCache)
1694{
1695 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1696 return result;
1697}
1698
1699VkResult VKAPI vkDestroyPipelineCache(
1700 VkDevice device,
1701 VkPipelineCache pipelineCache)
1702{
1703 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1704 return result;
1705}
1706
1707size_t VKAPI vkGetPipelineCacheSize(
1708 VkDevice device,
1709 VkPipelineCache pipelineCache)
1710{
1711 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1712 return size;
1713}
1714
1715VkResult VKAPI vkGetPipelineCacheData(
1716 VkDevice device,
1717 VkPipelineCache pipelineCache,
1718 void* pData)
1719{
1720 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1721 return result;
1722}
1723
1724VkResult VKAPI vkMergePipelineCaches(
1725 VkDevice device,
1726 VkPipelineCache destCache,
1727 uint32_t srcCacheCount,
1728 const VkPipelineCache* pSrcCaches)
1729{
1730 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1731 return result;
1732}
1733
1734VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001735{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001736 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001737 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001738 // The order of operations here is a little convoluted but gets the job done
1739 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1740 // 2. Create state is then validated (which uses flags setup during shadowing)
1741 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1742 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001743 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001744 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001745 loader_platform_thread_unlock_mutex(&globalLock);
1746 if (VK_TRUE == valid) {
Jon Ashburnc669cc62015-07-09 15:02:25 -06001747 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001748 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1749 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001750 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001751 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001752 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001753 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001754 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001755 if (pPipeNode) {
1756 // If we allocated a pipeNode, need to clean it up here
1757 delete[] pPipeNode->pVertexBindingDescriptions;
1758 delete[] pPipeNode->pVertexAttributeDescriptions;
1759 delete[] pPipeNode->pAttachments;
1760 delete pPipeNode;
1761 }
1762 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001763 return result;
1764}
1765
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001766VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001767{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001768 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001769 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001770 loader_platform_thread_lock_mutex(&globalLock);
1771 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1772 pNewNode->sampler = *pSampler;
1773 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001774 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001775 loader_platform_thread_unlock_mutex(&globalLock);
1776 }
1777 return result;
1778}
1779
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001780VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001781{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001782 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001783 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001784 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1785 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001786 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001787 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001788 }
1789 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001790 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1791 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1792 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001793 uint32_t totalCount = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001794 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001795 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001796 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001797 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001798 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1799 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001800 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001801 }
1802 if (totalCount > 0) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001803 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001804 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001805 uint32_t j = 0;
1806 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001807 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001808 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001809 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001810 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001811 }
1812 }
1813 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001814 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001815 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1816 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001817 // Put new node at Head of global Layer list
1818 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001819 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001820 loader_platform_thread_unlock_mutex(&globalLock);
1821 }
1822 return result;
1823}
1824
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001825VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001826{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001827 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001828 if (VK_SUCCESS == result) {
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001829 // TODO : Need to capture the pipeline layout
Tobin Ehlis793ad302015-04-03 12:01:11 -06001830 }
1831 return result;
1832}
1833
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001834VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001835{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001836 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001837 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001838 // Insert this pool into Global Pool LL at head
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001839 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1840 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001841 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001842 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001843 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001844 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001845 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisce132d82015-06-19 15:07:05 -06001846 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001847 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001848 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1849 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001850 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001851 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1852 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001853 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1854 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001855 pNewNode->poolUsage = poolUsage;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001856 pNewNode->maxSets = maxSets;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001857 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001858 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001859 }
1860 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001861 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001862 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001863 }
1864 return result;
1865}
1866
Mike Stroyanb050c682015-04-17 12:36:38 -06001867VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001868{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001869 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001870 if (VK_SUCCESS == result) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001871 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001872 }
1873 return result;
1874}
1875
Cody Northrop1e4f8022015-08-03 12:47:29 -06001876VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001877{
Cody Northrop1e4f8022015-08-03 12:47:29 -06001878 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1879 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001880 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1881 if (!pPoolNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001882 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1883 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001884 } else {
Cody Northrop1e4f8022015-08-03 12:47:29 -06001885 if (count == 0) {
1886 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1887 "AllocDescriptorSets called with 0 count");
1888 }
1889 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001890 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1891 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001892 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001893 SET_NODE* pNewNode = new SET_NODE;
1894 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001895 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001896 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisce132d82015-06-19 15:07:05 -06001897 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001898 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001899 // Insert set at head of Set LL for this pool
1900 pNewNode->pNext = pPoolNode->pSets;
1901 pPoolNode->pSets = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001902 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1903 if (NULL == pLayout) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001904 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1905 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001906 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001907 pNewNode->pLayout = pLayout;
1908 pNewNode->pool = descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001909 pNewNode->set = pDescriptorSets[i];
1910 pNewNode->setUsage = setUsage;
1911 pNewNode->descriptorCount = pLayout->endIndex + 1;
1912 if (pNewNode->descriptorCount) {
1913 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1914 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1915 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1916 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001917 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001918 }
1919 }
1920 }
1921 }
1922 return result;
1923}
1924
Tony Barbour34ec6922015-07-10 10:50:45 -06001925VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1926{
1927 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1928 // TODO : Clean up any internal data structures using this obj.
1929 return result;
1930}
1931
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001932VK_LAYER_EXPORT VkResult VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001933{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001934 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1935 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001936 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001937 }
1938 return VK_ERROR_UNKNOWN;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001939}
1940
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001941VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001942{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001943 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001944 VkDynamicViewportStateCreateInfo local_ci;
1945 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1946 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1947 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1948 loader_platform_thread_lock_mutex(&globalLock);
1949 dynamicVpStateMap[pState->handle] = local_ci;
1950 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001951 return result;
1952}
1953
Cody Northrop271ba752015-08-26 10:01:32 -06001954VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicLineWidthState(VkDevice device, const VkDynamicLineWidthStateCreateInfo* pCreateInfo, VkDynamicLineWidthState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001955{
Cody Northrop271ba752015-08-26 10:01:32 -06001956 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicLineWidthState(device, pCreateInfo, pState);
1957 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_LINE_WIDTH);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001958 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06001959 dynamicLineWidthStateMap[pState->handle] = *pCreateInfo;
Cody Northrop12365112015-08-17 11:10:49 -06001960 loader_platform_thread_unlock_mutex(&globalLock);
1961 return result;
1962}
1963
Cody Northrop271ba752015-08-26 10:01:32 -06001964VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBiasState(VkDevice device, const VkDynamicDepthBiasStateCreateInfo* pCreateInfo, VkDynamicDepthBiasState* pState)
Cody Northrop12365112015-08-17 11:10:49 -06001965{
Cody Northrop271ba752015-08-26 10:01:32 -06001966 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBiasState(device, pCreateInfo, pState);
1967 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BIAS);
Cody Northrop12365112015-08-17 11:10:49 -06001968 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06001969 dynamicDepthBiasStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001970 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001971 return result;
1972}
1973
Cody Northrop271ba752015-08-26 10:01:32 -06001974VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicBlendState(VkDevice device, const VkDynamicBlendStateCreateInfo* pCreateInfo, VkDynamicBlendState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001975{
Cody Northrop271ba752015-08-26 10:01:32 -06001976 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicBlendState(device, pCreateInfo, pState);
1977 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_BLEND);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001978 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06001979 dynamicBlendStateMap[pState->handle] = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001980 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001981 return result;
1982}
1983
Cody Northrop271ba752015-08-26 10:01:32 -06001984VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthBoundsState(VkDevice device, const VkDynamicDepthBoundsStateCreateInfo* pCreateInfo, VkDynamicDepthBoundsState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001985{
Cody Northrop271ba752015-08-26 10:01:32 -06001986 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthBoundsState(device, pCreateInfo, pState);
1987 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_BOUNDS);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001988 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06001989 dynamicDepthBoundsStateMap[pState->handle] = *pCreateInfo;
Cody Northrop82485a82015-08-18 15:21:16 -06001990 loader_platform_thread_unlock_mutex(&globalLock);
1991 return result;
1992}
1993
1994VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicStencilState(VkDevice device, const VkDynamicStencilStateCreateInfo* pCreateInfoFront, const VkDynamicStencilStateCreateInfo* pCreateInfoBack, VkDynamicStencilState* pState)
1995{
1996 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicStencilState(device, pCreateInfoFront, pCreateInfoBack, pState);
1997 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_STENCIL);
1998 loader_platform_thread_lock_mutex(&globalLock);
1999
2000 // Bug 14406 - If back is NULL or equal to front, then single sided.
2001 // To support NULL case, simply track front twice
2002 const VkDynamicStencilStateCreateInfo* pLocalCreateInfoBack = (pCreateInfoBack == NULL) ? pCreateInfoFront : pCreateInfoBack;
2003
2004 std::pair<VkDynamicStencilStateCreateInfo, VkDynamicStencilStateCreateInfo> infos(*pCreateInfoFront, *pLocalCreateInfoBack);
2005 dynamicStencilStateMap[pState->handle] = infos;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002006 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002007 return result;
2008}
2009
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002010VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002011{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002012 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002013 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002014 loader_platform_thread_lock_mutex(&globalLock);
2015 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
2016 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
2017 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002018 pCB->createInfo = *pCreateInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002019 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002020 pCB->level = pCreateInfo->level;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002021 cmdBufferMap[*pCmdBuffer] = pCB;
2022 loader_platform_thread_unlock_mutex(&globalLock);
2023 updateCBTracking(*pCmdBuffer);
2024 }
2025 return result;
2026}
2027
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002028VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002029{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002030 // Validate command buffer level
2031 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2032 if (pCB) {
2033 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
2034 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2035 // These should be NULL for a Primary CB
2036 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2037 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2038 }
2039 } else {
2040 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2041 // These should NOT be null for an Secondary CB
2042 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2043 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2044 }
2045 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002046 pCB->beginInfo = *pBeginInfo;
2047 } else {
2048 // TODO : Need to pass cmdBuffer as objType here
2049 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
2050 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002051 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002052 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002053 if (VK_SUCCESS == result) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002054 if (CB_NEW != pCB->state)
2055 resetCB(cmdBuffer);
2056 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002057 updateCBTracking(cmdBuffer);
2058 }
2059 return result;
2060}
2061
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002062VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002063{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002064 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2065 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2066 if (pCB) {
2067 if (pCB->state == CB_UPDATE_ACTIVE) {
2068 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2069 if (VK_SUCCESS == result) {
2070 updateCBTracking(cmdBuffer);
2071 pCB->state = CB_UPDATE_COMPLETE;
2072 // Reset CB status flags
2073 pCB->status = 0;
2074 printCB(cmdBuffer);
2075 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002076 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002077 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002078 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002079 }
2080 return result;
2081}
2082
Cody Northrope62183e2015-07-09 18:08:05 -06002083VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002084{
Cody Northrope62183e2015-07-09 18:08:05 -06002085 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002086 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002087 resetCB(cmdBuffer);
2088 updateCBTracking(cmdBuffer);
2089 }
2090 return result;
2091}
2092
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002093VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002094{
2095 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2096 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002097 if (pCB->state == CB_UPDATE_ACTIVE) {
2098 updateCBTracking(cmdBuffer);
2099 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis6d58e6d2015-06-23 08:46:18 -06002100 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002101 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2102 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002103 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002104 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2105 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002106 } else {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002107 PIPELINE_NODE* pPN = getPipeline(pipeline);
2108 if (pPN) {
2109 pCB->lastBoundPipeline = pipeline;
2110 loader_platform_thread_lock_mutex(&globalLock);
2111 set_cb_pso_status(pCB, pPN);
2112 g_lastBoundPipeline = pPN;
2113 loader_platform_thread_unlock_mutex(&globalLock);
2114 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2115 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2116 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002117 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2118 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002119 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002120 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002121 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002122 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002123 }
2124 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002125}
2126
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002127VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002128{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002129 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2130 if (pCB) {
2131 if (pCB->state == CB_UPDATE_ACTIVE) {
2132 updateCBTracking(cmdBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002133 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002134 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002135 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2136 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlis502480b2015-06-24 15:53:07 -06002137 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002138 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002139 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2140 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002141 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 Ehlis60a9b4f2015-07-07 10:42:20 -06002142 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002143 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002144 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2145 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002146 }
2147 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002148 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002149 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002150 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002151 }
2152 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002153}
Cody Northrop271ba752015-08-26 10:01:32 -06002154VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(VkCmdBuffer cmdBuffer, VkDynamicLineWidthState dynamicLineWidthState)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002155{
2156 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2157 if (pCB) {
2158 if (pCB->state == CB_UPDATE_ACTIVE) {
2159 updateCBTracking(cmdBuffer);
Cody Northrop271ba752015-08-26 10:01:32 -06002160 addCmd(pCB, CMD_BINDDYNAMICLINEWIDTHSTATE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002161 if (!pCB->activeRenderPass) {
2162 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrop271ba752015-08-26 10:01:32 -06002163 "Incorrect call to vkCmdBindDynamicLineWidthState() without an active RenderPass.");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002164 }
2165 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002166 pCB->status |= CBSTATUS_LINE_WIDTH_BOUND;
2167 if (dynamicLineWidthStateMap.find(dynamicLineWidthState.handle) == dynamicLineWidthStateMap.end()) {
2168 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",
2169 "Unable to find VkDynamicLineWidthState object %#" PRIxLEAST64 ", was it ever created?", dynamicLineWidthState.handle);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002170 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002171 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
2172 g_lastBoundDynamicState[VK_STATE_BIND_POINT_LINE_WIDTH] = dynamicLineWidthState.handle;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002173 }
2174 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002175 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicLineWidthState(cmdBuffer, dynamicLineWidthState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002176 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002177 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northrop12365112015-08-17 11:10:49 -06002178 }
2179 }
2180}
Cody Northrop271ba752015-08-26 10:01:32 -06002181VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(VkCmdBuffer cmdBuffer, VkDynamicDepthBiasState dynamicDepthBiasState)
Cody Northrop12365112015-08-17 11:10:49 -06002182{
2183 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2184 if (pCB) {
2185 if (pCB->state == CB_UPDATE_ACTIVE) {
2186 updateCBTracking(cmdBuffer);
Cody Northrop271ba752015-08-26 10:01:32 -06002187 addCmd(pCB, CMD_BINDDYNAMICDEPTHBIASSTATE);
Cody Northrop12365112015-08-17 11:10:49 -06002188 if (!pCB->activeRenderPass) {
2189 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrop271ba752015-08-26 10:01:32 -06002190 "Incorrect call to vkCmdBindDynamicDepthBiasState() without an active RenderPass.");
Cody Northrop12365112015-08-17 11:10:49 -06002191 }
2192 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002193 pCB->status |= CBSTATUS_DEPTH_BIAS_BOUND;
2194 if (dynamicDepthBiasStateMap.find(dynamicDepthBiasState.handle) == dynamicDepthBiasStateMap.end()) {
2195 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",
2196 "Unable to find VkDynamicDepthBiasState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBiasState.handle);
Cody Northrop12365112015-08-17 11:10:49 -06002197 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002198 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
2199 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BIAS] = dynamicDepthBiasState.handle;
Cody Northrop12365112015-08-17 11:10:49 -06002200 }
2201 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002202 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBiasState(cmdBuffer, dynamicDepthBiasState);
Cody Northrop12365112015-08-17 11:10:49 -06002203 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002204 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBiasState()");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002205 }
2206 }
2207}
Cody Northrop271ba752015-08-26 10:01:32 -06002208VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicBlendState(VkCmdBuffer cmdBuffer, VkDynamicBlendState dynamicBlendState)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002209{
2210 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2211 if (pCB) {
2212 if (pCB->state == CB_UPDATE_ACTIVE) {
2213 updateCBTracking(cmdBuffer);
Cody Northrop271ba752015-08-26 10:01:32 -06002214 addCmd(pCB, CMD_BINDDYNAMICBLENDSTATE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002215 if (!pCB->activeRenderPass) {
2216 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrop271ba752015-08-26 10:01:32 -06002217 "Incorrect call to vkCmdBindDynamicBlendState() without an active RenderPass.");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002218 }
2219 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002220 pCB->status |= CBSTATUS_BLEND_BOUND;
2221 if (dynamicBlendStateMap.find(dynamicBlendState.handle) == dynamicBlendStateMap.end()) {
2222 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_BLEND_STATE, dynamicBlendState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
2223 "Unable to find VkDynamicBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicBlendState.handle);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002224 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002225 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
2226 g_lastBoundDynamicState[VK_STATE_BIND_POINT_BLEND] = dynamicBlendState.handle;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002227 }
2228 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002229 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicBlendState(cmdBuffer, dynamicBlendState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002230 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002231 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicBlendState()");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002232 }
2233 }
2234}
Cody Northrop271ba752015-08-26 10:01:32 -06002235VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(VkCmdBuffer cmdBuffer, VkDynamicDepthBoundsState dynamicDepthBoundsState)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002236{
2237 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2238 if (pCB) {
2239 if (pCB->state == CB_UPDATE_ACTIVE) {
2240 updateCBTracking(cmdBuffer);
Cody Northrop271ba752015-08-26 10:01:32 -06002241 addCmd(pCB, CMD_BINDDYNAMICDEPTHBOUNDSSTATE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002242 if (!pCB->activeRenderPass) {
2243 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Cody Northrop271ba752015-08-26 10:01:32 -06002244 "Incorrect call to vkCmdBindDynamicDepthBoundsState() without an active RenderPass.");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002245 }
2246 loader_platform_thread_lock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002247 pCB->status |= CBSTATUS_DEPTH_BOUNDS_BOUND;
2248 if (dynamicDepthBoundsStateMap.find(dynamicDepthBoundsState.handle) == dynamicDepthBoundsStateMap.end()) {
2249 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",
2250 "Unable to find VkDynamicDepthBoundsState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthBoundsState.handle);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002251 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002252 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
2253 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_BOUNDS] = dynamicDepthBoundsState.handle;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002254 }
2255 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrop271ba752015-08-26 10:01:32 -06002256 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthBoundsState(cmdBuffer, dynamicDepthBoundsState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002257 } else {
Cody Northrop271ba752015-08-26 10:01:32 -06002258 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthBoundsState()");
Cody Northrop82485a82015-08-18 15:21:16 -06002259 }
2260 }
2261}
2262VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStencilState(VkCmdBuffer cmdBuffer, VkDynamicStencilState dynamicStencilState)
2263{
2264 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2265 if (pCB) {
2266 if (pCB->state == CB_UPDATE_ACTIVE) {
2267 updateCBTracking(cmdBuffer);
2268 addCmd(pCB, CMD_BINDDYNAMICSTENCILSTATE);
2269 if (!pCB->activeRenderPass) {
2270 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2271 "Incorrect call to vkCmdBindDynamicStencilState() without an active RenderPass.");
2272 }
2273 loader_platform_thread_lock_mutex(&globalLock);
2274 pCB->status |= CBSTATUS_STENCIL_BOUND;
2275 if (dynamicStencilStateMap.find(dynamicStencilState.handle) == dynamicStencilStateMap.end()) {
2276 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_STENCIL_STATE, dynamicStencilState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
2277 "Unable to find VkDynamicStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicStencilState.handle);
2278 } else {
2279 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2280 g_lastBoundDynamicState[VK_STATE_BIND_POINT_STENCIL] = dynamicStencilState.handle;
2281 }
2282 loader_platform_thread_unlock_mutex(&globalLock);
2283 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicStencilState(cmdBuffer, dynamicStencilState);
2284 } else {
2285 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicStencilState()");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002286 }
2287 }
2288}
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06002289VK_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 Ehlis10ae8c12015-03-17 16:24:32 -06002290{
2291 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2292 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002293 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002294 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002295 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2296 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002297 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002298 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis502480b2015-06-24 15:53:07 -06002299 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06002300 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002301 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002302 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2303 if (pSet) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002304 loader_platform_thread_lock_mutex(&globalLock);
2305 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002306 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002307 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2308 g_lastBoundDescriptorSet = pDescriptorSets[i];
2309 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002310 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2311 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002312 if (!pSet->pUpdateStructs)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002313 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2314 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", pDescriptorSets[i].handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002315 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002316 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2317 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002318 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002319 }
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002320 updateCBTracking(cmdBuffer);
2321 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis7ae7c6a2015-06-22 18:00:14 -06002322 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002323 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002324 } else {
2325 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002326 }
2327 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002328}
2329
Tony Barbourd1c35722015-04-16 15:59:00 -06002330VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002331{
2332 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2333 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002334 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002335 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002336 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis502480b2015-06-24 15:53:07 -06002337 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2338 } else {
2339 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2340 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002341 updateCBTracking(cmdBuffer);
2342 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002343 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2344 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002345 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002346 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2347 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002348 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002349}
2350
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002351VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2352 VkCmdBuffer cmdBuffer,
2353 uint32_t startBinding,
2354 uint32_t bindingCount,
2355 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002356 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002357{
2358 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2359 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002360 if (pCB->state == CB_UPDATE_ACTIVE) {
2361 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis502480b2015-06-24 15:53:07 -06002362 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002363 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis502480b2015-06-24 15:53:07 -06002364 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2365 } else {
2366 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06002367 updateCBTracking(cmdBuffer);
2368 addCmd(pCB, CMD_BINDVERTEXBUFFER);
2369 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002370 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002371 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002372 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002373 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002374 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002375}
2376
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002377VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002378{
2379 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002380 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002381 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002382 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002383 pCB->drawCount[DRAW]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002384 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002385 // TODO : Need to pass cmdBuffer as srcObj here
2386 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002387 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2388 synchAndPrintDSConfig(cmdBuffer);
2389 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002390 updateCBTracking(cmdBuffer);
2391 addCmd(pCB, CMD_DRAW);
2392 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002393 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002394 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002395 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2396 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002397 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002398}
2399
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002400VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002401{
2402 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002403 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002404 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002405 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002406 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002407 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002408 // TODO : Need to pass cmdBuffer as srcObj here
2409 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002410 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2411 synchAndPrintDSConfig(cmdBuffer);
2412 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002413 updateCBTracking(cmdBuffer);
2414 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002415 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2416 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002417 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002418 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2419 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002420 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002421}
2422
Tony Barbourd1c35722015-04-16 15:59:00 -06002423VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002424{
2425 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002426 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002427 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002428 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002429 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002430 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002431 // TODO : Need to pass cmdBuffer as srcObj here
2432 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002433 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2434 synchAndPrintDSConfig(cmdBuffer);
2435 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002436 updateCBTracking(cmdBuffer);
2437 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002438 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2439 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002440 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002441 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2442 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002443 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002444}
2445
Tony Barbourd1c35722015-04-16 15:59:00 -06002446VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002447{
2448 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002449 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002450 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002451 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002452 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002453 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002454 // TODO : Need to pass cmdBuffer as srcObj here
2455 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis9c536442015-06-19 13:00:59 -06002456 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2457 synchAndPrintDSConfig(cmdBuffer);
2458 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002459 updateCBTracking(cmdBuffer);
2460 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2461 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002462 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002463 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002464 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2465 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002466 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002467}
2468
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002469VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002470{
2471 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2472 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002473 if (pCB->state == CB_UPDATE_ACTIVE) {
2474 updateCBTracking(cmdBuffer);
2475 addCmd(pCB, CMD_DISPATCH);
2476 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002477 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002478 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2479 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002480 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002481}
2482
Tony Barbourd1c35722015-04-16 15:59:00 -06002483VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002484{
2485 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2486 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002487 if (pCB->state == CB_UPDATE_ACTIVE) {
2488 updateCBTracking(cmdBuffer);
2489 addCmd(pCB, CMD_DISPATCHINDIRECT);
2490 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002491 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002492 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2493 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002494 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002495}
2496
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002497VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002498{
2499 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2500 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002501 if (pCB->state == CB_UPDATE_ACTIVE) {
2502 updateCBTracking(cmdBuffer);
2503 addCmd(pCB, CMD_COPYBUFFER);
2504 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002505 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002506 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2507 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002508 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002509}
2510
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002511VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2512 VkImage srcImage,
2513 VkImageLayout srcImageLayout,
2514 VkImage destImage,
2515 VkImageLayout destImageLayout,
2516 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002517{
2518 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2519 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002520 if (pCB->state == CB_UPDATE_ACTIVE) {
2521 updateCBTracking(cmdBuffer);
2522 addCmd(pCB, CMD_COPYIMAGE);
2523 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002524 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002525 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2526 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002527 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002528}
2529
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002530VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2531 VkImage srcImage, VkImageLayout srcImageLayout,
2532 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002533 uint32_t regionCount, const VkImageBlit* pRegions,
2534 VkTexFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002535{
2536 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2537 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002538 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehliseac83792015-06-23 10:41:13 -06002539 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002540 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2541 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002542 } else {
2543 updateCBTracking(cmdBuffer);
2544 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002545 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002546 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002547 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002548 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2549 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002550 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002551}
2552
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002553VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2554 VkBuffer srcBuffer,
2555 VkImage destImage, VkImageLayout destImageLayout,
2556 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002557{
2558 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2559 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002560 if (pCB->state == CB_UPDATE_ACTIVE) {
2561 updateCBTracking(cmdBuffer);
2562 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2563 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002564 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002565 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2566 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002567 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002568}
2569
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002570VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2571 VkImage srcImage, VkImageLayout srcImageLayout,
2572 VkBuffer destBuffer,
2573 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002574{
2575 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2576 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002577 if (pCB->state == CB_UPDATE_ACTIVE) {
2578 updateCBTracking(cmdBuffer);
2579 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2580 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002581 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002582 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2583 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002584 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002585}
2586
Tony Barbourd1c35722015-04-16 15:59:00 -06002587VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002588{
2589 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2590 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002591 if (pCB->state == CB_UPDATE_ACTIVE) {
2592 updateCBTracking(cmdBuffer);
2593 addCmd(pCB, CMD_UPDATEBUFFER);
2594 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002595 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002596 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2597 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002598 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002599}
2600
Tony Barbourd1c35722015-04-16 15:59:00 -06002601VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002602{
2603 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2604 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002605 if (pCB->state == CB_UPDATE_ACTIVE) {
2606 updateCBTracking(cmdBuffer);
2607 addCmd(pCB, CMD_FILLBUFFER);
2608 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002609 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002610 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2611 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002612 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002613}
2614
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002615VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2616 VkCmdBuffer cmdBuffer,
2617 uint32_t colorAttachment,
2618 VkImageLayout imageLayout,
2619 const VkClearColorValue* pColor,
2620 uint32_t rectCount,
2621 const VkRect3D* pRects)
2622{
2623 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2624 if (pCB) {
2625 if (pCB->state == CB_UPDATE_ACTIVE) {
2626 // Warn if this is issued prior to Draw Cmd
2627 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002628 // TODO : cmdBuffer should be srcObj
2629 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002630 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06002631 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002632 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002633 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002634 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002635 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2636 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2637 } else {
2638 updateCBTracking(cmdBuffer);
2639 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2640 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2641 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002642 } else {
2643 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2644 }
2645 }
2646}
2647
2648VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2649 VkCmdBuffer cmdBuffer,
2650 VkImageAspectFlags imageAspectMask,
2651 VkImageLayout imageLayout,
2652 float depth,
2653 uint32_t stencil,
2654 uint32_t rectCount,
2655 const VkRect3D* pRects)
2656{
2657 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2658 if (pCB) {
2659 if (pCB->state == CB_UPDATE_ACTIVE) {
2660 // Warn if this is issued prior to Draw Cmd
2661 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002662 // TODO : cmdBuffer should be srcObj
2663 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002664 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchterdee721d2015-08-26 15:09:25 -06002665 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002666 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002667 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002668 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002669 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2670 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2671 } else {
2672 updateCBTracking(cmdBuffer);
2673 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2674 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2675 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002676 } else {
2677 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2678 }
2679 }
2680}
2681
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002682VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2683 VkCmdBuffer cmdBuffer,
2684 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12002685 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002686 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002687{
2688 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2689 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002690 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002691 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002692 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002693 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2694 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2695 } else {
2696 updateCBTracking(cmdBuffer);
2697 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2698 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2699 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002700 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002701 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2702 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002703 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002704}
2705
Chris Forbesd9be82b2015-06-22 17:21:59 +12002706VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002707 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002708 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002709 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002710{
2711 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2712 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002713 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002714 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002715 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlise2473152015-06-23 11:34:28 -06002716 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2717 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2718 } else {
2719 updateCBTracking(cmdBuffer);
2720 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2721 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2722 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002723 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002724 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2725 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002726 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002727}
2728
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002729VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2730 VkImage srcImage, VkImageLayout srcImageLayout,
2731 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002732 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002733{
2734 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2735 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002736 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002737 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002738 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2739 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlise2473152015-06-23 11:34:28 -06002740 } else {
2741 updateCBTracking(cmdBuffer);
2742 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002743 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlise2473152015-06-23 11:34:28 -06002744 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002745 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002746 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2747 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002748 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002749}
2750
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002751VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002752{
2753 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2754 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002755 if (pCB->state == CB_UPDATE_ACTIVE) {
2756 updateCBTracking(cmdBuffer);
2757 addCmd(pCB, CMD_SETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002758 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002759 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002760 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2761 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002762 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002763}
2764
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002765VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002766{
2767 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2768 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002769 if (pCB->state == CB_UPDATE_ACTIVE) {
2770 updateCBTracking(cmdBuffer);
2771 addCmd(pCB, CMD_RESETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002772 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002773 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002774 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2775 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002776 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002777}
2778
Courtney Goeltzenleuchterdbd20322015-07-12 12:58:58 -06002779VK_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 Ehlis10ae8c12015-03-17 16:24:32 -06002780{
2781 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2782 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002783 if (pCB->state == CB_UPDATE_ACTIVE) {
2784 updateCBTracking(cmdBuffer);
2785 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002786 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002787 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002788 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2789 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002790 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002791}
2792
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06002793VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags destStageMask, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002794{
2795 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2796 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002797 if (pCB->state == CB_UPDATE_ACTIVE) {
2798 updateCBTracking(cmdBuffer);
2799 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter53043732015-07-12 13:20:05 -06002800 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002801 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002802 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2803 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002804 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002805}
2806
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002807VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002808{
2809 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2810 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002811 if (pCB->state == CB_UPDATE_ACTIVE) {
2812 updateCBTracking(cmdBuffer);
2813 addCmd(pCB, CMD_BEGINQUERY);
2814 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002815 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002816 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2817 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002818 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002819}
2820
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002821VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002822{
2823 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2824 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002825 if (pCB->state == CB_UPDATE_ACTIVE) {
2826 updateCBTracking(cmdBuffer);
2827 addCmd(pCB, CMD_ENDQUERY);
2828 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002829 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002830 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2831 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002832 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002833}
2834
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002835VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002836{
2837 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2838 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002839 if (pCB->state == CB_UPDATE_ACTIVE) {
2840 updateCBTracking(cmdBuffer);
2841 addCmd(pCB, CMD_RESETQUERYPOOL);
2842 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002843 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002844 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2845 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002846 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002847}
2848
Tony Barbourd1c35722015-04-16 15:59:00 -06002849VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002850{
2851 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2852 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002853 if (pCB->state == CB_UPDATE_ACTIVE) {
2854 updateCBTracking(cmdBuffer);
2855 addCmd(pCB, CMD_WRITETIMESTAMP);
2856 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002857 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002858 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2859 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002860 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002861}
2862
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002863VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002864{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002865 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002866 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002867 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002868 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002869 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter5861a1b2015-09-01 17:30:39 -06002870 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2871 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002872 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002873 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002874 }
2875 return result;
2876}
2877
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002878VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002879{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002880 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002881 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002882 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002883 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002884 if (pCreateInfo->pAttachments) {
2885 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2886 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002887 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002888 if (pCreateInfo->pSubpasses) {
2889 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2890 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2891
2892 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2893 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2894 const uint32_t attachmentCount = subpass->inputCount +
Cody Northropa505dda2015-08-04 11:16:41 -06002895 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu08accc62015-07-07 11:50:03 +08002896 subpass->preserveCount;
2897 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2898
Cody Northropa505dda2015-08-04 11:16:41 -06002899 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002900 sizeof(attachments[0]) * subpass->inputCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002901 subpass->pInputAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002902 attachments += subpass->inputCount;
2903
Cody Northropa505dda2015-08-04 11:16:41 -06002904 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002905 sizeof(attachments[0]) * subpass->colorCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002906 subpass->pColorAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002907 attachments += subpass->colorCount;
2908
Cody Northropa505dda2015-08-04 11:16:41 -06002909 if (subpass->pResolveAttachments) {
2910 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002911 sizeof(attachments[0]) * subpass->colorCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002912 subpass->pResolveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002913 attachments += subpass->colorCount;
2914 }
2915
Cody Northropa505dda2015-08-04 11:16:41 -06002916 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002917 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002918 subpass->pPreserveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002919 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06002920 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002921 if (pCreateInfo->pDependencies) {
2922 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2923 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002924 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002925 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002926 }
2927 return result;
2928}
2929
Chia-I Wu08accc62015-07-07 11:50:03 +08002930VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002931{
2932 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2933 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002934 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002935 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002936 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2937 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002938 } else {
2939 updateCBTracking(cmdBuffer);
2940 addCmd(pCB, CMD_BEGINRENDERPASS);
2941 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08002942 pCB->activeSubpass = 0;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002943 pCB->framebuffer = pRenderPassBegin->framebuffer;
2944 if (pCB->lastBoundPipeline) {
2945 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2946 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002947 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis259730a2015-06-23 16:13:03 -06002948 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06002949 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002950 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis259730a2015-06-23 16:13:03 -06002951 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06002952 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002953 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002954}
2955
Chia-I Wu08accc62015-07-07 11:50:03 +08002956VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2957{
2958 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2959 if (pCB) {
2960 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002961 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu08accc62015-07-07 11:50:03 +08002962 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2963 } else {
2964 updateCBTracking(cmdBuffer);
2965 addCmd(pCB, CMD_NEXTSUBPASS);
2966 pCB->activeSubpass++;
2967 if (pCB->lastBoundPipeline) {
2968 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2969 }
2970 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2971 }
2972 }
2973}
2974
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002975VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002976{
2977 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2978 if (pCB) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002979 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002980 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002981 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis59a9c832015-06-23 16:13:03 -06002982 } else {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002983 updateCBTracking(cmdBuffer);
2984 addCmd(pCB, CMD_ENDRENDERPASS);
2985 pCB->activeRenderPass = 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08002986 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002987 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2988 }
2989 }
2990}
2991
2992VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2993{
2994 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2995 if (pCB) {
2996 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002997 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002998 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2999 } else {
3000 updateCBTracking(cmdBuffer);
3001 addCmd(pCB, CMD_EXECUTECOMMANDS);
3002 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis259730a2015-06-23 16:13:03 -06003003 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003004 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003005}
3006
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003007VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3008 VkInstance instance,
3009 VkFlags msgFlags,
3010 const PFN_vkDbgMsgCallback pfnMsgCallback,
3011 void* pUserData,
3012 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003013{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003014 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06003015 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3016 if (VK_SUCCESS == res) {
3017 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3018 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3019 }
3020 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003021}
3022
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06003023VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3024 VkInstance instance,
3025 VkDbgMsgCallback msgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003026{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003027 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06003028 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3029 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3030 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3031 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003032}
3033
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003034VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003035{
3036 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06003037 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3038 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003039 // TODO : cmdBuffer should be srcObj
3040 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003041 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06003042 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003043 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003044 updateCBTracking(cmdBuffer);
3045 addCmd(pCB, CMD_DBGMARKERBEGIN);
3046 }
Jon Ashburneab34492015-06-01 09:37:38 -06003047 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003048}
3049
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06003050VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003051{
3052 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06003053 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3054 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003055 // TODO : cmdBuffer should be srcObj
3056 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003057 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06003058 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06003059 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003060 updateCBTracking(cmdBuffer);
3061 addCmd(pCB, CMD_DBGMARKEREND);
3062 }
Jon Ashburneab34492015-06-01 09:37:38 -06003063 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
3064}
3065
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003066//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3067//{
3068// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3069// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3070// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3071// "Attempt to use DbgSetObjectTag but extension disabled!");
3072// return VK_ERROR_UNAVAILABLE;
3073// }
3074// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3075//}
3076//
3077//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3078//{
3079// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3080// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3081// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3082// "Attempt to use DbgSetObjectName but extension disabled!");
3083// return VK_ERROR_UNAVAILABLE;
3084// }
3085// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3086//}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003087
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003088VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003089{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06003090 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003091 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003092
Jon Ashburn8fd08252015-05-28 16:25:02 -06003093 /* loader uses this to force layer initialization; device object is wrapped */
3094 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003095 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003096 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003097 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06003098 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003099 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003100 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003101 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003102 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003103 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003104 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003105 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003106 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003107 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003108 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003109 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003110 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003111 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003112 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003113 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003114 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003115 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003116 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003117 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003118 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003120 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003122 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003124 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003126 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003128 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003130 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003132 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003134 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003136 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003138 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Cody Northrop271ba752015-08-26 10:01:32 -06003140 if (!strcmp(funcName, "vkDestroyDynamicLineWidthState"))
3141 return (PFN_vkVoidFunction) vkDestroyDynamicLineWidthState;
3142 if (!strcmp(funcName, "vkDestroyDynamicDepthBiasState"))
3143 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBiasState;
3144 if (!strcmp(funcName, "vkDestroyDynamicBlendState"))
3145 return (PFN_vkVoidFunction) vkDestroyDynamicBlendState;
3146 if (!strcmp(funcName, "vkDestroyDynamicDepthBoundsState"))
3147 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBoundsState;
Cody Northrop82485a82015-08-18 15:21:16 -06003148 if (!strcmp(funcName, "vkDestroyDynamicStencilState"))
3149 return (PFN_vkVoidFunction) vkDestroyDynamicStencilState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003150 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003152 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003154 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003156 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003158 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003160 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003161 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003162 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003163 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003164 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003165 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003166 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003167 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003168 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003169 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003170 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003172 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003173 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003174 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003175 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05003176 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003177 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003178 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003179 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003180 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003181 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003182 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003183 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003184 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003185 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003186 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003187 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Cody Northrop271ba752015-08-26 10:01:32 -06003188 if (!strcmp(funcName, "vkCreateDynamicLineWidthState"))
3189 return (PFN_vkVoidFunction) vkCreateDynamicLineWidthState;
3190 if (!strcmp(funcName, "vkCreateDynamicDepthBiasState"))
3191 return (PFN_vkVoidFunction) vkCreateDynamicDepthBiasState;
3192 if (!strcmp(funcName, "vkCreateDynamicBlendState"))
3193 return (PFN_vkVoidFunction) vkCreateDynamicBlendState;
3194 if (!strcmp(funcName, "vkCreateDynamicDepthBoundsState"))
3195 return (PFN_vkVoidFunction) vkCreateDynamicDepthBoundsState;
Cody Northrop82485a82015-08-18 15:21:16 -06003196 if (!strcmp(funcName, "vkCreateDynamicStencilState"))
3197 return (PFN_vkVoidFunction) vkCreateDynamicStencilState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003198 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003199 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003200 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003201 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003202 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003204 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003206 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003208 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003209 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Cody Northrop271ba752015-08-26 10:01:32 -06003210 if (!strcmp(funcName, "vkCmdBindDynamicLineWidthState"))
3211 return (PFN_vkVoidFunction) vkCmdBindDynamicLineWidthState;
3212 if (!strcmp(funcName, "vkCmdBindDynamicDepthBiasState"))
3213 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBiasState;
3214 if (!strcmp(funcName, "vkCmdBindDynamicBlendState"))
3215 return (PFN_vkVoidFunction) vkCmdBindDynamicBlendState;
3216 if (!strcmp(funcName, "vkCmdBindDynamicDepthBoundsState"))
3217 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBoundsState;
Cody Northrop82485a82015-08-18 15:21:16 -06003218 if (!strcmp(funcName, "vkCmdBindDynamicStencilState"))
3219 return (PFN_vkVoidFunction) vkCmdBindDynamicStencilState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003220 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003221 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06003222 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003223 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003224 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003226 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003228 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003230 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003232 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003234 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003236 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003238 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003240 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003242 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003243 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003244 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003245 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003246 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003247 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003248 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003249 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003250 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003251 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12003252 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003253 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003254 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003256 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003258 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003260 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003262 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003264 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003265 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003266 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003267 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003268 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003269 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003270 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003271 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003272 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003273 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003274 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003276 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003278 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003280 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08003282 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003284 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburneab34492015-06-01 09:37:38 -06003286
Jon Ashburn747f2b62015-06-18 15:02:58 -06003287 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3288 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06003289 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06003290 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003291 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003292 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003293 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003294// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3295// return (void*) vkDbgSetObjectTag;
3296// if (!strcmp(funcName, "vkDbgSetObjectName"))
3297// return (void*) vkDbgSetObjectName;
Jon Ashburneab34492015-06-01 09:37:38 -06003298 }
3299 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06003300 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003301 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003302 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003303 }
3304}
3305
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003306VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003307{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003308 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003309 if (instance == NULL)
3310 return NULL;
3311
Jon Ashburn8fd08252015-05-28 16:25:02 -06003312 /* loader uses this to force layer initialization; instance object is wrapped */
3313 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003314 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003315 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003316 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003317 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003318 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003319 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003320 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003321 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003322 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003323 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003324 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003325 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003326 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour59a47322015-06-24 16:06:58 -06003327 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003328 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003329
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003330 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3331 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003332 if (fptr)
3333 return fptr;
3334
Jon Ashburn8fd08252015-05-28 16:25:02 -06003335 {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003336 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn8fd08252015-05-28 16:25:02 -06003337 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003338 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003339 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003340 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003341}