blob: 10fa70cd91e66220fd9099a3252a9632bd38a93f [file] [log] [blame]
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29
Tobin Ehlis7a51d902015-07-03 10:34:49 -060030#include "vk_loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
Tony Barboura938abb2015-04-22 11:36:22 -060033#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060034#pragma GCC diagnostic ignored "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060035#endif
Tony Barboura938abb2015-04-22 11:36:22 -060036#if defined(__GNUC__)
Tobin Ehlis63bb9482015-03-17 16:24:32 -060037#pragma GCC diagnostic warning "-Wwrite-strings"
Tony Barboura938abb2015-04-22 11:36:22 -060038#endif
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039#include "vk_struct_size_helper.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060040#include "draw_state.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060041#include "vk_layer_config.h"
Jon Ashburnf0615e22015-05-25 14:11:37 -060042#include "vk_debug_marker_layer.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060043// The following is #included again to catch certain OS-specific functions
44// being used:
Tobin Ehlis7a51d902015-07-03 10:34:49 -060045#include "vk_loader_platform.h"
Tobin Ehlis56d204a2015-07-03 10:15:26 -060046#include "vk_layer_msg.h"
47#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -060051#include "vk_layer_extension_utils.h"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060052
Tobin Ehlisc91330b2015-06-16 09:04:30 -060053typedef struct _layer_data {
54 debug_report_data *report_data;
55 // TODO: put instance data here
56 VkDbgMsgCallback logging_callback;
57} layer_data;
58
59static std::unordered_map<void *, layer_data *> layer_data_map;
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -060060static device_table_map draw_state_device_table_map;
61static instance_table_map draw_state_instance_table_map;
62
Mike Stroyan74b430c2015-09-11 13:29:21 -060063static unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
64static unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
65static unordered_map<uint64_t, VkImageViewCreateInfo> viewMap;
66static unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
Mike Stroyan74b430c2015-09-11 13:29:21 -060067static unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
68static unordered_map<uint64_t, POOL_NODE*> poolMap;
69static unordered_map<uint64_t, SET_NODE*> setMap;
70static unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060071// Map for layout chains
Mike Stroyan74b430c2015-09-11 13:29:21 -060072static unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
73static unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
74static unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060075
Jon Ashburn6f8cd632015-06-01 09:37:38 -060076struct devExts {
77 bool debug_marker_enabled;
78};
79
Jon Ashburn6f8cd632015-06-01 09:37:38 -060080static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060081
Tobin Ehlis63bb9482015-03-17 16:24:32 -060082static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060083
Tobin Ehlis63bb9482015-03-17 16:24:32 -060084// TODO : This can be much smarter, using separate locks for separate global data
85static int globalLockInitialized = 0;
86static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060087#define MAX_TID 513
88static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
89static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060090
91template layer_data *get_my_data_ptr<layer_data>(
92 void *data_key,
93 std::unordered_map<void *, layer_data *> &data_map);
94
Tobin Ehlis1dce5f12015-07-07 10:42:20 -060095debug_report_data *mdd(void* object)
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060096{
97 dispatch_key key = get_dispatch_key(object);
98 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
99#if DISPATCH_MAP_DEBUG
100 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
101#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600102 return my_data->report_data;
103}
104
105debug_report_data *mid(VkInstance object)
106{
107 dispatch_key key = get_dispatch_key(object);
Tobin Ehlis8354e022015-09-01 11:46:36 -0600108 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600109#if DISPATCH_MAP_DEBUG
110 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
111#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600112 return my_data->report_data;
113}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600114// Map actual TID to an index value and return that index
115// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
116static uint32_t getTIDIndex() {
117 loader_platform_thread_id tid = loader_platform_get_thread_id();
118 for (uint32_t i = 0; i < g_maxTID; i++) {
119 if (tid == g_tidMapping[i])
120 return i;
121 }
122 // Don't yet have mapping, set it and return newly set index
123 uint32_t retVal = (uint32_t) g_maxTID;
124 g_tidMapping[g_maxTID++] = tid;
125 assert(g_maxTID < MAX_TID);
126 return retVal;
127}
128// Return a string representation of CMD_TYPE enum
129static string cmdTypeToString(CMD_TYPE cmd)
130{
131 switch (cmd)
132 {
133 case CMD_BINDPIPELINE:
134 return "CMD_BINDPIPELINE";
135 case CMD_BINDPIPELINEDELTA:
136 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600137 case CMD_SETVIEWPORTSTATE:
138 return "CMD_SETVIEWPORTSTATE";
139 case CMD_SETLINEWIDTHSTATE:
140 return "CMD_SETLINEWIDTHSTATE";
141 case CMD_SETDEPTHBIASSTATE:
142 return "CMD_SETDEPTHBIASSTATE";
143 case CMD_SETBLENDSTATE:
144 return "CMD_SETBLENDSTATE";
145 case CMD_SETDEPTHBOUNDSSTATE:
146 return "CMD_SETDEPTHBOUNDSSTATE";
147 case CMD_SETSTENCILREADMASKSTATE:
148 return "CMD_SETSTENCILREADMASKSTATE";
149 case CMD_SETSTENCILWRITEMASKSTATE:
150 return "CMD_SETSTENCILWRITEMASKSTATE";
151 case CMD_SETSTENCILREFERENCESTATE:
152 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600153 case CMD_BINDDESCRIPTORSETS:
154 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600155 case CMD_BINDINDEXBUFFER:
156 return "CMD_BINDINDEXBUFFER";
157 case CMD_BINDVERTEXBUFFER:
158 return "CMD_BINDVERTEXBUFFER";
159 case CMD_DRAW:
160 return "CMD_DRAW";
161 case CMD_DRAWINDEXED:
162 return "CMD_DRAWINDEXED";
163 case CMD_DRAWINDIRECT:
164 return "CMD_DRAWINDIRECT";
165 case CMD_DRAWINDEXEDINDIRECT:
166 return "CMD_DRAWINDEXEDINDIRECT";
167 case CMD_DISPATCH:
168 return "CMD_DISPATCH";
169 case CMD_DISPATCHINDIRECT:
170 return "CMD_DISPATCHINDIRECT";
171 case CMD_COPYBUFFER:
172 return "CMD_COPYBUFFER";
173 case CMD_COPYIMAGE:
174 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600175 case CMD_BLITIMAGE:
176 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600177 case CMD_COPYBUFFERTOIMAGE:
178 return "CMD_COPYBUFFERTOIMAGE";
179 case CMD_COPYIMAGETOBUFFER:
180 return "CMD_COPYIMAGETOBUFFER";
181 case CMD_CLONEIMAGEDATA:
182 return "CMD_CLONEIMAGEDATA";
183 case CMD_UPDATEBUFFER:
184 return "CMD_UPDATEBUFFER";
185 case CMD_FILLBUFFER:
186 return "CMD_FILLBUFFER";
187 case CMD_CLEARCOLORIMAGE:
188 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600189 case CMD_CLEARCOLORATTACHMENT:
190 return "CMD_CLEARCOLORATTACHMENT";
191 case CMD_CLEARDEPTHSTENCILIMAGE:
192 return "CMD_CLEARDEPTHSTENCILIMAGE";
193 case CMD_CLEARDEPTHSTENCILATTACHMENT:
194 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600195 case CMD_RESOLVEIMAGE:
196 return "CMD_RESOLVEIMAGE";
197 case CMD_SETEVENT:
198 return "CMD_SETEVENT";
199 case CMD_RESETEVENT:
200 return "CMD_RESETEVENT";
201 case CMD_WAITEVENTS:
202 return "CMD_WAITEVENTS";
203 case CMD_PIPELINEBARRIER:
204 return "CMD_PIPELINEBARRIER";
205 case CMD_BEGINQUERY:
206 return "CMD_BEGINQUERY";
207 case CMD_ENDQUERY:
208 return "CMD_ENDQUERY";
209 case CMD_RESETQUERYPOOL:
210 return "CMD_RESETQUERYPOOL";
211 case CMD_WRITETIMESTAMP:
212 return "CMD_WRITETIMESTAMP";
213 case CMD_INITATOMICCOUNTERS:
214 return "CMD_INITATOMICCOUNTERS";
215 case CMD_LOADATOMICCOUNTERS:
216 return "CMD_LOADATOMICCOUNTERS";
217 case CMD_SAVEATOMICCOUNTERS:
218 return "CMD_SAVEATOMICCOUNTERS";
219 case CMD_BEGINRENDERPASS:
220 return "CMD_BEGINRENDERPASS";
221 case CMD_ENDRENDERPASS:
222 return "CMD_ENDRENDERPASS";
223 case CMD_DBGMARKERBEGIN:
224 return "CMD_DBGMARKERBEGIN";
225 case CMD_DBGMARKEREND:
226 return "CMD_DBGMARKEREND";
227 default:
228 return "UNKNOWN";
229 }
230}
231// Block of code at start here for managing/tracking Pipeline state that this layer cares about
232// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600233#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600234#define MAX_SLOTS 2048
235#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
236
237static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
238
239// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
240// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
241// to that same cmd buffer by separate thread are not changing state from underneath us
242// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600243static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600244// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600245static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
246static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600247// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600248static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
249static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Dana Jansens4a3e0862015-07-30 13:22:15 -0700250static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600251#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
252
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600253// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600254static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600255{
David Pinedof5997ab2015-04-27 16:36:17 -0600256 if (sampleMap.size() <= 0)
257 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600258 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600259 delete (*ii).second;
260 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600261 sampleMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600262}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600263static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600264{
265 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600266 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600267 loader_platform_thread_unlock_mutex(&globalLock);
268 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600269 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600270 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600271 return &imageMap[view.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600272 }
273}
274// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600275static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600276{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600277 if (imageMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -0600278 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600279 imageMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600280}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600281static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600282{
283 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600284 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600285 loader_platform_thread_unlock_mutex(&globalLock);
286 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600287 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600288 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600289 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600290 }
291}
292// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600293static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600294{
David Pinedof5997ab2015-04-27 16:36:17 -0600295 if (bufferMap.size() <= 0)
296 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600297 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600298 delete (*ii).second;
299 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600300 bufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600301}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600302static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600303// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600304static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600305{
306 g_lastCmdBuffer[getTIDIndex()] = cb;
307 GLOBAL_CB_NODE* pCB = getCBNode(cb);
308 loader_platform_thread_lock_mutex(&globalLock);
309 g_lastGlobalCB = pCB;
310 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
311 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
312 if (g_pLastTouchedCB[i] == pCB) {
313 loader_platform_thread_unlock_mutex(&globalLock);
314 return;
315 }
316 }
317 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
318 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
319 loader_platform_thread_unlock_mutex(&globalLock);
320}
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600321static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600322{
323 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
324 if (pCB->drawCount[i])
325 return VK_TRUE;
326 }
327 return VK_FALSE;
328}
Tobin Ehlis97866202015-06-10 12:57:07 -0600329// Check object status for selected flag state
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600330static VkBool32 validate_status(GLOBAL_CB_NODE* pNode, CBStatusFlags enable_mask, CBStatusFlags status_mask, CBStatusFlags status_flag, VkFlags msg_flags, DRAW_STATE_ERROR error_code, const char* fail_msg)
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600331{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600332 // If non-zero enable mask is present, check it against status but if enable_mask
333 // is 0 then no enable required so we should always just check status
334 if ((!enable_mask) || (enable_mask & pNode->status)) {
335 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600336 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600337 return log_msg(mdd(pNode->cmdBuffer), msg_flags, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, error_code, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -0600338 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->cmdBuffer), fail_msg);
Tobin Ehlis97866202015-06-10 12:57:07 -0600339 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600340 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600341 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600342}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600343// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600344static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600345{
346 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600347 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600348 loader_platform_thread_unlock_mutex(&globalLock);
349 return NULL;
350 }
351 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600352 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600353}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600354// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600355static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
356 VkBool32 result;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600357 result = validate_status(pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_SET, CBSTATUS_VIEWPORT_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");
358 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_LINE_WIDTH_SET, CBSTATUS_LINE_WIDTH_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_LINE_WIDTH_NOT_BOUND, "Line width object not bound to this command buffer");
359 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_DEPTH_BIAS_SET, CBSTATUS_DEPTH_BIAS_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_BIAS_NOT_BOUND, "Depth bias object not bound to this command buffer");
360 result |= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_BLEND_SET, CBSTATUS_BLEND_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_BLEND_NOT_BOUND, "Blend object not bound to this command buffer");
361 result |= validate_status(pCB, CBSTATUS_DEPTH_WRITE_ENABLE, CBSTATUS_DEPTH_BOUNDS_SET, CBSTATUS_DEPTH_BOUNDS_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_BOUNDS_NOT_BOUND, "Depth bounds object not bound to this command buffer");
362 result |= validate_status(pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_READ_MASK_SET, CBSTATUS_STENCIL_READ_MASK_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Stencil read mask not set on this command buffer");
363 result |= validate_status(pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_WRITE_MASK_SET, CBSTATUS_STENCIL_WRITE_MASK_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Stencil write mask not set on this command buffer");
364 result |= validate_status(pCB, CBSTATUS_STENCIL_TEST_ENABLE, CBSTATUS_STENCIL_REFERENCE_SET, CBSTATUS_STENCIL_REFERENCE_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Stencil reference not set on this command buffer");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600365 if (indexedDraw)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600366 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");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600367 return result;
368}
369// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600370static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600371 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600372 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600373 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
374 // Now complete other state checks
Tobin Ehlis12ab7dc2015-09-09 13:31:01 -0600375 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
376 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
377 // We should have that check separately and then gate this check based on that check
378 if (pPipe && (pCB->lastBoundPipelineLayout) && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600379 result = VK_FALSE;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600380 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE_LAYOUT, pCB->lastBoundPipelineLayout.handle, 0, DRAWSTATE_PIPELINE_LAYOUT_MISMATCH, "DS",
Mark Lobodzinskia98cf9b2015-08-04 10:54:43 -0600381 "Pipeline layout from last vkCmdBindDescriptorSets() (%#" PRIxLEAST64 ") does not match PSO Pipeline layout (%#" PRIxLEAST64 ") ", pCB->lastBoundPipelineLayout.handle, pPipe->graphicsPipelineCI.layout.handle);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600382 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600383 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600384 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis451efca2015-06-23 11:22:55 -0600385 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
386 }
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600387 // Verify Vtx binding
388 if (MAX_BINDING != pCB->lastVtxBinding) {
389 if (pCB->lastVtxBinding >= pPipe->vtxBindingCount) {
390 if (0 == pPipe->vtxBindingCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600391 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600392 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600393 }
394 else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600395 result |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, "DS",
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600396 "Vtx binding Index of %u exceeds PSO pVertexBindingDescriptions max array index of %u.", pCB->lastVtxBinding, (pPipe->vtxBindingCount - 1));
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600397 }
398 }
399 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600400 return result;
401}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600402// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600403static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600404{
405 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600406 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600407 loader_platform_thread_unlock_mutex(&globalLock);
408 return NULL;
409 }
410 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600411 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600412}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600413// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600414static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600415{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600416 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisde63c532015-06-18 15:59:33 -0600417 // VS is required
418 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600419 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600420 "Invalid Pipeline CreateInfo State: Vtx Shader required");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600421 }
422 // Either both or neither TC/TE shaders should be defined
423 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
424 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600425 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600426 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600427 }
428 // Compute shaders should be specified independent of Gfx shaders
429 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
430 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
431 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
432 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600433 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600434 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600435 }
436 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
437 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
438 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
439 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600440 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600441 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600442 }
Tobin Ehlis20693172015-09-17 08:46:18 -0600443 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) {
444 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) {
445 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
Tobin Ehlisde63c532015-06-18 15:59:33 -0600446 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
Tobin Ehlis20693172015-09-17 08:46:18 -0600447 }
448 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
449 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
450 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology used with patchControlPoints value %u."
451 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
452 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600453 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600454 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -0600455}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600456// Init the pipeline mapping info based on pipeline create info LL tree
457// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600458static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600459{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600460 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
461 if (pBasePipeline) {
462 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600463 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600464 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
465 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600466 // First init create info
Tobin Ehlis2464b882015-04-01 08:40:34 -0600467 // TODO : Validate that no create info is incorrectly replicated
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600468 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600469
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600470 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600471 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600472 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600473
474 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
475 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
476
477 switch (pPSSCI->stage) {
478 case VK_SHADER_STAGE_VERTEX:
479 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
480 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600481 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600482 case VK_SHADER_STAGE_TESS_CONTROL:
483 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
484 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600485 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600486 case VK_SHADER_STAGE_TESS_EVALUATION:
487 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
488 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600489 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600490 case VK_SHADER_STAGE_GEOMETRY:
491 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
492 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600493 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600494 case VK_SHADER_STAGE_FRAGMENT:
495 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
496 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600497 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600498 case VK_SHADER_STAGE_COMPUTE:
499 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
500 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600501 break;
502 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600503 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600504 break;
505 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600506 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600507
508 if (pCreateInfo->pVertexInputState != NULL) {
509 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
510 // Copy embedded ptrs
511 pVICI = pCreateInfo->pVertexInputState;
512 pPipeline->vtxBindingCount = pVICI->bindingCount;
513 if (pPipeline->vtxBindingCount) {
514 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
515 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
516 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
517 }
518 pPipeline->vtxAttributeCount = pVICI->attributeCount;
519 if (pPipeline->vtxAttributeCount) {
520 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
521 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
522 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
523 }
524 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
525 }
Tony Barboure307f582015-07-10 15:29:03 -0600526 if (pCreateInfo->pInputAssemblyState != NULL) {
527 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
528 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600529 }
Tony Barboure307f582015-07-10 15:29:03 -0600530 if (pCreateInfo->pTessellationState != NULL) {
531 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
532 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600533 }
Tony Barboure307f582015-07-10 15:29:03 -0600534 if (pCreateInfo->pViewportState != NULL) {
535 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
536 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600537 }
Tony Barboure307f582015-07-10 15:29:03 -0600538 if (pCreateInfo->pRasterState != NULL) {
539 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
540 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600541 }
Tony Barboure307f582015-07-10 15:29:03 -0600542 if (pCreateInfo->pMultisampleState != NULL) {
543 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
544 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600545 }
Tony Barboure307f582015-07-10 15:29:03 -0600546 if (pCreateInfo->pColorBlendState != NULL) {
547 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600548 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600549 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600550 pPipeline->attachmentCount = pCBCI->attachmentCount;
551 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600552 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
553 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600554 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
555 }
Tony Barboure307f582015-07-10 15:29:03 -0600556 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600557 }
Tony Barboure307f582015-07-10 15:29:03 -0600558 if (pCreateInfo->pDepthStencilState != NULL) {
559 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
560 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600561 }
562
563 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
564 if (pCreateInfo->stageCount != 0) {
565 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
566 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
567 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
568 }
569
Tobin Ehlisde63c532015-06-18 15:59:33 -0600570 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600571}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600572
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600573// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600574static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600575{
David Pinedof5997ab2015-04-27 16:36:17 -0600576 if (pipelineMap.size() <= 0)
577 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600578 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600579 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
580 delete[] (*ii).second->graphicsPipelineCI.pStages;
581 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600582 if ((*ii).second->pVertexBindingDescriptions) {
583 delete[] (*ii).second->pVertexBindingDescriptions;
584 }
585 if ((*ii).second->pVertexAttributeDescriptions) {
586 delete[] (*ii).second->pVertexAttributeDescriptions;
587 }
588 if ((*ii).second->pAttachments) {
589 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600590 }
591 delete (*ii).second;
592 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600593 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600594}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600595// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600596static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600597{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600598 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600599 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
600 return pPipe->msStateCI.rasterSamples;
601 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600602 return 1;
603}
604// Validate state related to the PSO
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600605static VkBool32 validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600606{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600607 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600608 // Verify that any MSAA request in PSO matches sample# in bound FB
609 uint32_t psoNumSamples = getNumSamples(pipeline);
610 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600611 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800612 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
613 int subpassNumSamples = 0;
614 uint32_t i;
615
616 for (i = 0; i < pSD->colorCount; i++) {
617 uint32_t samples;
618
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600619 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800620 continue;
621
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600622 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800623 if (subpassNumSamples == 0) {
624 subpassNumSamples = samples;
625 } else if (subpassNumSamples != samples) {
626 subpassNumSamples = -1;
627 break;
628 }
629 }
630 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
631 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
632 if (subpassNumSamples == 0)
633 subpassNumSamples = samples;
634 else if (subpassNumSamples != samples)
635 subpassNumSamples = -1;
636 }
637
638 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600639 return log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NUM_SAMPLES_MISMATCH, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600640 "Num samples mismatch! Binding PSO (%#" PRIxLEAST64 ") with %u samples while current RenderPass (%#" PRIxLEAST64 ") w/ %u samples!", pipeline.handle, psoNumSamples, pCB->activeRenderPass.handle, subpassNumSamples);
Tobin Ehlis2464b882015-04-01 08:40:34 -0600641 }
642 } else {
643 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
644 // Verify and flag error as appropriate
645 }
646 // TODO : Add more checks here
647 } else {
648 // TODO : Validate non-gfx pipeline updates
649 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600650 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600651}
652
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600653// Block of code at start here specifically for managing/tracking DSs
654
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600655// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600656static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600657{
658 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600659 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600660 loader_platform_thread_unlock_mutex(&globalLock);
661 return NULL;
662 }
663 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600664 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600665}
666// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600667static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600668{
669 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600670 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600671 loader_platform_thread_unlock_mutex(&globalLock);
672 return NULL;
673 }
674 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600675 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600676}
677
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600678static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600679 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600680 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600681 loader_platform_thread_unlock_mutex(&globalLock);
682 return NULL;
683 }
684 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600685 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600686}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600687// Return VK_FALSE if update struct is of valid type, otherwise flag error and return code from callback
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600688static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600689{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600690 switch (pUpdateStruct->sType)
691 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800692 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
693 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600694 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600695 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600696 return log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600697 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600698 }
699}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600700// For given update struct, return binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600701static VkBool32 getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* binding)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600702{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600703 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600704 switch (pUpdateStruct->sType)
705 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800706 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600707 *binding = ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
708 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800709 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600710 *binding = ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
711 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600712 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600713 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600714 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600715 *binding = 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600716 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600717 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600718}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600719// Set arrayIndex for given update struct in the last parameter
720// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
721static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* arrayIndex)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600722{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600723 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600724 switch (pUpdateStruct->sType)
725 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800726 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600727 *arrayIndex = ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
728 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800729 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600730 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600731 *arrayIndex = ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
732 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600733 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600734 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600735 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600736 *arrayIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600737 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600738 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600739}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600740// Set count for given update struct in the last parameter
741// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
742static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* count)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600743{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600744 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600745 switch (pUpdateStruct->sType)
746 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800747 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600748 *count = ((VkWriteDescriptorSet*)pUpdateStruct)->count;
749 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800750 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600751 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600752 *count = ((VkCopyDescriptorSet*)pUpdateStruct)->count;
753 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600754 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600755 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600756 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600757 *count = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600758 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600759 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600760}
761// For given Layout Node and binding, return index where that binding begins
762static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
763{
764 uint32_t offsetIndex = 0;
765 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800766 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600767 }
768 return offsetIndex;
769}
770// For given layout node and binding, return last index that is updated
771static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
772{
773 uint32_t offsetIndex = 0;
774 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800775 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600776 }
777 return offsetIndex-1;
778}
779// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600780static VkBool32 getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* startIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600781{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600782 uint32_t binding = 0, arrayIndex = 0;
783 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
784 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
785 if (VK_FALSE == skipCall)
786 *startIndex = getBindingStartIndex(pLayout, binding)+arrayIndex;
787 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600788}
789// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600790static VkBool32 getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* endIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600791{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600792 uint32_t binding = 0, arrayIndex = 0, count = 0;
793 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
794 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
795 skipCall |= getUpdateCount(device, pUpdateStruct, &count);
796 if (VK_FALSE == skipCall)
797 *endIndex = getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
798 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600799}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600800// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600801static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600802{
803 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600804 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600805 VkDescriptorType actualType;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600806 uint32_t i = 0, startIndex = 0, endIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600807 switch (pUpdateStruct->sType)
808 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800809 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
810 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600811 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800812 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
813 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600814 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600815 break;
816 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600817 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600818 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdateStruct->sType), pUpdateStruct->sType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600819 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600820 skipCall |= getUpdateStartIndex(device, pLayout, pUpdateStruct, &startIndex);
821 skipCall |= getUpdateEndIndex(device, pLayout, pUpdateStruct, &endIndex);
822 if (VK_FALSE == skipCall) {
823 for (i = startIndex; i <= endIndex; i++) {
824 if (pLayout->pTypes[i] != actualType)
825 return VK_TRUE;
826 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600827 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600828 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600829}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600830// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600831// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600832// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600833static VkBool32 shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600834{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600835 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800836 VkWriteDescriptorSet* pWDS = NULL;
837 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600838 size_t array_size = 0;
839 size_t base_array_size = 0;
840 size_t total_array_size = 0;
841 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600842 switch (pUpdate->sType)
843 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800844 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
845 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600846 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800847 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
848 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
849 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
850 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600851 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800852 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
853 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600854 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800855 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600856 break;
857 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600858 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
859 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
860 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600861 }
862 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600863 (*pNewNode)->pNext = NULL;
864 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600865}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800866// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600867static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600868{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800869 const VkWriteDescriptorSet *pWDS = NULL;
870 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600871 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800872
873 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
874 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
875 else
876 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
877
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600878 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600879 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600880 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600881 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600882 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600883 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800884 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600885 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800886 g_lastBoundDescriptorSet = pSet->set;
887 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600888 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600889 // First verify valid update struct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600890 if ((skipCall = validUpdateStruct(device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600891 break;
892 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600893 // Make sure that binding is within bounds
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600894 uint32_t binding = 0, endIndex = 0;
895 skipCall |= getUpdateBinding(device, pUpdate, &binding);
896 if (pLayout->createInfo.count < binding) {
897 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
898 "Descriptor Set %p does not have binding to match update binding %u for update type %s!", ds, binding, string_VkStructureType(pUpdate->sType));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600899 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600900 // Next verify that update falls within size of given binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600901 skipCall |= getUpdateBinding(device, pUpdate, &binding);
902 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
903 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tony Barbour29b12062015-07-13 13:37:24 -0600904 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600905 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600906 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600907 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, "DS",
908 "Descriptor update type of %s is out of bounds for matching binding %u in Layout w/ CI:\n%s!", string_VkStructureType(pUpdate->sType), binding, DSstr.c_str());
Tobin Ehlise42007c2015-06-19 13:00:59 -0600909 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600910 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600911 if ((skipCall = validateUpdateType(device, pLayout, pUpdate)) == VK_TRUE) {
912 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600913 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600914 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600915 // Save the update info
916 // TODO : Info message that update successful
917 // Create new update struct for this set's shadow copy
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600918 GENERIC_HEADER* pNewNode = NULL;
919 skipCall |= shadowUpdateNode(device, pUpdate, &pNewNode);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600920 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600921 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600922 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlise42007c2015-06-19 13:00:59 -0600923 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600924 // Insert shadow node into LL of updates for this set
925 pNewNode->pNext = pSet->pUpdateStructs;
926 pSet->pUpdateStructs = pNewNode;
927 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600928 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
929 uint32_t startIndex;
930 skipCall |= getUpdateStartIndex(device, pLayout, pUpdate, &startIndex);
931 for (uint32_t j = startIndex; j <= endIndex; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600932 assert(j<pSet->descriptorCount);
933 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600934 }
935 }
936 }
937 }
938 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600939 }
940 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600941 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600942}
943// Free the shadowed update node for this Set
944// NOTE : Calls to this function should be wrapped in mutex
945static void freeShadowUpdateTree(SET_NODE* pSet)
946{
947 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
948 pSet->pUpdateStructs = NULL;
949 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
950 // Clear the descriptor mappings as they will now be invalid
951 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
952 while(pShadowUpdate) {
953 pFreeUpdate = pShadowUpdate;
954 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
955 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800956 VkWriteDescriptorSet * pWDS = NULL;
957 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600958 void** ppToFree = NULL;
959 switch (pFreeUpdate->sType)
960 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800961 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
962 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
963 if (pWDS->pDescriptors)
964 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600965 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800966 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600967 break;
968 default:
969 assert(0);
970 break;
971 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600972 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600973 }
974}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600975// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600976// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600977static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600978{
David Pinedof5997ab2015-04-27 16:36:17 -0600979 if (poolMap.size() <= 0)
980 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600981 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600982 SET_NODE* pSet = (*ii).second->pSets;
983 SET_NODE* pFreeSet = pSet;
984 while (pSet) {
985 pFreeSet = pSet;
986 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -0600987 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600988 // Free Update shadow struct tree
989 freeShadowUpdateTree(pFreeSet);
990 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200991 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600992 }
993 delete pFreeSet;
994 }
995 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +1200996 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600997 }
998 delete (*ii).second;
999 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001000 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001001}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001002// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001003// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001004static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001005{
David Pinedof5997ab2015-04-27 16:36:17 -06001006 if (layoutMap.size() <= 0)
1007 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001008 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001009 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001010 if (pLayout->createInfo.pBinding) {
1011 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1012 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1013 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1014 }
1015 delete[] pLayout->createInfo.pBinding;
1016 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001017 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001018 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001019 }
1020 delete pLayout;
1021 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001022 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001023}
1024// Currently clearing a set is removing all previous updates to that set
1025// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001026static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001027{
1028 SET_NODE* pSet = getSetNode(set);
1029 if (!pSet) {
1030 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001031 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001032 loader_platform_thread_lock_mutex(&globalLock);
1033 freeShadowUpdateTree(pSet);
1034 loader_platform_thread_unlock_mutex(&globalLock);
1035 }
1036}
1037
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001038static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001039{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001040 POOL_NODE* pPool = getPoolNode(pool);
1041 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001042 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1043 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001044 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001045 // For every set off of this pool, clear it
1046 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001047 while (pSet) {
1048 clearDescriptorSet(pSet->set);
1049 }
1050 }
1051}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001052// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001053static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001054{
1055 loader_platform_thread_lock_mutex(&globalLock);
1056 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1057 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001058 // TODO : How to pass cb as srcObj here?
1059 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001060 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001061 return NULL;
1062 }
1063 loader_platform_thread_unlock_mutex(&globalLock);
1064 return cmdBufferMap[cb];
1065}
1066// Free all CB Nodes
1067// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001068static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001069{
David Pinedof5997ab2015-04-27 16:36:17 -06001070 if (cmdBufferMap.size() <= 0)
1071 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001072 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001073 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1074 while (!cmd_node_list.empty()) {
1075 CMD_NODE* cmd_node = cmd_node_list.back();
1076 delete cmd_node;
1077 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001078 }
1079 delete (*ii).second;
1080 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001081 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001082}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001083static VkBool32 report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
Tobin Ehlise42007c2015-06-19 13:00:59 -06001084{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001085 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001086 return log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_BEGIN_CMD_BUFFER, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06001087 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1088}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001089static VkBool32 addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001090{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001091 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001092 CMD_NODE* pCmd = new CMD_NODE;
1093 if (pCmd) {
1094 // init cmd node and append to end of cmd LL
1095 memset(pCmd, 0, sizeof(CMD_NODE));
1096 pCmd->cmdNumber = ++pCB->numCmds;
1097 pCmd->type = cmd;
1098 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001099 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001100 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001101 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001102 "Out of memory while attempting to allocate new CMD_NODE for cmdBuffer %#" PRIxLEAST64, reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001103 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001104 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001105}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001106static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001107{
1108 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1109 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001110 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1111 while (!cmd_list.empty()) {
1112 delete cmd_list.back();
1113 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001114 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001115 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001116 // Reset CB state (need to save createInfo)
1117 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001118 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1119 pCB->cmdBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001120 pCB->createInfo = saveCBCI;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001121 pCB->lastVtxBinding = MAX_BINDING;
1122 }
1123}
Tobin Ehlis97866202015-06-10 12:57:07 -06001124// Set PSO-related status bits for CB
1125static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1126{
1127 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1128 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1129 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1130 }
1131 }
1132 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06001133 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1134 }
1135
1136 if (pPipe->dsStateCI.stencilTestEnable) {
1137 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001138 }
1139}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001140// Print the last bound Gfx Pipeline
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001141static VkBool32 printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001142{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001143 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001144 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1145 if (pCB) {
1146 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1147 if (!pPipeTrav) {
1148 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001149 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001150 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001151 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001152 }
1153 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001154 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001155}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001156// Print details of DS config to stdout
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001157static VkBool32 printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001158{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001159 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001160 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.
1161 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001162 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001163 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001164 POOL_NODE* pPool = getPoolNode(pSet->pool);
1165 // Print out pool details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001166 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001167 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001168 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001169 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001170 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001171 // Print out set details
1172 char prefix[10];
1173 uint32_t index = 0;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001174 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001175 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001176 LAYOUT_NODE* pLayout = pSet->pLayout;
1177 // Print layout details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001178 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001179 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001180 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001181 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001182 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001183 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001184 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001185 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1186 if (pUpdate) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001187 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001188 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001189 sprintf(prefix, " [UC] ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001190 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001191 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001192 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001193 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001194 if (0 != pSet->descriptorCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001195 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001196 "No Update Chain for descriptor set %#" PRIxLEAST64 " which has %u descriptors (vkUpdateDescriptors has not been called)", pSet->set.handle, pSet->descriptorCount);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001197 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001198 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001199 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001200 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001201 }
1202 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001203 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001204}
1205
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001206static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001207{
1208 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001209 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001210 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001211 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001212 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001213 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1214 // TODO : Need to pass cb as srcObj here
1215 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001216 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001217 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001218 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001219 // Nothing to print
1220 }
1221}
1222
1223
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001224static VkBool32 synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001225{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001226 VkBool32 skipCall = VK_FALSE;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001227 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001228 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001229 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001230 skipCall |= printDSConfig(cb);
1231 skipCall |= printPipeline(cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001232 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001233}
1234
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001235static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001236{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001237 uint32_t report_flags = 0;
1238 uint32_t debug_action = 0;
1239 FILE *log_output = NULL;
1240 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001241 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001242 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1243 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001244
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001245 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001246 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001247 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06001248 log_output = getLayerLogOutput(option_str, "DrawState");
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001249 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001250 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001251
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001252 if (!globalLockInitialized)
1253 {
Mike Stroyand9dd0072015-08-18 15:56:18 -06001254 // This mutex may be deleted by vkDestroyInstance of last instance.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001255 loader_platform_thread_create_mutex(&globalLock);
1256 globalLockInitialized = 1;
1257 }
1258}
1259
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001260VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1261{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001262 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001263 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1264
1265 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001266 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1267 my_data->report_data = debug_report_create_instance(
1268 pTable,
1269 *pInstance,
1270 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001271 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001272
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001273 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001274 }
1275 return result;
1276}
1277
Jon Ashburne0fa2282015-05-20 09:00:28 -06001278/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001279VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Jon Ashburne0fa2282015-05-20 09:00:28 -06001280{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001281 dispatch_key key = get_dispatch_key(instance);
1282 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001283 pTable->DestroyInstance(instance);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001284
1285 // Clean up logging callback, if any
1286 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1287 if (my_data->logging_callback) {
1288 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1289 }
1290
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001291 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001292 layer_data_map.erase(pTable);
1293
1294 draw_state_instance_table_map.erase(key);
Mike Stroyand9dd0072015-08-18 15:56:18 -06001295 if (draw_state_instance_table_map.empty()) {
1296 // Release mutex when destroying last instance.
1297 loader_platform_thread_delete_mutex(&globalLock);
1298 globalLockInitialized = 0;
1299 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001300}
1301
Jon Ashburnf0615e22015-05-25 14:11:37 -06001302static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1303{
Tony Barbour29b12062015-07-13 13:37:24 -06001304 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001305 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001306 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001307
1308 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001309 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001310 /* Found a matching extension name, mark it enabled and init dispatch table*/
1311 initDebugMarkerTable(device);
1312 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001313 }
1314
1315 }
1316}
1317
Tony Barbour8205d902015-04-16 15:59:00 -06001318VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001319{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001320 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1321 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001322 if (result == VK_SUCCESS) {
1323 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1324 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1325 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1326 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001327 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001328 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001329 return result;
1330}
1331
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001332VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001333{
1334 // Free all the memory
1335 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001336 deletePipelines();
1337 deleteSamplers();
1338 deleteImages();
1339 deleteBuffers();
1340 deleteCmdBuffers();
Tobin Ehliseaf28662015-04-08 10:58:37 -06001341 deletePools();
1342 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001343 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001344
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001345 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001346 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001347 pDisp->DestroyDevice(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001348 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001349 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001350 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001351}
1352
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001353static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001354 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001355 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001356 VK_API_VERSION,
1357 VK_MAKE_VERSION(0, 1, 0),
1358 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001359 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001360};
1361
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001362VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001363 const char *pLayerName,
1364 uint32_t *pCount,
1365 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001366{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001367 /* DrawState does not have any global extensions */
1368 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1369}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001370
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001371VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001372 uint32_t *pCount,
1373 VkLayerProperties* pProperties)
1374{
1375 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1376 ds_global_layers,
1377 pCount, pProperties);
1378}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001379
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001380static const VkExtensionProperties ds_device_extensions[] = {
1381 {
1382 DEBUG_MARKER_EXTENSION_NAME,
1383 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001384 }
1385};
1386
1387static const VkLayerProperties ds_device_layers[] = {
1388 {
1389 "DrawState",
1390 VK_API_VERSION,
1391 VK_MAKE_VERSION(0, 1, 0),
1392 "Validation layer: DrawState",
1393 }
1394};
1395
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001396VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001397 VkPhysicalDevice physicalDevice,
1398 const char* pLayerName,
1399 uint32_t* pCount,
1400 VkExtensionProperties* pProperties)
1401{
1402 /* Mem tracker does not have any physical device extensions */
1403 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1404 pCount, pProperties);
1405}
1406
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001407VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001408 VkPhysicalDevice physicalDevice,
1409 uint32_t* pCount,
1410 VkLayerProperties* pProperties)
1411{
1412 /* Mem tracker's physical device layers are the same as global */
1413 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1414 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001415}
1416
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001417VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001418{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001419 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001420 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001421 for (uint32_t i=0; i < cmdBufferCount; i++) {
1422 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001423 pCB = getCBNode(pCmdBuffers[i]);
1424 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001425 pCB->submitCount++; // increment submit count
1426 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001427 skipCall |= log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CMD_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001428 "CB %#" PRIxLEAST64 " was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.", reinterpret_cast<uint64_t>(pCB->cmdBuffer), pCB->submitCount);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001429 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001430 if (CB_UPDATE_COMPLETE != pCB->state) {
1431 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001432 // TODO : How to pass cb as srcObj?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001433 skipCall |= log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NO_END_CMD_BUFFER, "DS",
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06001434 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", reinterpret_cast<uint64_t>(pCB->cmdBuffer));
Tobin Ehlise90b1712015-05-27 14:30:06 -06001435 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001436 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001437 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001438 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001439 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001440 if (VK_FALSE == skipCall)
1441 return get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
1442 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001443}
1444
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001445VK_LAYER_EXPORT void VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001446{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001447 get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001448 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001449}
1450
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001451VK_LAYER_EXPORT void VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001452{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001453 get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001454 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001455}
1456
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001457VK_LAYER_EXPORT void VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001458{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001459 get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001460 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001461}
1462
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001463VK_LAYER_EXPORT void VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001464{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001465 get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001466 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001467}
1468
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001469VK_LAYER_EXPORT void VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001470{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001471 get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001472 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001473}
1474
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001475VK_LAYER_EXPORT void VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001476{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001477 get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001478 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001479}
1480
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001481VK_LAYER_EXPORT void VKAPI vkDestroyImage(VkDevice device, VkImage image)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001482{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001483 get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001484 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001485}
1486
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001487VK_LAYER_EXPORT void VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001488{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001489 get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001490 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001491}
1492
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001493VK_LAYER_EXPORT void VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001494{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001495 get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001496 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001497}
1498
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001499VK_LAYER_EXPORT void VKAPI vkDestroyShader(VkDevice device, VkShader shader)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001500{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001501 get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001502 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001503}
1504
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001505VK_LAYER_EXPORT void VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001506{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001507 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001508 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001509}
1510
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001511VK_LAYER_EXPORT void VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001512{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001513 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001514 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001515}
1516
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001517VK_LAYER_EXPORT void VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001518{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001519 get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001520 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001521}
1522
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001523VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001524{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001525 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001526 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001527}
1528
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001529VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001530{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001531 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001532 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001533}
1534
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001535VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001536{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001537 get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001538 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001539}
1540
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001541VK_LAYER_EXPORT void VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001542{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001543 get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001544 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001545}
1546
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001547VK_LAYER_EXPORT void VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001548{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001549 get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001550 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001551}
1552
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001553VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001554{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001555 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001556 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001557 loader_platform_thread_lock_mutex(&globalLock);
1558 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1559 pNewNode->buffer = *pView;
1560 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001561 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001562 loader_platform_thread_unlock_mutex(&globalLock);
1563 }
1564 return result;
1565}
1566
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001567VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001568{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001569 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001570 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001571 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001572 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001573 loader_platform_thread_unlock_mutex(&globalLock);
1574 }
1575 return result;
1576}
1577
Jon Ashburn0d60d272015-07-09 15:02:25 -06001578//TODO handle pipeline caches
1579VkResult VKAPI vkCreatePipelineCache(
1580 VkDevice device,
1581 const VkPipelineCacheCreateInfo* pCreateInfo,
1582 VkPipelineCache* pPipelineCache)
1583{
1584 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1585 return result;
1586}
1587
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001588void VKAPI vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06001589 VkDevice device,
1590 VkPipelineCache pipelineCache)
1591{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001592 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001593}
1594
1595size_t VKAPI vkGetPipelineCacheSize(
1596 VkDevice device,
1597 VkPipelineCache pipelineCache)
1598{
1599 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1600 return size;
1601}
1602
1603VkResult VKAPI vkGetPipelineCacheData(
1604 VkDevice device,
1605 VkPipelineCache pipelineCache,
1606 void* pData)
1607{
1608 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1609 return result;
1610}
1611
1612VkResult VKAPI vkMergePipelineCaches(
1613 VkDevice device,
1614 VkPipelineCache destCache,
1615 uint32_t srcCacheCount,
1616 const VkPipelineCache* pSrcCaches)
1617{
1618 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1619 return result;
1620}
1621
1622VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001623{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001624 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06001625 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06001626 // The order of operations here is a little convoluted but gets the job done
1627 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1628 // 2. Create state is then validated (which uses flags setup during shadowing)
1629 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06001630 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06001631 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
1632 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise48be202015-09-16 10:33:53 -06001633 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001634 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001635 for (i=0; i<count; i++) {
1636 pPipeNode[i] = initPipeline(&pCreateInfos[i], NULL);
1637 skipCall |= verifyPipelineCreateState(device, pPipeNode[i]);
1638 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001639 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001640 if (VK_FALSE == skipCall) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001641 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001642 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001643 for (i=0; i<count; i++) {
1644 pPipeNode[i]->pipeline = pPipelines[i];
1645 pipelineMap[pPipeNode[i]->pipeline.handle] = pPipeNode[i];
1646 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001647 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001648 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06001649 for (i=0; i<count; i++) {
1650 if (pPipeNode[i]) {
1651 // If we allocated a pipeNode, need to clean it up here
1652 delete[] pPipeNode[i]->pVertexBindingDescriptions;
1653 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
1654 delete[] pPipeNode[i]->pAttachments;
1655 delete pPipeNode[i];
1656 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001657 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001658 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001659 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001660 return result;
1661}
1662
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001663VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001664{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001665 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001666 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001667 loader_platform_thread_lock_mutex(&globalLock);
1668 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1669 pNewNode->sampler = *pSampler;
1670 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001671 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001672 loader_platform_thread_unlock_mutex(&globalLock);
1673 }
1674 return result;
1675}
1676
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001677VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001678{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001679 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001681 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1682 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001683 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1684 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
1685 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001686 }
1687 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001688 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1689 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1690 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001691 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001692 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001693 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001694 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001695 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001696 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1697 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001698 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001699 }
1700 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001701 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001702 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001703 uint32_t j = 0;
1704 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001705 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001706 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001707 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001708 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001709 }
1710 }
1711 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001712 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001713 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1714 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001715 // Put new node at Head of global Layer list
1716 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001717 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001718 loader_platform_thread_unlock_mutex(&globalLock);
1719 }
1720 return result;
1721}
1722
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001723VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001724{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001725 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001726 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001727 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001728 }
1729 return result;
1730}
1731
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001732VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001733{
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001734 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001735 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001736 // Insert this pool into Global Pool LL at head
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001737 if (log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1738 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle))
1739 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001740 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001741 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001742 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001743 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1744 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()"))
1745 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001746 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001747 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001748 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1749 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001750 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001751 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1752 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001753 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1754 }
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001755 pNewNode->poolUsage = pCreateInfo->poolUsage;
1756 pNewNode->maxSets = pCreateInfo->maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001757 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001758 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001759 }
1760 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001761 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001762 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001763 }
1764 return result;
1765}
1766
Mike Stroyan230e6252015-04-17 12:36:38 -06001767VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001768{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001769 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001770 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001771 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001772 }
1773 return result;
1774}
1775
Cody Northropc8aa4a52015-08-03 12:47:29 -06001776VK_LAYER_EXPORT VkResult VKAPI vkAllocDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSetUsage setUsage, uint32_t count, const VkDescriptorSetLayout* pSetLayouts, VkDescriptorSet* pDescriptorSets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001777{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001778 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1779 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001780 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1781 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001782 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1783 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001784 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001785 if (count == 0) {
1786 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1787 "AllocDescriptorSets called with 0 count");
1788 }
1789 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001790 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1791 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001792 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001793 SET_NODE* pNewNode = new SET_NODE;
1794 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001795 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1796 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()"))
1797 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001798 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001799 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001800 // Insert set at head of Set LL for this pool
1801 pNewNode->pNext = pPoolNode->pSets;
1802 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001803 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1804 if (NULL == pLayout) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001805 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1806 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle))
1807 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001808 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001809 pNewNode->pLayout = pLayout;
1810 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001811 pNewNode->set = pDescriptorSets[i];
1812 pNewNode->setUsage = setUsage;
1813 pNewNode->descriptorCount = pLayout->endIndex + 1;
1814 if (pNewNode->descriptorCount) {
1815 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1816 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1817 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1818 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001819 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001820 }
1821 }
1822 }
1823 }
1824 return result;
1825}
1826
Tony Barbourb857d312015-07-10 10:50:45 -06001827VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1828{
1829 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1830 // TODO : Clean up any internal data structures using this obj.
1831 return result;
1832}
1833
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001834VK_LAYER_EXPORT void VKAPI vkUpdateDescriptorSets(VkDevice device, uint32_t writeCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t copyCount, const VkCopyDescriptorSet* pDescriptorCopies)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001835{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001836 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when both updates return VK_FALSE
1837 if (!dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1838 !dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001839 get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001840 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001841}
1842
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001843VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001845 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001846 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001847 loader_platform_thread_lock_mutex(&globalLock);
1848 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1849 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1850 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001851 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001852 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001853 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001854 cmdBufferMap[*pCmdBuffer] = pCB;
1855 loader_platform_thread_unlock_mutex(&globalLock);
1856 updateCBTracking(*pCmdBuffer);
1857 }
1858 return result;
1859}
1860
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001861VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001863 VkBool32 skipCall = false;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001864 // Validate command buffer level
1865 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1866 if (pCB) {
1867 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
1868 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
1869 // These should be NULL for a Primary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001870 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001871 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
1872 }
1873 } else {
1874 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
1875 // These should NOT be null for an Secondary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001876 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_BEGIN_CB_INVALID_STATE, "DS",
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001877 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
1878 }
1879 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001880 pCB->beginInfo = *pBeginInfo;
1881 } else {
1882 // TODO : Need to pass cmdBuffer as objType here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001883 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS",
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001884 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001885 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001886 if (skipCall) {
1887 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06001888 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001889 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001890 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001891 if (CB_NEW != pCB->state)
1892 resetCB(cmdBuffer);
1893 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001894 updateCBTracking(cmdBuffer);
1895 }
1896 return result;
1897}
1898
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001899VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001900{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001901 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001902 VkResult result = VK_SUCCESS;
Tobin Ehlise42007c2015-06-19 13:00:59 -06001903 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001904 /* TODO: preference is to always call API function after reporting any validation errors */
Tobin Ehlise42007c2015-06-19 13:00:59 -06001905 if (pCB) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001906 if (pCB->state != CB_UPDATE_ACTIVE) {
1907 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001908 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001909 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001910 if (VK_FALSE == skipCall) {
1911 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
1912 if (VK_SUCCESS == result) {
1913 updateCBTracking(cmdBuffer);
1914 pCB->state = CB_UPDATE_COMPLETE;
1915 // Reset CB status flags
1916 pCB->status = 0;
1917 printCB(cmdBuffer);
1918 }
1919 } else {
1920 result = VK_ERROR_VALIDATION_FAILED;
1921 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001922 return result;
1923}
1924
Cody Northropf02f9f82015-07-09 18:08:05 -06001925VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001926{
Cody Northropf02f9f82015-07-09 18:08:05 -06001927 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001928 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001929 resetCB(cmdBuffer);
1930 updateCBTracking(cmdBuffer);
1931 }
1932 return result;
1933}
1934
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001935VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001936{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001937 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001938 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1939 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06001940 if (pCB->state == CB_UPDATE_ACTIVE) {
1941 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001942 skipCall |= addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06001943 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001944 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001945 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06001946 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001947 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001948 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001949 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06001950 PIPELINE_NODE* pPN = getPipeline(pipeline);
1951 if (pPN) {
1952 pCB->lastBoundPipeline = pipeline;
1953 loader_platform_thread_lock_mutex(&globalLock);
1954 set_cb_pso_status(pCB, pPN);
1955 g_lastBoundPipeline = pPN;
1956 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001957 skipCall |= validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06001958 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001959 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline.handle, 0, DRAWSTATE_INVALID_PIPELINE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001960 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06001961 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06001962 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001963 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001964 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001965 }
1966 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001967 if (VK_FALSE == skipCall)
1968 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001969}
1970
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001971VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
1972 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06001973 uint32_t viewportCount,
1974 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001975{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001976 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise42007c2015-06-19 13:00:59 -06001977 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1978 if (pCB) {
1979 if (pCB->state == CB_UPDATE_ACTIVE) {
1980 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001981 skipCall |= addCmd(pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06001982 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001983 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001984 "Incorrect call to vkCmdSetViewport() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06001985 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06001986 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001987 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06001988 pCB->viewports.resize(viewportCount);
1989 memcpy(pCB->viewports.data(), pViewports, viewportCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06001990 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06001991 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001992 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetViewport()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06001993 }
1994 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001995 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06001996 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
1997}
1998
1999VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
2000 VkCmdBuffer cmdBuffer,
2001 uint32_t scissorCount,
2002 const VkRect2D* pScissors)
2003{
2004 VkBool32 skipCall = VK_FALSE;
2005 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2006 if (pCB) {
2007 if (pCB->state == CB_UPDATE_ACTIVE) {
2008 updateCBTracking(cmdBuffer);
2009 skipCall |= addCmd(pCB, CMD_SETSCISSORSTATE);
2010 if (!pCB->activeRenderPass) {
2011 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2012 "Incorrect call to vkCmdSetScissor() without an active RenderPass.");
2013 }
2014 loader_platform_thread_lock_mutex(&globalLock);
2015 pCB->status |= CBSTATUS_SCISSOR_SET;
2016 pCB->scissors.resize(scissorCount);
2017 memcpy(pCB->scissors.data(), pScissors, scissorCount);
2018 loader_platform_thread_unlock_mutex(&globalLock);
2019 } else {
2020 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetScissor()");
2021 }
2022 }
2023 if (VK_FALSE == skipCall)
2024 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002025}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002026
2027VK_LAYER_EXPORT void VKAPI vkCmdSetLineWidth(VkCmdBuffer cmdBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002028{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002029 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002030 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2031 if (pCB) {
2032 if (pCB->state == CB_UPDATE_ACTIVE) {
2033 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002034 skipCall |= addCmd(pCB, CMD_SETLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002035 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002036 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002037 "Incorrect call to vkCmdSetLineWidth() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002038 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002039 /* TODO: Do we still need this lock? */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002040 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002041 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
2042 pCB->lineWidth = lineWidth;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002043 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002044 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002045 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002046 }
2047 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002048 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002049 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetLineWidth(cmdBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06002050}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002051
2052VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBias(
2053 VkCmdBuffer cmdBuffer,
2054 float depthBias,
2055 float depthBiasClamp,
2056 float slopeScaledDepthBias)
Cody Northropf5bd2252015-08-17 11:10:49 -06002057{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002058 VkBool32 skipCall = VK_FALSE;
Cody Northropf5bd2252015-08-17 11:10:49 -06002059 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2060 if (pCB) {
2061 if (pCB->state == CB_UPDATE_ACTIVE) {
2062 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002063 skipCall |= addCmd(pCB, CMD_SETDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002064 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002065 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002066 "Incorrect call to vkCmdSetDepthBias() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002067 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002068 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
2069 pCB->depthBias = depthBias;
2070 pCB->depthBiasClamp = depthBiasClamp;
2071 pCB->slopeScaledDepthBias = slopeScaledDepthBias;
Cody Northropf5bd2252015-08-17 11:10:49 -06002072 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002073 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002074 }
2075 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002076 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002077 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBias(cmdBuffer, depthBias, depthBiasClamp, slopeScaledDepthBias);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002078}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002079
2080VK_LAYER_EXPORT void VKAPI vkCmdSetBlendConstants(VkCmdBuffer cmdBuffer, const float blendConst[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002081{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002082 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002083 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2084 if (pCB) {
2085 if (pCB->state == CB_UPDATE_ACTIVE) {
2086 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002087 skipCall |= addCmd(pCB, CMD_SETBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002088 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002089 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002090 "Incorrect call to vkSetBlendConstants() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002091 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002092 pCB->status |= CBSTATUS_BLEND_SET;
2093 memcpy(pCB->blendConst, blendConst, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002094 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002095 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002096 }
2097 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002098 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002099 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetBlendConstants(cmdBuffer, blendConst);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002100}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002101
2102VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBounds(
2103 VkCmdBuffer cmdBuffer,
2104 float minDepthBounds,
2105 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002106{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002107 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002108 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2109 if (pCB) {
2110 if (pCB->state == CB_UPDATE_ACTIVE) {
2111 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002112 skipCall |= addCmd(pCB, CMD_SETDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002113 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002114 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002115 "Incorrect call to vkCmdSetDepthBounds() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002116 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002117 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
2118 pCB->minDepthBounds = minDepthBounds;
2119 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002120 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002121 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBounds()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002122 }
2123 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002124 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002125 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBounds(cmdBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06002126}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002127
2128VK_LAYER_EXPORT void VKAPI vkCmdSetStencilCompareMask(
2129 VkCmdBuffer cmdBuffer,
2130 VkStencilFaceFlags faceMask,
2131 uint32_t stencilCompareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06002132{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002133 VkBool32 skipCall = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -06002134 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2135 if (pCB) {
2136 if (pCB->state == CB_UPDATE_ACTIVE) {
2137 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002138 skipCall |= addCmd(pCB, CMD_SETSTENCILREADMASKSTATE);
Cody Northrop2605cb02015-08-18 15:21:16 -06002139 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002140 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002141 "Incorrect call to vkCmdSetStencilCompareMask() without an active RenderPass.");
Cody Northrop2605cb02015-08-18 15:21:16 -06002142 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002143 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2144 pCB->front.stencilCompareMask = stencilCompareMask;
Cody Northrop2605cb02015-08-18 15:21:16 -06002145 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002146 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2147 pCB->back.stencilCompareMask = stencilCompareMask;
2148 }
2149 /* TODO: Do we need to track front and back separately? */
2150 /* TODO: We aren't capturing the faceMask, do we need to? */
2151 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop2605cb02015-08-18 15:21:16 -06002152 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002153 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002154 }
2155 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002156 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002157 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilCompareMask(cmdBuffer, faceMask, stencilCompareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002158}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002159
2160VK_LAYER_EXPORT void VKAPI vkCmdSetStencilWriteMask(
2161 VkCmdBuffer cmdBuffer,
2162 VkStencilFaceFlags faceMask,
2163 uint32_t stencilWriteMask)
2164{
2165 VkBool32 skipCall = VK_FALSE;
2166 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2167 if (pCB) {
2168 if (pCB->state == CB_UPDATE_ACTIVE) {
2169 updateCBTracking(cmdBuffer);
2170 skipCall |= addCmd(pCB, CMD_SETSTENCILWRITEMASKSTATE);
2171 if (!pCB->activeRenderPass) {
2172 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2173 "Incorrect call to vkCmdSetStencilWriteMask() without an active RenderPass.");
2174 }
2175 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2176 pCB->front.stencilWriteMask = stencilWriteMask;
2177 }
2178 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2179 pCB->back.stencilWriteMask = stencilWriteMask;
2180 }
2181 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
2182 } else {
2183 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilWriteMask()");
2184 }
2185 }
2186 if (VK_FALSE == skipCall)
2187 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilWriteMask(cmdBuffer, faceMask, stencilWriteMask);
2188}
2189
2190VK_LAYER_EXPORT void VKAPI vkCmdSetStencilReference(
2191 VkCmdBuffer cmdBuffer,
2192 VkStencilFaceFlags faceMask,
2193 uint32_t stencilReference)
2194{
2195 VkBool32 skipCall = VK_FALSE;
2196 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2197 if (pCB) {
2198 if (pCB->state == CB_UPDATE_ACTIVE) {
2199 updateCBTracking(cmdBuffer);
2200 skipCall |= addCmd(pCB, CMD_SETSTENCILREFERENCESTATE);
2201 if (!pCB->activeRenderPass) {
2202 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2203 "Incorrect call to vkCmdSetStencilReference() without an active RenderPass.");
2204 }
2205 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2206 pCB->front.stencilReference = stencilReference;
2207 }
2208 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2209 pCB->back.stencilReference = stencilReference;
2210 }
2211 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
2212 } else {
2213 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilReference()");
2214 }
2215 }
2216 if (VK_FALSE == skipCall)
2217 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilReference(cmdBuffer, faceMask, stencilReference);
2218}
2219
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002220VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t setCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002221{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002222 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002223 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2224 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002225 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002226 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002227 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002228 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002229 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002230 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06002231 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002232 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002233 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002234 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2235 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002236 loader_platform_thread_lock_mutex(&globalLock);
2237 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002238 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002239 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2240 g_lastBoundDescriptorSet = pDescriptorSets[i];
2241 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002242 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002243 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002244 if (!pSet->pUpdateStructs)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002245 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_DESCRIPTOR_SET_NOT_UPDATED, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002246 "DS %#" PRIxLEAST64 " bound but it was never updated. You may want to either update it or not bind it.", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002247 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002248 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_INVALID_SET, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002249 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002250 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002251 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002252 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002253 skipCall |= addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002254 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002255 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002256 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002257 }
2258 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002259 if (VK_FALSE == skipCall)
2260 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002261}
2262
Tony Barbour8205d902015-04-16 15:59:00 -06002263VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002264{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002265 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002266 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2267 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002268 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002269 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002270 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06002271 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002272 }
2273 VkDeviceSize offset_align = 0;
2274 switch (indexType) {
2275 case VK_INDEX_TYPE_UINT16:
2276 offset_align = 2;
2277 break;
2278 case VK_INDEX_TYPE_UINT32:
2279 offset_align = 4;
2280 break;
2281 default:
2282 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
2283 break;
2284 }
2285 if (!offset_align || (offset % offset_align)) {
2286 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
2287 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06002288 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002289 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002290 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002291 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002292 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
2293 updateCBTracking(cmdBuffer);
2294 skipCall |= addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002295 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002296 if (VK_FALSE == skipCall)
2297 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002298}
2299
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002300VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2301 VkCmdBuffer cmdBuffer,
2302 uint32_t startBinding,
2303 uint32_t bindingCount,
2304 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002305 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002306{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002307 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002308 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2309 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002310 if (pCB->state == CB_UPDATE_ACTIVE) {
2311 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002312 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002313 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlise4076782015-06-24 15:53:07 -06002314 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2315 } else {
2316 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002317 updateCBTracking(cmdBuffer);
2318 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002319 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002320 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002321 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002322 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002323 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002324 if (VK_FALSE == skipCall)
2325 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002326}
2327
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002328VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002329{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002330 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002331 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2332 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002333 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002334 pCB->drawCount[DRAW]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002335 skipCall |= validate_draw_state(pCB, VK_FALSE);
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -06002336 /* TODOVV: Check that scissor and viewport counts are the same */
2337 /* TODOVV: Do we need to check that viewportCount given in pipeline's
2338 * VkPipelineViewportStateCreateInfo matches scissor & viewport counts
2339 * given as dynamic state? Or is the count given in VkPipelineViewportStateCreateInfo
2340 * simply indicate the number of viewport / scissor to use at this time?
2341 */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002342 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002343 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002344 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002345 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2346 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002347 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002348 skipCall |= addCmd(pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002349 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002350 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002351 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002352 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002353 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002354 if (VK_FALSE == skipCall)
2355 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, firstVertex, vertexCount, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002356}
2357
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002358VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359{
2360 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002361 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002363 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002364 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002365 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002366 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002367 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002368 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002369 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2370 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002371 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002372 skipCall |= addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002373 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002374 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002375 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002376 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002377 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002378 if (VK_FALSE == skipCall)
2379 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, firstIndex, indexCount, vertexOffset, firstInstance, instanceCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002380}
2381
Tony Barbour8205d902015-04-16 15:59:00 -06002382VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002383{
2384 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002385 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002386 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002387 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002388 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002389 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002390 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002391 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002392 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002393 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2394 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002395 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002396 skipCall |= addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002397 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002398 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002399 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002400 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002401 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002402 if (VK_FALSE == skipCall)
2403 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002404}
2405
Tony Barbour8205d902015-04-16 15:59:00 -06002406VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002407{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002408 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002409 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2410 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002411 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002412 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002413 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002414 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002415 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlise42007c2015-06-19 13:00:59 -06002416 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002417 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2418 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002419 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002420 skipCall |= addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002421 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002422 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002423 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002424 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002425 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002426 if (VK_FALSE == skipCall)
2427 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002428}
2429
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002430VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002431{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002432 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002433 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2434 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002435 if (pCB->state == CB_UPDATE_ACTIVE) {
2436 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002437 skipCall |= addCmd(pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002438 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002439 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002440 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002441 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002442 if (VK_FALSE == skipCall)
2443 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002444}
2445
Tony Barbour8205d902015-04-16 15:59:00 -06002446VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002447{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002448 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002449 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2450 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002451 if (pCB->state == CB_UPDATE_ACTIVE) {
2452 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002453 skipCall |= addCmd(pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002454 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002455 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002456 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002457 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002458 if (VK_FALSE == skipCall)
2459 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002460}
2461
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002462VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002464 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002465 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2466 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002467 if (pCB->state == CB_UPDATE_ACTIVE) {
2468 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002469 skipCall |= addCmd(pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002470 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002471 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002472 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002473 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002474 if (VK_FALSE == skipCall)
2475 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002476}
2477
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002478VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2479 VkImage srcImage,
2480 VkImageLayout srcImageLayout,
2481 VkImage destImage,
2482 VkImageLayout destImageLayout,
2483 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002485 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002486 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2487 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002488 if (pCB->state == CB_UPDATE_ACTIVE) {
2489 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002490 skipCall |= addCmd(pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002491 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002492 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002493 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002494 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002495 if (VK_FALSE == skipCall)
2496 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002497}
2498
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002499VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2500 VkImage srcImage, VkImageLayout srcImageLayout,
2501 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002502 uint32_t regionCount, const VkImageBlit* pRegions,
2503 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002504{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002505 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002506 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2507 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002508 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002509 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002510 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002511 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002512 } else {
2513 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002514 skipCall |= addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002515 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002516 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002517 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002518 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002519 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002520 if (VK_FALSE == skipCall)
2521 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002522}
2523
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002524VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2525 VkBuffer srcBuffer,
2526 VkImage destImage, VkImageLayout destImageLayout,
2527 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002528{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002529 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002530 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2531 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002532 if (pCB->state == CB_UPDATE_ACTIVE) {
2533 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002534 skipCall |= addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002535 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002536 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002537 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002538 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002539 if (VK_FALSE == skipCall)
2540 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002541}
2542
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002543VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2544 VkImage srcImage, VkImageLayout srcImageLayout,
2545 VkBuffer destBuffer,
2546 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002547{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002548 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002549 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2550 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002551 if (pCB->state == CB_UPDATE_ACTIVE) {
2552 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002553 skipCall |= addCmd(pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002554 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002555 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002556 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002557 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002558 if (VK_FALSE == skipCall)
2559 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002560}
2561
Tony Barbour8205d902015-04-16 15:59:00 -06002562VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002563{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002564 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002565 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2566 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002567 if (pCB->state == CB_UPDATE_ACTIVE) {
2568 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002569 skipCall |= addCmd(pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002570 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002571 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002572 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002573 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002574 if (VK_FALSE == skipCall)
2575 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002576}
2577
Tony Barbour8205d902015-04-16 15:59:00 -06002578VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002579{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002580 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002581 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2582 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002583 if (pCB->state == CB_UPDATE_ACTIVE) {
2584 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002585 skipCall |= addCmd(pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002586 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002587 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002588 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002589 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002590 if (VK_FALSE == skipCall)
2591 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002592}
2593
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002594VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2595 VkCmdBuffer cmdBuffer,
2596 uint32_t colorAttachment,
2597 VkImageLayout imageLayout,
2598 const VkClearColorValue* pColor,
2599 uint32_t rectCount,
2600 const VkRect3D* pRects)
2601{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002602 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002603 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2604 if (pCB) {
2605 if (pCB->state == CB_UPDATE_ACTIVE) {
2606 // Warn if this is issued prior to Draw Cmd
2607 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002608 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002609 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002610 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002611 " It is recommended you use RenderPass LOAD_OP_CLEAR on Color Attachments prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002612 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002613 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002614 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002615 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearColorAttachment() must only be called inside of a RenderPass."
2616 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2617 } else {
2618 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002619 skipCall |= addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002620 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002621 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002622 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002623 }
2624 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002625 if (VK_FALSE == skipCall)
2626 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002627}
2628
2629VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2630 VkCmdBuffer cmdBuffer,
2631 VkImageAspectFlags imageAspectMask,
2632 VkImageLayout imageLayout,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002633 const VkClearDepthStencilValue* pDepthStencil,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002634 uint32_t rectCount,
2635 const VkRect3D* pRects)
2636{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002637 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002638 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2639 if (pCB) {
2640 if (pCB->state == CB_UPDATE_ACTIVE) {
2641 // Warn if this is issued prior to Draw Cmd
2642 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002643 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002644 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_CLEAR_CMD_BEFORE_DRAW, "DS",
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002645 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002646 " It is recommended you use RenderPass LOAD_OP_CLEAR on DS Attachment prior to any Draw.", reinterpret_cast<uint64_t>(cmdBuffer));
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002647 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002648 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002649 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002650 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2651 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2652 } else {
2653 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002654 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002655 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002656 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002657 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002658 }
2659 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002660 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002661 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, pDepthStencil, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002662}
2663
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002664VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2665 VkCmdBuffer cmdBuffer,
2666 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002667 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002668 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002669{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002670 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002671 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2672 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002673 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002674 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002675 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002676 "Clear*Image cmd issued with an active RenderPass. vkCmdClearColorImage() must only be called outside of a RenderPass."
2677 " vkCmdClearColorAttachment() should be used within a RenderPass.");
2678 } else {
2679 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002680 skipCall |= addCmd(pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002681 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002682 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002683 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002684 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002685 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002686 if (VK_FALSE == skipCall)
2687 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002688}
2689
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002690VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(
2691 VkCmdBuffer cmdBuffer,
2692 VkImage image, VkImageLayout imageLayout,
2693 const VkClearDepthStencilValue *pDepthStencil,
2694 uint32_t rangeCount,
2695 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002696{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002697 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002698 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2699 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002700 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002701 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002702 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis92a89912015-06-23 11:34:28 -06002703 "Clear*Image cmd issued with an active RenderPass. vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
2704 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2705 } else {
2706 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002707 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002708 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002709 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002710 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002711 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002712 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002713 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002714 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002715}
2716
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002717VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2718 VkImage srcImage, VkImageLayout srcImageLayout,
2719 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002720 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002721{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002722 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002723 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2724 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002725 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002726 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002727 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002728 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002729 } else {
2730 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002731 skipCall |= addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002732 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002733 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002734 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002735 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002736 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002737 if (VK_FALSE == skipCall)
2738 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002739}
2740
Tony Barbourc2e987e2015-06-29 16:20:35 -06002741VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002742{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002743 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002744 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2745 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002746 if (pCB->state == CB_UPDATE_ACTIVE) {
2747 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002748 skipCall |= addCmd(pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002749 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002750 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002751 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002752 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002753 if (VK_FALSE == skipCall)
2754 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002755}
2756
Tony Barbourc2e987e2015-06-29 16:20:35 -06002757VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002758{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002759 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002760 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2761 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002762 if (pCB->state == CB_UPDATE_ACTIVE) {
2763 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002764 skipCall |= addCmd(pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002765 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002766 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002767 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002768 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002769 if (VK_FALSE == skipCall)
2770 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002771}
2772
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002773VK_LAYER_EXPORT void VKAPI vkCmdWaitEvents(VkCmdBuffer cmdBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags destStageMask, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002774{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002775 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002776 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2777 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002778 if (pCB->state == CB_UPDATE_ACTIVE) {
2779 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002780 skipCall |= addCmd(pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002781 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002782 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002783 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002784 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002785 if (VK_FALSE == skipCall)
2786 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002787}
2788
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002789VK_LAYER_EXPORT void VKAPI vkCmdPipelineBarrier(VkCmdBuffer cmdBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags destStageMask, VkBool32 byRegion, uint32_t memBarrierCount, const void* const* ppMemBarriers)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002790{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002791 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002792 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2793 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002794 if (pCB->state == CB_UPDATE_ACTIVE) {
2795 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002796 skipCall |= addCmd(pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002797 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002798 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002799 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002800 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002801 if (VK_FALSE == skipCall)
2802 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002803}
2804
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002805VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002806{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002807 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002808 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2809 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002810 if (pCB->state == CB_UPDATE_ACTIVE) {
2811 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002812 skipCall |= addCmd(pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002813 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002814 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002815 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002816 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002817 if (VK_FALSE == skipCall)
2818 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002819}
2820
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002821VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002822{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002823 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002824 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2825 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002826 if (pCB->state == CB_UPDATE_ACTIVE) {
2827 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002828 skipCall |= addCmd(pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002829 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002830 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002831 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002832 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002833 if (VK_FALSE == skipCall)
2834 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002835}
2836
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002837VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002838{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002839 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002840 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2841 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002842 if (pCB->state == CB_UPDATE_ACTIVE) {
2843 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002844 skipCall |= addCmd(pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002845 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002846 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002847 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002848 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002849 if (VK_FALSE == skipCall)
2850 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002851}
2852
Tony Barbour8205d902015-04-16 15:59:00 -06002853VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002854{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002855 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2857 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002858 if (pCB->state == CB_UPDATE_ACTIVE) {
2859 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002860 skipCall |= addCmd(pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002861 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002862 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002863 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002864 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002865 if (VK_FALSE == skipCall)
2866 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002867}
2868
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002869VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002870{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002871 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002872 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002873 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002874 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002875 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002876 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2877 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002878 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002879 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002880 }
2881 return result;
2882}
2883
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002884VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002885{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002886 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002887 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002888 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002889 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002890 if (pCreateInfo->pAttachments) {
2891 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2892 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002893 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002894 if (pCreateInfo->pSubpasses) {
2895 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2896 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2897
2898 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2899 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2900 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002901 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002902 subpass->preserveCount;
2903 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2904
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002905 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002906 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002907 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002908 attachments += subpass->inputCount;
2909
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002910 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002911 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002912 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002913 attachments += subpass->colorCount;
2914
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002915 if (subpass->pResolveAttachments) {
2916 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002917 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002918 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002919 attachments += subpass->colorCount;
2920 }
2921
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002922 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002923 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002924 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002925 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002926 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002927 if (pCreateInfo->pDependencies) {
2928 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2929 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002930 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002931 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002932 }
2933 return result;
2934}
2935
Chia-I Wuc278df82015-07-07 11:50:03 +08002936VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002937{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002938 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002939 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2940 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002941 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002942 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002943 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002944 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002945 } else {
2946 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002947 skipCall |= addCmd(pCB, CMD_BEGINRENDERPASS);
Tobin Ehlise4076782015-06-24 15:53:07 -06002948 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08002949 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06002950 pCB->framebuffer = pRenderPassBegin->framebuffer;
2951 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002952 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002953 }
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002954 }
Tobin Ehlise4076782015-06-24 15:53:07 -06002955 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002956 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_RENDERPASS, "DS",
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06002957 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06002958 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002959 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002960 if (VK_FALSE == skipCall)
2961 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002962}
2963
Chia-I Wuc278df82015-07-07 11:50:03 +08002964VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
2965{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002966 VkBool32 skipCall = VK_FALSE;
Chia-I Wuc278df82015-07-07 11:50:03 +08002967 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2968 if (pCB) {
2969 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002970 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wuc278df82015-07-07 11:50:03 +08002971 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
2972 } else {
2973 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002974 skipCall |= addCmd(pCB, CMD_NEXTSUBPASS);
Chia-I Wuc278df82015-07-07 11:50:03 +08002975 pCB->activeSubpass++;
2976 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002977 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08002978 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002979 }
2980 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002981 if (VK_FALSE == skipCall)
2982 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08002983}
2984
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002985VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002986{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002987 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002988 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2989 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002990 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002991 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002992 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06002993 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002994 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002995 skipCall |= addCmd(pCB, CMD_ENDRENDERPASS);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002996 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08002997 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08002998 }
2999 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003000 if (VK_FALSE == skipCall)
3001 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003002}
3003
3004VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3005{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003006 VkBool32 skipCall = VK_FALSE;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003007 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3008 if (pCB) {
3009 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003010 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003011 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003012 }
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003013 GLOBAL_CB_NODE* pSubCB = NULL;
3014 for (uint32_t i=0; i<cmdBuffersCount; i++) {
3015 pSubCB = getCBNode(pCmdBuffers[i]);
3016 if (!pSubCB) {
3017 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3018 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCmdBuffers array.", (void*)pCmdBuffers[i], i);
3019 } else if (VK_CMD_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
3020 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3021 "vkCmdExecuteCommands() called w/ Primary Cmd Buffer %p in element %u of pCmdBuffers array. All cmd buffers in pCmdBuffers array must be secondary.", (void*)pCmdBuffers[i], i);
3022 }
3023 }
3024 updateCBTracking(cmdBuffer);
3025 skipCall |= addCmd(pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003026 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003027 if (VK_FALSE == skipCall)
3028 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003029}
3030
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003031VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3032 VkInstance instance,
3033 VkFlags msgFlags,
3034 const PFN_vkDbgMsgCallback pfnMsgCallback,
3035 void* pUserData,
3036 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003037{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003038 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003039 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3040 if (VK_SUCCESS == res) {
3041 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3042 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3043 }
3044 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003045}
3046
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003047VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3048 VkInstance instance,
3049 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003050{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003051 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003052 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3053 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3054 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3055 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003056}
3057
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003058VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003059{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003060 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003061 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003062 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3063 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003064 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003065 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003066 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003067 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003068 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003069 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003070 skipCall |= addCmd(pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003071 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003072 if (VK_FALSE == skipCall)
3073 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003074}
3075
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003076VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003077{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003078 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003079 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003080 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3081 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003082 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003083 skipCall |= log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003084 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003085 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003086 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003087 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003088 skipCall |= addCmd(pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003089 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003090 if (VK_FALSE == skipCall)
3091 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003092}
3093
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003094//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3095//{
3096// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3097// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3098// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3099// "Attempt to use DbgSetObjectTag but extension disabled!");
3100// return VK_ERROR_UNAVAILABLE;
3101// }
3102// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3103//}
3104//
3105//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3106//{
3107// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3108// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3109// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3110// "Attempt to use DbgSetObjectName but extension disabled!");
3111// return VK_ERROR_UNAVAILABLE;
3112// }
3113// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3114//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003115
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003116VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003117{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003118 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003119 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003120
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003121 /* loader uses this to force layer initialization; device object is wrapped */
3122 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003123 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003124 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003125 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003126 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003128 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003130 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003132 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003134 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003136 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003138 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003140 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003142 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003143 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003144 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003145 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003146 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003147 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003148 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003150 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003152 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003154 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003155 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003156 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003157 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003158 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003159 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003160 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003161 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003162 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003163 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003164 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003165 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003166 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003167 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003168 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003169 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003170 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003171 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003172 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003173 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003174 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003175 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003176 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003177 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003178 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003179 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003180 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003181 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003182 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003183 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003184 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003185 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003186 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003187 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003188 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003189 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003190 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003191 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003192 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003193 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003194 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003195 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003196 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003197 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003198 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003199 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003200 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003201 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003202 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003204 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003206 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003208 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003209 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003210 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003211 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003212 if (!strcmp(funcName, "vkCmdSetViewport"))
3213 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003214 if (!strcmp(funcName, "vkCmdSetScissor"))
3215 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003216 if (!strcmp(funcName, "vkCmdSetLineWidth"))
3217 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
3218 if (!strcmp(funcName, "vkCmdSetDepthBias"))
3219 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
3220 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
3221 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
3222 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
3223 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
3224 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
3225 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
3226 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
3227 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
3228 if (!strcmp(funcName, "vkCmdSetStencilReference"))
3229 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003230 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003232 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003234 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003236 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003238 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003240 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003242 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003243 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003244 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003245 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003246 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003247 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003248 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003249 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003250 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003251 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003252 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003253 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003254 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003256 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003258 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003260 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003262 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003264 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003265 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003266 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003267 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003268 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003269 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003270 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003271 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003272 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003273 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003274 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003276 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003278 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003280 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003282 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003284 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003286 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003287 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003288 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003289 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003290 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003291 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003292 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003293 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003294 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003295 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003296 if (!strcmp(funcName, "vkCmdExecuteCommands"))
3297 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003298
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003299 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3300 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003301 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003302 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003303 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003304 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003305 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003306// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3307// return (void*) vkDbgSetObjectTag;
3308// if (!strcmp(funcName, "vkDbgSetObjectName"))
3309// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003310 }
3311 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003312 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003313 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003314 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003315 }
3316}
3317
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003318VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003319{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003320 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003321 if (instance == NULL)
3322 return NULL;
3323
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003324 /* loader uses this to force layer initialization; instance object is wrapped */
3325 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003326 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003327 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003328 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003329 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003330 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003331 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003332 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06003333 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
3334 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
3335 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
3336 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
3337 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
3338 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
3339 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
3340 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003341
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003342 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3343 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003344 if (fptr)
3345 return fptr;
3346
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003347 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003348 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003349 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003350 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003351 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003352 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003353}