blob: b65bef77bd781b55c261a1ef559577920a407e07 [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};
247static VkDescriptorSet g_lastBoundDescriptorSet = VkDescriptorSet(0);
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++) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600378 void* pDynStateCI = getDynamicStateCreateInfo(pCB->lastBoundDynamicState[i], (DYNAMIC_STATE_BIND_POINT)i);
379 if (pDynStateCI) {
380 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
381 "Reporting CreateInfo for currently bound %s object %#" PRIxLEAST64, string_DYNAMIC_STATE_BIND_POINT((DYNAMIC_STATE_BIND_POINT)i).c_str(), pCB->lastBoundDynamicState[i]);
382 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, dynamicStateBindPointToObjType((DYNAMIC_STATE_BIND_POINT)i), pCB->lastBoundDynamicState[i], 0, DRAWSTATE_NONE, "DS",
383 dynamic_display(pDynStateCI, " ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600384 break;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600385 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600386 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());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600388 }
389 }
390 loader_platform_thread_unlock_mutex(&globalLock);
391 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600392}
393// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600394static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600395{
396 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600397 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600398 loader_platform_thread_unlock_mutex(&globalLock);
399 return NULL;
400 }
401 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600402 return pipelineMap[pipeline.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600403}
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600404// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600405static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
406 VkBool32 result;
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600407 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");
408 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");
409 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");
410 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");
411 if (indexedDraw)
412 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");
413 return result;
414}
415// Validate overall state at the time of a draw call
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600416static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600417 // First check flag states
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600418 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600419 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
420 // Now complete other state checks
Tobin Ehlis502480b2015-06-24 15:53:07 -0600421 if (pPipe && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600422 result = VK_FALSE;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600423 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600424 "Pipeline layout from last vkCmdBindDescriptorSets() (%s) does not match PSO Pipeline layout (%s)", pCB->lastBoundPipelineLayout, pPipe->graphicsPipelineCI.layout);
425 }
Tobin Ehlisd1fe4ec2015-06-23 11:22:55 -0600426 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600427 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 -0600428 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
429 }
Tobin Ehlis429b91d2015-06-22 17:20:50 -0600430 return result;
431}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600432// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600433static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600434{
435 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600436 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600437 loader_platform_thread_unlock_mutex(&globalLock);
438 return NULL;
439 }
440 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600441 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600442}
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600443// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600444static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600445{
446 // VS is required
447 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600448 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 -0600449 "Invalid Pipeline CreateInfo State: Vtx Shader required");
450 return VK_FALSE;
451 }
452 // Either both or neither TC/TE shaders should be defined
453 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
454 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600455 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 -0600456 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
457 return VK_FALSE;
458 }
459 // Compute shaders should be specified independent of Gfx shaders
460 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
461 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
462 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
463 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600464 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 -0600465 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
466 return VK_FALSE;
467 }
468 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
469 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
470 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
471 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600472 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 -0600473 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
474 return VK_FALSE;
475 }
476 if ((pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) &&
477 (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600478 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 -0600479 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
480 return VK_FALSE;
481 }
482 return VK_TRUE;
483}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600484// Init the pipeline mapping info based on pipeline create info LL tree
485// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600486static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600487{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600488 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
489 if (pBasePipeline) {
490 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlis9c536442015-06-19 13:00:59 -0600491 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600492 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
493 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600494 // First init create info
Tobin Ehliseba312c2015-04-01 08:40:34 -0600495 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600496 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600497
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600498 size_t bufferSize = 0;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600499 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600500 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600501
502 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
503 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
504
505 switch (pPSSCI->stage) {
506 case VK_SHADER_STAGE_VERTEX:
507 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
508 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600509 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600510 case VK_SHADER_STAGE_TESS_CONTROL:
511 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
512 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600513 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600514 case VK_SHADER_STAGE_TESS_EVALUATION:
515 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
516 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600517 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600518 case VK_SHADER_STAGE_GEOMETRY:
519 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
520 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600521 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600522 case VK_SHADER_STAGE_FRAGMENT:
523 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
524 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600525 break;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600526 case VK_SHADER_STAGE_COMPUTE:
527 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
528 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600529 break;
530 default:
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600531 // TODO : Flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600532 break;
533 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600534 }
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600535
536 if (pCreateInfo->pVertexInputState != NULL) {
537 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
538 // Copy embedded ptrs
539 pVICI = pCreateInfo->pVertexInputState;
540 pPipeline->vtxBindingCount = pVICI->bindingCount;
541 if (pPipeline->vtxBindingCount) {
542 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
543 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
544 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
545 }
546 pPipeline->vtxAttributeCount = pVICI->attributeCount;
547 if (pPipeline->vtxAttributeCount) {
548 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
549 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
550 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
551 }
552 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
553 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600554 if (pCreateInfo->pInputAssemblyState != NULL) {
555 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
556 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600557 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600558 if (pCreateInfo->pTessellationState != NULL) {
559 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600561 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600562 if (pCreateInfo->pViewportState != NULL) {
563 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
564 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600565 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600566 if (pCreateInfo->pRasterState != NULL) {
567 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
568 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600569 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600570 if (pCreateInfo->pMultisampleState != NULL) {
571 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
572 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600573 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600574 if (pCreateInfo->pColorBlendState != NULL) {
575 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600576 // Copy embedded ptrs
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600577 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600578 pPipeline->attachmentCount = pCBCI->attachmentCount;
579 if (pPipeline->attachmentCount) {
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600580 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
581 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600582 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
583 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600584 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600585 }
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600586 if (pCreateInfo->pDepthStencilState != NULL) {
587 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
588 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600589 }
590
591 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
592 if (pCreateInfo->stageCount != 0) {
593 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
594 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
595 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
596 }
597
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600598 return pPipeline;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600599}
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600600
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600601// Free the Pipeline nodes
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600602static void deletePipelines()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600603{
David Pinedod8f83d82015-04-27 16:36:17 -0600604 if (pipelineMap.size() <= 0)
605 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600606 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinskid5732f32015-06-23 15:11:57 -0600607 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
608 delete[] (*ii).second->graphicsPipelineCI.pStages;
609 }
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600610 if ((*ii).second->pVertexBindingDescriptions) {
611 delete[] (*ii).second->pVertexBindingDescriptions;
612 }
613 if ((*ii).second->pVertexAttributeDescriptions) {
614 delete[] (*ii).second->pVertexAttributeDescriptions;
615 }
616 if ((*ii).second->pAttachments) {
617 delete[] (*ii).second->pAttachments;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600618 }
619 delete (*ii).second;
620 }
Jon Ashburn25012f72015-06-15 10:58:28 -0600621 pipelineMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600622}
Tobin Ehliseba312c2015-04-01 08:40:34 -0600623// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600624static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600625{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600626 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tony Barbourdd6e32e2015-07-10 15:29:03 -0600627 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
Tobin Ehlisf313c8b2015-04-01 11:59:08 -0600628 if (pPipe->msStateCI.multisampleEnable)
Tony Barbourdfd533a2015-06-26 10:18:34 -0600629 return pPipe->msStateCI.rasterSamples;
Tobin Ehliseba312c2015-04-01 08:40:34 -0600630 }
631 return 1;
632}
633// Validate state related to the PSO
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600634static void validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehliseba312c2015-04-01 08:40:34 -0600635{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600636 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehliseba312c2015-04-01 08:40:34 -0600637 // Verify that any MSAA request in PSO matches sample# in bound FB
638 uint32_t psoNumSamples = getNumSamples(pipeline);
639 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600640 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wu08accc62015-07-07 11:50:03 +0800641 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
642 int subpassNumSamples = 0;
643 uint32_t i;
644
645 for (i = 0; i < pSD->colorCount; i++) {
646 uint32_t samples;
647
648 if (pSD->colorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
649 continue;
650
651 samples = pRPCI->pAttachments[pSD->colorAttachments[i].attachment].samples;
652 if (subpassNumSamples == 0) {
653 subpassNumSamples = samples;
654 } else if (subpassNumSamples != samples) {
655 subpassNumSamples = -1;
656 break;
657 }
658 }
659 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
660 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
661 if (subpassNumSamples == 0)
662 subpassNumSamples = samples;
663 else if (subpassNumSamples != samples)
664 subpassNumSamples = -1;
665 }
666
667 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600668 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
669 "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 -0600670 }
671 } else {
672 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
673 // Verify and flag error as appropriate
674 }
675 // TODO : Add more checks here
676 } else {
677 // TODO : Validate non-gfx pipeline updates
678 }
679}
680
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600681// Block of code at start here specifically for managing/tracking DSs
682
Tobin Ehlis793ad302015-04-03 12:01:11 -0600683// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600684static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600685{
686 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600687 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600688 loader_platform_thread_unlock_mutex(&globalLock);
689 return NULL;
690 }
691 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600692 return poolMap[pool.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600693}
694// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600695static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600696{
697 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600698 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600699 loader_platform_thread_unlock_mutex(&globalLock);
700 return NULL;
701 }
702 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600703 return setMap[set.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600704}
705
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600706static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600707 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600708 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600709 loader_platform_thread_unlock_mutex(&globalLock);
710 return NULL;
711 }
712 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600713 return layoutMap[layout.handle];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600714}
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600715// Return 1 if update struct is of valid type, 0 otherwise
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600716static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600717{
718 char str[1024];
719 switch (pUpdateStruct->sType)
720 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800721 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
722 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600723 return 1;
724 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600725 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 -0600726 "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 -0600727 return 0;
728 }
729}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600730// For given update struct, return binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600731static uint32_t getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600732{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600733 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600734 switch (pUpdateStruct->sType)
735 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800736 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
737 return ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
738 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
739 return ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600740 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600741 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600742 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600743 return 0xFFFFFFFF;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600744 }
745}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600746// Return count for given update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600747static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600748{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600749 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600750 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{
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600766 char str[1024];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600767 switch (pUpdateStruct->sType)
768 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800769 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
770 return ((VkWriteDescriptorSet*)pUpdateStruct)->count;
771 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis793ad302015-04-03 12:01:11 -0600772 // TODO : Need to understand this case better and make sure code is correct
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800773 return ((VkCopyDescriptorSet*)pUpdateStruct)->count;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600774 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600775 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -0600776 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600777 return 0;
778 }
779}
780// For given Layout Node and binding, return index where that binding begins
781static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
782{
783 uint32_t offsetIndex = 0;
784 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800785 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600786 }
787 return offsetIndex;
788}
789// For given layout node and binding, return last index that is updated
790static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
791{
792 uint32_t offsetIndex = 0;
793 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +0800794 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -0600795 }
796 return offsetIndex-1;
797}
798// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600799static uint32_t getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600800{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600801 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct));
Tobin Ehlis793ad302015-04-03 12:01:11 -0600802}
803// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600804static uint32_t getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis793ad302015-04-03 12:01:11 -0600805{
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600806 return (getBindingStartIndex(pLayout, getUpdateBinding(device, pUpdateStruct))+getUpdateArrayIndex(device, pUpdateStruct)+getUpdateCount(device, pUpdateStruct)-1);
Tobin Ehlis793ad302015-04-03 12:01:11 -0600807}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600808// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600809static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600810{
811 // First get actual type of update
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600812 VkDescriptorType actualType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600813 uint32_t i = 0;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600814 char str[1024];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600815 switch (pUpdateStruct->sType)
816 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800817 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
818 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600819 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800820 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
821 /* no need to validate */
822 return 1;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600823 break;
824 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600825 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 -0600826 "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 -0600827 return 0;
828 }
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600829 for (i = getUpdateStartIndex(device, pLayout, pUpdateStruct); i <= getUpdateEndIndex(device, pLayout, pUpdateStruct); i++) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600830 if (pLayout->pTypes[i] != actualType)
831 return 0;
832 }
833 return 1;
834}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600835// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
836// struct into the new struct and return ptr to shadow struct cast as GENERIC_HEADER
837// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600838static GENERIC_HEADER* shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600839{
840 GENERIC_HEADER* pNewNode = NULL;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800841 VkWriteDescriptorSet* pWDS = NULL;
842 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600843 size_t array_size = 0;
844 size_t base_array_size = 0;
845 size_t total_array_size = 0;
846 size_t baseBuffAddr = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600847 char str[1024];
848 switch (pUpdate->sType)
849 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800850 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
851 pWDS = new VkWriteDescriptorSet;
852 pNewNode = (GENERIC_HEADER*)pWDS;
853 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
854 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
855 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
856 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600857 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800858 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
859 pCDS = new VkCopyDescriptorSet;
860 pUpdate = (GENERIC_HEADER*)pCDS;
861 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600862 break;
863 default:
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600864 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 -0600865 "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 -0600866 return NULL;
867 }
868 // Make sure that pNext for the end of shadow copy is NULL
869 pNewNode->pNext = NULL;
870 return pNewNode;
871}
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800872// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600873static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600874{
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800875 const VkWriteDescriptorSet *pWDS = NULL;
876 const VkCopyDescriptorSet *pCDS = NULL;
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600877 VkBool32 result = 1;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800878
879 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
880 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
881 else
882 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
883
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600884 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600885 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600886 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600887 // TODO : If pCIList is NULL, flag error
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600888 // Perform all updates
Tobin Ehlis793ad302015-04-03 12:01:11 -0600889 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800890 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600891 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800892 g_lastBoundDescriptorSet = pSet->set;
893 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlis793ad302015-04-03 12:01:11 -0600894 pLayout = pSet->pLayout;
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600895 // First verify valid update struct
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600896 if (!validUpdateStruct(device, pUpdate)) {
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600897 result = 0;
898 break;
899 }
Tobin Ehlis793ad302015-04-03 12:01:11 -0600900 // Make sure that binding is within bounds
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600901 if (pLayout->createInfo.count < getUpdateBinding(device, pUpdate)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600902 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 -0600903 "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 -0600904 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600905 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600906 // Next verify that update falls within size of given binding
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600907 if (getBindingEndIndex(pLayout, getUpdateBinding(device, pUpdate)) < getUpdateEndIndex(device, pLayout, pUpdate)) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600908 char str[48*1024]; // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlis793ad302015-04-03 12:01:11 -0600909 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600910 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600911 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 -0600912 "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 -0600913 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600914 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlis793ad302015-04-03 12:01:11 -0600915 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600916 if (!validateUpdateType(device, pLayout, pUpdate)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600917 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 -0600918 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600919 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600920 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600921 // Save the update info
922 // TODO : Info message that update successful
923 // Create new update struct for this set's shadow copy
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600924 GENERIC_HEADER* pNewNode = shadowUpdateNode(device, pUpdate);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600925 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600926 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 -0600927 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600928 result = 0;
Tobin Ehlis9c536442015-06-19 13:00:59 -0600929 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600930 // Insert shadow node into LL of updates for this set
931 pNewNode->pNext = pSet->pUpdateStructs;
932 pSet->pUpdateStructs = pNewNode;
933 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis75283bf2015-06-18 15:59:33 -0600934 for (uint32_t j = getUpdateStartIndex(device, pLayout, pUpdate); j <= getUpdateEndIndex(device, pLayout, pUpdate); j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -0600935 assert(j<pSet->descriptorCount);
936 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600937 }
938 }
939 }
940 }
941 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600942 }
943 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis0174fed2015-05-28 12:10:17 -0600944 return result;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600945}
946// Free the shadowed update node for this Set
947// NOTE : Calls to this function should be wrapped in mutex
948static void freeShadowUpdateTree(SET_NODE* pSet)
949{
950 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
951 pSet->pUpdateStructs = NULL;
952 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
953 // Clear the descriptor mappings as they will now be invalid
954 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
955 while(pShadowUpdate) {
956 pFreeUpdate = pShadowUpdate;
957 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
958 uint32_t index = 0;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800959 VkWriteDescriptorSet * pWDS = NULL;
960 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600961 void** ppToFree = NULL;
962 switch (pFreeUpdate->sType)
963 {
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800964 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
965 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
966 if (pWDS->pDescriptors)
967 delete[] pWDS->pDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600968 break;
Chia-I Wu9d00ed72015-05-25 16:27:55 +0800969 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600970 break;
971 default:
972 assert(0);
973 break;
974 }
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600975 delete pFreeUpdate;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600976 }
977}
Tobin Ehlis793ad302015-04-03 12:01:11 -0600978// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600979// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600980static void deletePools()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600981{
David Pinedod8f83d82015-04-27 16:36:17 -0600982 if (poolMap.size() <= 0)
983 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -0600984 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600985 SET_NODE* pSet = (*ii).second->pSets;
986 SET_NODE* pFreeSet = pSet;
987 while (pSet) {
988 pFreeSet = pSet;
989 pSet = pSet->pNext;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -0600990 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600991 // Free Update shadow struct tree
992 freeShadowUpdateTree(pFreeSet);
993 if (pFreeSet->ppDescriptors) {
Chris Forbes02038792015-06-04 10:49:27 +1200994 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -0600995 }
996 delete pFreeSet;
997 }
998 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes02038792015-06-04 10:49:27 +1200999 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001000 }
1001 delete (*ii).second;
1002 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001003 poolMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001004}
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001005// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001006// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001007static void deleteLayouts()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001008{
David Pinedod8f83d82015-04-27 16:36:17 -06001009 if (layoutMap.size() <= 0)
1010 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001011 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001012 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001013 if (pLayout->createInfo.pBinding) {
1014 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1015 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1016 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1017 }
1018 delete[] pLayout->createInfo.pBinding;
1019 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001020 if (pLayout->pTypes) {
Chris Forbes02038792015-06-04 10:49:27 +12001021 delete[] pLayout->pTypes;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001022 }
1023 delete pLayout;
1024 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001025 layoutMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001026}
1027// Currently clearing a set is removing all previous updates to that set
1028// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001029static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001030{
1031 SET_NODE* pSet = getSetNode(set);
1032 if (!pSet) {
1033 // TODO : Return error
Tobin Ehlisce132d82015-06-19 15:07:05 -06001034 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001035 loader_platform_thread_lock_mutex(&globalLock);
1036 freeShadowUpdateTree(pSet);
1037 loader_platform_thread_unlock_mutex(&globalLock);
1038 }
1039}
1040
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001041static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001042{
Tobin Ehlis793ad302015-04-03 12:01:11 -06001043 POOL_NODE* pPool = getPoolNode(pool);
1044 if (!pPool) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001045 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1046 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001047 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001048 // For every set off of this pool, clear it
1049 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001050 while (pSet) {
1051 clearDescriptorSet(pSet->set);
1052 }
1053 }
1054}
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001055// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001056static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001057{
1058 loader_platform_thread_lock_mutex(&globalLock);
1059 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1060 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001061 // TODO : How to pass cb as srcObj here?
1062 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
1063 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<VkUintPtrLeast64>(cb));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001064 return NULL;
1065 }
1066 loader_platform_thread_unlock_mutex(&globalLock);
1067 return cmdBufferMap[cb];
1068}
1069// Free all CB Nodes
1070// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001071static void deleteCmdBuffers()
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001072{
David Pinedod8f83d82015-04-27 16:36:17 -06001073 if (cmdBufferMap.size() <= 0)
1074 return;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001075 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchterea3117c2015-04-27 15:04:43 -06001076 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1077 while (!cmd_node_list.empty()) {
1078 CMD_NODE* cmd_node = cmd_node_list.back();
1079 delete cmd_node;
1080 cmd_node_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001081 }
1082 delete (*ii).second;
1083 }
Jon Ashburn25012f72015-06-15 10:58:28 -06001084 cmdBufferMap.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001085}
Tobin Ehlis9c536442015-06-19 13:00:59 -06001086static void report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
1087{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001088 // TODO : How to pass cb as srcObj here?
1089 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 -06001090 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1091}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001092static void addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
1093{
1094 CMD_NODE* pCmd = new CMD_NODE;
1095 if (pCmd) {
1096 // init cmd node and append to end of cmd LL
1097 memset(pCmd, 0, sizeof(CMD_NODE));
1098 pCmd->cmdNumber = ++pCB->numCmds;
1099 pCmd->type = cmd;
1100 pCB->pCmds.push_back(pCmd);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001101 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001102 // TODO : How to pass cb as srcObj here?
1103 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1104 "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 -06001105 }
1106}
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001107static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001108{
1109 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1110 if (pCB) {
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001111 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1112 while (!cmd_list.empty()) {
1113 delete cmd_list.back();
1114 cmd_list.pop_back();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001115 }
Courtney Goeltzenleuchter3597a202015-04-27 17:16:56 -06001116 pCB->pCmds.clear();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001117 // Reset CB state
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001118 VkFlags saveFlags = pCB->flags;
Cody Northrope62183e2015-07-09 18:08:05 -06001119 VkCmdPool savedPool = pCB->pool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001120 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1121 pCB->cmdBuffer = cb;
1122 pCB->flags = saveFlags;
Cody Northrope62183e2015-07-09 18:08:05 -06001123 pCB->pool = savedPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001124 pCB->lastVtxBinding = MAX_BINDING;
1125 }
1126}
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001127// Set PSO-related status bits for CB
1128static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1129{
1130 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1131 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1132 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1133 }
1134 }
1135 if (pPipe->dsStateCI.depthWriteEnable) {
1136 pCB->status |= CBSTATUS_DEPTH_STENCIL_WRITE_ENABLE;
1137 }
1138}
1139// Set dyn-state related status bits for an object node
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001140static void set_cb_dyn_status(GLOBAL_CB_NODE* pNode, DYNAMIC_STATE_BIND_POINT stateBindPoint) {
Tobin Ehlise382c5a2015-06-10 12:57:07 -06001141 if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {
1142 pNode->status |= CBSTATUS_VIEWPORT_BOUND;
1143 } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {
1144 pNode->status |= CBSTATUS_RASTER_BOUND;
1145 } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {
1146 pNode->status |= CBSTATUS_COLOR_BLEND_BOUND;
1147 } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {
1148 pNode->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
1149 }
1150}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001151// Print the last bound Gfx Pipeline
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001152static void printPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001153{
1154 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1155 if (pCB) {
1156 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1157 if (!pPipeTrav) {
1158 // nothing to print
Tobin Ehlisce132d82015-06-19 15:07:05 -06001159 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001160 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001161 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001162 }
1163 }
1164}
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001165// Verify bound Pipeline State Object
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001166static bool validateBoundPipeline(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001167{
1168 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1169 if (pCB && pCB->lastBoundPipeline) {
1170 // First verify that we have a Node for bound pipeline
1171 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1172 char str[1024];
1173 if (!pPipeTrav) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001174 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_PIPELINE_BOUND, "DS",
1175 "Can't find last bound Pipeline %#" PRIxLEAST64 "!", pCB->lastBoundPipeline.handle);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001176 return false;
Tobin Ehlisce132d82015-06-19 15:07:05 -06001177 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001178 // Verify Vtx binding
1179 if (MAX_BINDING != pCB->lastVtxBinding) {
1180 if (pCB->lastVtxBinding >= pPipeTrav->vtxBindingCount) {
1181 if (0 == pPipeTrav->vtxBindingCount) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001182 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 -06001183 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001184 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001185 }
1186 else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001187 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 -06001188 "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 -06001189 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001190 }
1191 }
1192 else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001193 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001194 vk_print_vkvertexinputbindingdescription(&pPipeTrav->pVertexBindingDescriptions[pCB->lastVtxBinding], "{DS}INFO : ").c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001195 }
1196 }
1197 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001198 return true;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001199 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06001200 return false;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001201}
1202// Print details of DS config to stdout
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001203static void printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001204{
1205 char tmp_str[1024];
1206 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.
1207 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis93f89e82015-06-09 08:39:32 -06001208 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001209 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001210 POOL_NODE* pPool = getPoolNode(pSet->pool);
1211 // Print out pool details
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001212 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1213 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001214 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001215 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001216 "%s", poolStr.c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001217 // Print out set details
1218 char prefix[10];
1219 uint32_t index = 0;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001220 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1221 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001222 LAYOUT_NODE* pLayout = pSet->pLayout;
1223 // Print layout details
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001224 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1225 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001226 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001227 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001228 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001229 "%s", DSLstr.c_str());
Tobin Ehlis793ad302015-04-03 12:01:11 -06001230 index++;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001231 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1232 if (pUpdate) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001233 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1234 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001235 sprintf(prefix, " [UC] ");
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001236 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001237 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001238 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisce132d82015-06-19 15:07:05 -06001239 } else {
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001240 if (0 != pSet->descriptorCount) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001241 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1242 "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 -06001243 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001244 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
1245 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisbf081f32015-06-15 08:41:17 -06001246 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001247 }
1248 }
1249}
1250
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001251static void printCB(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001252{
1253 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedod8f83d82015-04-27 16:36:17 -06001254 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001255 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001256 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchterba348a92015-04-27 11:16:35 -06001257 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001258 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1259 // TODO : Need to pass cb as srcObj here
1260 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 -06001261 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001262 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06001263 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001264 // Nothing to print
1265 }
1266}
1267
1268
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001269static void synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001270{
Tobin Ehlis2717d132015-07-10 18:25:07 -06001271 // TODO : Re-enable these print funcs
1272// printDSConfig(cb);
1273// printPipeline(cb);
1274// printDynamicState(cb);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001275}
1276
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001277static void init_draw_state(layer_data *my_data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001278{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001279 uint32_t report_flags = 0;
1280 uint32_t debug_action = 0;
1281 FILE *log_output = NULL;
1282 const char *option_str;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001283 // initialize DrawState options
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001284 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1285 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001286
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001287 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001288 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001289 option_str = getLayerOption("DrawStateLogFilename");
1290 if (option_str)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001291 {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001292 log_output = fopen(option_str, "w");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001293 }
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001294 if (log_output == NULL)
1295 log_output = stdout;
1296
1297 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 -06001298 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001299
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001300 if (!globalLockInitialized)
1301 {
1302 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001303 // suggestion is to call this during vkCreateInstance(), and then we
1304 // can clean it up during vkDestroyInstance(). However, that requires
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001305 // that the layer have per-instance locks. We need to come back and
1306 // address this soon.
1307 loader_platform_thread_create_mutex(&globalLock);
1308 globalLockInitialized = 1;
1309 }
1310}
1311
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001312VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1313{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001314 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001315 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1316
1317 if (result == VK_SUCCESS) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001318 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1319 my_data->report_data = debug_report_create_instance(
1320 pTable,
1321 *pInstance,
1322 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001323 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001324
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001325 init_draw_state(my_data);
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06001326 }
1327 return result;
1328}
1329
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001330/* hook DestroyInstance to remove tableInstanceMap entry */
1331VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1332{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001333 dispatch_key key = get_dispatch_key(instance);
1334 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
1335 VkResult res = pTable->DestroyInstance(instance);
1336
1337 // Clean up logging callback, if any
1338 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1339 if (my_data->logging_callback) {
1340 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1341 }
1342
Courtney Goeltzenleuchteree4027d2015-06-28 13:01:17 -06001343 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001344 layer_data_map.erase(pTable);
1345
1346 draw_state_instance_table_map.erase(key);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001347 return res;
1348}
1349
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001350static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1351{
1352 uint32_t i, ext_idx;
Jon Ashburn747f2b62015-06-18 15:02:58 -06001353 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburneab34492015-06-01 09:37:38 -06001354 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001355
1356 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001357 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburneab34492015-06-01 09:37:38 -06001358 /* Found a matching extension name, mark it enabled and init dispatch table*/
1359 initDebugMarkerTable(device);
1360 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburne68a9ff2015-05-25 14:11:37 -06001361 }
1362
1363 }
1364}
1365
Tony Barbourd1c35722015-04-16 15:59:00 -06001366VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001367{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06001368 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1369 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001370 if (result == VK_SUCCESS) {
1371 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1372 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1373 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1374 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001375 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001376 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001377 return result;
1378}
1379
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001380VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001381{
1382 // Free all the memory
1383 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisecc6bd02015-04-08 10:58:37 -06001384 deletePipelines();
1385 deleteSamplers();
1386 deleteImages();
1387 deleteBuffers();
1388 deleteCmdBuffers();
1389 deleteDynamicState();
1390 deletePools();
1391 deleteLayouts();
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001392 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001393
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001394 dispatch_key key = get_dispatch_key(device);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001395 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
1396 VkResult result = pDisp->DestroyDevice(device);
1397 deviceExtMap.erase(pDisp);
Jeremy Hayes5d29ce32015-06-19 11:37:38 -06001398 draw_state_device_table_map.erase(key);
Jon Ashburneab34492015-06-01 09:37:38 -06001399 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001400 return result;
1401}
1402
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001403static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001404 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001405 "DrawState",
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001406 VK_API_VERSION,
1407 VK_MAKE_VERSION(0, 1, 0),
1408 "Validation layer: DrawState",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001409 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001410};
1411
Tony Barbour59a47322015-06-24 16:06:58 -06001412VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001413 const char *pLayerName,
1414 uint32_t *pCount,
1415 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001416{
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001417 /* DrawState does not have any global extensions */
1418 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1419}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001420
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001421VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1422 uint32_t *pCount,
1423 VkLayerProperties* pProperties)
1424{
1425 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1426 ds_global_layers,
1427 pCount, pProperties);
1428}
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001429
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06001430static const VkExtensionProperties ds_device_extensions[] = {
1431 {
1432 DEBUG_MARKER_EXTENSION_NAME,
1433 VK_MAKE_VERSION(0, 1, 0),
1434 VK_API_VERSION
1435 }
1436};
1437
1438static const VkLayerProperties ds_device_layers[] = {
1439 {
1440 "DrawState",
1441 VK_API_VERSION,
1442 VK_MAKE_VERSION(0, 1, 0),
1443 "Validation layer: DrawState",
1444 }
1445};
1446
1447VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
1448 VkPhysicalDevice physicalDevice,
1449 const char* pLayerName,
1450 uint32_t* pCount,
1451 VkExtensionProperties* pProperties)
1452{
1453 /* Mem tracker does not have any physical device extensions */
1454 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1455 pCount, pProperties);
1456}
1457
1458VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1459 VkPhysicalDevice physicalDevice,
1460 uint32_t* pCount,
1461 VkLayerProperties* pProperties)
1462{
1463 /* Mem tracker's physical device layers are the same as global */
1464 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1465 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001466}
1467
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001468VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001469{
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001470 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001471 for (uint32_t i=0; i < cmdBufferCount; i++) {
1472 // Validate that cmd buffers have been updated
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001473 pCB = getCBNode(pCmdBuffers[i]);
1474 loader_platform_thread_lock_mutex(&globalLock);
1475 if (CB_UPDATE_COMPLETE != pCB->state) {
1476 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001477 // TODO : How to pass cb as srcObj?
1478 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
1479 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<VkUintPtrLeast64>(pCB->cmdBuffer));
Tobin Ehlisc4bdde12015-05-27 14:30:06 -06001480 loader_platform_thread_unlock_mutex(&globalLock);
1481 return VK_ERROR_UNKNOWN;
Tobin Ehlisa9f3d762015-05-22 12:38:16 -06001482 }
Tobin Ehlisdea6ddf2015-05-26 16:06:50 -06001483 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001484 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001485
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001486 VkResult result = get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001487 return result;
1488}
1489
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001490VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001491{
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001492 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
1493 // TODO : Clean up any internal data structures using this obj.
1494 return result;
1495}
1496
1497VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1498{
1499 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
1500 // TODO : Clean up any internal data structures using this obj.
1501 return result;
1502}
1503
1504VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1505{
1506 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
1507 // TODO : Clean up any internal data structures using this obj.
1508 return result;
1509}
1510
1511VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1512{
1513 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
1514 // TODO : Clean up any internal data structures using this obj.
1515 return result;
1516}
1517
1518VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
1519{
1520 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
1521 // TODO : Clean up any internal data structures using this obj.
1522 return result;
1523}
1524
1525VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1526{
1527 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
1528 // TODO : Clean up any internal data structures using this obj.
1529 return result;
1530}
1531
1532VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
1533{
1534 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
1535 // TODO : Clean up any internal data structures using this obj.
1536 return result;
1537}
1538
1539VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1540{
1541 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
1542 // TODO : Clean up any internal data structures using this obj.
1543 return result;
1544}
1545
1546VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1547{
1548 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1549 // TODO : Clean up any internal data structures using this obj.
1550 return result;
1551}
1552
1553VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1554{
1555 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1556 // TODO : Clean up any internal data structures using this obj.
1557 return result;
1558}
1559
1560VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1561{
1562 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
1563 // TODO : Clean up any internal data structures using this obj.
1564 return result;
1565}
1566
1567VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1568{
1569 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
1570 // TODO : Clean up any internal data structures using this obj.
1571 return result;
1572}
1573
1574VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1575{
1576 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1577 // TODO : Clean up any internal data structures using this obj.
1578 return result;
1579}
1580
1581VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1582{
1583 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
1584 // TODO : Clean up any internal data structures using this obj.
1585 return result;
1586}
1587
1588VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1589{
1590 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1591 // TODO : Clean up any internal data structures using this obj.
1592 return result;
1593}
1594
1595VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1596{
1597 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1598 // TODO : Clean up any internal data structures using this obj.
1599 return result;
1600}
1601
1602VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1603{
1604 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1605 // TODO : Clean up any internal data structures using this obj.
1606 return result;
1607}
1608
1609VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1610{
1611 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1612 // TODO : Clean up any internal data structures using this obj.
1613 return result;
1614}
1615
1616VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1617{
1618 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1619 // TODO : Clean up any internal data structures using this obj.
1620 return result;
1621}
1622
1623VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1624{
1625 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1626 // TODO : Clean up any internal data structures using this obj.
1627 return result;
1628}
1629
1630VK_LAYER_EXPORT VkResult VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
1631{
1632 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
1633 // TODO : Clean up any internal data structures using this obj.
1634 return result;
1635}
1636
1637VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1638{
1639 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
1640 // TODO : Clean up any internal data structures using this obj.
1641 return result;
1642}
1643
1644VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1645{
1646 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
1647 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001648 return result;
1649}
1650
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001651VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001652{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001653 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001654 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001655 loader_platform_thread_lock_mutex(&globalLock);
1656 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1657 pNewNode->buffer = *pView;
1658 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001659 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001660 loader_platform_thread_unlock_mutex(&globalLock);
1661 }
1662 return result;
1663}
1664
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001665VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001666{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001667 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001668 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001669 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001670 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001671 loader_platform_thread_unlock_mutex(&globalLock);
1672 }
1673 return result;
1674}
1675
Tobin Ehlisffe35812015-07-10 12:15:19 -06001676VkResult VKAPI vkCreateAttachmentView(
1677 VkDevice device,
1678 const VkAttachmentViewCreateInfo* pCreateInfo,
1679 VkAttachmentView* pView)
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001680{
Tobin Ehlisffe35812015-07-10 12:15:19 -06001681 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06001682 if (VK_SUCCESS == result) {
1683 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001684 viewMap[pView->handle] = *pCreateInfo;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001685 loader_platform_thread_unlock_mutex(&globalLock);
1686 }
1687 return result;
1688}
1689
Jon Ashburnc669cc62015-07-09 15:02:25 -06001690//TODO handle pipeline caches
1691VkResult VKAPI vkCreatePipelineCache(
1692 VkDevice device,
1693 const VkPipelineCacheCreateInfo* pCreateInfo,
1694 VkPipelineCache* pPipelineCache)
1695{
1696 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1697 return result;
1698}
1699
1700VkResult VKAPI vkDestroyPipelineCache(
1701 VkDevice device,
1702 VkPipelineCache pipelineCache)
1703{
1704 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
1705 return result;
1706}
1707
1708size_t VKAPI vkGetPipelineCacheSize(
1709 VkDevice device,
1710 VkPipelineCache pipelineCache)
1711{
1712 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1713 return size;
1714}
1715
1716VkResult VKAPI vkGetPipelineCacheData(
1717 VkDevice device,
1718 VkPipelineCache pipelineCache,
1719 void* pData)
1720{
1721 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1722 return result;
1723}
1724
1725VkResult VKAPI vkMergePipelineCaches(
1726 VkDevice device,
1727 VkPipelineCache destCache,
1728 uint32_t srcCacheCount,
1729 const VkPipelineCache* pSrcCaches)
1730{
1731 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1732 return result;
1733}
1734
1735VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001736{
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001737 VkResult result = VK_ERROR_BAD_PIPELINE_DATA;
Jon Ashburnc669cc62015-07-09 15:02:25 -06001738 //TODO handle count > 1 and handle pipelineCache
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001739 // The order of operations here is a little convoluted but gets the job done
1740 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1741 // 2. Create state is then validated (which uses flags setup during shadowing)
1742 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
1743 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001744 PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001745 VkBool32 valid = verifyPipelineCreateState(device, pPipeNode);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001746 loader_platform_thread_unlock_mutex(&globalLock);
1747 if (VK_TRUE == valid) {
Jon Ashburnc669cc62015-07-09 15:02:25 -06001748 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001749 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
1750 "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001751 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001752 pPipeNode->pipeline = *pPipelines;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001753 pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001754 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001755 } else {
Tobin Ehlis75283bf2015-06-18 15:59:33 -06001756 if (pPipeNode) {
1757 // If we allocated a pipeNode, need to clean it up here
1758 delete[] pPipeNode->pVertexBindingDescriptions;
1759 delete[] pPipeNode->pVertexAttributeDescriptions;
1760 delete[] pPipeNode->pAttachments;
1761 delete pPipeNode;
1762 }
1763 }
Courtney Goeltzenleuchtere2aaad02015-04-13 16:16:04 -06001764 return result;
1765}
1766
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001767VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001768{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001769 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001770 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001771 loader_platform_thread_lock_mutex(&globalLock);
1772 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1773 pNewNode->sampler = *pSampler;
1774 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001775 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001776 loader_platform_thread_unlock_mutex(&globalLock);
1777 }
1778 return result;
1779}
1780
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001781VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001782{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001783 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001784 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001785 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1786 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001787 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 -06001788 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001789 }
1790 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001791 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1792 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1793 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001794 uint32_t totalCount = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001795 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001796 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001797 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001798 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001799 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1800 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001801 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001802 }
1803 if (totalCount > 0) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001804 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001805 uint32_t offset = 0;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001806 uint32_t j = 0;
1807 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wu712bb5d2015-05-25 16:22:52 +08001808 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001809 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001810 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001811 offset += j;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001812 }
1813 }
1814 pNewNode->layout = *pSetLayout;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001815 pNewNode->startIndex = 0;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001816 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1817 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001818 // Put new node at Head of global Layer list
1819 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001820 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001821 loader_platform_thread_unlock_mutex(&globalLock);
1822 }
1823 return result;
1824}
1825
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001826VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001827{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001828 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001829 if (VK_SUCCESS == result) {
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05001830 // TODO : Need to capture the pipeline layout
Tobin Ehlis793ad302015-04-03 12:01:11 -06001831 }
1832 return result;
1833}
1834
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001835VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolUsage poolUsage, uint32_t maxSets, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001836{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001837 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, poolUsage, maxSets, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001838 if (VK_SUCCESS == result) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001839 // Insert this pool into Global Pool LL at head
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001840 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1841 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001842 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001843 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001844 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001845 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 -06001846 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()");
Tobin Ehlisce132d82015-06-19 15:07:05 -06001847 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001848 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001849 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1850 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001851 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001852 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1853 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001854 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1855 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001856 pNewNode->poolUsage = poolUsage;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001857 pNewNode->maxSets = maxSets;
Tobin Ehlis793ad302015-04-03 12:01:11 -06001858 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001859 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001860 }
1861 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001862 } else {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001863 // Need to do anything if pool create fails?
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001864 }
1865 return result;
1866}
1867
Mike Stroyanb050c682015-04-17 12:36:38 -06001868VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001869{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001870 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001871 if (VK_SUCCESS == result) {
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001872 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001873 }
1874 return result;
1875}
1876
Mike Stroyanb050c682015-04-17 12:36:38 -06001877VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets, uint32_t* pCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001878{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001879 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets, pCount);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001880 if ((VK_SUCCESS == result) || (*pCount > 0)) {
Tobin Ehlis793ad302015-04-03 12:01:11 -06001881 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1882 if (!pPoolNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001883 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1884 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06001885 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001886 for (uint32_t i = 0; i < *pCount; i++) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001887 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1888 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlis793ad302015-04-03 12:01:11 -06001889 // Create new set node and add to head of pool nodes
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001890 SET_NODE* pNewNode = new SET_NODE;
1891 if (NULL == pNewNode) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001892 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 -06001893 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()");
Tobin Ehlisce132d82015-06-19 15:07:05 -06001894 } else {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001895 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlis793ad302015-04-03 12:01:11 -06001896 // Insert set at head of Set LL for this pool
1897 pNewNode->pNext = pPoolNode->pSets;
1898 pPoolNode->pSets = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001899 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1900 if (NULL == pLayout) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001901 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1902 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001903 }
Tobin Ehlis793ad302015-04-03 12:01:11 -06001904 pNewNode->pLayout = pLayout;
1905 pNewNode->pool = descriptorPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001906 pNewNode->set = pDescriptorSets[i];
1907 pNewNode->setUsage = setUsage;
1908 pNewNode->descriptorCount = pLayout->endIndex + 1;
1909 if (pNewNode->descriptorCount) {
1910 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1911 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1912 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1913 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001914 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001915 }
1916 }
1917 }
1918 }
1919 return result;
1920}
1921
Tony Barbour34ec6922015-07-10 10:50:45 -06001922VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1923{
1924 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1925 // TODO : Clean up any internal data structures using this obj.
1926 return result;
1927}
1928
Chia-I Wu9d00ed72015-05-25 16:27:55 +08001929VK_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 -06001930{
Tobin Ehlisa16e8922015-06-16 15:50:44 -06001931 if (dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1932 dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001933 return get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburn3950e1b2015-05-20 09:00:28 -06001934 }
1935 return VK_ERROR_UNKNOWN;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001936}
1937
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001938VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicViewportStateCreateInfo* pCreateInfo, VkDynamicViewportState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001939{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001940 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001941 VkDynamicViewportStateCreateInfo local_ci;
1942 memcpy(&local_ci, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
1943 local_ci.pViewports = new VkViewport[pCreateInfo->viewportAndScissorCount];
1944 local_ci.pScissors = new VkRect2D[pCreateInfo->viewportAndScissorCount];
1945 loader_platform_thread_lock_mutex(&globalLock);
1946 dynamicVpStateMap[pState->handle] = local_ci;
1947 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001948 return result;
1949}
1950
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001951VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRasterStateCreateInfo* pCreateInfo, VkDynamicRasterState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001952{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001953 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001954 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_RASTER);
1955 loader_platform_thread_lock_mutex(&globalLock);
1956 dynamicRsStateMap[pState->handle] = *pCreateInfo;
1957 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001958 return result;
1959}
1960
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001961VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicColorBlendStateCreateInfo* pCreateInfo, VkDynamicColorBlendState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001962{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001963 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001964 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_COLOR_BLEND);
1965 loader_platform_thread_lock_mutex(&globalLock);
1966 dynamicCbStateMap[pState->handle] = *pCreateInfo;
1967 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001968 return result;
1969}
1970
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001971VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDepthStencilStateCreateInfo* pCreateInfo, VkDynamicDepthStencilState* pState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001972{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001973 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06001974 //insertDynamicState(*pState, (GENERIC_HEADER*)pCreateInfo, VK_STATE_BIND_POINT_DEPTH_STENCIL);
1975 loader_platform_thread_lock_mutex(&globalLock);
1976 dynamicDsStateMap[pState->handle] = *pCreateInfo;
1977 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001978 return result;
1979}
1980
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001981VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001982{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06001983 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001984 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001985 loader_platform_thread_lock_mutex(&globalLock);
1986 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1987 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1988 pCB->cmdBuffer = *pCmdBuffer;
1989 pCB->flags = pCreateInfo->flags;
Cody Northrope62183e2015-07-09 18:08:05 -06001990 pCB->pool = pCreateInfo->cmdPool;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06001991 pCB->lastVtxBinding = MAX_BINDING;
1992 cmdBufferMap[*pCmdBuffer] = pCB;
1993 loader_platform_thread_unlock_mutex(&globalLock);
1994 updateCBTracking(*pCmdBuffer);
1995 }
1996 return result;
1997}
1998
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001999VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002000{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002001 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002002 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002003 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2004 if (pCB) {
2005 if (CB_NEW != pCB->state)
2006 resetCB(cmdBuffer);
2007 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlisce132d82015-06-19 15:07:05 -06002008 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002009 // TODO : Need to pass cmdBuffer as objType here
2010 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Tobin Ehlisa16e8922015-06-16 15:50:44 -06002011 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002012 }
2013 updateCBTracking(cmdBuffer);
2014 }
2015 return result;
2016}
2017
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002018VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002019{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002020 VkResult result = VK_ERROR_BUILDING_COMMAND_BUFFER;
2021 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2022 if (pCB) {
2023 if (pCB->state == CB_UPDATE_ACTIVE) {
2024 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
2025 if (VK_SUCCESS == result) {
2026 updateCBTracking(cmdBuffer);
2027 pCB->state = CB_UPDATE_COMPLETE;
2028 // Reset CB status flags
2029 pCB->status = 0;
2030 printCB(cmdBuffer);
2031 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002032 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002033 report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002034 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002035 }
2036 return result;
2037}
2038
Cody Northrope62183e2015-07-09 18:08:05 -06002039VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002040{
Cody Northrope62183e2015-07-09 18:08:05 -06002041 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002042 if (VK_SUCCESS == result) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002043 resetCB(cmdBuffer);
2044 updateCBTracking(cmdBuffer);
2045 }
2046 return result;
2047}
2048
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002049VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002050{
2051 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2052 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002053 if (pCB->state == CB_UPDATE_ACTIVE) {
2054 updateCBTracking(cmdBuffer);
2055 addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis6d58e6d2015-06-23 08:46:18 -06002056 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002057 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2058 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002059 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002060 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2061 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002062 } else {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002063 PIPELINE_NODE* pPN = getPipeline(pipeline);
2064 if (pPN) {
2065 pCB->lastBoundPipeline = pipeline;
2066 loader_platform_thread_lock_mutex(&globalLock);
2067 set_cb_pso_status(pCB, pPN);
2068 g_lastBoundPipeline = pPN;
2069 loader_platform_thread_unlock_mutex(&globalLock);
2070 validatePipelineState(pCB, pipelineBindPoint, pipeline);
2071 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
2072 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002073 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
2074 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002075 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002076 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002077 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002078 report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002079 }
2080 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002081}
2082
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002083VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicViewportState(VkCmdBuffer cmdBuffer, VkDynamicViewportState dynamicViewportState)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002084{
Tobin Ehlis9c536442015-06-19 13:00:59 -06002085 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2086 if (pCB) {
2087 if (pCB->state == CB_UPDATE_ACTIVE) {
2088 updateCBTracking(cmdBuffer);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002089 addCmd(pCB, CMD_BINDDYNAMICVIEWPORTSTATE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002090 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002091 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2092 "Incorrect call to vkCmdBindDynamicViewportState() without an active RenderPass.");
Tobin Ehlis502480b2015-06-24 15:53:07 -06002093 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002094 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002095 pCB->status |= CBSTATUS_VIEWPORT_BOUND;
2096 if (dynamicVpStateMap.find(dynamicViewportState.handle) == dynamicVpStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002097 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 -06002098 "Unable to find VkDynamicViewportState object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002099 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002100 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
2101 g_lastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002102 }
2103 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002104 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002105 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002106 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicViewportState()");
Tobin Ehlis9c536442015-06-19 13:00:59 -06002107 }
2108 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002109}
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002110VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicRasterState(VkCmdBuffer cmdBuffer, VkDynamicRasterState dynamicRasterState)
2111{
2112 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2113 if (pCB) {
2114 if (pCB->state == CB_UPDATE_ACTIVE) {
2115 updateCBTracking(cmdBuffer);
2116 addCmd(pCB, CMD_BINDDYNAMICRASTERSTATE);
2117 if (!pCB->activeRenderPass) {
2118 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2119 "Incorrect call to vkCmdBindDynamicRasterState() without an active RenderPass.");
2120 }
2121 loader_platform_thread_lock_mutex(&globalLock);
2122 pCB->status |= CBSTATUS_RASTER_BOUND;
2123 if (dynamicRsStateMap.find(dynamicRasterState.handle) == dynamicRsStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002124 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 -06002125 "Unable to find VkDynamicRasterState object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2126 } else {
2127 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2128 g_lastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2129 }
2130 loader_platform_thread_unlock_mutex(&globalLock);
2131 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2132 } else {
2133 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicRasterState()");
2134 }
2135 }
2136}
2137VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(VkCmdBuffer cmdBuffer, VkDynamicColorBlendState dynamicColorBlendState)
2138{
2139 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2140 if (pCB) {
2141 if (pCB->state == CB_UPDATE_ACTIVE) {
2142 updateCBTracking(cmdBuffer);
2143 addCmd(pCB, CMD_BINDDYNAMICCOLORBLENDSTATE);
2144 if (!pCB->activeRenderPass) {
2145 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2146 "Incorrect call to vkCmdBindDynamicColorBlendState() without an active RenderPass.");
2147 }
2148 loader_platform_thread_lock_mutex(&globalLock);
2149 pCB->status |= CBSTATUS_COLOR_BLEND_BOUND;
2150 if (dynamicCbStateMap.find(dynamicColorBlendState.handle) == dynamicCbStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002151 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 -06002152 "Unable to find VkDynamicColorBlendState object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2153 } else {
2154 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2155 g_lastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2156 }
2157 loader_platform_thread_unlock_mutex(&globalLock);
2158 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2159 } else {
2160 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicColorBlendState()");
2161 }
2162 }
2163}
2164VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(VkCmdBuffer cmdBuffer, VkDynamicDepthStencilState dynamicDepthStencilState)
2165{
2166 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2167 if (pCB) {
2168 if (pCB->state == CB_UPDATE_ACTIVE) {
2169 updateCBTracking(cmdBuffer);
2170 addCmd(pCB, CMD_BINDDYNAMICDEPTHSTENCILSTATE);
2171 if (!pCB->activeRenderPass) {
2172 log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2173 "Incorrect call to vkCmdBindDynamicDepthStencilState() without an active RenderPass.");
2174 }
2175 loader_platform_thread_lock_mutex(&globalLock);
2176 pCB->status |= CBSTATUS_DEPTH_STENCIL_BOUND;
2177 if (dynamicDsStateMap.find(dynamicDepthStencilState.handle) == dynamicDsStateMap.end()) {
Tony Barboura05dbaa2015-07-09 17:31:46 -06002178 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 -06002179 "Unable to find VkDynamicDepthStencilState object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2180 } else {
2181 pCB->lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2182 g_lastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2183 }
2184 loader_platform_thread_unlock_mutex(&globalLock);
2185 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
2186 } else {
2187 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicDepthStencilState()");
2188 }
2189 }
2190}
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06002191VK_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 -06002192{
2193 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2194 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002195 if (pCB->state == CB_UPDATE_ACTIVE) {
2196 updateCBTracking(cmdBuffer);
2197 addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002198 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002199 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2200 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002201 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002202 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 -06002203 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
2204 } else if (validateBoundPipeline(cmdBuffer)) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002205 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002206 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2207 if (pSet) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002208 loader_platform_thread_lock_mutex(&globalLock);
2209 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002210 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlis9c536442015-06-19 13:00:59 -06002211 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2212 g_lastBoundDescriptorSet = pDescriptorSets[i];
2213 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002214 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
2215 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis3e75b2a2015-06-24 17:27:33 -06002216 if (!pSet->pUpdateStructs)
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002217 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
2218 "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 -06002219 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002220 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
2221 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlis9c536442015-06-19 13:00:59 -06002222 }
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002223 }
Tobin Ehlis7ae7c6a2015-06-22 18:00:14 -06002224 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 -06002225 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002226 } else {
2227 report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002228 }
2229 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002230}
2231
Tony Barbourd1c35722015-04-16 15:59:00 -06002232VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002233{
2234 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2235 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002236 if (pCB->state == CB_UPDATE_ACTIVE) {
2237 updateCBTracking(cmdBuffer);
2238 addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002239 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002240 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 -06002241 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
2242 } else {
2243 // TODO : Can be more exact in tracking/validating details for Idx buffer, for now just make sure *something* was bound
2244 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
2245 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
2246 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002247 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002248 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2249 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002250 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002251}
2252
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002253VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2254 VkCmdBuffer cmdBuffer,
2255 uint32_t startBinding,
2256 uint32_t bindingCount,
2257 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06002258 const VkDeviceSize* pOffsets)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002259{
2260 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2261 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002262 if (pCB->state == CB_UPDATE_ACTIVE) {
2263 /* TODO: Need to track all the vertex buffers, not just last one */
2264 updateCBTracking(cmdBuffer);
2265 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002266 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002267 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 -06002268 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2269 } else {
2270 pCB->lastVtxBinding = startBinding + bindingCount -1;
2271 if (validateBoundPipeline(cmdBuffer)) {
2272 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
2273 }
Tobin Ehlis9c536442015-06-19 13:00:59 -06002274 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002275 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002276 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0174fed2015-05-28 12:10:17 -06002277 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002278 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002279}
2280
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002281VK_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 -06002282{
2283 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002284 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002285 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002286 if (pCB->state == CB_UPDATE_ACTIVE) {
2287 updateCBTracking(cmdBuffer);
2288 addCmd(pCB, CMD_DRAW);
2289 pCB->drawCount[DRAW]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002290 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002291 // TODO : Need to pass cmdBuffer as srcObj here
2292 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 -06002293 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
2294 synchAndPrintDSConfig(cmdBuffer);
2295 if (valid) {
2296 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
2297 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002298 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002299 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2300 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002301 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002302}
2303
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002304VK_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 -06002305{
2306 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002307 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002308 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002309 if (pCB->state == CB_UPDATE_ACTIVE) {
2310 updateCBTracking(cmdBuffer);
2311 addCmd(pCB, CMD_DRAWINDEXED);
2312 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002313 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002314 // TODO : Need to pass cmdBuffer as srcObj here
2315 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 -06002316 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
2317 synchAndPrintDSConfig(cmdBuffer);
2318 if (valid) {
2319 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
2320 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002321 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002322 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2323 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002324 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002325}
2326
Tony Barbourd1c35722015-04-16 15:59:00 -06002327VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002328{
2329 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002330 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002331 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002332 if (pCB->state == CB_UPDATE_ACTIVE) {
2333 updateCBTracking(cmdBuffer);
2334 addCmd(pCB, CMD_DRAWINDIRECT);
2335 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002336 valid = validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002337 // TODO : Need to pass cmdBuffer as srcObj here
2338 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 -06002339 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
2340 synchAndPrintDSConfig(cmdBuffer);
2341 if (valid) {
2342 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
2343 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002344 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002345 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2346 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002347 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002348}
2349
Tony Barbourd1c35722015-04-16 15:59:00 -06002350VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002351{
2352 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06002353 VkBool32 valid = VK_FALSE;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002354 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002355 if (pCB->state == CB_UPDATE_ACTIVE) {
2356 updateCBTracking(cmdBuffer);
2357 addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
2358 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis429b91d2015-06-22 17:20:50 -06002359 valid = validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002360 // TODO : Need to pass cmdBuffer as srcObj here
2361 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 -06002362 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
2363 synchAndPrintDSConfig(cmdBuffer);
2364 if (valid) {
2365 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
2366 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002367 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002368 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2369 }
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002370 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002371}
2372
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002373VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002374{
2375 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2376 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002377 if (pCB->state == CB_UPDATE_ACTIVE) {
2378 updateCBTracking(cmdBuffer);
2379 addCmd(pCB, CMD_DISPATCH);
2380 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002381 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002382 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2383 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002384 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002385}
2386
Tony Barbourd1c35722015-04-16 15:59:00 -06002387VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002388{
2389 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2390 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002391 if (pCB->state == CB_UPDATE_ACTIVE) {
2392 updateCBTracking(cmdBuffer);
2393 addCmd(pCB, CMD_DISPATCHINDIRECT);
2394 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002395 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002396 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2397 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002398 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002399}
2400
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002401VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002402{
2403 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2404 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002405 if (pCB->state == CB_UPDATE_ACTIVE) {
2406 updateCBTracking(cmdBuffer);
2407 addCmd(pCB, CMD_COPYBUFFER);
2408 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002409 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002410 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2411 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002412 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002413}
2414
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002415VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2416 VkImage srcImage,
2417 VkImageLayout srcImageLayout,
2418 VkImage destImage,
2419 VkImageLayout destImageLayout,
2420 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002421{
2422 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2423 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002424 if (pCB->state == CB_UPDATE_ACTIVE) {
2425 updateCBTracking(cmdBuffer);
2426 addCmd(pCB, CMD_COPYIMAGE);
2427 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002428 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002429 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2430 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002431 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002432}
2433
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002434VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2435 VkImage srcImage, VkImageLayout srcImageLayout,
2436 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002437 uint32_t regionCount, const VkImageBlit* pRegions,
2438 VkTexFilter filter)
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -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_BLITIMAGE);
Tobin Ehliseac83792015-06-23 10:41:13 -06002445 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002446 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2447 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehliseac83792015-06-23 10:41:13 -06002448 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06002449 else
2450 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002451 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002452 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2453 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002454 }
Courtney Goeltzenleuchter91f9cee2015-04-03 14:42:51 -06002455}
2456
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002457VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2458 VkBuffer srcBuffer,
2459 VkImage destImage, VkImageLayout destImageLayout,
2460 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002461{
2462 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2463 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002464 if (pCB->state == CB_UPDATE_ACTIVE) {
2465 updateCBTracking(cmdBuffer);
2466 addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
2467 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002468 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002469 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2470 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002471 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002472}
2473
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002474VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2475 VkImage srcImage, VkImageLayout srcImageLayout,
2476 VkBuffer destBuffer,
2477 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002478{
2479 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2480 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002481 if (pCB->state == CB_UPDATE_ACTIVE) {
2482 updateCBTracking(cmdBuffer);
2483 addCmd(pCB, CMD_COPYIMAGETOBUFFER);
2484 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002485 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002486 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2487 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002488 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002489}
2490
Tony Barbourd1c35722015-04-16 15:59:00 -06002491VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002492{
2493 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2494 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002495 if (pCB->state == CB_UPDATE_ACTIVE) {
2496 updateCBTracking(cmdBuffer);
2497 addCmd(pCB, CMD_UPDATEBUFFER);
2498 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002499 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002500 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2501 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002502 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002503}
2504
Tony Barbourd1c35722015-04-16 15:59:00 -06002505VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002506{
2507 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2508 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002509 if (pCB->state == CB_UPDATE_ACTIVE) {
2510 updateCBTracking(cmdBuffer);
2511 addCmd(pCB, CMD_FILLBUFFER);
2512 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002513 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002514 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2515 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002516 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002517}
2518
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002519VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2520 VkCmdBuffer cmdBuffer,
2521 uint32_t colorAttachment,
2522 VkImageLayout imageLayout,
2523 const VkClearColorValue* pColor,
2524 uint32_t rectCount,
2525 const VkRect3D* pRects)
2526{
2527 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2528 if (pCB) {
2529 if (pCB->state == CB_UPDATE_ACTIVE) {
2530 // Warn if this is issued prior to Draw Cmd
2531 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002532 // TODO : cmdBuffer should be srcObj
2533 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 -06002534 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2535 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2536 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002537 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002538 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 -06002539 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2540 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2541 } else {
2542 updateCBTracking(cmdBuffer);
2543 addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
2544 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
2545 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002546 } else {
2547 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2548 }
2549 }
2550}
2551
2552VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2553 VkCmdBuffer cmdBuffer,
2554 VkImageAspectFlags imageAspectMask,
2555 VkImageLayout imageLayout,
2556 float depth,
2557 uint32_t stencil,
2558 uint32_t rectCount,
2559 const VkRect3D* pRects)
2560{
2561 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2562 if (pCB) {
2563 if (pCB->state == CB_UPDATE_ACTIVE) {
2564 // Warn if this is issued prior to Draw Cmd
2565 if (!hasDrawCmd(pCB)) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002566 // TODO : cmdBuffer should be srcObj
2567 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 -06002568 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
2569 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<VkUintPtrLeast64>(cmdBuffer));
2570 }
Tobin Ehlise2473152015-06-23 11:34:28 -06002571 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002572 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 -06002573 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2574 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2575 } else {
2576 updateCBTracking(cmdBuffer);
2577 addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
2578 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, depth, stencil, rectCount, pRects);
2579 }
Tobin Ehlis53eddda2015-07-01 16:46:13 -06002580 } else {
2581 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2582 }
2583 }
2584}
2585
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002586VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2587 VkCmdBuffer cmdBuffer,
2588 VkImage image, VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12002589 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06002590 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002591{
2592 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2593 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002594 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002595 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002596 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 -06002597 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2598 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2599 } else {
2600 updateCBTracking(cmdBuffer);
2601 addCmd(pCB, CMD_CLEARCOLORIMAGE);
2602 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
2603 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002604 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002605 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2606 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002607 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002608}
2609
Chris Forbesd9be82b2015-06-22 17:21:59 +12002610VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002611 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002612 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002613 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002614{
2615 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2616 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002617 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise2473152015-06-23 11:34:28 -06002618 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002619 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 -06002620 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2621 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2622 } else {
2623 updateCBTracking(cmdBuffer);
2624 addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
2625 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
2626 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002627 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002628 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2629 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002630 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002631}
2632
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002633VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2634 VkImage srcImage, VkImageLayout srcImageLayout,
2635 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06002636 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002637{
2638 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2639 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002640 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002641 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002642 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2643 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlise2473152015-06-23 11:34:28 -06002644 } else {
2645 updateCBTracking(cmdBuffer);
2646 addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002647 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlise2473152015-06-23 11:34:28 -06002648 }
Tobin Ehlisce132d82015-06-19 15:07:05 -06002649 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002650 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2651 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002652 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002653}
2654
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002655VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002656{
2657 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2658 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002659 if (pCB->state == CB_UPDATE_ACTIVE) {
2660 updateCBTracking(cmdBuffer);
2661 addCmd(pCB, CMD_SETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002662 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002663 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002664 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2665 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002666 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002667}
2668
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002669VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002670{
2671 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2672 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002673 if (pCB->state == CB_UPDATE_ACTIVE) {
2674 updateCBTracking(cmdBuffer);
2675 addCmd(pCB, CMD_RESETEVENT);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002676 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002677 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002678 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2679 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002680 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002681}
2682
Courtney Goeltzenleuchterdbd20322015-07-12 12:58:58 -06002683VK_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 -06002684{
2685 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2686 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002687 if (pCB->state == CB_UPDATE_ACTIVE) {
2688 updateCBTracking(cmdBuffer);
2689 addCmd(pCB, CMD_WAITEVENTS);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002690 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002691 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002692 report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
2693 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002694 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002695}
2696
Courtney Goeltzenleuchterceebbb12015-07-12 13:07:46 -06002697VK_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 -06002698{
2699 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2700 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002701 if (pCB->state == CB_UPDATE_ACTIVE) {
2702 updateCBTracking(cmdBuffer);
2703 addCmd(pCB, CMD_PIPELINEBARRIER);
Tony Barbour0b2cfb22015-06-29 16:20:35 -06002704 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, sourceStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002705 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002706 report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
2707 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002708 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002709}
2710
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002711VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002712{
2713 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2714 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002715 if (pCB->state == CB_UPDATE_ACTIVE) {
2716 updateCBTracking(cmdBuffer);
2717 addCmd(pCB, CMD_BEGINQUERY);
2718 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002719 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002720 report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
2721 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002722 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002723}
2724
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002725VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002726{
2727 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2728 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002729 if (pCB->state == CB_UPDATE_ACTIVE) {
2730 updateCBTracking(cmdBuffer);
2731 addCmd(pCB, CMD_ENDQUERY);
2732 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002733 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002734 report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
2735 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002736 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002737}
2738
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002739VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002740{
2741 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2742 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002743 if (pCB->state == CB_UPDATE_ACTIVE) {
2744 updateCBTracking(cmdBuffer);
2745 addCmd(pCB, CMD_RESETQUERYPOOL);
2746 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002747 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002748 report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
2749 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002750 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002751}
2752
Tony Barbourd1c35722015-04-16 15:59:00 -06002753VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002754{
2755 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2756 if (pCB) {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002757 if (pCB->state == CB_UPDATE_ACTIVE) {
2758 updateCBTracking(cmdBuffer);
2759 addCmd(pCB, CMD_WRITETIMESTAMP);
2760 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlisce132d82015-06-19 15:07:05 -06002761 } else {
Tobin Ehlis9c536442015-06-19 13:00:59 -06002762 report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
2763 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002764 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002765}
2766
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002767VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002768{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002769 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002770 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002771 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002772 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002773 if (pCreateInfo->pAttachments) {
2774 localFBCI->pAttachments = new VkAttachmentBindInfo[localFBCI->attachmentCount];
2775 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkAttachmentBindInfo));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002776 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002777 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002778 }
2779 return result;
2780}
2781
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002782VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehliseba312c2015-04-01 08:40:34 -06002783{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002784 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002785 if (VK_SUCCESS == result) {
Tobin Ehliseba312c2015-04-01 08:40:34 -06002786 // Shadow create info and store in map
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002787 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wu08accc62015-07-07 11:50:03 +08002788 if (pCreateInfo->pAttachments) {
2789 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2790 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002791 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002792 if (pCreateInfo->pSubpasses) {
2793 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2794 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2795
2796 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2797 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2798 const uint32_t attachmentCount = subpass->inputCount +
2799 subpass->colorCount * (1 + (bool) subpass->resolveAttachments) +
2800 subpass->preserveCount;
2801 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2802
2803 memcpy(attachments, subpass->inputAttachments,
2804 sizeof(attachments[0]) * subpass->inputCount);
2805 subpass->inputAttachments = attachments;
2806 attachments += subpass->inputCount;
2807
2808 memcpy(attachments, subpass->colorAttachments,
2809 sizeof(attachments[0]) * subpass->colorCount);
2810 subpass->colorAttachments = attachments;
2811 attachments += subpass->colorCount;
2812
2813 if (subpass->resolveAttachments) {
2814 memcpy(attachments, subpass->resolveAttachments,
2815 sizeof(attachments[0]) * subpass->colorCount);
2816 subpass->resolveAttachments = attachments;
2817 attachments += subpass->colorCount;
2818 }
2819
2820 memcpy(attachments, subpass->preserveAttachments,
2821 sizeof(attachments[0]) * subpass->preserveCount);
2822 subpass->preserveAttachments = attachments;
2823 }
Tobin Ehliseba312c2015-04-01 08:40:34 -06002824 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002825 if (pCreateInfo->pDependencies) {
2826 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2827 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehliseba312c2015-04-01 08:40:34 -06002828 }
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002829 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehliseba312c2015-04-01 08:40:34 -06002830 }
2831 return result;
2832}
2833
Chia-I Wu08accc62015-07-07 11:50:03 +08002834VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002835{
2836 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2837 if (pCB) {
Tobin Ehlis259730a2015-06-23 16:13:03 -06002838 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlis502480b2015-06-24 15:53:07 -06002839 if (pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002840 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2841 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlis502480b2015-06-24 15:53:07 -06002842 } else {
2843 updateCBTracking(cmdBuffer);
2844 addCmd(pCB, CMD_BEGINRENDERPASS);
2845 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08002846 pCB->activeSubpass = 0;
Tobin Ehlis502480b2015-06-24 15:53:07 -06002847 pCB->framebuffer = pRenderPassBegin->framebuffer;
2848 if (pCB->lastBoundPipeline) {
2849 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2850 }
Chia-I Wu08accc62015-07-07 11:50:03 +08002851 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis259730a2015-06-23 16:13:03 -06002852 }
Tobin Ehlis502480b2015-06-24 15:53:07 -06002853 } else {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002854 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis259730a2015-06-23 16:13:03 -06002855 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourbadda992015-04-06 11:09:26 -06002856 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002857 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002858}
2859
Chia-I Wu08accc62015-07-07 11:50:03 +08002860VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2861{
2862 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2863 if (pCB) {
2864 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002865 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 +08002866 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2867 } else {
2868 updateCBTracking(cmdBuffer);
2869 addCmd(pCB, CMD_NEXTSUBPASS);
2870 pCB->activeSubpass++;
2871 if (pCB->lastBoundPipeline) {
2872 validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
2873 }
2874 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
2875 }
2876 }
2877}
2878
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002879VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002880{
2881 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2882 if (pCB) {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002883 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002884 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 +08002885 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis59a9c832015-06-23 16:13:03 -06002886 } else {
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002887 updateCBTracking(cmdBuffer);
2888 addCmd(pCB, CMD_ENDRENDERPASS);
2889 pCB->activeRenderPass = 0;
Chia-I Wu08accc62015-07-07 11:50:03 +08002890 pCB->activeSubpass = 0;
Chia-I Wu0b50a1c2015-06-26 15:34:39 +08002891 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
2892 }
2893 }
2894}
2895
2896VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
2897{
2898 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2899 if (pCB) {
2900 if (!pCB->activeRenderPass) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002901 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 +08002902 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
2903 } else {
2904 updateCBTracking(cmdBuffer);
2905 addCmd(pCB, CMD_EXECUTECOMMANDS);
2906 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis259730a2015-06-23 16:13:03 -06002907 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002908 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002909}
2910
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002911VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2912 VkInstance instance,
2913 VkFlags msgFlags,
2914 const PFN_vkDbgMsgCallback pfnMsgCallback,
2915 void* pUserData,
2916 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002917{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002918 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002919 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2920 if (VK_SUCCESS == res) {
2921 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2922 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2923 }
2924 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002925}
2926
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002927VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2928 VkInstance instance,
2929 VkDbgMsgCallback msgCallback)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002930{
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002931 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc16c3e92015-06-16 09:04:30 -06002932 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2933 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2934 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2935 return res;
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002936}
2937
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002938VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002939{
2940 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002941 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2942 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002943 // TODO : cmdBuffer should be srcObj
2944 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 -06002945 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002946 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06002947 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002948 updateCBTracking(cmdBuffer);
2949 addCmd(pCB, CMD_DBGMARKERBEGIN);
2950 }
Jon Ashburneab34492015-06-01 09:37:38 -06002951 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002952}
2953
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002954VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002955{
2956 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburneab34492015-06-01 09:37:38 -06002957 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
2958 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002959 // TODO : cmdBuffer should be srcObj
2960 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 -06002961 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburneab34492015-06-01 09:37:38 -06002962 return;
Tobin Ehlisce132d82015-06-19 15:07:05 -06002963 } else if (pCB) {
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002964 updateCBTracking(cmdBuffer);
2965 addCmd(pCB, CMD_DBGMARKEREND);
2966 }
Jon Ashburneab34492015-06-01 09:37:38 -06002967 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
2968}
2969
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06002970//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
2971//{
2972// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2973// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2974// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2975// "Attempt to use DbgSetObjectTag but extension disabled!");
2976// return VK_ERROR_UNAVAILABLE;
2977// }
2978// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
2979//}
2980//
2981//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
2982//{
2983// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
2984// if (!deviceExtMap[pDisp].debug_marker_enabled) {
2985// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
2986// "Attempt to use DbgSetObjectName but extension disabled!");
2987// return VK_ERROR_UNAVAILABLE;
2988// }
2989// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
2990//}
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002991
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002992VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002993{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002994 if (dev == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06002995 return NULL;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06002996
Jon Ashburn8fd08252015-05-28 16:25:02 -06002997 /* loader uses this to force layer initialization; device object is wrapped */
2998 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06002999 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06003000 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003001 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06003002 if (!strcmp(funcName, "vkCreateDevice"))
3003 return (void*) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003004 if (!strcmp(funcName, "vkDestroyDevice"))
3005 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003006 if (!strcmp(funcName, "vkQueueSubmit"))
3007 return (void*) vkQueueSubmit;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003008 if (!strcmp(funcName, "vkDestroyInstance"))
3009 return (void*) vkDestroyInstance;
3010 if (!strcmp(funcName, "vkDestroyDevice"))
3011 return (void*) vkDestroyDevice;
3012 if (!strcmp(funcName, "vkDestroyFence"))
3013 return (void*) vkDestroyFence;
3014 if (!strcmp(funcName, "vkDestroySemaphore"))
3015 return (void*) vkDestroySemaphore;
3016 if (!strcmp(funcName, "vkDestroyEvent"))
3017 return (void*) vkDestroyEvent;
3018 if (!strcmp(funcName, "vkDestroyQueryPool"))
3019 return (void*) vkDestroyQueryPool;
3020 if (!strcmp(funcName, "vkDestroyBuffer"))
3021 return (void*) vkDestroyBuffer;
3022 if (!strcmp(funcName, "vkDestroyBufferView"))
3023 return (void*) vkDestroyBufferView;
3024 if (!strcmp(funcName, "vkDestroyImage"))
3025 return (void*) vkDestroyImage;
3026 if (!strcmp(funcName, "vkDestroyImageView"))
3027 return (void*) vkDestroyImageView;
3028 if (!strcmp(funcName, "vkDestroyAttachmentView"))
3029 return (void*) vkDestroyAttachmentView;
3030 if (!strcmp(funcName, "vkDestroyShaderModule"))
3031 return (void*) vkDestroyShaderModule;
3032 if (!strcmp(funcName, "vkDestroyShader"))
3033 return (void*) vkDestroyShader;
3034 if (!strcmp(funcName, "vkDestroyPipeline"))
3035 return (void*) vkDestroyPipeline;
3036 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
3037 return (void*) vkDestroyPipelineLayout;
3038 if (!strcmp(funcName, "vkDestroySampler"))
3039 return (void*) vkDestroySampler;
3040 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
3041 return (void*) vkDestroyDescriptorSetLayout;
3042 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
3043 return (void*) vkDestroyDescriptorPool;
3044 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
3045 return (void*) vkDestroyDynamicViewportState;
3046 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
3047 return (void*) vkDestroyDynamicRasterState;
3048 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
3049 return (void*) vkDestroyDynamicColorBlendState;
3050 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
3051 return (void*) vkDestroyDynamicDepthStencilState;
3052 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
3053 return (void*) vkDestroyCommandBuffer;
3054 if (!strcmp(funcName, "vkDestroyFramebuffer"))
3055 return (void*) vkDestroyFramebuffer;
3056 if (!strcmp(funcName, "vkDestroyRenderPass"))
3057 return (void*) vkDestroyRenderPass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003058 if (!strcmp(funcName, "vkCreateBufferView"))
3059 return (void*) vkCreateBufferView;
3060 if (!strcmp(funcName, "vkCreateImageView"))
3061 return (void*) vkCreateImageView;
Tobin Ehlisffe35812015-07-10 12:15:19 -06003062 if (!strcmp(funcName, "vkCreateAttachmentView"))
3063 return (void*) vkCreateAttachmentView;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003064 if (!strcmp(funcName, "CreatePipelineCache"))
3065 return (void*) vkCreatePipelineCache;
3066 if (!strcmp(funcName, "DestroyPipelineCache"))
3067 return (void*) vkDestroyPipelineCache;
3068 if (!strcmp(funcName, "GetPipelineCacheSize"))
3069 return (void*) vkGetPipelineCacheSize;
3070 if (!strcmp(funcName, "GetPipelineCacheData"))
3071 return (void*) vkGetPipelineCacheData;
3072 if (!strcmp(funcName, "MergePipelineCaches"))
3073 return (void*) vkMergePipelineCaches;
3074 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
3075 return (void*) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003076 if (!strcmp(funcName, "vkCreateSampler"))
3077 return (void*) vkCreateSampler;
3078 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
3079 return (void*) vkCreateDescriptorSetLayout;
Mark Lobodzinski0fadf5f2015-04-17 14:11:39 -05003080 if (!strcmp(funcName, "vkCreatePipelineLayout"))
3081 return (void*) vkCreatePipelineLayout;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003082 if (!strcmp(funcName, "vkCreateDescriptorPool"))
3083 return (void*) vkCreateDescriptorPool;
3084 if (!strcmp(funcName, "vkResetDescriptorPool"))
3085 return (void*) vkResetDescriptorPool;
3086 if (!strcmp(funcName, "vkAllocDescriptorSets"))
3087 return (void*) vkAllocDescriptorSets;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08003088 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
3089 return (void*) vkUpdateDescriptorSets;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003090 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
3091 return (void*) vkCreateDynamicViewportState;
3092 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
3093 return (void*) vkCreateDynamicRasterState;
3094 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
3095 return (void*) vkCreateDynamicColorBlendState;
3096 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
3097 return (void*) vkCreateDynamicDepthStencilState;
3098 if (!strcmp(funcName, "vkCreateCommandBuffer"))
3099 return (void*) vkCreateCommandBuffer;
3100 if (!strcmp(funcName, "vkBeginCommandBuffer"))
3101 return (void*) vkBeginCommandBuffer;
3102 if (!strcmp(funcName, "vkEndCommandBuffer"))
3103 return (void*) vkEndCommandBuffer;
3104 if (!strcmp(funcName, "vkResetCommandBuffer"))
3105 return (void*) vkResetCommandBuffer;
3106 if (!strcmp(funcName, "vkCmdBindPipeline"))
3107 return (void*) vkCmdBindPipeline;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003108 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
3109 return (void*) vkCmdBindDynamicViewportState;
3110 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
3111 return (void*) vkCmdBindDynamicRasterState;
3112 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
3113 return (void*) vkCmdBindDynamicColorBlendState;
3114 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
3115 return (void*) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003116 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
3117 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06003118 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
3119 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003120 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
3121 return (void*) vkCmdBindIndexBuffer;
3122 if (!strcmp(funcName, "vkCmdDraw"))
3123 return (void*) vkCmdDraw;
3124 if (!strcmp(funcName, "vkCmdDrawIndexed"))
3125 return (void*) vkCmdDrawIndexed;
3126 if (!strcmp(funcName, "vkCmdDrawIndirect"))
3127 return (void*) vkCmdDrawIndirect;
3128 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
3129 return (void*) vkCmdDrawIndexedIndirect;
3130 if (!strcmp(funcName, "vkCmdDispatch"))
3131 return (void*) vkCmdDispatch;
3132 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
3133 return (void*) vkCmdDispatchIndirect;
3134 if (!strcmp(funcName, "vkCmdCopyBuffer"))
3135 return (void*) vkCmdCopyBuffer;
3136 if (!strcmp(funcName, "vkCmdCopyImage"))
3137 return (void*) vkCmdCopyImage;
3138 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
3139 return (void*) vkCmdCopyBufferToImage;
3140 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
3141 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003142 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
3143 return (void*) vkCmdUpdateBuffer;
3144 if (!strcmp(funcName, "vkCmdFillBuffer"))
3145 return (void*) vkCmdFillBuffer;
3146 if (!strcmp(funcName, "vkCmdClearColorImage"))
3147 return (void*) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12003148 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
3149 return (void*) vkCmdClearDepthStencilImage;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06003150 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
3151 return (void*) vkCmdClearColorAttachment;
3152 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
3153 return (void*) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003154 if (!strcmp(funcName, "vkCmdResolveImage"))
3155 return (void*) vkCmdResolveImage;
3156 if (!strcmp(funcName, "vkCmdSetEvent"))
3157 return (void*) vkCmdSetEvent;
3158 if (!strcmp(funcName, "vkCmdResetEvent"))
3159 return (void*) vkCmdResetEvent;
3160 if (!strcmp(funcName, "vkCmdWaitEvents"))
3161 return (void*) vkCmdWaitEvents;
3162 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
3163 return (void*) vkCmdPipelineBarrier;
3164 if (!strcmp(funcName, "vkCmdBeginQuery"))
3165 return (void*) vkCmdBeginQuery;
3166 if (!strcmp(funcName, "vkCmdEndQuery"))
3167 return (void*) vkCmdEndQuery;
3168 if (!strcmp(funcName, "vkCmdResetQueryPool"))
3169 return (void*) vkCmdResetQueryPool;
3170 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
3171 return (void*) vkCmdWriteTimestamp;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003172 if (!strcmp(funcName, "vkCreateFramebuffer"))
3173 return (void*) vkCreateFramebuffer;
3174 if (!strcmp(funcName, "vkCreateRenderPass"))
3175 return (void*) vkCreateRenderPass;
3176 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
3177 return (void*) vkCmdBeginRenderPass;
Chia-I Wu08accc62015-07-07 11:50:03 +08003178 if (!strcmp(funcName, "vkCmdNextSubpass"))
3179 return (void*) vkCmdNextSubpass;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003180 if (!strcmp(funcName, "vkCmdEndRenderPass"))
3181 return (void*) vkCmdEndRenderPass;
Jon Ashburneab34492015-06-01 09:37:38 -06003182
Jon Ashburn747f2b62015-06-18 15:02:58 -06003183 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3184 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn8fd08252015-05-28 16:25:02 -06003185 {
Jon Ashburn747f2b62015-06-18 15:02:58 -06003186 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Jon Ashburneab34492015-06-01 09:37:38 -06003187 return (void*) vkCmdDbgMarkerBegin;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003188 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Jon Ashburneab34492015-06-01 09:37:38 -06003189 return (void*) vkCmdDbgMarkerEnd;
Tobin Ehlis60a9b4f2015-07-07 10:42:20 -06003190// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3191// return (void*) vkDbgSetObjectTag;
3192// if (!strcmp(funcName, "vkDbgSetObjectName"))
3193// return (void*) vkDbgSetObjectName;
Jon Ashburneab34492015-06-01 09:37:38 -06003194 }
3195 {
Jon Ashburn8fd08252015-05-28 16:25:02 -06003196 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003197 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003198 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003199 }
3200}
3201
3202VK_LAYER_EXPORT void * VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
3203{
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003204 void *fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003205 if (instance == NULL)
3206 return NULL;
3207
Jon Ashburn8fd08252015-05-28 16:25:02 -06003208 /* loader uses this to force layer initialization; instance object is wrapped */
3209 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003210 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003211 return (void *) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003212 }
Courtney Goeltzenleuchterabc035e2015-06-01 14:29:58 -06003213 if (!strcmp(funcName, "vkCreateInstance"))
3214 return (void *) vkCreateInstance;
Jon Ashburn3950e1b2015-05-20 09:00:28 -06003215 if (!strcmp(funcName, "vkDestroyInstance"))
3216 return (void *) vkDestroyInstance;
Courtney Goeltzenleuchter7ad58c02015-07-06 22:31:52 -06003217 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
3218 return (void*) vkGetGlobalLayerProperties;
3219 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
3220 return (void*) vkGetGlobalExtensionProperties;
3221 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
3222 return (void*) vkGetPhysicalDeviceLayerProperties;
Tony Barbour59a47322015-06-24 16:06:58 -06003223 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
3224 return (void*) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003225
Tobin Ehlisa16e8922015-06-16 15:50:44 -06003226 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3227 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchteree562872015-06-01 14:33:14 -06003228 if (fptr)
3229 return fptr;
3230
Jon Ashburn8fd08252015-05-28 16:25:02 -06003231 {
Courtney Goeltzenleuchter3d0dfad2015-06-13 21:23:09 -06003232 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn8fd08252015-05-28 16:25:02 -06003233 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003234 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003235 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003236 }
Tobin Ehlis10ae8c12015-03-17 16:24:32 -06003237}