blob: a0b867a452eae735f50828d8938e16985957c02d [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;
65unordered_map<uint64_t, VkAttachmentViewCreateInfo> viewMap;
66unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
67unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicVpStateMap;
68unordered_map<uint64_t, VkDynamicRasterStateCreateInfo> dynamicRsStateMap;
69unordered_map<uint64_t, VkDynamicColorBlendStateCreateInfo> dynamicCbStateMap;
70unordered_map<uint64_t, VkDynamicDepthStencilStateCreateInfo> dynamicDsStateMap;
71unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
72unordered_map<uint64_t, POOL_NODE*> poolMap;
73unordered_map<uint64_t, SET_NODE*> setMap;
74unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlis793ad302015-04-03 12:01:11 -060075// Map for layout chains
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -060076unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
77unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
78unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060079
Jon Ashburneab34492015-06-01 09:37:38 -060080struct devExts {
81 bool debug_marker_enabled;
82};
83
Jon Ashburneab34492015-06-01 09:37:38 -060084static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburn3950e1b2015-05-20 09:00:28 -060085
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060086static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060087
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060088// TODO : This can be much smarter, using separate locks for separate global data
89static int globalLockInitialized = 0;
90static loader_platform_thread_mutex globalLock;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -060091#define MAX_TID 513
92static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
93static uint32_t g_maxTID = 0;
Tobin Ehlisa16e8922015-06-16 15:50:44 -060094
95template layer_data *get_my_data_ptr<layer_data>(
96 void *data_key,
97 std::unordered_map<void *, layer_data *> &data_map);
98
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -060099debug_report_data *mdd(void* object)
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600100{
101 dispatch_key key = get_dispatch_key(object);
102 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
103#if DISPATCH_MAP_DEBUG
104 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
105#endif
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600106 return my_data->report_data;
107}
108
109debug_report_data *mid(VkInstance object)
110{
111 dispatch_key key = get_dispatch_key(object);
112 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
113#if DISPATCH_MAP_DEBUG
114 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
115#endif
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600116 return my_data->report_data;
117}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600118// Map actual TID to an index value and return that index
119// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
120static uint32_t getTIDIndex() {
121 loader_platform_thread_id tid = loader_platform_get_thread_id();
122 for (uint32_t i = 0; i < g_maxTID; i++) {
123 if (tid == g_tidMapping[i])
124 return i;
125 }
126 // Don't yet have mapping, set it and return newly set index
127 uint32_t retVal = (uint32_t) g_maxTID;
128 g_tidMapping[g_maxTID++] = tid;
129 assert(g_maxTID < MAX_TID);
130 return retVal;
131}
132// Return a string representation of CMD_TYPE enum
133static string cmdTypeToString(CMD_TYPE cmd)
134{
135 switch (cmd)
136 {
137 case CMD_BINDPIPELINE:
138 return "CMD_BINDPIPELINE";
139 case CMD_BINDPIPELINEDELTA:
140 return "CMD_BINDPIPELINEDELTA";
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600141 case CMD_BINDDYNAMICVIEWPORTSTATE:
142 return "CMD_BINDDYNAMICVIEWPORTSTATE";
143 case CMD_BINDDYNAMICRASTERSTATE:
144 return "CMD_BINDDYNAMICRASTERSTATE";
145 case CMD_BINDDYNAMICCOLORBLENDSTATE:
146 return "CMD_BINDDYNAMICCOLORBLENDSTATE";
147 case CMD_BINDDYNAMICDEPTHSTENCILSTATE:
148 return "CMD_BINDDYNAMICDEPTHSTENCILSTATE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600149 case CMD_BINDDESCRIPTORSETS:
150 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600151 case CMD_BINDINDEXBUFFER:
152 return "CMD_BINDINDEXBUFFER";
153 case CMD_BINDVERTEXBUFFER:
154 return "CMD_BINDVERTEXBUFFER";
155 case CMD_DRAW:
156 return "CMD_DRAW";
157 case CMD_DRAWINDEXED:
158 return "CMD_DRAWINDEXED";
159 case CMD_DRAWINDIRECT:
160 return "CMD_DRAWINDIRECT";
161 case CMD_DRAWINDEXEDINDIRECT:
162 return "CMD_DRAWINDEXEDINDIRECT";
163 case CMD_DISPATCH:
164 return "CMD_DISPATCH";
165 case CMD_DISPATCHINDIRECT:
166 return "CMD_DISPATCHINDIRECT";
167 case CMD_COPYBUFFER:
168 return "CMD_COPYBUFFER";
169 case CMD_COPYIMAGE:
170 return "CMD_COPYIMAGE";
Tobin Ehlis793ad302015-04-03 12:01:11 -0600171 case CMD_BLITIMAGE:
172 return "CMD_BLITIMAGE";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600173 case CMD_COPYBUFFERTOIMAGE:
174 return "CMD_COPYBUFFERTOIMAGE";
175 case CMD_COPYIMAGETOBUFFER:
176 return "CMD_COPYIMAGETOBUFFER";
177 case CMD_CLONEIMAGEDATA:
178 return "CMD_CLONEIMAGEDATA";
179 case CMD_UPDATEBUFFER:
180 return "CMD_UPDATEBUFFER";
181 case CMD_FILLBUFFER:
182 return "CMD_FILLBUFFER";
183 case CMD_CLEARCOLORIMAGE:
184 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600185 case CMD_CLEARCOLORATTACHMENT:
186 return "CMD_CLEARCOLORATTACHMENT";
187 case CMD_CLEARDEPTHSTENCILIMAGE:
188 return "CMD_CLEARDEPTHSTENCILIMAGE";
189 case CMD_CLEARDEPTHSTENCILATTACHMENT:
190 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600191 case CMD_RESOLVEIMAGE:
192 return "CMD_RESOLVEIMAGE";
193 case CMD_SETEVENT:
194 return "CMD_SETEVENT";
195 case CMD_RESETEVENT:
196 return "CMD_RESETEVENT";
197 case CMD_WAITEVENTS:
198 return "CMD_WAITEVENTS";
199 case CMD_PIPELINEBARRIER:
200 return "CMD_PIPELINEBARRIER";
201 case CMD_BEGINQUERY:
202 return "CMD_BEGINQUERY";
203 case CMD_ENDQUERY:
204 return "CMD_ENDQUERY";
205 case CMD_RESETQUERYPOOL:
206 return "CMD_RESETQUERYPOOL";
207 case CMD_WRITETIMESTAMP:
208 return "CMD_WRITETIMESTAMP";
209 case CMD_INITATOMICCOUNTERS:
210 return "CMD_INITATOMICCOUNTERS";
211 case CMD_LOADATOMICCOUNTERS:
212 return "CMD_LOADATOMICCOUNTERS";
213 case CMD_SAVEATOMICCOUNTERS:
214 return "CMD_SAVEATOMICCOUNTERS";
215 case CMD_BEGINRENDERPASS:
216 return "CMD_BEGINRENDERPASS";
217 case CMD_ENDRENDERPASS:
218 return "CMD_ENDRENDERPASS";
219 case CMD_DBGMARKERBEGIN:
220 return "CMD_DBGMARKERBEGIN";
221 case CMD_DBGMARKEREND:
222 return "CMD_DBGMARKEREND";
223 default:
224 return "UNKNOWN";
225 }
226}
227// Block of code at start here for managing/tracking Pipeline state that this layer cares about
228// Just track 2 shaders for now
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600229#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600230#define MAX_SLOTS 2048
231#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
232
233static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
234
235// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
236// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
237// to that same cmd buffer by separate thread are not changing state from underneath us
238// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600239static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600240// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600241static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
242static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600243// Track the last global DrawState of interest touched by any thread
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600244static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
245static PIPELINE_NODE* g_lastBoundPipeline = NULL;
246static uint64_t g_lastBoundDynamicState[VK_NUM_STATE_BIND_POINT] = {0};
Dana Jansensc73ff982015-07-30 13:22:15 -0700247static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600248#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
249
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600250//static DYNAMIC_STATE_NODE* g_pDynamicStateHead[VK_NUM_STATE_BIND_POINT] = {0};
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600251
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600252// Free all allocated nodes for Dynamic State objs
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600253static void deleteDynamicState()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600254{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600255 for (auto ii=dynamicVpStateMap.begin(); ii!=dynamicVpStateMap.end(); ++ii) {
256 delete[] (*ii).second.pScissors;
257 delete[] (*ii).second.pViewports;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600258 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600259 dynamicVpStateMap.clear();
260 dynamicRsStateMap.clear();
261 dynamicCbStateMap.clear();
262 dynamicDsStateMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600263}
264// Free all sampler nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600265static void deleteSamplers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600266{
David Pinedod8f83d82015-04-27 16:36:17 -0600267 if (sampleMap.size() <= 0)
268 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600269 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600270 delete (*ii).second;
271 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600272 sampleMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600273}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600274static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600275{
276 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600277 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600278 loader_platform_thread_unlock_mutex(&globalLock);
279 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600280 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600281 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600282 return &imageMap[view.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600283 }
284}
285// Free all image nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600286static void deleteImages()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600287{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600288 if (imageMap.size() <= 0)
David Pinedod8f83d82015-04-27 16:36:17 -0600289 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600290 imageMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600291}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600292static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600293{
294 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600295 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600296 loader_platform_thread_unlock_mutex(&globalLock);
297 return NULL;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600298 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600299 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600300 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600301 }
302}
303// Free all buffer nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600304static void deleteBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600305{
David Pinedod8f83d82015-04-27 16:36:17 -0600306 if (bufferMap.size() <= 0)
307 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600308 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600309 delete (*ii).second;
310 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600311 bufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600312}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600313static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600314// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600315static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600316{
317 g_lastCmdBuffer[getTIDIndex()] = cb;
318 GLOBAL_CB_NODE* pCB = getCBNode(cb);
319 loader_platform_thread_lock_mutex(&globalLock);
320 g_lastGlobalCB = pCB;
321 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
322 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
323 if (g_pLastTouchedCB[i] == pCB) {
324 loader_platform_thread_unlock_mutex(&globalLock);
325 return;
326 }
327 }
328 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
329 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
330 loader_platform_thread_unlock_mutex(&globalLock);
331}
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600332static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis53eddda2015-07-01 16:46:13 -0600333{
334 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
335 if (pCB->drawCount[i])
336 return VK_TRUE;
337 }
338 return VK_FALSE;
339}
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600340// Check object status for selected flag state
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600341static 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 -0600342{
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600343 // If non-zero enable mask is present, check it against status but if enable_mask
344 // is 0 then no enable required so we should always just check status
345 if ((!enable_mask) || (enable_mask & pNode->status)) {
346 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600347 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
348 log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
349 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<VkUintPtrLeast64>(pNode->cmdBuffer), fail_msg);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600350 return VK_FALSE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600351 }
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600352 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600353 return VK_TRUE;
Tobin Ehlise382c5a2015-06-10 12:57:07 -0600354}
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600355// For given dynamic state handle and type, return CreateInfo for that Dynamic State
356static void* getDynamicStateCreateInfo(const uint64_t handle, const DYNAMIC_STATE_BIND_POINT type)
357{
358 switch (type) {
359 case VK_STATE_BIND_POINT_VIEWPORT:
360 return (void*)&dynamicVpStateMap[handle];
361 case VK_STATE_BIND_POINT_RASTER:
362 return (void*)&dynamicRsStateMap[handle];
363 case VK_STATE_BIND_POINT_COLOR_BLEND:
364 return (void*)&dynamicCbStateMap[handle];
365 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
366 return (void*)&dynamicDsStateMap[handle];
367 default:
368 return NULL;
369 }
370}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600371// Print the last bound dynamic state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600372static void printDynamicState(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600373{
374 GLOBAL_CB_NODE* pCB = getCBNode(cb);
375 if (pCB) {
376 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600377 for (uint32_t i = 0; i < VK_NUM_STATE_BIND_POINT; i++) {
Mark Lobodzinski31422ee2015-08-11 15:44:15 -0600378 if (pCB->lastBoundDynamicState[i]) {
379 void* pDynStateCI = getDynamicStateCreateInfo(pCB->lastBoundDynamicState[i], (DYNAMIC_STATE_BIND_POINT)i);
380 if (pDynStateCI) {
381 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
382 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
383 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
384 dynamic_display(pDynStateCI, " ").c_str());
385 } else {
386 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
387 "No dynamic state of type %s bound", string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str());
388 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600389 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600390 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
391 "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 -0600392 }
393 }
394 loader_platform_thread_unlock_mutex(&globalLock);
395 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600396}
397// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600398static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600399{
400 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600401 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600402 loader_platform_thread_unlock_mutex(&globalLock);
403 return NULL;
404 }
405 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600406 return pipelineMap[pipeline.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600407}
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600408// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600409static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
410 VkBool32 result;
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600411 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");
412 result &= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_RASTER_BOUND, CBSTATUS_RASTER_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");
413 result &= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_COLOR_BLEND_BOUND, CBSTATUS_COLOR_BLEND_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");
414 result &= validate_status(pCB, CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE, CBSTATUS_DEPTH_STENCIL_BOUND, CBSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");
415 if (indexedDraw)
416 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");
417 return result;
418}
419// Validate overall state at the time of a draw call
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600420static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600421 // First check flag states
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600422 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600423 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
424 // Now complete other state checks
Tobin Ehlis502480b2015-06-24 15:53:07 -0600425 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600426 result = VK_FALSE;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600427 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 -0600428 "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 -0600429 }
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -0600430 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600431 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 -0600432 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
433 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600434 return result;
435}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600436// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600437static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600438{
439 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600440 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600441 loader_platform_thread_unlock_mutex(&globalLock);
442 return NULL;
443 }
444 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600445 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600446}
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600447// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600448static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600449{
450 // VS is required
451 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600452 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 -0600453 "Invalid Pipeline CreateInfo State: Vtx Shader required");
454 return VK_FALSE;
455 }
456 // Either both or neither TC/TE shaders should be defined
457 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
458 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600459 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 -0600460 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
461 return VK_FALSE;
462 }
463 // Compute shaders should be specified independent of Gfx shaders
464 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
465 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
466 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
467 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600468 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 -0600469 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
470 return VK_FALSE;
471 }
472 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
473 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
474 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
475 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600476 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600477 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
478 return VK_FALSE;
479 }
480 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
481 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600482 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600483 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
484 return VK_FALSE;
485 }
486 return VK_TRUE;
487}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600488// Init the pipeline mapping info based on pipeline create info LL tree
489// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600490static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600491{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600492 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
493 if (pBasePipeline) {
494 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlis9c536442015-06-19 13:00:59 -0600495 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600496 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
497 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600498 // First init create info
Tobin Ehliseba312c2015-04-01 08:40:34 -0600499 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600500 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600501
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600502 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600503 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -0600504 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600505
506 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
507 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
508
509 switch (pPSSCI->stage) {
510 case VK_SHADER_STAGE_VERTEX:
511 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
512 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600513 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600514 case VK_SHADER_STAGE_TESS_CONTROL:
515 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
516 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600517 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600518 case VK_SHADER_STAGE_TESS_EVALUATION:
519 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
520 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600521 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600522 case VK_SHADER_STAGE_GEOMETRY:
523 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
524 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600525 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600526 case VK_SHADER_STAGE_FRAGMENT:
527 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
528 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600529 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600530 case VK_SHADER_STAGE_COMPUTE:
531 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
532 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600533 break;
534 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600535 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600536 break;
537 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600538 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600539
540 if (pCreateInfo->pVertexInputState != NULL) {
541 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
542 // Copy embedded ptrs
543 pVICI = pCreateInfo->pVertexInputState;
544 pPipeline->vtxBindingCount = pVICI->bindingCount;
545 if (pPipeline->vtxBindingCount) {
546 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
547 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
548 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
549 }
550 pPipeline->vtxAttributeCount = pVICI->attributeCount;
551 if (pPipeline->vtxAttributeCount) {
552 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
553 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
554 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
555 }
556 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
557 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600558 if (pCreateInfo->pInputAssemblyState != NULL) {
559 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600561 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600562 if (pCreateInfo->pTessellationState != NULL) {
563 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
564 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600565 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600566 if (pCreateInfo->pViewportState != NULL) {
567 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
568 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600569 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600570 if (pCreateInfo->pRasterState != NULL) {
571 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
572 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600573 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600574 if (pCreateInfo->pMultisampleState != NULL) {
575 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
576 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600577 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600578 if (pCreateInfo->pColorBlendState != NULL) {
579 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600580 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600581 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600582 pPipeline->attachmentCount = pCBCI->attachmentCount;
583 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600584 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
585 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600586 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
587 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600588 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600589 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600590 if (pCreateInfo->pDepthStencilState != NULL) {
591 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
592 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600593 }
594
595 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
596 if (pCreateInfo->stageCount != 0) {
597 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
598 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
599 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
600 }
601
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600602 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600603}
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600604
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600605// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600606static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600607{
David Pinedod8f83d82015-04-27 16:36:17 -0600608 if (pipelineMap.size() <= 0)
609 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600610 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600611 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
612 delete[] (*ii).second->graphicsPipelineCI.pStages;
613 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600614 if ((*ii).second->pVertexBindingDescriptions) {
615 delete[] (*ii).second->pVertexBindingDescriptions;
616 }
617 if ((*ii).second->pVertexAttributeDescriptions) {
618 delete[] (*ii).second->pVertexAttributeDescriptions;
619 }
620 if ((*ii).second->pAttachments) {
621 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600622 }
623 delete (*ii).second;
624 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600625 pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600626}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600627// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600628static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600629{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600630 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlis577188e2015-07-13 14:51:15 -0600631 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
632 return pPipe->msStateCI.rasterSamples;
633 }
Tobin Ehliseba312c2015-04-01 08:40:34 -0600634 return 1;
635}
636// Validate state related to the PSO
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600637static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600638{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600639 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600640 // Verify that any MSAA request in PSO matches sample# in bound FB
641 uint32_t psoNumSamples = getNumSamples(pipeline);
642 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600643 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wu08accc62015-07-07 11:50:03 +0800644 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
645 int subpassNumSamples = 0;
646 uint32_t i;
647
648 for (i = 0; i < pSD->colorCount; i++) {
649 uint32_t samples;
650
Cody Northropa505dda2015-08-04 11:16:41 -0600651 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wu08accc62015-07-07 11:50:03 +0800652 continue;
653
Cody Northropa505dda2015-08-04 11:16:41 -0600654 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wu08accc62015-07-07 11:50:03 +0800655 if (subpassNumSamples == 0) {
656 subpassNumSamples = samples;
657 } else if (subpassNumSamples != samples) {
658 subpassNumSamples = -1;
659 break;
660 }
661 }
662 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
663 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
664 if (subpassNumSamples == 0)
665 subpassNumSamples = samples;
666 else if (subpassNumSamples != samples)
667 subpassNumSamples = -1;
668 }
669
670 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600671 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
672 "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 -0600673 }
674 } else {
675 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
676 // Verify and flag error as appropriate
677 }
678 // TODO : Add more checks here
679 } else {
680 // TODO : Validate non-gfx pipeline updates
681 }
682}
683
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600684// Block of code at start here specifically for managing/tracking DSs
685
Tobin Ehlis793ad302015-04-03 12:01:11 -0600686// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600687static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600688{
689 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600690 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600691 loader_platform_thread_unlock_mutex(&globalLock);
692 return NULL;
693 }
694 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600695 return poolMap[pool.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600696}
697// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600698static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600699{
700 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600701 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600702 loader_platform_thread_unlock_mutex(&globalLock);
703 return NULL;
704 }
705 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600706 return setMap[set.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600707}
708
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600709static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600710 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600711 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600712 loader_platform_thread_unlock_mutex(&globalLock);
713 return NULL;
714 }
715 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600716 return layoutMap[layout.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600717}
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600718// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600719static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600720{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600721 switch (pUpdateStruct->sType)
722 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800723 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
724 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600725 return 1;
726 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600727 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 -0600728 "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 -0600729 return 0;
730 }
731}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600732// For given update struct, return binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600733static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600734{
735 switch (pUpdateStruct->sType)
736 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800737 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
738 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
739 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
740 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600741 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600742 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 -0600743 "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 -0600744 return 0xFFFFFFFF;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600745 }
746}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600747// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600748static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600749{
750 switch (pUpdateStruct->sType)
751 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800752 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
753 return ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
754 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600755 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800756 return ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600757 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600758 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 -0600759 "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 -0600760 return 0;
761 }
762}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600763// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600764static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600765{
766 switch (pUpdateStruct->sType)
767 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800768 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
769 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
770 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600771 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800772 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlis793ad302015-04-03 12:01:11 -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 Ehlis793ad302015-04-03 12:01:11 -0600776 return 0;
777 }
778}
779// For given Layout Node and binding, return index where that binding begins
780static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
781{
782 uint32_t offsetIndex = 0;
783 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800784 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600785 }
786 return offsetIndex;
787}
788// For given layout node and binding, return last index that is updated
789static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
790{
791 uint32_t offsetIndex = 0;
792 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800793 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600794 }
795 return offsetIndex-1;
796}
797// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600798static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600799{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600800 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlis793ad302015-04-03 12:01:11 -0600801}
802// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600803static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600804{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600805 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600806}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600807// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600808static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600809{
810 // First get actual type of update
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600811 VkDescriptorType actualType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600812 uint32_t i = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600813 switch (pUpdateStruct->sType)
814 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800815 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
816 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600817 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800818 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
819 /* no need to validate */
820 return 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600821 break;
822 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600823 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 -0600824 "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 -0600825 return 0;
826 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600827 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600828 if (pLayout->pTypes[i] != actualType)
829 return 0;
830 }
831 return 1;
832}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600833// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
834// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
835// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600836static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600837{
838 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800839 VkWriteDescriptorSet* pWDS = NULL;
840 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600841 size_t array_size = 0;
842 size_t base_array_size = 0;
843 size_t total_array_size = 0;
844 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600845 switch (pUpdate->sType)
846 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800847 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
848 pWDS = new VkWriteDescriptorSet;
849 pNewNode = (GENERIC_HEADER*)pWDS;
850 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
851 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
852 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
853 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600854 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800855 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
856 pCDS = new VkCopyDescriptorSet;
857 pUpdate = (GENERIC_HEADER*)pCDS;
858 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600859 break;
860 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600861 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 -0600862 "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 -0600863 return NULL;
864 }
865 // Make sure that pNext for the end of shadow copy is NULL
866 pNewNode->pNext = NULL;
867 return pNewNode;
868}
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800869// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600870static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600871{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800872 const VkWriteDescriptorSet *pWDS = NULL;
873 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600874 VkBool32 result = 1;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800875
876 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
877 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
878 else
879 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
880
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600881 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600882 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600883 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600884 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600885 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600886 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800887 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600888 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800889 g_lastBoundDescriptorSet = pSet->set;
890 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600891 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600892 // First verify valid update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600893 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600894 result = 0;
895 break;
896 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600897 // Make sure that binding is within bounds
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600898 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600899 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 -0600900 "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 -0600901 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600902 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600903 // Next verify that update falls within size of given binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600904 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tony Barbour3b4732f2015-07-13 13:37:24 -0600905 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlis793ad302015-04-03 12:01:11 -0600906 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600907 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600908 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 -0600909 "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 -0600910 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600911 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600912 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600913 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600914 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 -0600915 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600916 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600917 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600918 // Save the update info
919 // TODO : Info message that update successful
920 // Create new update struct for this set's shadow copy
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600921 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600922 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600923 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 -0600924 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600925 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600926 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600927 // Insert shadow node into LL of updates for this set
928 pNewNode->pNext = pSet->pUpdateStructs;
929 pSet->pUpdateStructs = pNewNode;
930 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600931 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600932 assert(j<pSet->descriptorCount);
933 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600934 }
935 }
936 }
937 }
938 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600939 }
940 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600941 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600942}
943// Free the shadowed update node for this Set
944// NOTE : Calls to this function should be wrapped in mutex
945static void freeShadowUpdateTree(SET_NODE* pSet)
946{
947 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
948 pSet->pUpdateStructs = NULL;
949 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
950 // Clear the descriptor mappings as they will now be invalid
951 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
952 while(pShadowUpdate) {
953 pFreeUpdate = pShadowUpdate;
954 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
955 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800956 VkWriteDescriptorSet * pWDS = NULL;
957 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600958 void** ppToFree = NULL;
959 switch (pFreeUpdate->sType)
960 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800961 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
962 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
963 if (pWDS->pDescriptors)
964 delete[] pWDS->pDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600965 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800966 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600967 break;
968 default:
969 assert(0);
970 break;
971 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600972 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600973 }
974}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600975// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600976// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600977static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600978{
David Pinedod8f83d82015-04-27 16:36:17 -0600979 if (poolMap.size() <= 0)
980 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600981 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600982 SET_NODE* pSet = (*ii).second->pSets;
983 SET_NODE* pFreeSet = pSet;
984 while (pSet) {
985 pFreeSet = pSet;
986 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600987 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600988 // Free Update shadow struct tree
989 freeShadowUpdateTree(pFreeSet);
990 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +1200991 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600992 }
993 delete pFreeSet;
994 }
995 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes02038792015-06-04 10:49:27 +1200996 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600997 }
998 delete (*ii).second;
999 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001000 poolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001001}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001002// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001003// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001004static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001005{
David Pinedod8f83d82015-04-27 16:36:17 -06001006 if (layoutMap.size() <= 0)
1007 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001008 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001009 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001010 if (pLayout->createInfo.pBinding) {
1011 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1012 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1013 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1014 }
1015 delete[] pLayout->createInfo.pBinding;
1016 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001017 if (pLayout->pTypes) {
Chris Forbes02038792015-06-04 10:49:27 +12001018 delete[] pLayout->pTypes;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001019 }
1020 delete pLayout;
1021 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001022 layoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001023}
1024// Currently clearing a set is removing all previous updates to that set
1025// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001026static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001027{
1028 SET_NODE* pSet = getSetNode(set);
1029 if (!pSet) {
1030 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06001031 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001032 loader_platform_thread_lock_mutex(&globalLock);
1033 freeShadowUpdateTree(pSet);
1034 loader_platform_thread_unlock_mutex(&globalLock);
1035 }
1036}
1037
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001038static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001039{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001040 POOL_NODE* pPool = getPoolNode(pool);
1041 if (!pPool) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001042 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1043 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001044 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001045 // For every set off of this pool, clear it
1046 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001047 while (pSet) {
1048 clearDescriptorSet(pSet->set);
1049 }
1050 }
1051}
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001052// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001053static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001054{
1055 loader_platform_thread_lock_mutex(&globalLock);
1056 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1057 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001058 // TODO : How to pass cb as srcObj here?
1059 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1060 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001061 return NULL;
1062 }
1063 loader_platform_thread_unlock_mutex(&globalLock);
1064 return cmdBufferMap[cb];
1065}
1066// Free all CB Nodes
1067// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001068static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001069{
David Pinedod8f83d82015-04-27 16:36:17 -06001070 if (cmdBufferMap.size() <= 0)
1071 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001072 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06001073 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1074 while (!cmd_node_list.empty()) {
1075 CMD_NODE* cmd_node = cmd_node_list.back();
1076 delete cmd_node;
1077 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001078 }
1079 delete (*ii).second;
1080 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001081 cmdBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001082}
Tobin Ehlis9c536442015-06-19 13:00:59 -06001083static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1084{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001085 // TODO : How to pass cb as srcObj here?
1086 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 -06001087 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1088}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001089static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1090{
1091 CMD_NODE* pCmd = new CMD_NODE;
1092 if (pCmd) {
1093 // init cmd node and append to end of cmd LL
1094 memset(pCmd, 0, sizeof(CMD_NODE));
1095 pCmd->cmdNumber = ++pCB->numCmds;
1096 pCmd->type = cmd;
1097 pCB->pCmds.push_back(pCmd);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001098 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001099 // TODO : How to pass cb as srcObj here?
1100 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1101 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %#" PRIxLEAST64, reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001102 }
1103}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001104static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001105{
1106 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1107 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001108 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1109 while (!cmd_list.empty()) {
1110 delete cmd_list.back();
1111 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001112 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001113 pCB->pCmds.clear();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001114 // Reset CB state (need to save createInfo)
1115 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001116 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1117 pCB->cmdBuffer = cb;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001118 pCB->createInfo = saveCBCI;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001119 pCB->lastVtxBinding = MAX_BINDING;
1120 }
1121}
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001122// Set PSO-related status bits for CB
1123static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1124{
1125 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1126 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1127 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1128 }
1129 }
1130 if (pPipe->dsStateCI.depthWriteEnable) {
1131 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1132 }
1133}
1134// Set dyn-state related status bits for an object node
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001135static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001136 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1137 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1138 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1139 pNode->status |= CBSTATUS_RASTER_BOUND;
1140 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1141 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1142 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1143 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1144 }
1145}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001146// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001147static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001148{
1149 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1150 if (pCB) {
1151 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1152 if (!pPipeTrav) {
1153 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06001154 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001155 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001156 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001157 }
1158 }
1159}
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001160// Verify bound Pipeline State Object
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001161static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001162{
1163 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1164 if (pCB && pCB->lastBoundPipeline) {
1165 // First verify that we have a Node for bound pipeline
1166 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001167 if (!pPipeTrav) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001168 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1169 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001170 return false;
Tobin Ehlisce132d82015-06-19 15:07:05 -06001171 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001172 // Verify Vtx binding
1173 if (MAX_BINDING != pCB->lastVtxBinding) {
1174 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1175 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001176 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001177 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001178 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001179 }
1180 else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001181 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001182 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipeTrav->vtxBindingCount - 1));
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001183 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001184 }
1185 }
1186 else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001187 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001188 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001189 }
1190 }
1191 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001192 return true;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001193 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001194 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001195}
1196// Print details of DS config to stdout
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001197static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001198{
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001199 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.
1200 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06001201 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001202 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001203 POOL_NODE* pPool = getPoolNode(pSet->pool);
1204 // Print out pool details
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001205 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1206 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001207 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001208 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001209 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001210 // Print out set details
1211 char prefix[10];
1212 uint32_t index = 0;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001213 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1214 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001215 LAYOUT_NODE* pLayout = pSet->pLayout;
1216 // Print layout details
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 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001219 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001220 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001221 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001222 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06001223 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001224 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1225 if (pUpdate) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001226 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1227 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001228 sprintf(prefix, " [UC] ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001229 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001230 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001231 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06001232 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001233 if (0 != pSet->descriptorCount) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001234 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1235 "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 -06001236 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001237 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1238 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001239 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001240 }
1241 }
1242}
1243
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001244static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001245{
1246 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001247 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001248 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001249 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001250 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001251 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1252 // TODO : Need to pass cb as srcObj here
1253 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 -06001254 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001255 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06001256 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001257 // Nothing to print
1258 }
1259}
1260
1261
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001262static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001263{
Mike Stroyanba35e352015-08-12 17:11:28 -06001264 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
1265 return;
1266 }
Mark Lobodzinski3f41c7c2015-08-07 17:11:09 -06001267 printDSConfig(cb);
1268 printPipeline(cb);
1269 printDynamicState(cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001270}
1271
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001272static void init_draw_state(layer_data *my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001273{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001274 uint32_t report_flags = 0;
1275 uint32_t debug_action = 0;
1276 FILE *log_output = NULL;
1277 const char *option_str;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001278 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001279 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1280 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001281
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001282 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001283 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001284 option_str = getLayerOption("DrawStateLogFilename");
1285 if (option_str)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001286 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001287 log_output = fopen(option_str, "w");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001288 }
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001289 if (log_output == NULL)
1290 log_output = stdout;
1291
1292 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 -06001293 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001294
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001295 if (!globalLockInitialized)
1296 {
1297 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001298 // suggestion is to call this during vkCreateInstance(), and then we
1299 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001300 // that the layer have per-instance locks. We need to come back and
1301 // address this soon.
1302 loader_platform_thread_create_mutex(&globalLock);
1303 globalLockInitialized = 1;
1304 }
1305}
1306
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001307VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1308{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001309 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001310 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1311
1312 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001313 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1314 my_data->report_data = debug_report_create_instance(
1315 pTable,
1316 *pInstance,
1317 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001318 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001319
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001320 init_draw_state(my_data);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001321 }
1322 return result;
1323}
1324
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001325/* hook DestroyInstance to remove tableInstanceMap entry */
1326VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1327{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001328 dispatch_key key = get_dispatch_key(instance);
1329 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1330 VkResult res = pTable->DestroyInstance(instance);
1331
1332 // Clean up logging callback, if any
1333 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1334 if (my_data->logging_callback) {
1335 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1336 }
1337
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001338 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001339 layer_data_map.erase(pTable);
1340
1341 draw_state_instance_table_map.erase(key);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001342 return res;
1343}
1344
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001345static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1346{
Tony Barbour3b4732f2015-07-13 13:37:24 -06001347 uint32_t i;
Jon Ashburn747f2b62015-06-18 15:02:58 -06001348 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburneab34492015-06-01 09:37:38 -06001349 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001350
1351 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001352 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06001353 /* Found a matching extension name, mark it enabled and init dispatch table*/
1354 initDebugMarkerTable(device);
1355 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001356 }
1357
1358 }
1359}
1360
Tony Barbourd1c35722015-04-16 15:59:00 -06001361VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001362{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06001363 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1364 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001365 if (result == VK_SUCCESS) {
1366 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1367 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1368 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1369 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001370 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001371 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001372 return result;
1373}
1374
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001375VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001376{
1377 // Free all the memory
1378 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001379 deletePipelines();
1380 deleteSamplers();
1381 deleteImages();
1382 deleteBuffers();
1383 deleteCmdBuffers();
1384 deleteDynamicState();
1385 deletePools();
1386 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001387 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001388
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001389 dispatch_key key = get_dispatch_key(device);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001390 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1391 VkResult result = pDisp->DestroyDevice(device);
1392 deviceExtMap.erase(pDisp);
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001393 draw_state_device_table_map.erase(key);
Jon Ashburneab34492015-06-01 09:37:38 -06001394 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001395 return result;
1396}
1397
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001398static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001399 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001400 "DrawState",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001401 VK_API_VERSION,
1402 VK_MAKE_VERSION(0, 1, 0),
1403 "Validation layer: DrawState",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001404 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001405};
1406
Tony Barbour59a47322015-06-24 16:06:58 -06001407VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001408 const char *pLayerName,
1409 uint32_t *pCount,
1410 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001411{
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001412 /* DrawState does not have any global extensions */
1413 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1414}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001415
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001416VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1417 uint32_t *pCount,
1418 VkLayerProperties* pProperties)
1419{
1420 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1421 ds_global_layers,
1422 pCount, pProperties);
1423}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001424
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001425static const VkExtensionProperties ds_device_extensions[] = {
1426 {
1427 DEBUG_MARKER_EXTENSION_NAME,
1428 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001429 }
1430};
1431
1432static const VkLayerProperties ds_device_layers[] = {
1433 {
1434 "DrawState",
1435 VK_API_VERSION,
1436 VK_MAKE_VERSION(0, 1, 0),
1437 "Validation layer: DrawState",
1438 }
1439};
1440
1441VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1442 VkPhysicalDevice physicalDevice,
1443 const char* pLayerName,
1444 uint32_t* pCount,
1445 VkExtensionProperties* pProperties)
1446{
1447 /* Mem tracker does not have any physical device extensions */
1448 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1449 pCount, pProperties);
1450}
1451
1452VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1453 VkPhysicalDevice physicalDevice,
1454 uint32_t* pCount,
1455 VkLayerProperties* pProperties)
1456{
1457 /* Mem tracker's physical device layers are the same as global */
1458 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1459 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001460}
1461
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001462VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001463{
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001464 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001465 for (uint32_t i=0; i < cmdBufferCount; i++) {
1466 // Validate that cmd buffers have been updated
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001467 pCB = getCBNode(pCmdBuffers[i]);
1468 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001469 pCB->submitCount++; // increment submit count
1470 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
1471 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CMD_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Tobin Ehlisf1878c72015-08-18 14:24:32 -06001472 "CB %#" PRIxLEAST64 " was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer), pCB->submitCount);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001473 }
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001474 if (CB_UPDATE_COMPLETE != pCB->state) {
1475 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001476 // TODO : How to pass cb as srcObj?
1477 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1478 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001479 loader_platform_thread_unlock_mutex(&globalLock);
1480 return VK_ERROR_UNKNOWN;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001481 }
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06001482 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001483 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001484
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001485 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001486 return result;
1487}
1488
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001489VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001490{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001491 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1492 // TODO : Clean up any internal data structures using this obj.
1493 return result;
1494}
1495
1496VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1497{
1498 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1499 // TODO : Clean up any internal data structures using this obj.
1500 return result;
1501}
1502
1503VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1504{
1505 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1506 // TODO : Clean up any internal data structures using this obj.
1507 return result;
1508}
1509
1510VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1511{
1512 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1513 // TODO : Clean up any internal data structures using this obj.
1514 return result;
1515}
1516
1517VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1518{
1519 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1520 // TODO : Clean up any internal data structures using this obj.
1521 return result;
1522}
1523
1524VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1525{
1526 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1527 // TODO : Clean up any internal data structures using this obj.
1528 return result;
1529}
1530
1531VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1532{
1533 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1534 // TODO : Clean up any internal data structures using this obj.
1535 return result;
1536}
1537
1538VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1539{
1540 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1541 // TODO : Clean up any internal data structures using this obj.
1542 return result;
1543}
1544
1545VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1546{
1547 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1548 // TODO : Clean up any internal data structures using this obj.
1549 return result;
1550}
1551
1552VK_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
1608VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1609{
1610 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1611 // TODO : Clean up any internal data structures using this obj.
1612 return result;
1613}
1614
1615VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1616{
1617 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1618 // TODO : Clean up any internal data structures using this obj.
1619 return result;
1620}
1621
1622VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1623{
1624 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1625 // TODO : Clean up any internal data structures using this obj.
1626 return result;
1627}
1628
1629VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1630{
1631 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1632 // TODO : Clean up any internal data structures using this obj.
1633 return result;
1634}
1635
1636VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1637{
1638 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1639 // TODO : Clean up any internal data structures using this obj.
1640 return result;
1641}
1642
1643VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1644{
1645 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1646 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001647 return result;
1648}
1649
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001650VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001651{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001652 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001653 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001654 loader_platform_thread_lock_mutex(&globalLock);
1655 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1656 pNewNode->buffer = *pView;
1657 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001658 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001659 loader_platform_thread_unlock_mutex(&globalLock);
1660 }
1661 return result;
1662}
1663
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001664VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* 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)->CreateImageView(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);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001669 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001670 loader_platform_thread_unlock_mutex(&globalLock);
1671 }
1672 return result;
1673}
1674
Tobin Ehlisffe35812015-07-10 12:15:19 -06001675VkResult VKAPI vkCreateAttachmentView(
1676 VkDevice device,
1677 const VkAttachmentViewCreateInfo* pCreateInfo,
1678 VkAttachmentView* pView)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001679{
Tobin Ehlisffe35812015-07-10 12:15:19 -06001680 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001681 if (VK_SUCCESS == result) {
1682 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001683 viewMap[pView->handle] = *pCreateInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -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
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001954VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRasterStateCreateInfo* pCreateInfo, VkDynamicRasterState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001955{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001956 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001957 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
1958 loader_platform_thread_lock_mutex(&globalLock);
1959 dynamicRsStateMap[pState->handle] = *pCreateInfo;
1960 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001961 return result;
1962}
1963
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001964VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicColorBlendStateCreateInfo* pCreateInfo, VkDynamicColorBlendState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001965{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001966 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001967 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
1968 loader_platform_thread_lock_mutex(&globalLock);
1969 dynamicCbStateMap[pState->handle] = *pCreateInfo;
1970 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001971 return result;
1972}
1973
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001974VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDepthStencilStateCreateInfo* pCreateInfo, VkDynamicDepthStencilState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001975{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001976 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001977 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
1978 loader_platform_thread_lock_mutex(&globalLock);
1979 dynamicDsStateMap[pState->handle] = *pCreateInfo;
1980 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001981 return result;
1982}
1983
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001984VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001985{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001986 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001987 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001988 loader_platform_thread_lock_mutex(&globalLock);
1989 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1990 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1991 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis59278bf2015-08-18 07:10:58 -06001992 pCB->createInfo = *pCreateInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001993 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06001994 pCB->level = pCreateInfo->level;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001995 cmdBufferMap[*pCmdBuffer] = pCB;
1996 loader_platform_thread_unlock_mutex(&globalLock);
1997 updateCBTracking(*pCmdBuffer);
1998 }
1999 return result;
2000}
2001
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002002VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002003{
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002004 // Validate command buffer level
2005 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2006 if (pCB) {
2007 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
2008 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
2009 // These should be NULL for a Primary CB
2010 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2011 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
2012 }
2013 } else {
2014 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
2015 // These should NOT be null for an Secondary CB
2016 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
2017 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
2018 }
2019 }
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002020 pCB->beginInfo = *pBeginInfo;
2021 } else {
2022 // TODO : Need to pass cmdBuffer as objType here
2023 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
2024 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06002025 }
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002026 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002027 if (VK_SUCCESS == result) {
Tobin Ehlis59278bf2015-08-18 07:10:58 -06002028 if (CB_NEW != pCB->state)
2029 resetCB(cmdBuffer);
2030 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002031 updateCBTracking(cmdBuffer);
2032 }
2033 return result;
2034}
2035
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002036VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002037{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002038 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2039 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2040 if (pCB) {
2041 if (pCB->state == CB_UPDATE_ACTIVE) {
2042 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2043 if (VK_SUCCESS == result) {
2044 updateCBTracking(cmdBuffer);
2045 pCB->state = CB_UPDATE_COMPLETE;
2046 // Reset CB status flags
2047 pCB->status = 0;
2048 printCB(cmdBuffer);
2049 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002050 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002051 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002052 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002053 }
2054 return result;
2055}
2056
Cody Northrope62183e2015-07-09 18:08:05 -06002057VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002058{
Cody Northrope62183e2015-07-09 18:08:05 -06002059 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002060 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002061 resetCB(cmdBuffer);
2062 updateCBTracking(cmdBuffer);
2063 }
2064 return result;
2065}
2066
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002067VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002068{
2069 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2070 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002071 if (pCB->state == CB_UPDATE_ACTIVE) {
2072 updateCBTracking(cmdBuffer);
2073 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis6d58e6d2015-06-23 08:46:18 -06002074 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002075 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2076 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002077 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002078 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2079 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002080 } else {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002081 PIPELINE_NODE* pPN = getPipeline(pipeline);
2082 if (pPN) {
2083 pCB->lastBoundPipeline = pipeline;
2084 loader_platform_thread_lock_mutex(&globalLock);
2085 set_cb_pso_status(pCB, pPN);
2086 g_lastBoundPipeline = pPN;
2087 loader_platform_thread_unlock_mutex(&globalLock);
2088 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2089 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2090 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002091 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2092 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002093 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002094 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002095 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002096 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002097 }
2098 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002099}
2100
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002101VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002102{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002103 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2104 if (pCB) {
2105 if (pCB->state == CB_UPDATE_ACTIVE) {
2106 updateCBTracking(cmdBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002107 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002108 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002109 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2110 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlis502480b2015-06-24 15:53:07 -06002111 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002112 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002113 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2114 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002115 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 -06002116 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002117 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002118 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2119 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002120 }
2121 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002122 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002123 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002124 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002125 }
2126 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002127}
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002128VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicRasterState(VkCmdBuffer cmdBuffer, VkDynamicRasterState dynamicRasterState)
2129{
2130 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2131 if (pCB) {
2132 if (pCB->state == CB_UPDATE_ACTIVE) {
2133 updateCBTracking(cmdBuffer);
2134 addCmd(pCB, CMD_BINDDYNAMICRASTERSTATE);
2135 if (!pCB->activeRenderPass) {
2136 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2137 "Incorrect call to vkCmdBindDynamicRasterState() without an active RenderPass.");
2138 }
2139 loader_platform_thread_lock_mutex(&globalLock);
2140 pCB->status |= CBSTATUS_RASTER_BOUND;
2141 if (dynamicRsStateMap.find(dynamicRasterState.handle) == dynamicRsStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002142 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_RASTER_STATE, dynamicRasterState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002143 "Unable to find VkDynamicRasterState object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2144 } else {
2145 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2146 g_lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2147 }
2148 loader_platform_thread_unlock_mutex(&globalLock);
2149 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2150 } else {
2151 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicRasterState()");
2152 }
2153 }
2154}
2155VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(VkCmdBuffer cmdBuffer, VkDynamicColorBlendState dynamicColorBlendState)
2156{
2157 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2158 if (pCB) {
2159 if (pCB->state == CB_UPDATE_ACTIVE) {
2160 updateCBTracking(cmdBuffer);
2161 addCmd(pCB, CMD_BINDDYNAMICCOLORBLENDSTATE);
2162 if (!pCB->activeRenderPass) {
2163 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2164 "Incorrect call to vkCmdBindDynamicColorBlendState() without an active RenderPass.");
2165 }
2166 loader_platform_thread_lock_mutex(&globalLock);
2167 pCB->status |= CBSTATUS_COLOR_BLEND_BOUND;
2168 if (dynamicCbStateMap.find(dynamicColorBlendState.handle) == dynamicCbStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002169 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_COLOR_BLEND_STATE, dynamicColorBlendState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002170 "Unable to find VkDynamicColorBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2171 } else {
2172 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2173 g_lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2174 }
2175 loader_platform_thread_unlock_mutex(&globalLock);
2176 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2177 } else {
2178 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicColorBlendState()");
2179 }
2180 }
2181}
2182VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(VkCmdBuffer cmdBuffer, VkDynamicDepthStencilState dynamicDepthStencilState)
2183{
2184 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2185 if (pCB) {
2186 if (pCB->state == CB_UPDATE_ACTIVE) {
2187 updateCBTracking(cmdBuffer);
2188 addCmd(pCB, CMD_BINDDYNAMICDEPTHSTENCILSTATE);
2189 if (!pCB->activeRenderPass) {
2190 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2191 "Incorrect call to vkCmdBindDynamicDepthStencilState() without an active RenderPass.");
2192 }
2193 loader_platform_thread_lock_mutex(&globalLock);
2194 pCB->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
2195 if (dynamicDsStateMap.find(dynamicDepthStencilState.handle) == dynamicDsStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002196 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_DEPTH_STENCIL_STATE, dynamicDepthStencilState.handle, 0, DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, "DS",
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002197 "Unable to find VkDynamicDepthStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2198 } else {
2199 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2200 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2201 }
2202 loader_platform_thread_unlock_mutex(&globalLock);
2203 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
2204 } else {
2205 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthStencilState()");
2206 }
2207 }
2208}
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06002209VK_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 -06002210{
2211 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2212 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002213 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002214 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002215 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2216 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002217 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002218 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 -06002219 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2220 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002221 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002222 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2223 if (pSet) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002224 loader_platform_thread_lock_mutex(&globalLock);
2225 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002226 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002227 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2228 g_lastBoundDescriptorSet = pDescriptorSets[i];
2229 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002230 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2231 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002232 if (!pSet->pUpdateStructs)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002233 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2234 "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 -06002235 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002236 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2237 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002238 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002239 }
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002240 updateCBTracking(cmdBuffer);
2241 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis7ae7c6a2015-06-22 18:00:14 -06002242 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 -06002243 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002244 } else {
2245 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002246 }
2247 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002248}
2249
Tony Barbourd1c35722015-04-16 15:59:00 -06002250VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002251{
2252 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2253 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002254 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002255 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002256 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 -06002257 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2258 } else {
2259 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2260 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002261 updateCBTracking(cmdBuffer);
2262 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002263 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2264 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002265 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002266 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2267 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002268 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002269}
2270
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002271VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2272 VkCmdBuffer cmdBuffer,
2273 uint32_t startBinding,
2274 uint32_t bindingCount,
2275 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002276 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002277{
2278 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2279 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002280 if (pCB->state == CB_UPDATE_ACTIVE) {
2281 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlis502480b2015-06-24 15:53:07 -06002282 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002283 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 -06002284 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2285 } else {
2286 pCB->lastVtxBinding = startBinding + bindingCount -1;
2287 if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002288 updateCBTracking(cmdBuffer);
2289 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002290 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2291 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002292 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002293 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002294 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002295 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002296 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002297}
2298
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002299VK_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 -06002300{
2301 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002302 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002303 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002304 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002305 pCB->drawCount[DRAW]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002306 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002307 // TODO : Need to pass cmdBuffer as srcObj here
2308 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 -06002309 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2310 synchAndPrintDSConfig(cmdBuffer);
2311 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002312 updateCBTracking(cmdBuffer);
2313 addCmd(pCB, CMD_DRAW);
2314 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002315 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002316 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002317 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2318 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002319 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002320}
2321
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002322VK_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 -06002323{
2324 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002325 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002326 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002327 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002328 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002329 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002330 // TODO : Need to pass cmdBuffer as srcObj here
2331 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 -06002332 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2333 synchAndPrintDSConfig(cmdBuffer);
2334 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002335 updateCBTracking(cmdBuffer);
2336 addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002337 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2338 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002339 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002340 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2341 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002342 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002343}
2344
Tony Barbourd1c35722015-04-16 15:59:00 -06002345VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002346{
2347 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002348 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002349 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002350 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002351 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002352 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002353 // TODO : Need to pass cmdBuffer as srcObj here
2354 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 -06002355 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2356 synchAndPrintDSConfig(cmdBuffer);
2357 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002358 updateCBTracking(cmdBuffer);
2359 addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002360 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2361 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002362 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002363 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2364 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002365 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002366}
2367
Tony Barbourd1c35722015-04-16 15:59:00 -06002368VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002369{
2370 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002371 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002372 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002373 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002374 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002375 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002376 // TODO : Need to pass cmdBuffer as srcObj here
2377 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 -06002378 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2379 synchAndPrintDSConfig(cmdBuffer);
2380 if (valid) {
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002381 updateCBTracking(cmdBuffer);
2382 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2383 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002384 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002385 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002386 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2387 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002388 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002389}
2390
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002391VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002392{
2393 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2394 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002395 if (pCB->state == CB_UPDATE_ACTIVE) {
2396 updateCBTracking(cmdBuffer);
2397 addCmd(pCB, CMD_DISPATCH);
2398 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002399 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002400 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2401 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002402 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002403}
2404
Tony Barbourd1c35722015-04-16 15:59:00 -06002405VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002406{
2407 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2408 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002409 if (pCB->state == CB_UPDATE_ACTIVE) {
2410 updateCBTracking(cmdBuffer);
2411 addCmd(pCB, CMD_DISPATCHINDIRECT);
2412 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002413 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002414 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2415 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002416 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002417}
2418
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002419VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002420{
2421 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2422 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002423 if (pCB->state == CB_UPDATE_ACTIVE) {
2424 updateCBTracking(cmdBuffer);
2425 addCmd(pCB, CMD_COPYBUFFER);
2426 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002427 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002428 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2429 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002430 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002431}
2432
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002433VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2434 VkImage srcImage,
2435 VkImageLayout srcImageLayout,
2436 VkImage destImage,
2437 VkImageLayout destImageLayout,
2438 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002439{
2440 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2441 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002442 if (pCB->state == CB_UPDATE_ACTIVE) {
2443 updateCBTracking(cmdBuffer);
2444 addCmd(pCB, CMD_COPYIMAGE);
2445 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002446 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002447 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2448 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002449 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002450}
2451
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002452VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2453 VkImage srcImage, VkImageLayout srcImageLayout,
2454 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002455 uint32_t regionCount, const VkImageBlit* pRegions,
2456 VkTexFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002457{
2458 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2459 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002460 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehliseac83792015-06-23 10:41:13 -06002461 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002462 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2463 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis5a65cca2015-07-13 13:14:24 -06002464 } else {
2465 updateCBTracking(cmdBuffer);
2466 addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002467 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 -06002468 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002469 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002470 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2471 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002472 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002473}
2474
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002475VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2476 VkBuffer srcBuffer,
2477 VkImage destImage, VkImageLayout destImageLayout,
2478 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002479{
2480 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2481 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002482 if (pCB->state == CB_UPDATE_ACTIVE) {
2483 updateCBTracking(cmdBuffer);
2484 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2485 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002486 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002487 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2488 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002489 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002490}
2491
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002492VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2493 VkImage srcImage, VkImageLayout srcImageLayout,
2494 VkBuffer destBuffer,
2495 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002496{
2497 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2498 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002499 if (pCB->state == CB_UPDATE_ACTIVE) {
2500 updateCBTracking(cmdBuffer);
2501 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2502 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002503 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002504 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2505 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002506 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002507}
2508
Tony Barbourd1c35722015-04-16 15:59:00 -06002509VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002510{
2511 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2512 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002513 if (pCB->state == CB_UPDATE_ACTIVE) {
2514 updateCBTracking(cmdBuffer);
2515 addCmd(pCB, CMD_UPDATEBUFFER);
2516 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002517 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002518 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2519 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002520 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002521}
2522
Tony Barbourd1c35722015-04-16 15:59:00 -06002523VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002524{
2525 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2526 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002527 if (pCB->state == CB_UPDATE_ACTIVE) {
2528 updateCBTracking(cmdBuffer);
2529 addCmd(pCB, CMD_FILLBUFFER);
2530 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002531 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002532 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2533 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002534 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002535}
2536
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002537VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2538 VkCmdBuffer cmdBuffer,
2539 uint32_t colorAttachment,
2540 VkImageLayout imageLayout,
2541 const VkClearColorValue* pColor,
2542 uint32_t rectCount,
2543 const VkRect3D* pRects)
2544{
2545 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2546 if (pCB) {
2547 if (pCB->state == CB_UPDATE_ACTIVE) {
2548 // Warn if this is issued prior to Draw Cmd
2549 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002550 // TODO : cmdBuffer should be srcObj
2551 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 -06002552 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2553 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2554 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002555 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002556 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 -06002557 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2558 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2559 } else {
2560 updateCBTracking(cmdBuffer);
2561 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2562 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2563 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002564 } else {
2565 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2566 }
2567 }
2568}
2569
2570VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2571 VkCmdBuffer cmdBuffer,
2572 VkImageAspectFlags imageAspectMask,
2573 VkImageLayout imageLayout,
2574 float depth,
2575 uint32_t stencil,
2576 uint32_t rectCount,
2577 const VkRect3D* pRects)
2578{
2579 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2580 if (pCB) {
2581 if (pCB->state == CB_UPDATE_ACTIVE) {
2582 // Warn if this is issued prior to Draw Cmd
2583 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002584 // TODO : cmdBuffer should be srcObj
2585 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 -06002586 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2587 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2588 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002589 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002590 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 -06002591 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2592 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2593 } else {
2594 updateCBTracking(cmdBuffer);
2595 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2596 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2597 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002598 } else {
2599 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2600 }
2601 }
2602}
2603
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002604VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2605 VkCmdBuffer cmdBuffer,
2606 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12002607 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002608 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002609{
2610 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2611 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002612 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002613 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002614 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 -06002615 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2616 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2617 } else {
2618 updateCBTracking(cmdBuffer);
2619 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2620 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2621 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002622 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002623 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2624 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002625 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002626}
2627
Chris Forbesd9be82b2015-06-22 17:21:59 +12002628VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002629 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002630 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002631 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002632{
2633 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2634 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002635 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002636 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002637 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 -06002638 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2639 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2640 } else {
2641 updateCBTracking(cmdBuffer);
2642 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2643 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2644 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002645 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002646 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2647 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002648 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002649}
2650
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002651VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2652 VkImage srcImage, VkImageLayout srcImageLayout,
2653 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002654 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002655{
2656 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2657 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002658 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002659 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002660 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2661 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlise2473152015-06-23 11:34:28 -06002662 } else {
2663 updateCBTracking(cmdBuffer);
2664 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002665 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlise2473152015-06-23 11:34:28 -06002666 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002667 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002668 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2669 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002670 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002671}
2672
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002673VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002674{
2675 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2676 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002677 if (pCB->state == CB_UPDATE_ACTIVE) {
2678 updateCBTracking(cmdBuffer);
2679 addCmd(pCB, CMD_SETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002680 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002681 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002682 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2683 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002684 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002685}
2686
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002687VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002688{
2689 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2690 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002691 if (pCB->state == CB_UPDATE_ACTIVE) {
2692 updateCBTracking(cmdBuffer);
2693 addCmd(pCB, CMD_RESETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002694 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002695 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002696 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2697 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002698 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002699}
2700
Courtney Goeltzenleuchterdbd20322015-07-12 12:58:58 -06002701VK_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 -06002702{
2703 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2704 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002705 if (pCB->state == CB_UPDATE_ACTIVE) {
2706 updateCBTracking(cmdBuffer);
2707 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002708 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002709 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002710 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2711 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002712 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002713}
2714
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06002715VK_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 -06002716{
2717 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2718 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002719 if (pCB->state == CB_UPDATE_ACTIVE) {
2720 updateCBTracking(cmdBuffer);
2721 addCmd(pCB, CMD_PIPELINEBARRIER);
Courtney Goeltzenleuchter53043732015-07-12 13:20:05 -06002722 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002723 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002724 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
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 vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002730{
2731 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2732 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002733 if (pCB->state == CB_UPDATE_ACTIVE) {
2734 updateCBTracking(cmdBuffer);
2735 addCmd(pCB, CMD_BEGINQUERY);
2736 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002737 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002738 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2739 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002740 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002741}
2742
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002743VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002744{
2745 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2746 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002747 if (pCB->state == CB_UPDATE_ACTIVE) {
2748 updateCBTracking(cmdBuffer);
2749 addCmd(pCB, CMD_ENDQUERY);
2750 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002751 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002752 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2753 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002754 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002755}
2756
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002757VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002758{
2759 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2760 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002761 if (pCB->state == CB_UPDATE_ACTIVE) {
2762 updateCBTracking(cmdBuffer);
2763 addCmd(pCB, CMD_RESETQUERYPOOL);
2764 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002765 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002766 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2767 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002768 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002769}
2770
Tony Barbourd1c35722015-04-16 15:59:00 -06002771VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002772{
2773 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2774 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002775 if (pCB->state == CB_UPDATE_ACTIVE) {
2776 updateCBTracking(cmdBuffer);
2777 addCmd(pCB, CMD_WRITETIMESTAMP);
2778 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002779 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002780 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2781 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002782 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002783}
2784
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002785VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002786{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002787 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002788 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002789 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002790 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002791 if (pCreateInfo->pAttachments) {
Cody Northrop3cc85e92015-08-04 10:47:08 -06002792 localFBCI->pAttachments = new VkAttachmentView[localFBCI->attachmentCount];
2793 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkAttachmentView));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002794 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002795 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002796 }
2797 return result;
2798}
2799
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002800VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002801{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002802 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002803 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002804 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002805 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002806 if (pCreateInfo->pAttachments) {
2807 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2808 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002809 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002810 if (pCreateInfo->pSubpasses) {
2811 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2812 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2813
2814 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2815 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2816 const uint32_t attachmentCount = subpass->inputCount +
Cody Northropa505dda2015-08-04 11:16:41 -06002817 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wu08accc62015-07-07 11:50:03 +08002818 subpass->preserveCount;
2819 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2820
Cody Northropa505dda2015-08-04 11:16:41 -06002821 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002822 sizeof(attachments[0]) * subpass->inputCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002823 subpass->pInputAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002824 attachments += subpass->inputCount;
2825
Cody Northropa505dda2015-08-04 11:16:41 -06002826 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002827 sizeof(attachments[0]) * subpass->colorCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002828 subpass->pColorAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002829 attachments += subpass->colorCount;
2830
Cody Northropa505dda2015-08-04 11:16:41 -06002831 if (subpass->pResolveAttachments) {
2832 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002833 sizeof(attachments[0]) * subpass->colorCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002834 subpass->pResolveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002835 attachments += subpass->colorCount;
2836 }
2837
Cody Northropa505dda2015-08-04 11:16:41 -06002838 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wu08accc62015-07-07 11:50:03 +08002839 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northropa505dda2015-08-04 11:16:41 -06002840 subpass->pPreserveAttachments = attachments;
Chia-I Wu08accc62015-07-07 11:50:03 +08002841 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06002842 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002843 if (pCreateInfo->pDependencies) {
2844 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2845 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002846 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002847 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002848 }
2849 return result;
2850}
2851
Chia-I Wu08accc62015-07-07 11:50:03 +08002852VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002853{
2854 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2855 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002856 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002857 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002858 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2859 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002860 } else {
2861 updateCBTracking(cmdBuffer);
2862 addCmd(pCB, CMD_BEGINRENDERPASS);
2863 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08002864 pCB->activeSubpass = 0;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002865 pCB->framebuffer = pRenderPassBegin->framebuffer;
2866 if (pCB->lastBoundPipeline) {
2867 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2868 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002869 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis259730a2015-06-23 16:13:03 -06002870 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06002871 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002872 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis259730a2015-06-23 16:13:03 -06002873 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06002874 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002875 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002876}
2877
Chia-I Wu08accc62015-07-07 11:50:03 +08002878VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2879{
2880 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2881 if (pCB) {
2882 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002883 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 +08002884 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2885 } else {
2886 updateCBTracking(cmdBuffer);
2887 addCmd(pCB, CMD_NEXTSUBPASS);
2888 pCB->activeSubpass++;
2889 if (pCB->lastBoundPipeline) {
2890 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2891 }
2892 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2893 }
2894 }
2895}
2896
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002897VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002898{
2899 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2900 if (pCB) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002901 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002902 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 +08002903 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis59a9c832015-06-23 16:13:03 -06002904 } else {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002905 updateCBTracking(cmdBuffer);
2906 addCmd(pCB, CMD_ENDRENDERPASS);
2907 pCB->activeRenderPass = 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08002908 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002909 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2910 }
2911 }
2912}
2913
2914VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2915{
2916 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2917 if (pCB) {
2918 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002919 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 +08002920 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2921 } else {
2922 updateCBTracking(cmdBuffer);
2923 addCmd(pCB, CMD_EXECUTECOMMANDS);
2924 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis259730a2015-06-23 16:13:03 -06002925 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002926 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002927}
2928
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002929VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2930 VkInstance instance,
2931 VkFlags msgFlags,
2932 const PFN_vkDbgMsgCallback pfnMsgCallback,
2933 void* pUserData,
2934 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002935{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002936 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002937 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2938 if (VK_SUCCESS == res) {
2939 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2940 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2941 }
2942 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002943}
2944
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002945VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2946 VkInstance instance,
2947 VkDbgMsgCallback msgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002948{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002949 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002950 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2951 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2952 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2953 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002954}
2955
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002956VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002957{
2958 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002959 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2960 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002961 // TODO : cmdBuffer should be srcObj
2962 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 -06002963 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002964 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06002965 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002966 updateCBTracking(cmdBuffer);
2967 addCmd(pCB, CMD_DBGMARKERBEGIN);
2968 }
Jon Ashburneab34492015-06-01 09:37:38 -06002969 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002970}
2971
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002972VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002973{
2974 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002975 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2976 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002977 // TODO : cmdBuffer should be srcObj
2978 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 -06002979 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002980 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06002981 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002982 updateCBTracking(cmdBuffer);
2983 addCmd(pCB, CMD_DBGMARKEREND);
2984 }
Jon Ashburneab34492015-06-01 09:37:38 -06002985 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2986}
2987
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002988//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2989//{
2990// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2991// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2992// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2993// "Attempt to use DbgSetObjectTag but extension disabled!");
2994// return VK_ERROR_UNAVAILABLE;
2995// }
2996// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2997//}
2998//
2999//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3000//{
3001// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3002// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3003// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3004// "Attempt to use DbgSetObjectName but extension disabled!");
3005// return VK_ERROR_UNAVAILABLE;
3006// }
3007// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3008//}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003009
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003010VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003011{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06003012 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003013 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003014
Jon Ashburn8fd08252015-05-28 16:25:02 -06003015 /* loader uses this to force layer initialization; device object is wrapped */
3016 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003017 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003018 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003019 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06003020 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003021 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003022 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003023 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003024 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003025 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003026 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003027 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003028 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003029 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003030 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003031 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003032 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003033 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003034 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003035 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003036 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003037 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003038 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003039 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003040 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003041 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003042 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003043 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003044 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003045 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003046 if (!strcmp(funcName, "vkDestroyAttachmentView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003047 return (PFN_vkVoidFunction) vkDestroyAttachmentView;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003048 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003049 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003050 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003051 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003052 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003053 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003054 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003055 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003056 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003057 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003058 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003059 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003060 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003061 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003062 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003063 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003064 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003065 return (PFN_vkVoidFunction) vkDestroyDynamicRasterState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003066 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003067 return (PFN_vkVoidFunction) vkDestroyDynamicColorBlendState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003068 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003069 return (PFN_vkVoidFunction) vkDestroyDynamicDepthStencilState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003070 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003071 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003072 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003073 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003074 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003075 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003076 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003077 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003078 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003079 return (PFN_vkVoidFunction) vkCreateImageView;
Tobin Ehlisffe35812015-07-10 12:15:19 -06003080 if (!strcmp(funcName, "vkCreateAttachmentView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003081 return (PFN_vkVoidFunction) vkCreateAttachmentView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003082 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003083 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003084 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003085 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003086 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003087 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003088 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003089 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003090 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003091 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003092 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003093 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003094 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003095 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003096 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003097 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05003098 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003099 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003100 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003101 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003102 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003103 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003104 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003105 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003106 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003107 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003108 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003109 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003110 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003111 return (PFN_vkVoidFunction) vkCreateDynamicRasterState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003112 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003113 return (PFN_vkVoidFunction) vkCreateDynamicColorBlendState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003114 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003115 return (PFN_vkVoidFunction) vkCreateDynamicDepthStencilState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003116 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003117 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003118 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003120 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003122 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003124 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003126 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003128 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkCmdBindDynamicRasterState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003130 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkCmdBindDynamicColorBlendState;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003132 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003134 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06003136 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003138 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003140 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003142 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003143 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003144 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003145 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003146 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003147 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003148 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003150 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003152 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003154 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003156 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003158 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003160 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003161 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003162 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003163 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003164 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003165 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12003166 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003167 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003168 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003169 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003170 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003172 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003173 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003174 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003175 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003176 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003177 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003178 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003179 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003180 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003181 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003182 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003183 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003184 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003185 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003186 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003187 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003188 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003189 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003190 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003191 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003192 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003193 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003194 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003195 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08003196 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003197 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003198 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003199 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Jon Ashburneab34492015-06-01 09:37:38 -06003200
Jon Ashburn747f2b62015-06-18 15:02:58 -06003201 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3202 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06003203 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06003204 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003206 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003208// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3209// return (void*) vkDbgSetObjectTag;
3210// if (!strcmp(funcName, "vkDbgSetObjectName"))
3211// return (void*) vkDbgSetObjectName;
Jon Ashburneab34492015-06-01 09:37:38 -06003212 }
3213 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06003214 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003215 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003216 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003217 }
3218}
3219
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003220VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003221{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003222 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003223 if (instance == NULL)
3224 return NULL;
3225
Jon Ashburn8fd08252015-05-28 16:25:02 -06003226 /* loader uses this to force layer initialization; instance object is wrapped */
3227 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003228 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003230 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003231 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003232 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003233 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003234 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003235 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003236 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003237 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003238 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003239 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003240 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Tony Barbour59a47322015-06-24 16:06:58 -06003241 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003242 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003243
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003244 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3245 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003246 if (fptr)
3247 return fptr;
3248
Jon Ashburn8fd08252015-05-28 16:25:02 -06003249 {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003250 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn8fd08252015-05-28 16:25:02 -06003251 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003252 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003253 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003254 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003255}