blob: 239a9b0ef460a7412b24599937396b3062978fba [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
Cody Northrop73bb6572015-09-28 15:09:32 -060053struct layer_data {
Tobin Ehlisc91330b2015-06-16 09:04:30 -060054 debug_report_data *report_data;
55 // TODO: put instance data here
56 VkDbgMsgCallback logging_callback;
Cody Northrop73bb6572015-09-28 15:09:32 -060057
58 layer_data() :
59 report_data(nullptr),
60 logging_callback(nullptr)
61 {};
62};
Tobin Ehlisc91330b2015-06-16 09:04:30 -060063
64static std::unordered_map<void *, layer_data *> layer_data_map;
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -060065static device_table_map draw_state_device_table_map;
66static instance_table_map draw_state_instance_table_map;
67
Mike Stroyan74b430c2015-09-11 13:29:21 -060068static unordered_map<uint64_t, SAMPLER_NODE*> sampleMap;
69static unordered_map<uint64_t, VkImageViewCreateInfo> imageMap;
70static unordered_map<uint64_t, VkImageViewCreateInfo> viewMap;
71static unordered_map<uint64_t, BUFFER_NODE*> bufferMap;
Mike Stroyan74b430c2015-09-11 13:29:21 -060072static unordered_map<uint64_t, PIPELINE_NODE*> pipelineMap;
73static unordered_map<uint64_t, POOL_NODE*> poolMap;
74static unordered_map<uint64_t, SET_NODE*> setMap;
75static unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -060076// Map for layout chains
Mike Stroyan74b430c2015-09-11 13:29:21 -060077static unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
78static unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
79static unordered_map<uint64_t, VkFramebufferCreateInfo*> frameBufferMap;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060080
Jon Ashburn6f8cd632015-06-01 09:37:38 -060081struct devExts {
82 bool debug_marker_enabled;
83};
84
Jon Ashburn6f8cd632015-06-01 09:37:38 -060085static std::unordered_map<void *, struct devExts> deviceExtMap;
Jon Ashburne0fa2282015-05-20 09:00:28 -060086
Tobin Ehlis63bb9482015-03-17 16:24:32 -060087static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburnd9564002015-05-07 10:27:37 -060088
Tobin Ehlis63bb9482015-03-17 16:24:32 -060089// TODO : This can be much smarter, using separate locks for separate global data
90static int globalLockInitialized = 0;
91static loader_platform_thread_mutex globalLock;
Tobin Ehlis63bb9482015-03-17 16:24:32 -060092#define MAX_TID 513
93static loader_platform_thread_id g_tidMapping[MAX_TID] = {0};
94static uint32_t g_maxTID = 0;
Tobin Ehlisfde4dce2015-06-16 15:50:44 -060095
96template layer_data *get_my_data_ptr<layer_data>(
97 void *data_key,
98 std::unordered_map<void *, layer_data *> &data_map);
99
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600100debug_report_data *mdd(void* object)
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600101{
102 dispatch_key key = get_dispatch_key(object);
103 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
104#if DISPATCH_MAP_DEBUG
105 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
106#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600107 return my_data->report_data;
108}
109
110debug_report_data *mid(VkInstance object)
111{
112 dispatch_key key = get_dispatch_key(object);
Tobin Ehlis8354e022015-09-01 11:46:36 -0600113 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600114#if DISPATCH_MAP_DEBUG
115 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
116#endif
Tobin Ehlisfde4dce2015-06-16 15:50:44 -0600117 return my_data->report_data;
118}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600119// Map actual TID to an index value and return that index
120// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs
121static uint32_t getTIDIndex() {
122 loader_platform_thread_id tid = loader_platform_get_thread_id();
123 for (uint32_t i = 0; i < g_maxTID; i++) {
124 if (tid == g_tidMapping[i])
125 return i;
126 }
127 // Don't yet have mapping, set it and return newly set index
128 uint32_t retVal = (uint32_t) g_maxTID;
129 g_tidMapping[g_maxTID++] = tid;
130 assert(g_maxTID < MAX_TID);
131 return retVal;
132}
133// Return a string representation of CMD_TYPE enum
134static string cmdTypeToString(CMD_TYPE cmd)
135{
136 switch (cmd)
137 {
138 case CMD_BINDPIPELINE:
139 return "CMD_BINDPIPELINE";
140 case CMD_BINDPIPELINEDELTA:
141 return "CMD_BINDPIPELINEDELTA";
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600142 case CMD_SETVIEWPORTSTATE:
143 return "CMD_SETVIEWPORTSTATE";
144 case CMD_SETLINEWIDTHSTATE:
145 return "CMD_SETLINEWIDTHSTATE";
146 case CMD_SETDEPTHBIASSTATE:
147 return "CMD_SETDEPTHBIASSTATE";
148 case CMD_SETBLENDSTATE:
149 return "CMD_SETBLENDSTATE";
150 case CMD_SETDEPTHBOUNDSSTATE:
151 return "CMD_SETDEPTHBOUNDSSTATE";
152 case CMD_SETSTENCILREADMASKSTATE:
153 return "CMD_SETSTENCILREADMASKSTATE";
154 case CMD_SETSTENCILWRITEMASKSTATE:
155 return "CMD_SETSTENCILWRITEMASKSTATE";
156 case CMD_SETSTENCILREFERENCESTATE:
157 return "CMD_SETSTENCILREFERENCESTATE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600158 case CMD_BINDDESCRIPTORSETS:
159 return "CMD_BINDDESCRIPTORSETS";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600160 case CMD_BINDINDEXBUFFER:
161 return "CMD_BINDINDEXBUFFER";
162 case CMD_BINDVERTEXBUFFER:
163 return "CMD_BINDVERTEXBUFFER";
164 case CMD_DRAW:
165 return "CMD_DRAW";
166 case CMD_DRAWINDEXED:
167 return "CMD_DRAWINDEXED";
168 case CMD_DRAWINDIRECT:
169 return "CMD_DRAWINDIRECT";
170 case CMD_DRAWINDEXEDINDIRECT:
171 return "CMD_DRAWINDEXEDINDIRECT";
172 case CMD_DISPATCH:
173 return "CMD_DISPATCH";
174 case CMD_DISPATCHINDIRECT:
175 return "CMD_DISPATCHINDIRECT";
176 case CMD_COPYBUFFER:
177 return "CMD_COPYBUFFER";
178 case CMD_COPYIMAGE:
179 return "CMD_COPYIMAGE";
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600180 case CMD_BLITIMAGE:
181 return "CMD_BLITIMAGE";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600182 case CMD_COPYBUFFERTOIMAGE:
183 return "CMD_COPYBUFFERTOIMAGE";
184 case CMD_COPYIMAGETOBUFFER:
185 return "CMD_COPYIMAGETOBUFFER";
186 case CMD_CLONEIMAGEDATA:
187 return "CMD_CLONEIMAGEDATA";
188 case CMD_UPDATEBUFFER:
189 return "CMD_UPDATEBUFFER";
190 case CMD_FILLBUFFER:
191 return "CMD_FILLBUFFER";
192 case CMD_CLEARCOLORIMAGE:
193 return "CMD_CLEARCOLORIMAGE";
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600194 case CMD_CLEARCOLORATTACHMENT:
195 return "CMD_CLEARCOLORATTACHMENT";
196 case CMD_CLEARDEPTHSTENCILIMAGE:
197 return "CMD_CLEARDEPTHSTENCILIMAGE";
198 case CMD_CLEARDEPTHSTENCILATTACHMENT:
199 return "CMD_CLEARDEPTHSTENCILATTACHMENT";
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600200 case CMD_RESOLVEIMAGE:
201 return "CMD_RESOLVEIMAGE";
202 case CMD_SETEVENT:
203 return "CMD_SETEVENT";
204 case CMD_RESETEVENT:
205 return "CMD_RESETEVENT";
206 case CMD_WAITEVENTS:
207 return "CMD_WAITEVENTS";
208 case CMD_PIPELINEBARRIER:
209 return "CMD_PIPELINEBARRIER";
210 case CMD_BEGINQUERY:
211 return "CMD_BEGINQUERY";
212 case CMD_ENDQUERY:
213 return "CMD_ENDQUERY";
214 case CMD_RESETQUERYPOOL:
215 return "CMD_RESETQUERYPOOL";
216 case CMD_WRITETIMESTAMP:
217 return "CMD_WRITETIMESTAMP";
218 case CMD_INITATOMICCOUNTERS:
219 return "CMD_INITATOMICCOUNTERS";
220 case CMD_LOADATOMICCOUNTERS:
221 return "CMD_LOADATOMICCOUNTERS";
222 case CMD_SAVEATOMICCOUNTERS:
223 return "CMD_SAVEATOMICCOUNTERS";
224 case CMD_BEGINRENDERPASS:
225 return "CMD_BEGINRENDERPASS";
226 case CMD_ENDRENDERPASS:
227 return "CMD_ENDRENDERPASS";
228 case CMD_DBGMARKERBEGIN:
229 return "CMD_DBGMARKERBEGIN";
230 case CMD_DBGMARKEREND:
231 return "CMD_DBGMARKEREND";
232 default:
233 return "UNKNOWN";
234 }
235}
236// Block of code at start here for managing/tracking Pipeline state that this layer cares about
237// Just track 2 shaders for now
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600238#define VK_NUM_GRAPHICS_SHADERS VK_SHADER_STAGE_COMPUTE
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600239#define MAX_SLOTS 2048
240#define NUM_COMMAND_BUFFERS_TO_DISPLAY 10
241
242static uint64_t g_drawCount[NUM_DRAW_TYPES] = {0, 0, 0, 0};
243
244// TODO : Should be tracking lastBound per cmdBuffer and when draws occur, report based on that cmd buffer lastBound
245// Then need to synchronize the accesses based on cmd buffer so that if I'm reading state on one cmd buffer, updates
246// to that same cmd buffer by separate thread are not changing state from underneath us
247// Track the last cmd buffer touched by this thread
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600248static VkCmdBuffer g_lastCmdBuffer[MAX_TID] = {NULL};
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600249// Track the last group of CBs touched for displaying to dot file
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600250static GLOBAL_CB_NODE* g_pLastTouchedCB[NUM_COMMAND_BUFFERS_TO_DISPLAY] = {NULL};
251static uint32_t g_lastTouchedCBIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600252// Track the last global DrawState of interest touched by any thread
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600253static GLOBAL_CB_NODE* g_lastGlobalCB = NULL;
254static PIPELINE_NODE* g_lastBoundPipeline = NULL;
Dana Jansens4a3e0862015-07-30 13:22:15 -0700255static VkDescriptorSet g_lastBoundDescriptorSet = VK_NULL_HANDLE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600256#define MAX_BINDING 0xFFFFFFFF // Default vtxBinding value in CB Node to identify if no vtxBinding set
257
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600258// Free all sampler nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600259static void deleteSamplers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600260{
David Pinedof5997ab2015-04-27 16:36:17 -0600261 if (sampleMap.size() <= 0)
262 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600263 for (auto ii=sampleMap.begin(); ii!=sampleMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600264 delete (*ii).second;
265 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600266 sampleMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600267}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600268static VkImageViewCreateInfo* getImageViewCreateInfo(VkImageView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600269{
270 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600271 if (imageMap.find(view.handle) == imageMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600272 loader_platform_thread_unlock_mutex(&globalLock);
273 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600274 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600275 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600276 return &imageMap[view.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600277 }
278}
279// Free all image nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600280static void deleteImages()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600281{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600282 if (imageMap.size() <= 0)
David Pinedof5997ab2015-04-27 16:36:17 -0600283 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600284 imageMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600285}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600286static VkBufferViewCreateInfo* getBufferViewCreateInfo(VkBufferView view)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600287{
288 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600289 if (bufferMap.find(view.handle) == bufferMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600290 loader_platform_thread_unlock_mutex(&globalLock);
291 return NULL;
Tobin Ehlise42007c2015-06-19 13:00:59 -0600292 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600293 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600294 return &bufferMap[view.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600295 }
296}
297// Free all buffer nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600298static void deleteBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600299{
David Pinedof5997ab2015-04-27 16:36:17 -0600300 if (bufferMap.size() <= 0)
301 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600302 for (auto ii=bufferMap.begin(); ii!=bufferMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600303 delete (*ii).second;
304 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600305 bufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600306}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600307static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600308// Update global ptrs to reflect that specified cmdBuffer has been used
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600309static void updateCBTracking(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600310{
311 g_lastCmdBuffer[getTIDIndex()] = cb;
312 GLOBAL_CB_NODE* pCB = getCBNode(cb);
313 loader_platform_thread_lock_mutex(&globalLock);
314 g_lastGlobalCB = pCB;
315 // TODO : This is a dumb algorithm. Need smart LRU that drops off oldest
316 for (uint32_t i = 0; i < NUM_COMMAND_BUFFERS_TO_DISPLAY; i++) {
317 if (g_pLastTouchedCB[i] == pCB) {
318 loader_platform_thread_unlock_mutex(&globalLock);
319 return;
320 }
321 }
322 g_pLastTouchedCB[g_lastTouchedCBIndex++] = pCB;
323 g_lastTouchedCBIndex = g_lastTouchedCBIndex % NUM_COMMAND_BUFFERS_TO_DISPLAY;
324 loader_platform_thread_unlock_mutex(&globalLock);
325}
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600326static VkBool32 hasDrawCmd(GLOBAL_CB_NODE* pCB)
Tobin Ehlis8cd650e2015-07-01 16:46:13 -0600327{
328 for (uint32_t i=0; i<NUM_DRAW_TYPES; i++) {
329 if (pCB->drawCount[i])
330 return VK_TRUE;
331 }
332 return VK_FALSE;
333}
Tobin Ehlis97866202015-06-10 12:57:07 -0600334// Check object status for selected flag state
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600335static 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 -0600336{
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600337 // If non-zero enable mask is present, check it against status but if enable_mask
338 // is 0 then no enable required so we should always just check status
339 if ((!enable_mask) || (enable_mask & pNode->status)) {
340 if ((pNode->status & status_mask) != status_flag) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600341 // TODO : How to pass dispatchable objects as srcObject? Here src obj should be cmd buffer
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600342 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 -0600343 "CB object %#" PRIxLEAST64 ": %s", reinterpret_cast<uint64_t>(pNode->cmdBuffer), fail_msg);
Tobin Ehlis97866202015-06-10 12:57:07 -0600344 }
Tobin Ehlis97866202015-06-10 12:57:07 -0600345 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600346 return VK_FALSE;
Tobin Ehlis97866202015-06-10 12:57:07 -0600347}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600348// Retrieve pipeline node ptr for given pipeline object
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600349static PIPELINE_NODE* getPipeline(VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600350{
351 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600352 if (pipelineMap.find(pipeline.handle) == pipelineMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600353 loader_platform_thread_unlock_mutex(&globalLock);
354 return NULL;
355 }
356 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600357 return pipelineMap[pipeline.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600358}
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600359// Validate state stored as flags at time of draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600360static VkBool32 validate_draw_state_flags(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
361 VkBool32 result;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -0600362 result = validate_status(pCB, CBSTATUS_NONE, CBSTATUS_VIEWPORT_SET, CBSTATUS_VIEWPORT_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_VIEWPORT_NOT_BOUND, "Dynamic viewport state not set for this command buffer");
363 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_SCISSOR_SET, CBSTATUS_SCISSOR_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_STENCIL_NOT_BOUND, "Dynamic scissor state not set for this command buffer");
364 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_LINE_WIDTH_SET, CBSTATUS_LINE_WIDTH_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_LINE_WIDTH_NOT_BOUND, "Dynamic line width state not set for this command buffer");
365 result |= validate_status(pCB, CBSTATUS_NONE, CBSTATUS_DEPTH_BIAS_SET, CBSTATUS_DEPTH_BIAS_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_DEPTH_BIAS_NOT_BOUND, "Dynamic depth bias state not set for this command buffer");
366 result |= validate_status(pCB, CBSTATUS_COLOR_BLEND_WRITE_ENABLE, CBSTATUS_BLEND_SET, CBSTATUS_BLEND_SET, VK_DBG_REPORT_ERROR_BIT, DRAWSTATE_BLEND_NOT_BOUND, "Dynamic blend object state not set for this command buffer");
367 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, "Dynamic depth bounds state not set for this command buffer");
368 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, "Dynamic stencil read mask state not set for this command buffer");
369 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, "Dynamic stencil write mask state not set for this command buffer");
370 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, "Dynamic stencil reference state not set for this command buffer");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600371 if (indexedDraw)
Tobin Ehlisf6cb4672015-09-29 08:18:34 -0600372 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 Indexed Draw attempted");
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600373 return result;
374}
375// Validate overall state at the time of a draw call
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600376static VkBool32 validate_draw_state(GLOBAL_CB_NODE* pCB, VkBool32 indexedDraw) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600377 // First check flag states
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600378 VkBool32 result = validate_draw_state_flags(pCB, indexedDraw);
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600379 PIPELINE_NODE* pPipe = getPipeline(pCB->lastBoundPipeline);
380 // Now complete other state checks
Tobin Ehlis12ab7dc2015-09-09 13:31:01 -0600381 // TODO : Currently only performing next check if *something* was bound (non-zero last bound)
382 // There is probably a better way to gate when this check happens, and to know if something *should* have been bound
383 // We should have that check separately and then gate this check based on that check
384 if (pPipe && (pCB->lastBoundPipelineLayout) && (pCB->lastBoundPipelineLayout != pPipe->graphicsPipelineCI.layout)) {
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600385 result = VK_FALSE;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600386 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 -0600387 "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 -0600388 }
Tobin Ehlis451efca2015-06-23 11:22:55 -0600389 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600390 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 -0600391 "Draw cmd issued without an active RenderPass. vkCmdDraw*() must only be called within a RenderPass.");
392 }
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600393 // Verify Vtx binding
394 if (MAX_BINDING != pCB->lastVtxBinding) {
395 if (pCB->lastVtxBinding >= pPipe->vtxBindingCount) {
396 if (0 == pPipe->vtxBindingCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600397 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 -0600398 "Vtx Buffer Index %u was bound, but no vtx buffers are attached to PSO.", pCB->lastVtxBinding);
Tobin Ehlisd28acef2015-09-09 15:12:35 -0600399 }
400 else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600401 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 -0600402 "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 -0600403 }
404 }
405 }
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -0600406 return result;
407}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600408// For given sampler, return a ptr to its Create Info struct, or NULL if sampler not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409static VkSamplerCreateInfo* getSamplerCreateInfo(const VkSampler sampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600410{
411 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600412 if (sampleMap.find(sampler.handle) == sampleMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600413 loader_platform_thread_unlock_mutex(&globalLock);
414 return NULL;
415 }
416 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600417 return &sampleMap[sampler.handle]->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600418}
Tobin Ehlisde63c532015-06-18 15:59:33 -0600419// Verify that create state for a pipeline is valid
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600420static VkBool32 verifyPipelineCreateState(const VkDevice device, const PIPELINE_NODE* pPipeline)
Tobin Ehlisde63c532015-06-18 15:59:33 -0600421{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600422 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisde63c532015-06-18 15:59:33 -0600423 // VS is required
424 if (!(pPipeline->active_shaders & VK_SHADER_STAGE_VERTEX_BIT)) {
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: Vtx Shader required");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600427 }
428 // Either both or neither TC/TE shaders should be defined
429 if (((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) == 0) !=
430 ((pPipeline->active_shaders & VK_SHADER_STAGE_TESS_EVALUATION_BIT) == 0) ) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600431 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 -0600432 "Invalid Pipeline CreateInfo State: TE and TC shaders must be included or excluded as a pair");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600433 }
434 // Compute shaders should be specified independent of Gfx shaders
435 if ((pPipeline->active_shaders & VK_SHADER_STAGE_COMPUTE_BIT) &&
436 (pPipeline->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESS_CONTROL_BIT |
437 VK_SHADER_STAGE_TESS_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT |
438 VK_SHADER_STAGE_FRAGMENT_BIT))) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600439 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 -0600440 "Invalid Pipeline CreateInfo State: Do not specify Compute Shader for Gfx Pipeline");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600441 }
442 // VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines.
443 // Mismatching primitive topology and tessellation fails graphics pipeline creation.
444 if (pPipeline->active_shaders & (VK_SHADER_STAGE_TESS_CONTROL_BIT | VK_SHADER_STAGE_TESS_EVALUATION_BIT) &&
445 (pPipeline->iaStateCI.topology != VK_PRIMITIVE_TOPOLOGY_PATCH)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600446 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 -0600447 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH must be set as IA topology for tessellation pipelines");
Tobin Ehlisde63c532015-06-18 15:59:33 -0600448 }
Tobin Ehlis20693172015-09-17 08:46:18 -0600449 if (pPipeline->iaStateCI.topology == VK_PRIMITIVE_TOPOLOGY_PATCH) {
450 if (~pPipeline->active_shaders & VK_SHADER_STAGE_TESS_CONTROL_BIT) {
451 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 -0600452 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology is only valid for tessellation pipelines");
Tobin Ehlis20693172015-09-17 08:46:18 -0600453 }
454 if (!pPipeline->tessStateCI.patchControlPoints || (pPipeline->tessStateCI.patchControlPoints > 32)) {
455 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_PIPELINE_CREATE_STATE, "DS",
456 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH primitive topology used with patchControlPoints value %u."
457 " patchControlPoints should be >0 and <=32.", pPipeline->tessStateCI.patchControlPoints);
458 }
Tobin Ehlisde63c532015-06-18 15:59:33 -0600459 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600460 return skipCall;
Tobin Ehlisde63c532015-06-18 15:59:33 -0600461}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600462// Init the pipeline mapping info based on pipeline create info LL tree
463// Threading note : Calls to this function should wrapped in mutex
Tobin Ehlisde63c532015-06-18 15:59:33 -0600464static PIPELINE_NODE* initPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, PIPELINE_NODE* pBasePipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600465{
Tobin Ehlisde63c532015-06-18 15:59:33 -0600466 PIPELINE_NODE* pPipeline = new PIPELINE_NODE;
467 if (pBasePipeline) {
468 memcpy((void*)pPipeline, (void*)pBasePipeline, sizeof(PIPELINE_NODE));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600469 } else {
Tobin Ehlisde63c532015-06-18 15:59:33 -0600470 memset((void*)pPipeline, 0, sizeof(PIPELINE_NODE));
471 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600472 // First init create info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600473 memcpy(&pPipeline->graphicsPipelineCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600474
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600475 size_t bufferSize = 0;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600476 const VkPipelineVertexInputStateCreateInfo* pVICI = NULL;
Tobin Ehlis59db5712015-07-13 13:14:24 -0600477 const VkPipelineColorBlendStateCreateInfo* pCBCI = NULL;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600478
479 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
480 const VkPipelineShaderStageCreateInfo *pPSSCI = &pCreateInfo->pStages[i];
481
482 switch (pPSSCI->stage) {
483 case VK_SHADER_STAGE_VERTEX:
484 memcpy(&pPipeline->vsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
485 pPipeline->active_shaders |= VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600486 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600487 case VK_SHADER_STAGE_TESS_CONTROL:
488 memcpy(&pPipeline->tcsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
489 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_CONTROL_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600490 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600491 case VK_SHADER_STAGE_TESS_EVALUATION:
492 memcpy(&pPipeline->tesCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
493 pPipeline->active_shaders |= VK_SHADER_STAGE_TESS_EVALUATION_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600494 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600495 case VK_SHADER_STAGE_GEOMETRY:
496 memcpy(&pPipeline->gsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
497 pPipeline->active_shaders |= VK_SHADER_STAGE_GEOMETRY_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600498 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600499 case VK_SHADER_STAGE_FRAGMENT:
500 memcpy(&pPipeline->fsCI, pPSSCI, sizeof(VkPipelineShaderStageCreateInfo));
501 pPipeline->active_shaders |= VK_SHADER_STAGE_FRAGMENT_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600502 break;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600503 case VK_SHADER_STAGE_COMPUTE:
504 // TODO : Flag error, CS is specified through VkComputePipelineCreateInfo
505 pPipeline->active_shaders |= VK_SHADER_STAGE_COMPUTE_BIT;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600506 break;
507 default:
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600508 // TODO : Flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600509 break;
510 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600511 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -0600512 // Copy over GraphicsPipelineCreateInfo structure embedded pointers
513 if (pCreateInfo->stageCount != 0) {
514 pPipeline->graphicsPipelineCI.pStages = new VkPipelineShaderStageCreateInfo[pCreateInfo->stageCount];
515 bufferSize = pCreateInfo->stageCount * sizeof(VkPipelineShaderStageCreateInfo);
516 memcpy((void*)pPipeline->graphicsPipelineCI.pStages, pCreateInfo->pStages, bufferSize);
517 }
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600518 if (pCreateInfo->pVertexInputState != NULL) {
519 memcpy((void*)&pPipeline->vertexInputCI, pCreateInfo->pVertexInputState , sizeof(VkPipelineVertexInputStateCreateInfo));
520 // Copy embedded ptrs
521 pVICI = pCreateInfo->pVertexInputState;
522 pPipeline->vtxBindingCount = pVICI->bindingCount;
523 if (pPipeline->vtxBindingCount) {
524 pPipeline->pVertexBindingDescriptions = new VkVertexInputBindingDescription[pPipeline->vtxBindingCount];
525 bufferSize = pPipeline->vtxBindingCount * sizeof(VkVertexInputBindingDescription);
526 memcpy((void*)pPipeline->pVertexBindingDescriptions, pVICI->pVertexBindingDescriptions, bufferSize);
527 }
528 pPipeline->vtxAttributeCount = pVICI->attributeCount;
529 if (pPipeline->vtxAttributeCount) {
530 pPipeline->pVertexAttributeDescriptions = new VkVertexInputAttributeDescription[pPipeline->vtxAttributeCount];
531 bufferSize = pPipeline->vtxAttributeCount * sizeof(VkVertexInputAttributeDescription);
532 memcpy((void*)pPipeline->pVertexAttributeDescriptions, pVICI->pVertexAttributeDescriptions, bufferSize);
533 }
534 pPipeline->graphicsPipelineCI.pVertexInputState = &pPipeline->vertexInputCI;
535 }
Tony Barboure307f582015-07-10 15:29:03 -0600536 if (pCreateInfo->pInputAssemblyState != NULL) {
537 memcpy((void*)&pPipeline->iaStateCI, pCreateInfo->pInputAssemblyState, sizeof(VkPipelineInputAssemblyStateCreateInfo));
538 pPipeline->graphicsPipelineCI.pInputAssemblyState = &pPipeline->iaStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600539 }
Tony Barboure307f582015-07-10 15:29:03 -0600540 if (pCreateInfo->pTessellationState != NULL) {
541 memcpy((void*)&pPipeline->tessStateCI, pCreateInfo->pTessellationState, sizeof(VkPipelineTessellationStateCreateInfo));
542 pPipeline->graphicsPipelineCI.pTessellationState = &pPipeline->tessStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600543 }
Tony Barboure307f582015-07-10 15:29:03 -0600544 if (pCreateInfo->pViewportState != NULL) {
545 memcpy((void*)&pPipeline->vpStateCI, pCreateInfo->pViewportState, sizeof(VkPipelineViewportStateCreateInfo));
546 pPipeline->graphicsPipelineCI.pViewportState = &pPipeline->vpStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600547 }
Tony Barboure307f582015-07-10 15:29:03 -0600548 if (pCreateInfo->pRasterState != NULL) {
549 memcpy((void*)&pPipeline->rsStateCI, pCreateInfo->pRasterState, sizeof(VkPipelineRasterStateCreateInfo));
550 pPipeline->graphicsPipelineCI.pRasterState = &pPipeline->rsStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600551 }
Tony Barboure307f582015-07-10 15:29:03 -0600552 if (pCreateInfo->pMultisampleState != NULL) {
553 memcpy((void*)&pPipeline->msStateCI, pCreateInfo->pMultisampleState, sizeof(VkPipelineMultisampleStateCreateInfo));
554 pPipeline->graphicsPipelineCI.pMultisampleState = &pPipeline->msStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600555 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -0600556 if (pCreateInfo->pDepthStencilState != NULL) {
557 memcpy((void*)&pPipeline->dsStateCI, pCreateInfo->pDepthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo));
558 pPipeline->graphicsPipelineCI.pDepthStencilState = &pPipeline->dsStateCI;
559 }
Tony Barboure307f582015-07-10 15:29:03 -0600560 if (pCreateInfo->pColorBlendState != NULL) {
561 memcpy((void*)&pPipeline->cbStateCI, pCreateInfo->pColorBlendState, sizeof(VkPipelineColorBlendStateCreateInfo));
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600562 // Copy embedded ptrs
Tony Barboure307f582015-07-10 15:29:03 -0600563 pCBCI = pCreateInfo->pColorBlendState;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600564 pPipeline->attachmentCount = pCBCI->attachmentCount;
565 if (pPipeline->attachmentCount) {
Tony Barboure307f582015-07-10 15:29:03 -0600566 pPipeline->pAttachments = new VkPipelineColorBlendAttachmentState[pPipeline->attachmentCount];
567 bufferSize = pPipeline->attachmentCount * sizeof(VkPipelineColorBlendAttachmentState);
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600568 memcpy((void*)pPipeline->pAttachments, pCBCI->pAttachments, bufferSize);
569 }
Tony Barboure307f582015-07-10 15:29:03 -0600570 pPipeline->graphicsPipelineCI.pColorBlendState = &pPipeline->cbStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600571 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -0600572 if (pCreateInfo->pDynamicState != NULL) {
573 memcpy((void*)&pPipeline->dynStateCI, pCreateInfo->pDynamicState, sizeof(VkPipelineDynamicStateCreateInfo));
574 if (pPipeline->dynStateCI.dynamicStateCount) {
575 pPipeline->dynStateCI.pDynamicStates = new VkDynamicState[pPipeline->dynStateCI.dynamicStateCount];
576 bufferSize = pPipeline->dynStateCI.dynamicStateCount * sizeof(VkDynamicState);
577 memcpy((void*)pPipeline->dynStateCI.pDynamicStates, pCreateInfo->pDynamicState->pDynamicStates, bufferSize);
578 }
579 pPipeline->graphicsPipelineCI.pDynamicState = &pPipeline->dynStateCI;
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600580 }
581
Tobin Ehlisde63c532015-06-18 15:59:33 -0600582 return pPipeline;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600583}
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600584
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600585// Free the Pipeline nodes
Tobin Ehliseaf28662015-04-08 10:58:37 -0600586static void deletePipelines()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600587{
David Pinedof5997ab2015-04-27 16:36:17 -0600588 if (pipelineMap.size() <= 0)
589 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600590 for (auto ii=pipelineMap.begin(); ii!=pipelineMap.end(); ++ii) {
Mark Lobodzinski0e0fb5c2015-06-23 15:11:57 -0600591 if ((*ii).second->graphicsPipelineCI.stageCount != 0) {
592 delete[] (*ii).second->graphicsPipelineCI.pStages;
593 }
Tobin Ehliscd3109e2015-04-01 11:59:08 -0600594 if ((*ii).second->pVertexBindingDescriptions) {
595 delete[] (*ii).second->pVertexBindingDescriptions;
596 }
597 if ((*ii).second->pVertexAttributeDescriptions) {
598 delete[] (*ii).second->pVertexAttributeDescriptions;
599 }
600 if ((*ii).second->pAttachments) {
601 delete[] (*ii).second->pAttachments;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600602 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -0600603 if ((*ii).second->dynStateCI.dynamicStateCount != 0) {
604 delete[] (*ii).second->dynStateCI.pDynamicStates;
605 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600606 delete (*ii).second;
607 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -0600608 pipelineMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600609}
Tobin Ehlis2464b882015-04-01 08:40:34 -0600610// For given pipeline, return number of MSAA samples, or one if MSAA disabled
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600611static uint32_t getNumSamples(const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600612{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600613 PIPELINE_NODE* pPipe = pipelineMap[pipeline.handle];
Tobin Ehlisb3a506f2015-07-13 14:51:15 -0600614 if (VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO == pPipe->msStateCI.sType) {
615 return pPipe->msStateCI.rasterSamples;
616 }
Tobin Ehlis2464b882015-04-01 08:40:34 -0600617 return 1;
618}
619// Validate state related to the PSO
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600620static VkBool32 validatePipelineState(const GLOBAL_CB_NODE* pCB, const VkPipelineBindPoint pipelineBindPoint, const VkPipeline pipeline)
Tobin Ehlis2464b882015-04-01 08:40:34 -0600621{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Tobin Ehlis2464b882015-04-01 08:40:34 -0600623 // Verify that any MSAA request in PSO matches sample# in bound FB
624 uint32_t psoNumSamples = getNumSamples(pipeline);
625 if (pCB->activeRenderPass) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600626 const VkRenderPassCreateInfo* pRPCI = renderPassMap[pCB->activeRenderPass.handle];
Chia-I Wuc278df82015-07-07 11:50:03 +0800627 const VkSubpassDescription* pSD = &pRPCI->pSubpasses[pCB->activeSubpass];
628 int subpassNumSamples = 0;
629 uint32_t i;
630
631 for (i = 0; i < pSD->colorCount; i++) {
632 uint32_t samples;
633
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600634 if (pSD->pColorAttachments[i].attachment == VK_ATTACHMENT_UNUSED)
Chia-I Wuc278df82015-07-07 11:50:03 +0800635 continue;
636
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600637 samples = pRPCI->pAttachments[pSD->pColorAttachments[i].attachment].samples;
Chia-I Wuc278df82015-07-07 11:50:03 +0800638 if (subpassNumSamples == 0) {
639 subpassNumSamples = samples;
640 } else if (subpassNumSamples != samples) {
641 subpassNumSamples = -1;
642 break;
643 }
644 }
645 if (pSD->depthStencilAttachment.attachment != VK_ATTACHMENT_UNUSED) {
646 const uint32_t samples = pRPCI->pAttachments[pSD->depthStencilAttachment.attachment].samples;
647 if (subpassNumSamples == 0)
648 subpassNumSamples = samples;
649 else if (subpassNumSamples != samples)
650 subpassNumSamples = -1;
651 }
652
653 if (psoNumSamples != subpassNumSamples) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600654 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 -0600655 "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 -0600656 }
657 } else {
658 // TODO : I believe it's an error if we reach this point and don't have an activeRenderPass
659 // Verify and flag error as appropriate
660 }
661 // TODO : Add more checks here
662 } else {
663 // TODO : Validate non-gfx pipeline updates
664 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600665 return VK_FALSE;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600666}
667
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600668// Block of code at start here specifically for managing/tracking DSs
669
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600670// Return Pool node ptr for specified pool or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600671static POOL_NODE* getPoolNode(VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600672{
673 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600674 if (poolMap.find(pool.handle) == poolMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600675 loader_platform_thread_unlock_mutex(&globalLock);
676 return NULL;
677 }
678 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600679 return poolMap[pool.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600680}
681// Return Set node ptr for specified set or else NULL
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600682static SET_NODE* getSetNode(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600683{
684 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600685 if (setMap.find(set.handle) == setMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600686 loader_platform_thread_unlock_mutex(&globalLock);
687 return NULL;
688 }
689 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600690 return setMap[set.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600691}
692
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600693static LAYOUT_NODE* getLayoutNode(const VkDescriptorSetLayout layout) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600694 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600695 if (layoutMap.find(layout.handle) == layoutMap.end()) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600696 loader_platform_thread_unlock_mutex(&globalLock);
697 return NULL;
698 }
699 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600700 return layoutMap[layout.handle];
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600701}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600702// 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 -0600703static VkBool32 validUpdateStruct(const VkDevice device, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600704{
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600705 switch (pUpdateStruct->sType)
706 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800707 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
708 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600709 return VK_FALSE;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600710 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600711 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 -0600712 "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 -0600713 }
714}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600715// For given update struct, return binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600716static VkBool32 getUpdateBinding(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* binding)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600717{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600718 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600719 switch (pUpdateStruct->sType)
720 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800721 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600722 *binding = ((VkWriteDescriptorSet*)pUpdateStruct)->destBinding;
723 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800724 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600725 *binding = ((VkCopyDescriptorSet*)pUpdateStruct)->destBinding;
726 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600727 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600728 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 -0600729 "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 -0600730 *binding = 0xFFFFFFFF;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600731 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600732 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600733}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600734// Set arrayIndex for given update struct in the last parameter
735// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
736static uint32_t getUpdateArrayIndex(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* arrayIndex)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600737{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600738 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600739 switch (pUpdateStruct->sType)
740 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800741 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600742 *arrayIndex = ((VkWriteDescriptorSet*)pUpdateStruct)->destArrayElement;
743 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800744 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600745 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600746 *arrayIndex = ((VkCopyDescriptorSet*)pUpdateStruct)->destArrayElement;
747 break;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600748 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600749 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 -0600750 "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 -0600751 *arrayIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600752 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600753 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600754}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600755// Set count for given update struct in the last parameter
756// Return value of skipCall, which is only VK_TRUE is error occurs and callback signals execution to cease
757static uint32_t getUpdateCount(const VkDevice device, const GENERIC_HEADER* pUpdateStruct, uint32_t* count)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600758{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600759 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600760 switch (pUpdateStruct->sType)
761 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800762 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600763 *count = ((VkWriteDescriptorSet*)pUpdateStruct)->count;
764 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800765 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600766 // TODO : Need to understand this case better and make sure code is correct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600767 *count = ((VkCopyDescriptorSet*)pUpdateStruct)->count;
768 break;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600769 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600770 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 -0600771 "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 -0600772 *count = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600773 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600774 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600775}
776// For given Layout Node and binding, return index where that binding begins
777static uint32_t getBindingStartIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
778{
779 uint32_t offsetIndex = 0;
780 for (uint32_t i = 0; i<binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800781 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600782 }
783 return offsetIndex;
784}
785// For given layout node and binding, return last index that is updated
786static uint32_t getBindingEndIndex(const LAYOUT_NODE* pLayout, const uint32_t binding)
787{
788 uint32_t offsetIndex = 0;
789 for (uint32_t i = 0; i<=binding; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +0800790 offsetIndex += pLayout->createInfo.pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600791 }
792 return offsetIndex-1;
793}
794// For given layout and update, return the first overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600795static VkBool32 getUpdateStartIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* startIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600796{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600797 uint32_t binding = 0, arrayIndex = 0;
798 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
799 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
800 if (VK_FALSE == skipCall)
801 *startIndex = getBindingStartIndex(pLayout, binding)+arrayIndex;
802 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600803}
804// For given layout and update, return the last overall index of the layout that is update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600805static VkBool32 getUpdateEndIndex(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct, uint32_t* endIndex)
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600806{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600807 uint32_t binding = 0, arrayIndex = 0, count = 0;
808 VkBool32 skipCall = getUpdateBinding(device, pUpdateStruct, &binding);
809 skipCall |= getUpdateArrayIndex(device, pUpdateStruct, &arrayIndex);
810 skipCall |= getUpdateCount(device, pUpdateStruct, &count);
811 if (VK_FALSE == skipCall)
812 *endIndex = getBindingStartIndex(pLayout, binding)+arrayIndex+count-1;
813 return skipCall;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600814}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600815// Verify that the descriptor type in the update struct matches what's expected by the layout
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600816static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLayout, const GENERIC_HEADER* pUpdateStruct)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600817{
818 // First get actual type of update
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600819 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600820 VkDescriptorType actualType;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600821 uint32_t i = 0, startIndex = 0, endIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600822 switch (pUpdateStruct->sType)
823 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800824 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
825 actualType = ((VkWriteDescriptorSet*)pUpdateStruct)->descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600826 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800827 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
828 /* no need to validate */
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600829 return VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600830 break;
831 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600832 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 -0600833 "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 -0600834 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600835 skipCall |= getUpdateStartIndex(device, pLayout, pUpdateStruct, &startIndex);
836 skipCall |= getUpdateEndIndex(device, pLayout, pUpdateStruct, &endIndex);
837 if (VK_FALSE == skipCall) {
838 for (i = startIndex; i <= endIndex; i++) {
839 if (pLayout->pTypes[i] != actualType)
840 return VK_TRUE;
841 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600842 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600843 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600844}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600845// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600846// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600847// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600848static VkBool32 shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600849{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600850 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800851 VkWriteDescriptorSet* pWDS = NULL;
852 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600853 size_t array_size = 0;
854 size_t base_array_size = 0;
855 size_t total_array_size = 0;
856 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600857 switch (pUpdate->sType)
858 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800859 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
860 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600861 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800862 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
863 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
864 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
865 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600866 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800867 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
868 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600869 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800870 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600871 break;
872 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600873 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
874 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
875 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600876 }
877 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600878 (*pNewNode)->pNext = NULL;
879 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600880}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800881// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600882static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600883{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800884 const VkWriteDescriptorSet *pWDS = NULL;
885 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600886 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800887
888 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
889 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
890 else
891 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
892
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600893 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600894 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600895 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600896 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600897 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600898 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800899 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600900 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800901 g_lastBoundDescriptorSet = pSet->set;
902 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600903 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600904 // First verify valid update struct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600905 if ((skipCall = validUpdateStruct(device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600906 break;
907 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600908 // Make sure that binding is within bounds
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600909 uint32_t binding = 0, endIndex = 0;
910 skipCall |= getUpdateBinding(device, pUpdate, &binding);
911 if (pLayout->createInfo.count < binding) {
912 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
913 "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 -0600914 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600915 // Next verify that update falls within size of given binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600916 skipCall |= getUpdateBinding(device, pUpdate, &binding);
917 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
918 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tony Barbour29b12062015-07-13 13:37:24 -0600919 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600920 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600921 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600922 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",
923 "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 -0600924 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600925 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600926 if ((skipCall = validateUpdateType(device, pLayout, pUpdate)) == VK_TRUE) {
927 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 -0600928 "Descriptor update type of %s does not match overlapping binding type!", string_VkStructureType(pUpdate->sType));
Tobin Ehlise42007c2015-06-19 13:00:59 -0600929 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600930 // Save the update info
931 // TODO : Info message that update successful
932 // Create new update struct for this set's shadow copy
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600933 GENERIC_HEADER* pNewNode = NULL;
934 skipCall |= shadowUpdateNode(device, pUpdate, &pNewNode);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600935 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600936 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 -0600937 "Out of memory while attempting to allocate UPDATE struct in vkUpdateDescriptors()");
Tobin Ehlise42007c2015-06-19 13:00:59 -0600938 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600939 // Insert shadow node into LL of updates for this set
940 pNewNode->pNext = pSet->pUpdateStructs;
941 pSet->pUpdateStructs = pNewNode;
942 // Now update appropriate descriptor(s) to point to new Update node
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600943 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
944 uint32_t startIndex;
945 skipCall |= getUpdateStartIndex(device, pLayout, pUpdate, &startIndex);
946 for (uint32_t j = startIndex; j <= endIndex; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600947 assert(j<pSet->descriptorCount);
948 pSet->ppDescriptors[j] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600949 }
950 }
951 }
952 }
953 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600954 }
955 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600956 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600957}
958// Free the shadowed update node for this Set
959// NOTE : Calls to this function should be wrapped in mutex
960static void freeShadowUpdateTree(SET_NODE* pSet)
961{
962 GENERIC_HEADER* pShadowUpdate = pSet->pUpdateStructs;
963 pSet->pUpdateStructs = NULL;
964 GENERIC_HEADER* pFreeUpdate = pShadowUpdate;
965 // Clear the descriptor mappings as they will now be invalid
966 memset(pSet->ppDescriptors, 0, pSet->descriptorCount*sizeof(GENERIC_HEADER*));
967 while(pShadowUpdate) {
968 pFreeUpdate = pShadowUpdate;
969 pShadowUpdate = (GENERIC_HEADER*)pShadowUpdate->pNext;
970 uint32_t index = 0;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800971 VkWriteDescriptorSet * pWDS = NULL;
972 VkCopyDescriptorSet * pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600973 void** ppToFree = NULL;
974 switch (pFreeUpdate->sType)
975 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800976 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
977 pWDS = (VkWriteDescriptorSet*)pFreeUpdate;
978 if (pWDS->pDescriptors)
979 delete[] pWDS->pDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600980 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800981 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600982 break;
983 default:
984 assert(0);
985 break;
986 }
Tobin Ehliseaf28662015-04-08 10:58:37 -0600987 delete pFreeUpdate;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600988 }
989}
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600990// Free all DS Pools including their Sets & related sub-structs
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600991// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -0600992static void deletePools()
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600993{
David Pinedof5997ab2015-04-27 16:36:17 -0600994 if (poolMap.size() <= 0)
995 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600996 for (auto ii=poolMap.begin(); ii!=poolMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600997 SET_NODE* pSet = (*ii).second->pSets;
998 SET_NODE* pFreeSet = pSet;
999 while (pSet) {
1000 pFreeSet = pSet;
1001 pSet = pSet->pNext;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001002 // Freeing layouts handled in deleteLayouts() function
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001003 // Free Update shadow struct tree
1004 freeShadowUpdateTree(pFreeSet);
1005 if (pFreeSet->ppDescriptors) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001006 delete[] pFreeSet->ppDescriptors;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001007 }
1008 delete pFreeSet;
1009 }
1010 if ((*ii).second->createInfo.pTypeCount) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001011 delete[] (*ii).second->createInfo.pTypeCount;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001012 }
1013 delete (*ii).second;
1014 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001015 poolMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001016}
Tobin Ehliseaf28662015-04-08 10:58:37 -06001017// WARN : Once deleteLayouts() called, any layout ptrs in Pool/Set data structure will be invalid
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001018// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001019static void deleteLayouts()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001020{
David Pinedof5997ab2015-04-27 16:36:17 -06001021 if (layoutMap.size() <= 0)
1022 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001023 for (auto ii=layoutMap.begin(); ii!=layoutMap.end(); ++ii) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001024 LAYOUT_NODE* pLayout = (*ii).second;
Tobin Ehliseaf28662015-04-08 10:58:37 -06001025 if (pLayout->createInfo.pBinding) {
1026 for (uint32_t i=0; i<pLayout->createInfo.count; i++) {
1027 if (pLayout->createInfo.pBinding[i].pImmutableSamplers)
1028 delete[] pLayout->createInfo.pBinding[i].pImmutableSamplers;
1029 }
1030 delete[] pLayout->createInfo.pBinding;
1031 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001032 if (pLayout->pTypes) {
Chris Forbes4506d3f2015-06-04 10:49:27 +12001033 delete[] pLayout->pTypes;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001034 }
1035 delete pLayout;
1036 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001037 layoutMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001038}
1039// Currently clearing a set is removing all previous updates to that set
1040// TODO : Validate if this is correct clearing behavior
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001041static void clearDescriptorSet(VkDescriptorSet set)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001042{
1043 SET_NODE* pSet = getSetNode(set);
1044 if (!pSet) {
1045 // TODO : Return error
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001046 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001047 loader_platform_thread_lock_mutex(&globalLock);
1048 freeShadowUpdateTree(pSet);
1049 loader_platform_thread_unlock_mutex(&globalLock);
1050 }
1051}
1052
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001053static void clearDescriptorPool(VkDevice device, VkDescriptorPool pool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001054{
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001055 POOL_NODE* pPool = getPoolNode(pool);
1056 if (!pPool) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001057 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, pool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1058 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkResetDescriptorPool() call", pool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001059 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001060 // For every set off of this pool, clear it
1061 SET_NODE* pSet = pPool->pSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001062 while (pSet) {
1063 clearDescriptorSet(pSet->set);
1064 }
1065 }
1066}
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001067// For given CB object, fetch associated CB Node from map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001068static GLOBAL_CB_NODE* getCBNode(VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001069{
1070 loader_platform_thread_lock_mutex(&globalLock);
1071 if (cmdBufferMap.find(cb) == cmdBufferMap.end()) {
1072 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001073 // TODO : How to pass cb as srcObj here?
1074 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 -06001075 "Attempt to use CmdBuffer %#" PRIxLEAST64 " that doesn't exist!", reinterpret_cast<uint64_t>(cb));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001076 return NULL;
1077 }
1078 loader_platform_thread_unlock_mutex(&globalLock);
1079 return cmdBufferMap[cb];
1080}
1081// Free all CB Nodes
1082// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehliseaf28662015-04-08 10:58:37 -06001083static void deleteCmdBuffers()
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001084{
David Pinedof5997ab2015-04-27 16:36:17 -06001085 if (cmdBufferMap.size() <= 0)
1086 return;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001087 for (auto ii=cmdBufferMap.begin(); ii!=cmdBufferMap.end(); ++ii) {
Courtney Goeltzenleuchter09098a72015-04-27 15:04:43 -06001088 vector<CMD_NODE*> cmd_node_list = (*ii).second->pCmds;
1089 while (!cmd_node_list.empty()) {
1090 CMD_NODE* cmd_node = cmd_node_list.back();
1091 delete cmd_node;
1092 cmd_node_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001093 }
1094 delete (*ii).second;
1095 }
Jon Ashburnd0cb7cd2015-06-15 10:58:28 -06001096 cmdBufferMap.clear();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001097}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001098static VkBool32 report_error_no_cb_begin(const VkCmdBuffer cb, const char* caller_name)
Tobin Ehlise42007c2015-06-19 13:00:59 -06001099{
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001100 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001101 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 -06001102 "You must call vkBeginCommandBuffer() before this call to %s", (void*)caller_name);
1103}
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001104static VkBool32 addCmd(GLOBAL_CB_NODE* pCB, const CMD_TYPE cmd)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001105{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001106 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001107 CMD_NODE* pCmd = new CMD_NODE;
1108 if (pCmd) {
1109 // init cmd node and append to end of cmd LL
1110 memset(pCmd, 0, sizeof(CMD_NODE));
1111 pCmd->cmdNumber = ++pCB->numCmds;
1112 pCmd->type = cmd;
1113 pCB->pCmds.push_back(pCmd);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001114 } else {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001115 // TODO : How to pass cb as srcObj here?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001116 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 -06001117 "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 -06001118 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001119 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001120}
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001121static void resetCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001122{
1123 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1124 if (pCB) {
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001125 vector<CMD_NODE*> cmd_list = pCB->pCmds;
1126 while (!cmd_list.empty()) {
1127 delete cmd_list.back();
1128 cmd_list.pop_back();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001129 }
Courtney Goeltzenleuchterf03711e2015-04-27 17:16:56 -06001130 pCB->pCmds.clear();
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001131 // Reset CB state (need to save createInfo)
1132 VkCmdBufferCreateInfo saveCBCI = pCB->createInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001133 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1134 pCB->cmdBuffer = cb;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001135 pCB->createInfo = saveCBCI;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001136 pCB->lastVtxBinding = MAX_BINDING;
1137 }
1138}
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001139// Set PSO-related status bits for CB, including dynamic state set via PSO
Tobin Ehlis97866202015-06-10 12:57:07 -06001140static void set_cb_pso_status(GLOBAL_CB_NODE* pCB, const PIPELINE_NODE* pPipe)
1141{
1142 for (uint32_t i = 0; i < pPipe->cbStateCI.attachmentCount; i++) {
1143 if (0 != pPipe->pAttachments[i].channelWriteMask) {
1144 pCB->status |= CBSTATUS_COLOR_BLEND_WRITE_ENABLE;
1145 }
1146 }
1147 if (pPipe->dsStateCI.depthWriteEnable) {
Cody Northrop2605cb02015-08-18 15:21:16 -06001148 pCB->status |= CBSTATUS_DEPTH_WRITE_ENABLE;
1149 }
Cody Northrop2605cb02015-08-18 15:21:16 -06001150 if (pPipe->dsStateCI.stencilTestEnable) {
1151 pCB->status |= CBSTATUS_STENCIL_TEST_ENABLE;
Tobin Ehlis97866202015-06-10 12:57:07 -06001152 }
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001153 if (pPipe->dynStateCI.dynamicStateCount) {
1154 // Account for any dynamic state set via this PSO
1155 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
1156 switch (pPipe->dynStateCI.pDynamicStates[i]) {
1157 case VK_DYNAMIC_STATE_VIEWPORT:
1158 pCB->status |= CBSTATUS_VIEWPORT_SET;
1159 break;
1160 case VK_DYNAMIC_STATE_SCISSOR:
1161 pCB->status |= CBSTATUS_SCISSOR_SET;
1162 break;
1163 case VK_DYNAMIC_STATE_LINE_WIDTH:
1164 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
1165 break;
1166 case VK_DYNAMIC_STATE_DEPTH_BIAS:
1167 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
1168 break;
1169 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
1170 pCB->status |= CBSTATUS_BLEND_SET;
1171 break;
1172 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
1173 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
1174 break;
1175 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
1176 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
1177 break;
1178 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
1179 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
1180 break;
1181 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
1182 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
1183 break;
1184 default:
1185 // TODO : Flag error here
1186 break;
1187 }
1188 }
1189 }
Tobin Ehlis97866202015-06-10 12:57:07 -06001190}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001191// Print the last bound Gfx Pipeline
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001192static VkBool32 printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001193{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001194 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001195 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1196 if (pCB) {
1197 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1198 if (!pPipeTrav) {
1199 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001200 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001201 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001202 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001203 }
1204 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001205 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001206}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001207// Print details of DS config to stdout
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001208static VkBool32 printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001209{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001210 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001211 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.
1212 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001213 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001214 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001215 POOL_NODE* pPool = getPoolNode(pSet->pool);
1216 // Print out pool details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001217 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001218 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001219 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001220 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001221 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001222 // Print out set details
1223 char prefix[10];
1224 uint32_t index = 0;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001225 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001226 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001227 LAYOUT_NODE* pLayout = pSet->pLayout;
1228 // Print layout details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001229 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001230 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001231 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001232 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001233 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001234 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001235 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001236 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1237 if (pUpdate) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001238 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001239 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001240 sprintf(prefix, " [UC] ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001241 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001242 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001243 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001244 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001245 if (0 != pSet->descriptorCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001246 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001247 "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 -06001248 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001249 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001250 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001251 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001252 }
1253 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001254 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001255}
1256
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001257static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001258{
1259 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001260 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001261 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001262 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001263 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001264 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1265 // TODO : Need to pass cb as srcObj here
1266 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 -06001267 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001268 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001269 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001270 // Nothing to print
1271 }
1272}
1273
1274
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001275static VkBool32 synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001276{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001277 VkBool32 skipCall = VK_FALSE;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001278 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001279 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001280 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001281 skipCall |= printDSConfig(cb);
1282 skipCall |= printPipeline(cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001283 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001284}
1285
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001286static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001287{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001288 uint32_t report_flags = 0;
1289 uint32_t debug_action = 0;
1290 FILE *log_output = NULL;
1291 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001292 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001293 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1294 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001295
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001296 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001297 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001298 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06001299 log_output = getLayerLogOutput(option_str, "DrawState");
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001300 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 -06001301 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001302
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001303 if (!globalLockInitialized)
1304 {
Mike Stroyand9dd0072015-08-18 15:56:18 -06001305 // This mutex may be deleted by vkDestroyInstance of last instance.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001306 loader_platform_thread_create_mutex(&globalLock);
1307 globalLockInitialized = 1;
1308 }
1309}
1310
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001311VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1312{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001313 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001314 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1315
1316 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001317 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1318 my_data->report_data = debug_report_create_instance(
1319 pTable,
1320 *pInstance,
1321 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001322 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001323
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001324 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001325 }
1326 return result;
1327}
1328
Jon Ashburne0fa2282015-05-20 09:00:28 -06001329/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001330VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Jon Ashburne0fa2282015-05-20 09:00:28 -06001331{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001332 dispatch_key key = get_dispatch_key(instance);
1333 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001334 pTable->DestroyInstance(instance);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001335
1336 // Clean up logging callback, if any
1337 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1338 if (my_data->logging_callback) {
1339 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1340 }
1341
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001342 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001343 layer_data_map.erase(pTable);
1344
1345 draw_state_instance_table_map.erase(key);
Mike Stroyand9dd0072015-08-18 15:56:18 -06001346 if (draw_state_instance_table_map.empty()) {
1347 // Release mutex when destroying last instance.
1348 loader_platform_thread_delete_mutex(&globalLock);
1349 globalLockInitialized = 0;
1350 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001351}
1352
Jon Ashburnf0615e22015-05-25 14:11:37 -06001353static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1354{
Tony Barbour29b12062015-07-13 13:37:24 -06001355 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001356 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001357 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001358
1359 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001360 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001361 /* Found a matching extension name, mark it enabled and init dispatch table*/
1362 initDebugMarkerTable(device);
1363 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001364 }
1365
1366 }
1367}
1368
Tony Barbour8205d902015-04-16 15:59:00 -06001369VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001370{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001371 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1372 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001373 if (result == VK_SUCCESS) {
1374 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1375 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1376 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1377 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001378 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001379 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001380 return result;
1381}
1382
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001383VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001384{
1385 // Free all the memory
1386 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001387 deletePipelines();
1388 deleteSamplers();
1389 deleteImages();
1390 deleteBuffers();
1391 deleteCmdBuffers();
Tobin Ehliseaf28662015-04-08 10:58:37 -06001392 deletePools();
1393 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001394 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001395
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001396 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001397 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001398 pDisp->DestroyDevice(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001399 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001400 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001401 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001402}
1403
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001404static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001405 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001406 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001407 VK_API_VERSION,
1408 VK_MAKE_VERSION(0, 1, 0),
1409 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001410 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001411};
1412
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001413VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001414 const char *pLayerName,
1415 uint32_t *pCount,
1416 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001417{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001418 /* DrawState does not have any global extensions */
1419 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1420}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001421
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001422VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001423 uint32_t *pCount,
1424 VkLayerProperties* pProperties)
1425{
1426 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1427 ds_global_layers,
1428 pCount, pProperties);
1429}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001430
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001431static const VkExtensionProperties ds_device_extensions[] = {
1432 {
1433 DEBUG_MARKER_EXTENSION_NAME,
1434 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001435 }
1436};
1437
1438static const VkLayerProperties ds_device_layers[] = {
1439 {
1440 "DrawState",
1441 VK_API_VERSION,
1442 VK_MAKE_VERSION(0, 1, 0),
1443 "Validation layer: DrawState",
1444 }
1445};
1446
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001447VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001448 VkPhysicalDevice physicalDevice,
1449 const char* pLayerName,
1450 uint32_t* pCount,
1451 VkExtensionProperties* pProperties)
1452{
1453 /* Mem tracker does not have any physical device extensions */
1454 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1455 pCount, pProperties);
1456}
1457
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001458VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001459 VkPhysicalDevice physicalDevice,
1460 uint32_t* pCount,
1461 VkLayerProperties* pProperties)
1462{
1463 /* Mem tracker's physical device layers are the same as global */
1464 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1465 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001466}
1467
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001468VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001469{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001470 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001471 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001472 for (uint32_t i=0; i < cmdBufferCount; i++) {
1473 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001474 pCB = getCBNode(pCmdBuffers[i]);
1475 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001476 pCB->submitCount++; // increment submit count
1477 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001478 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 -06001479 "CB %#" PRIxLEAST64 " was begun w/ VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.", reinterpret_cast<uint64_t>(pCB->cmdBuffer), pCB->submitCount);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001480 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001481 if (CB_UPDATE_COMPLETE != pCB->state) {
1482 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001483 // TODO : How to pass cb as srcObj?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001484 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 -06001485 "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 -06001486 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001487 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001488 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001489 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001490 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001491 if (VK_FALSE == skipCall)
1492 return get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
1493 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001494}
1495
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001496VK_LAYER_EXPORT void VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001497{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001498 get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001499 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001500}
1501
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001502VK_LAYER_EXPORT void VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001503{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001504 get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001505 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001506}
1507
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001508VK_LAYER_EXPORT void VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001509{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001510 get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001511 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001512}
1513
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001514VK_LAYER_EXPORT void VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001515{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001516 get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001517 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001518}
1519
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001520VK_LAYER_EXPORT void VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001521{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001522 get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001523 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001524}
1525
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001526VK_LAYER_EXPORT void VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001527{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001528 get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001529 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001530}
1531
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001532VK_LAYER_EXPORT void VKAPI vkDestroyImage(VkDevice device, VkImage image)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001533{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001534 get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001535 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001536}
1537
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001538VK_LAYER_EXPORT void VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001539{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001540 get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001541 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001542}
1543
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001544VK_LAYER_EXPORT void VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001545{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001546 get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001547 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001548}
1549
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001550VK_LAYER_EXPORT void VKAPI vkDestroyShader(VkDevice device, VkShader shader)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001551{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001552 get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001553 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001554}
1555
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001556VK_LAYER_EXPORT void VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001557{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001558 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001559 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001560}
1561
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001562VK_LAYER_EXPORT void VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001563{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001564 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001565 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001566}
1567
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001568VK_LAYER_EXPORT void VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001569{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001570 get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001571 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001572}
1573
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001574VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001575{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001576 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001577 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001578}
1579
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001580VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001581{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001582 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001583 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001584}
1585
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001586VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001587{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001588 get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001589 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001590}
1591
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001592VK_LAYER_EXPORT void VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001593{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001594 get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001595 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001596}
1597
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001598VK_LAYER_EXPORT void VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001599{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001600 get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001601 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001602}
1603
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001604VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001605{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001606 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001607 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001608 loader_platform_thread_lock_mutex(&globalLock);
1609 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1610 pNewNode->buffer = *pView;
1611 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001612 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001613 loader_platform_thread_unlock_mutex(&globalLock);
1614 }
1615 return result;
1616}
1617
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001618VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001619{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001620 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001621 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001622 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001623 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001624 loader_platform_thread_unlock_mutex(&globalLock);
1625 }
1626 return result;
1627}
1628
Jon Ashburn0d60d272015-07-09 15:02:25 -06001629//TODO handle pipeline caches
1630VkResult VKAPI vkCreatePipelineCache(
1631 VkDevice device,
1632 const VkPipelineCacheCreateInfo* pCreateInfo,
1633 VkPipelineCache* pPipelineCache)
1634{
1635 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1636 return result;
1637}
1638
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001639void VKAPI vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06001640 VkDevice device,
1641 VkPipelineCache pipelineCache)
1642{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001643 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001644}
1645
1646size_t VKAPI vkGetPipelineCacheSize(
1647 VkDevice device,
1648 VkPipelineCache pipelineCache)
1649{
1650 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1651 return size;
1652}
1653
1654VkResult VKAPI vkGetPipelineCacheData(
1655 VkDevice device,
1656 VkPipelineCache pipelineCache,
1657 void* pData)
1658{
1659 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1660 return result;
1661}
1662
1663VkResult VKAPI vkMergePipelineCaches(
1664 VkDevice device,
1665 VkPipelineCache destCache,
1666 uint32_t srcCacheCount,
1667 const VkPipelineCache* pSrcCaches)
1668{
1669 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1670 return result;
1671}
1672
1673VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001674{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001675 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06001676 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06001677 // The order of operations here is a little convoluted but gets the job done
1678 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1679 // 2. Create state is then validated (which uses flags setup during shadowing)
1680 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06001681 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06001682 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
1683 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise48be202015-09-16 10:33:53 -06001684 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001685 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001686 for (i=0; i<count; i++) {
1687 pPipeNode[i] = initPipeline(&pCreateInfos[i], NULL);
1688 skipCall |= verifyPipelineCreateState(device, pPipeNode[i]);
1689 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001690 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001691 if (VK_FALSE == skipCall) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001692 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001693 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001694 for (i=0; i<count; i++) {
1695 pPipeNode[i]->pipeline = pPipelines[i];
1696 pipelineMap[pPipeNode[i]->pipeline.handle] = pPipeNode[i];
1697 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001698 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001699 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06001700 for (i=0; i<count; i++) {
1701 if (pPipeNode[i]) {
1702 // If we allocated a pipeNode, need to clean it up here
1703 delete[] pPipeNode[i]->pVertexBindingDescriptions;
1704 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
1705 delete[] pPipeNode[i]->pAttachments;
1706 delete pPipeNode[i];
1707 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001708 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001709 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001710 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001711 return result;
1712}
1713
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001714VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001715{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001716 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001717 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001718 loader_platform_thread_lock_mutex(&globalLock);
1719 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1720 pNewNode->sampler = *pSampler;
1721 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001722 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001723 loader_platform_thread_unlock_mutex(&globalLock);
1724 }
1725 return result;
1726}
1727
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001728VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001729{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001730 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001731 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001732 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1733 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001734 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1735 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
1736 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001737 }
1738 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001739 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1740 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1741 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001742 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001743 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001744 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001745 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001746 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001747 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1748 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001749 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001750 }
1751 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001752 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001753 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001754 uint32_t j = 0;
1755 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001756 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001757 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001758 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001759 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001760 }
1761 }
1762 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001763 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001764 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1765 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001766 // Put new node at Head of global Layer list
1767 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001768 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001769 loader_platform_thread_unlock_mutex(&globalLock);
1770 }
1771 return result;
1772}
1773
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001774VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001775{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001776 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001778 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001779 }
1780 return result;
1781}
1782
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001783VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001784{
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001785 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001786 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001787 // Insert this pool into Global Pool LL at head
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001788 if (log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1789 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle))
1790 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001791 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001792 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001793 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001794 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1795 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()"))
1796 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001797 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001798 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001799 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1800 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001801 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001802 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1803 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001804 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1805 }
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001806 pNewNode->poolUsage = pCreateInfo->poolUsage;
1807 pNewNode->maxSets = pCreateInfo->maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001808 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001809 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001810 }
1811 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001812 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001813 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001814 }
1815 return result;
1816}
1817
Mike Stroyan230e6252015-04-17 12:36:38 -06001818VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001819{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001820 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001821 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001822 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001823 }
1824 return result;
1825}
1826
Cody Northropc8aa4a52015-08-03 12:47:29 -06001827VK_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 -06001828{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001829 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1830 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001831 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1832 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001833 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1834 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001835 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001836 if (count == 0) {
1837 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1838 "AllocDescriptorSets called with 0 count");
1839 }
1840 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001841 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1842 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001843 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001844 SET_NODE* pNewNode = new SET_NODE;
1845 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001846 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1847 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()"))
1848 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001849 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001850 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001851 // Insert set at head of Set LL for this pool
1852 pNewNode->pNext = pPoolNode->pSets;
1853 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001854 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1855 if (NULL == pLayout) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001856 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1857 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle))
1858 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001859 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001860 pNewNode->pLayout = pLayout;
1861 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001862 pNewNode->set = pDescriptorSets[i];
1863 pNewNode->setUsage = setUsage;
1864 pNewNode->descriptorCount = pLayout->endIndex + 1;
1865 if (pNewNode->descriptorCount) {
1866 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1867 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1868 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1869 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001870 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001871 }
1872 }
1873 }
1874 }
1875 return result;
1876}
1877
Tony Barbourb857d312015-07-10 10:50:45 -06001878VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1879{
1880 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1881 // TODO : Clean up any internal data structures using this obj.
1882 return result;
1883}
1884
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001885VK_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 -06001886{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001887 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when both updates return VK_FALSE
1888 if (!dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1889 !dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001890 get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001891 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001892}
1893
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001894VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001895{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001896 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001897 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001898 loader_platform_thread_lock_mutex(&globalLock);
1899 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1900 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1901 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001902 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001904 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001905 cmdBufferMap[*pCmdBuffer] = pCB;
1906 loader_platform_thread_unlock_mutex(&globalLock);
1907 updateCBTracking(*pCmdBuffer);
1908 }
1909 return result;
1910}
1911
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001912VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001913{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001914 VkBool32 skipCall = false;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001915 // Validate command buffer level
1916 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1917 if (pCB) {
1918 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
1919 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
1920 // These should be NULL for a Primary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001921 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 -06001922 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
1923 }
1924 } else {
1925 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
1926 // These should NOT be null for an Secondary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001927 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 -06001928 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
1929 }
1930 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001931 pCB->beginInfo = *pBeginInfo;
1932 } else {
1933 // TODO : Need to pass cmdBuffer as objType here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001934 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 -06001935 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001936 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001937 if (skipCall) {
1938 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06001939 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001940 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001941 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001942 if (CB_NEW != pCB->state)
1943 resetCB(cmdBuffer);
1944 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001945 updateCBTracking(cmdBuffer);
1946 }
1947 return result;
1948}
1949
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001950VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001951{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001952 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001953 VkResult result = VK_SUCCESS;
Tobin Ehlise42007c2015-06-19 13:00:59 -06001954 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001955 /* TODO: preference is to always call API function after reporting any validation errors */
Tobin Ehlise42007c2015-06-19 13:00:59 -06001956 if (pCB) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001957 if (pCB->state != CB_UPDATE_ACTIVE) {
1958 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001959 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001960 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001961 if (VK_FALSE == skipCall) {
1962 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
1963 if (VK_SUCCESS == result) {
1964 updateCBTracking(cmdBuffer);
1965 pCB->state = CB_UPDATE_COMPLETE;
1966 // Reset CB status flags
1967 pCB->status = 0;
1968 printCB(cmdBuffer);
1969 }
1970 } else {
1971 result = VK_ERROR_VALIDATION_FAILED;
1972 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001973 return result;
1974}
1975
Cody Northropf02f9f82015-07-09 18:08:05 -06001976VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001977{
Cody Northropf02f9f82015-07-09 18:08:05 -06001978 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001979 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001980 resetCB(cmdBuffer);
1981 updateCBTracking(cmdBuffer);
1982 }
1983 return result;
1984}
1985
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001986VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001987{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001988 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001989 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1990 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06001991 if (pCB->state == CB_UPDATE_ACTIVE) {
1992 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001993 skipCall |= addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06001994 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001995 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 -06001996 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06001997 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001998 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 -06001999 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002000 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002001 PIPELINE_NODE* pPN = getPipeline(pipeline);
2002 if (pPN) {
2003 pCB->lastBoundPipeline = pipeline;
2004 loader_platform_thread_lock_mutex(&globalLock);
2005 set_cb_pso_status(pCB, pPN);
2006 g_lastBoundPipeline = pPN;
2007 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002008 skipCall |= validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002009 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002010 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 -06002011 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002012 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002013 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002014 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002015 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002016 }
2017 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002018 if (VK_FALSE == skipCall)
2019 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002020}
2021
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002022VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
2023 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002024 uint32_t viewportCount,
2025 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002026{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002027 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002028 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2029 if (pCB) {
2030 if (pCB->state == CB_UPDATE_ACTIVE) {
2031 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002032 skipCall |= addCmd(pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002033 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002034 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 -06002035 "Incorrect call to vkCmdSetViewport() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002036 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002037 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002038 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002039 pCB->viewports.resize(viewportCount);
2040 memcpy(pCB->viewports.data(), pViewports, viewportCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002041 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002042 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002043 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetViewport()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002044 }
2045 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002046 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002047 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
2048}
2049
2050VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
2051 VkCmdBuffer cmdBuffer,
2052 uint32_t scissorCount,
2053 const VkRect2D* pScissors)
2054{
2055 VkBool32 skipCall = VK_FALSE;
2056 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2057 if (pCB) {
2058 if (pCB->state == CB_UPDATE_ACTIVE) {
2059 updateCBTracking(cmdBuffer);
2060 skipCall |= addCmd(pCB, CMD_SETSCISSORSTATE);
2061 if (!pCB->activeRenderPass) {
2062 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2063 "Incorrect call to vkCmdSetScissor() without an active RenderPass.");
2064 }
2065 loader_platform_thread_lock_mutex(&globalLock);
2066 pCB->status |= CBSTATUS_SCISSOR_SET;
2067 pCB->scissors.resize(scissorCount);
2068 memcpy(pCB->scissors.data(), pScissors, scissorCount);
2069 loader_platform_thread_unlock_mutex(&globalLock);
2070 } else {
2071 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetScissor()");
2072 }
2073 }
2074 if (VK_FALSE == skipCall)
2075 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002076}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002077
2078VK_LAYER_EXPORT void VKAPI vkCmdSetLineWidth(VkCmdBuffer cmdBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002079{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002080 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002081 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2082 if (pCB) {
2083 if (pCB->state == CB_UPDATE_ACTIVE) {
2084 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002085 skipCall |= addCmd(pCB, CMD_SETLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002086 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002087 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 -06002088 "Incorrect call to vkCmdSetLineWidth() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002089 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002090 /* TODO: Do we still need this lock? */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002091 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002092 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
2093 pCB->lineWidth = lineWidth;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002094 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002095 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002096 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002097 }
2098 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002099 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002100 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetLineWidth(cmdBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06002101}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002102
2103VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBias(
2104 VkCmdBuffer cmdBuffer,
2105 float depthBias,
2106 float depthBiasClamp,
2107 float slopeScaledDepthBias)
Cody Northropf5bd2252015-08-17 11:10:49 -06002108{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002109 VkBool32 skipCall = VK_FALSE;
Cody Northropf5bd2252015-08-17 11:10:49 -06002110 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2111 if (pCB) {
2112 if (pCB->state == CB_UPDATE_ACTIVE) {
2113 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002114 skipCall |= addCmd(pCB, CMD_SETDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002115 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002116 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 -06002117 "Incorrect call to vkCmdSetDepthBias() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002118 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002119 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
2120 pCB->depthBias = depthBias;
2121 pCB->depthBiasClamp = depthBiasClamp;
2122 pCB->slopeScaledDepthBias = slopeScaledDepthBias;
Cody Northropf5bd2252015-08-17 11:10:49 -06002123 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002124 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002125 }
2126 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002127 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002128 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBias(cmdBuffer, depthBias, depthBiasClamp, slopeScaledDepthBias);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002129}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002130
2131VK_LAYER_EXPORT void VKAPI vkCmdSetBlendConstants(VkCmdBuffer cmdBuffer, const float blendConst[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002132{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002133 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -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_SETBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -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 vkSetBlendConstants() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002142 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002143 pCB->status |= CBSTATUS_BLEND_SET;
2144 memcpy(pCB->blendConst, blendConst, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002145 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002146 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002147 }
2148 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002149 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002150 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetBlendConstants(cmdBuffer, blendConst);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002151}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002152
2153VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBounds(
2154 VkCmdBuffer cmdBuffer,
2155 float minDepthBounds,
2156 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002157{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002158 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002159 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2160 if (pCB) {
2161 if (pCB->state == CB_UPDATE_ACTIVE) {
2162 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002163 skipCall |= addCmd(pCB, CMD_SETDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002164 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002165 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 -06002166 "Incorrect call to vkCmdSetDepthBounds() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002167 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002168 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
2169 pCB->minDepthBounds = minDepthBounds;
2170 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002171 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002172 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBounds()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002173 }
2174 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002175 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002176 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBounds(cmdBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06002177}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002178
2179VK_LAYER_EXPORT void VKAPI vkCmdSetStencilCompareMask(
2180 VkCmdBuffer cmdBuffer,
2181 VkStencilFaceFlags faceMask,
2182 uint32_t stencilCompareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06002183{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002184 VkBool32 skipCall = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -06002185 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2186 if (pCB) {
2187 if (pCB->state == CB_UPDATE_ACTIVE) {
2188 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002189 skipCall |= addCmd(pCB, CMD_SETSTENCILREADMASKSTATE);
Cody Northrop2605cb02015-08-18 15:21:16 -06002190 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002191 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 -06002192 "Incorrect call to vkCmdSetStencilCompareMask() without an active RenderPass.");
Cody Northrop2605cb02015-08-18 15:21:16 -06002193 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002194 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2195 pCB->front.stencilCompareMask = stencilCompareMask;
Cody Northrop2605cb02015-08-18 15:21:16 -06002196 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002197 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2198 pCB->back.stencilCompareMask = stencilCompareMask;
2199 }
2200 /* TODO: Do we need to track front and back separately? */
2201 /* TODO: We aren't capturing the faceMask, do we need to? */
2202 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop2605cb02015-08-18 15:21:16 -06002203 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002204 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002205 }
2206 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002207 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002208 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilCompareMask(cmdBuffer, faceMask, stencilCompareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002209}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002210
2211VK_LAYER_EXPORT void VKAPI vkCmdSetStencilWriteMask(
2212 VkCmdBuffer cmdBuffer,
2213 VkStencilFaceFlags faceMask,
2214 uint32_t stencilWriteMask)
2215{
2216 VkBool32 skipCall = VK_FALSE;
2217 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2218 if (pCB) {
2219 if (pCB->state == CB_UPDATE_ACTIVE) {
2220 updateCBTracking(cmdBuffer);
2221 skipCall |= addCmd(pCB, CMD_SETSTENCILWRITEMASKSTATE);
2222 if (!pCB->activeRenderPass) {
2223 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2224 "Incorrect call to vkCmdSetStencilWriteMask() without an active RenderPass.");
2225 }
2226 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2227 pCB->front.stencilWriteMask = stencilWriteMask;
2228 }
2229 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2230 pCB->back.stencilWriteMask = stencilWriteMask;
2231 }
2232 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
2233 } else {
2234 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilWriteMask()");
2235 }
2236 }
2237 if (VK_FALSE == skipCall)
2238 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilWriteMask(cmdBuffer, faceMask, stencilWriteMask);
2239}
2240
2241VK_LAYER_EXPORT void VKAPI vkCmdSetStencilReference(
2242 VkCmdBuffer cmdBuffer,
2243 VkStencilFaceFlags faceMask,
2244 uint32_t stencilReference)
2245{
2246 VkBool32 skipCall = VK_FALSE;
2247 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2248 if (pCB) {
2249 if (pCB->state == CB_UPDATE_ACTIVE) {
2250 updateCBTracking(cmdBuffer);
2251 skipCall |= addCmd(pCB, CMD_SETSTENCILREFERENCESTATE);
2252 if (!pCB->activeRenderPass) {
2253 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2254 "Incorrect call to vkCmdSetStencilReference() without an active RenderPass.");
2255 }
2256 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2257 pCB->front.stencilReference = stencilReference;
2258 }
2259 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2260 pCB->back.stencilReference = stencilReference;
2261 }
2262 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
2263 } else {
2264 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilReference()");
2265 }
2266 }
2267 if (VK_FALSE == skipCall)
2268 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilReference(cmdBuffer, faceMask, stencilReference);
2269}
2270
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002271VK_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 -06002272{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002273 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002274 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2275 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002276 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002277 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002278 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 -06002279 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002280 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002281 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 -06002282 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002283 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002284 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002285 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2286 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002287 loader_platform_thread_lock_mutex(&globalLock);
2288 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002289 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002290 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2291 g_lastBoundDescriptorSet = pDescriptorSets[i];
2292 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002293 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 -06002294 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002295 if (!pSet->pUpdateStructs)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002296 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 -06002297 "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 -06002298 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002299 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 -06002300 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002301 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002302 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002303 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002304 skipCall |= addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002305 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002306 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002307 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002308 }
2309 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002310 if (VK_FALSE == skipCall)
2311 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 -06002312}
2313
Tony Barbour8205d902015-04-16 15:59:00 -06002314VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002315{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002316 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002317 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2318 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002319 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002320 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002321 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 -06002322 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002323 }
2324 VkDeviceSize offset_align = 0;
2325 switch (indexType) {
2326 case VK_INDEX_TYPE_UINT16:
2327 offset_align = 2;
2328 break;
2329 case VK_INDEX_TYPE_UINT32:
2330 offset_align = 4;
2331 break;
2332 default:
2333 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
2334 break;
2335 }
2336 if (!offset_align || (offset % offset_align)) {
2337 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
2338 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06002339 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002340 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002341 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002342 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002343 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
2344 updateCBTracking(cmdBuffer);
2345 skipCall |= addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002346 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002347 if (VK_FALSE == skipCall)
2348 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002349}
2350
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002351VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2352 VkCmdBuffer cmdBuffer,
2353 uint32_t startBinding,
2354 uint32_t bindingCount,
2355 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002356 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002357{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002358 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002359 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2360 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002361 if (pCB->state == CB_UPDATE_ACTIVE) {
2362 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002363 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002364 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 -06002365 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2366 } else {
2367 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002368 updateCBTracking(cmdBuffer);
2369 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002370 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002371 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002372 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002373 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002374 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002375 if (VK_FALSE == skipCall)
2376 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002377}
2378
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002379VK_LAYER_EXPORT void VKAPI vkCmdDraw(VkCmdBuffer cmdBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002380{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002381 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002382 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2383 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002384 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002385 pCB->drawCount[DRAW]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002386 skipCall |= validate_draw_state(pCB, VK_FALSE);
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -06002387 /* TODOVV: Check that scissor and viewport counts are the same */
2388 /* TODOVV: Do we need to check that viewportCount given in pipeline's
2389 * VkPipelineViewportStateCreateInfo matches scissor & viewport counts
2390 * given as dynamic state? Or is the count given in VkPipelineViewportStateCreateInfo
2391 * simply indicate the number of viewport / scissor to use at this time?
2392 */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002393 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002394 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 -06002395 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002396 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2397 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002398 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002399 skipCall |= addCmd(pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002400 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002401 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002402 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002403 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002404 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002405 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002406 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002407}
2408
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002409VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexed(VkCmdBuffer cmdBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002410{
2411 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002412 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002413 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002414 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002415 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002416 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002417 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002418 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 -06002419 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002420 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2421 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002422 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002423 skipCall |= addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002424 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002425 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002426 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002427 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002428 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002429 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002430 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002431}
2432
Tony Barbour8205d902015-04-16 15:59:00 -06002433VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002434{
2435 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002436 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002437 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002438 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002439 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002440 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002441 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002442 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 -06002443 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002444 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2445 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002446 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002447 skipCall |= addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002448 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002449 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002450 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002451 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002452 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002453 if (VK_FALSE == skipCall)
2454 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002455}
2456
Tony Barbour8205d902015-04-16 15:59:00 -06002457VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002458{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002459 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002460 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2461 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002462 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002463 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002464 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002465 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002466 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 -06002467 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002468 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2469 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002470 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002471 skipCall |= addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002472 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002473 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002474 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002475 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002476 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002477 if (VK_FALSE == skipCall)
2478 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002479}
2480
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002481VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002482{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002483 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2485 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002486 if (pCB->state == CB_UPDATE_ACTIVE) {
2487 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002488 skipCall |= addCmd(pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002489 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002490 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002491 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002492 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002493 if (VK_FALSE == skipCall)
2494 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002495}
2496
Tony Barbour8205d902015-04-16 15:59:00 -06002497VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002498{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002499 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002500 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2501 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002502 if (pCB->state == CB_UPDATE_ACTIVE) {
2503 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002504 skipCall |= addCmd(pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002505 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002506 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002507 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002508 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002509 if (VK_FALSE == skipCall)
2510 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002511}
2512
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002513VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002514{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002515 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002516 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2517 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002518 if (pCB->state == CB_UPDATE_ACTIVE) {
2519 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002520 skipCall |= addCmd(pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002521 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002522 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002523 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002524 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002525 if (VK_FALSE == skipCall)
2526 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002527}
2528
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002529VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2530 VkImage srcImage,
2531 VkImageLayout srcImageLayout,
2532 VkImage destImage,
2533 VkImageLayout destImageLayout,
2534 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002535{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002536 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002537 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2538 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002539 if (pCB->state == CB_UPDATE_ACTIVE) {
2540 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002541 skipCall |= addCmd(pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002542 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002543 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002544 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002545 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002546 if (VK_FALSE == skipCall)
2547 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002548}
2549
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002550VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2551 VkImage srcImage, VkImageLayout srcImageLayout,
2552 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002553 uint32_t regionCount, const VkImageBlit* pRegions,
2554 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002555{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002556 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002557 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2558 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002559 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002560 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002561 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 -06002562 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002563 } else {
2564 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002565 skipCall |= addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002566 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002567 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002568 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002569 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002570 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002571 if (VK_FALSE == skipCall)
2572 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 -06002573}
2574
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002575VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2576 VkBuffer srcBuffer,
2577 VkImage destImage, VkImageLayout destImageLayout,
2578 uint32_t regionCount, const VkBufferImageCopy* pRegions)
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_COPYBUFFERTOIMAGE);
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)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002592}
2593
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002594VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2595 VkImage srcImage, VkImageLayout srcImageLayout,
2596 VkBuffer destBuffer,
2597 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002598{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002599 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002600 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2601 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002602 if (pCB->state == CB_UPDATE_ACTIVE) {
2603 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002604 skipCall |= addCmd(pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002605 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002606 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002607 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002608 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002609 if (VK_FALSE == skipCall)
2610 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002611}
2612
Tony Barbour8205d902015-04-16 15:59:00 -06002613VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002614{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002615 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002616 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2617 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002618 if (pCB->state == CB_UPDATE_ACTIVE) {
2619 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002620 skipCall |= addCmd(pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002621 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002622 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002623 }
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002624 if (pCB->activeRenderPass) {
2625 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2626 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2627 "CmdUpdateBuffer cmd issued within an active RenderPass -- vkCmdUpdateBuffer "
2628 "may only be called outside of a RenderPass.");
2629 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002630 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002631 if (VK_FALSE == skipCall)
2632 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002633}
2634
Tony Barbour8205d902015-04-16 15:59:00 -06002635VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002636{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002637 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002638 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2639 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002640 if (pCB->state == CB_UPDATE_ACTIVE) {
2641 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002642 skipCall |= addCmd(pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002643 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002644 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002645 }
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002646 if (pCB->activeRenderPass) {
2647 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2648 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2649 "CmdFillBuffer cmd issued within an active RenderPass -- vkCmdFillBuffer "
2650 "may only be called outside of a RenderPass.");
2651 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002652 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002653 if (VK_FALSE == skipCall)
2654 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002655}
2656
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002657VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2658 VkCmdBuffer cmdBuffer,
2659 uint32_t colorAttachment,
2660 VkImageLayout imageLayout,
2661 const VkClearColorValue* pColor,
2662 uint32_t rectCount,
2663 const VkRect3D* pRects)
2664{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002665 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002666 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2667 if (pCB) {
2668 if (pCB->state == CB_UPDATE_ACTIVE) {
2669 // Warn if this is issued prior to Draw Cmd
2670 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002671 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002672 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 -06002673 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002674 " 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 -06002675 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002676 if (!pCB->activeRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002677 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2678 (uint64_t)cmdBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2679 "CmdClearColorAttachment cmd issued outside of an active RenderPass. "
2680 "vkCmdClearColorAttachment() must only be called inside of a RenderPass."
Tobin Ehlis92a89912015-06-23 11:34:28 -06002681 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2682 } else {
2683 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002684 skipCall |= addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002685 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002686 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002687 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002688 }
2689 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002690 if (VK_FALSE == skipCall)
2691 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002692}
2693
2694VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2695 VkCmdBuffer cmdBuffer,
2696 VkImageAspectFlags imageAspectMask,
2697 VkImageLayout imageLayout,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002698 const VkClearDepthStencilValue* pDepthStencil,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002699 uint32_t rectCount,
2700 const VkRect3D* pRects)
2701{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002702 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002703 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2704 if (pCB) {
2705 if (pCB->state == CB_UPDATE_ACTIVE) {
2706 // Warn if this is issued prior to Draw Cmd
2707 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002708 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002709 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 -06002710 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002711 " 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 -06002712 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002713 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002714 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 -06002715 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2716 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2717 } else {
2718 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002719 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002720 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002721 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002722 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002723 }
2724 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002725 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002726 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, pDepthStencil, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002727}
2728
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002729VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2730 VkCmdBuffer cmdBuffer,
2731 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002732 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002733 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002734{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002735 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002736 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2737 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002738 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002739 if (pCB->activeRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002740 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2741 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2742 "CmdClearColorImage cmd issued within an active RenderPass. "
2743 "vkCmdClearColorImage() must only be called outside of a RenderPass. "
2744 "vkCmdClearColorAttachment() should be used within a RenderPass.");
Tobin Ehlis92a89912015-06-23 11:34:28 -06002745 } else {
2746 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002747 skipCall |= addCmd(pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002748 }
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)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002755}
2756
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002757VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(
2758 VkCmdBuffer cmdBuffer,
2759 VkImage image, VkImageLayout imageLayout,
2760 const VkClearDepthStencilValue *pDepthStencil,
2761 uint32_t rangeCount,
2762 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002763{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002764 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002765 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2766 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002767 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002768 if (pCB->activeRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002769 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2770 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2771 "CmdClearDepthStencilImage cmd issued within an active RenderPass. "
2772 "vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
Tobin Ehlis92a89912015-06-23 11:34:28 -06002773 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2774 } else {
2775 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002776 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002777 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002778 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002779 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002780 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002781 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002782 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002783 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002784}
2785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002786VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2787 VkImage srcImage, VkImageLayout srcImageLayout,
2788 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002789 uint32_t regionCount, const VkImageResolve* pRegions)
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) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002795 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002796 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 -06002797 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002798 } else {
2799 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002800 skipCall |= addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002801 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002802 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002803 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002804 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002805 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002806 if (VK_FALSE == skipCall)
2807 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002808}
2809
Tony Barbourc2e987e2015-06-29 16:20:35 -06002810VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002811{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002812 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002813 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2814 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002815 if (pCB->state == CB_UPDATE_ACTIVE) {
2816 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002817 skipCall |= addCmd(pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002818 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002819 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002820 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002821 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002822 if (VK_FALSE == skipCall)
2823 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002824}
2825
Tony Barbourc2e987e2015-06-29 16:20:35 -06002826VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002827{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002828 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002829 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2830 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002831 if (pCB->state == CB_UPDATE_ACTIVE) {
2832 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002833 skipCall |= addCmd(pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002834 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002835 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002836 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002837 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002838 if (VK_FALSE == skipCall)
2839 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002840}
2841
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002842VK_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 -06002843{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002844 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002845 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2846 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002847 if (pCB->state == CB_UPDATE_ACTIVE) {
2848 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002849 skipCall |= addCmd(pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002850 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002851 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002852 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002853 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002854 if (VK_FALSE == skipCall)
2855 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002856}
2857
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002858VK_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 -06002859{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002860 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002861 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2862 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002863 if (pCB->state == CB_UPDATE_ACTIVE) {
2864 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002865 skipCall |= addCmd(pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002866 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002867 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002868 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002869 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002870 if (VK_FALSE == skipCall)
2871 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002872}
2873
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002874VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002875{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002876 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002877 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2878 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002879 if (pCB->state == CB_UPDATE_ACTIVE) {
2880 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002881 skipCall |= addCmd(pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002882 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002883 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002884 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002885 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002886 if (VK_FALSE == skipCall)
2887 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002888}
2889
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002890VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002891{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002892 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002893 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2894 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002895 if (pCB->state == CB_UPDATE_ACTIVE) {
2896 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002897 skipCall |= addCmd(pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002898 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002899 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002900 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002901 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002902 if (VK_FALSE == skipCall)
2903 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002904}
2905
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002906VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002907{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002908 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002909 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2910 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002911 if (pCB->state == CB_UPDATE_ACTIVE) {
2912 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002913 skipCall |= addCmd(pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002914 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002915 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002916 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002917 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002918 if (VK_FALSE == skipCall)
2919 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002920}
2921
Tony Barbour8205d902015-04-16 15:59:00 -06002922VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002923{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002924 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002925 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2926 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002927 if (pCB->state == CB_UPDATE_ACTIVE) {
2928 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002929 skipCall |= addCmd(pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002930 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002931 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002932 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002933 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002934 if (VK_FALSE == skipCall)
2935 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002936}
2937
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002938VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002939{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002940 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002941 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002942 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002943 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002944 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002945 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2946 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002947 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002948 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002949 }
2950 return result;
2951}
2952
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002953VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002954{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002955 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002956 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002957 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002958 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002959 if (pCreateInfo->pAttachments) {
2960 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2961 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002962 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002963 if (pCreateInfo->pSubpasses) {
2964 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2965 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2966
2967 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2968 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2969 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002970 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002971 subpass->preserveCount;
2972 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2973
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002974 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002975 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002976 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002977 attachments += subpass->inputCount;
2978
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002979 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002980 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002981 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002982 attachments += subpass->colorCount;
2983
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002984 if (subpass->pResolveAttachments) {
2985 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002986 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002987 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002988 attachments += subpass->colorCount;
2989 }
2990
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002991 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002992 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002993 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002994 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06002995 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002996 if (pCreateInfo->pDependencies) {
2997 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
2998 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002999 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003000 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06003001 }
3002 return result;
3003}
3004
Chia-I Wuc278df82015-07-07 11:50:03 +08003005VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003006{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003007 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003008 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3009 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003010 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003011 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003012 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 -06003013 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06003014 } else {
3015 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003016 skipCall |= addCmd(pCB, CMD_BEGINRENDERPASS);
Tobin Ehlise4076782015-06-24 15:53:07 -06003017 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003018 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06003019 pCB->framebuffer = pRenderPassBegin->framebuffer;
3020 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003021 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06003022 }
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003023 }
Tobin Ehlise4076782015-06-24 15:53:07 -06003024 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003025 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 -06003026 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06003027 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003028 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003029 if (VK_FALSE == skipCall)
3030 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003031}
3032
Chia-I Wuc278df82015-07-07 11:50:03 +08003033VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
3034{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003035 VkBool32 skipCall = VK_FALSE;
Chia-I Wuc278df82015-07-07 11:50:03 +08003036 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3037 if (pCB) {
3038 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003039 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 +08003040 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
3041 } else {
3042 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003043 skipCall |= addCmd(pCB, CMD_NEXTSUBPASS);
Chia-I Wuc278df82015-07-07 11:50:03 +08003044 pCB->activeSubpass++;
3045 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003046 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08003047 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003048 }
3049 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003050 if (VK_FALSE == skipCall)
3051 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08003052}
3053
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003054VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003055{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003056 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003057 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3058 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003059 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003060 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 +08003061 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06003062 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003063 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003064 skipCall |= addCmd(pCB, CMD_ENDRENDERPASS);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003065 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08003066 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003067 }
3068 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003069 if (VK_FALSE == skipCall)
3070 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003071}
3072
3073VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3074{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003075 VkBool32 skipCall = VK_FALSE;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003076 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3077 if (pCB) {
3078 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003079 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 +08003080 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003081 }
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003082 GLOBAL_CB_NODE* pSubCB = NULL;
3083 for (uint32_t i=0; i<cmdBuffersCount; i++) {
3084 pSubCB = getCBNode(pCmdBuffers[i]);
3085 if (!pSubCB) {
3086 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3087 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCmdBuffers array.", (void*)pCmdBuffers[i], i);
3088 } else if (VK_CMD_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
3089 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3090 "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);
3091 }
3092 }
3093 updateCBTracking(cmdBuffer);
3094 skipCall |= addCmd(pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003095 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003096 if (VK_FALSE == skipCall)
3097 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003098}
3099
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003100VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3101 VkInstance instance,
3102 VkFlags msgFlags,
3103 const PFN_vkDbgMsgCallback pfnMsgCallback,
3104 void* pUserData,
3105 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003106{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003107 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003108 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3109 if (VK_SUCCESS == res) {
3110 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3111 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3112 }
3113 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003114}
3115
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003116VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3117 VkInstance instance,
3118 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003119{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003120 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003121 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3122 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3123 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3124 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003125}
3126
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003127VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003128{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003129 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003130 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003131 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3132 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003133 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003134 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 -06003135 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003136 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003137 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003138 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003139 skipCall |= addCmd(pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003140 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003141 if (VK_FALSE == skipCall)
3142 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003143}
3144
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003145VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003146{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003147 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003148 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003149 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3150 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003151 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003152 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 -06003153 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003154 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003155 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003156 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003157 skipCall |= addCmd(pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003158 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003159 if (VK_FALSE == skipCall)
3160 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003161}
3162
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003163//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3164//{
3165// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3166// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3167// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3168// "Attempt to use DbgSetObjectTag but extension disabled!");
3169// return VK_ERROR_UNAVAILABLE;
3170// }
3171// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3172//}
3173//
3174//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3175//{
3176// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3177// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3178// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3179// "Attempt to use DbgSetObjectName but extension disabled!");
3180// return VK_ERROR_UNAVAILABLE;
3181// }
3182// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3183//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003184
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003185VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003186{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003187 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003188 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003189
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003190 /* loader uses this to force layer initialization; device object is wrapped */
3191 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003192 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003193 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003194 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003195 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003196 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003197 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003198 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003199 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003200 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003201 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003202 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003203 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003204 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003205 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003206 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003207 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003208 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003209 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003210 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003211 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003212 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003213 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003214 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003215 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003216 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003217 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003218 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003219 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003220 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003221 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003222 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003223 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003224 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003225 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003226 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003227 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003228 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003229 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003230 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003231 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003232 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003233 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003234 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003235 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003236 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003237 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003238 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003239 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003240 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003241 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003242 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003243 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003244 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003245 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003246 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003247 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003248 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003249 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003250 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003251 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003252 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003253 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003254 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003255 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003256 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003257 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003258 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003259 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003260 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003261 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003262 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003263 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003264 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003265 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003266 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003267 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003268 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003269 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003270 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003271 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003272 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003273 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003274 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003275 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003276 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003277 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003278 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003279 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003280 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003281 if (!strcmp(funcName, "vkCmdSetViewport"))
3282 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003283 if (!strcmp(funcName, "vkCmdSetScissor"))
3284 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003285 if (!strcmp(funcName, "vkCmdSetLineWidth"))
3286 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
3287 if (!strcmp(funcName, "vkCmdSetDepthBias"))
3288 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
3289 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
3290 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
3291 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
3292 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
3293 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
3294 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
3295 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
3296 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
3297 if (!strcmp(funcName, "vkCmdSetStencilReference"))
3298 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003299 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003300 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003301 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003302 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003303 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003304 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003305 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003306 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003307 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003308 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003309 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003310 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003311 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003312 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003313 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003314 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003315 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003316 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003317 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003318 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003319 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003320 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003321 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003322 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003323 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003324 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003325 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003326 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003327 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003328 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003329 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003330 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003331 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003332 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003333 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003334 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003335 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003336 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003337 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003338 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003339 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003340 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003341 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003342 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003343 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003344 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003345 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003346 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003347 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003348 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003349 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003350 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003351 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003352 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003353 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003354 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003355 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003356 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003357 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003358 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003359 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003360 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003361 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003362 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003363 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003364 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003365 if (!strcmp(funcName, "vkCmdExecuteCommands"))
3366 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003367
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003368 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3369 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003370 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003371 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003372 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003373 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003374 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003375// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3376// return (void*) vkDbgSetObjectTag;
3377// if (!strcmp(funcName, "vkDbgSetObjectName"))
3378// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003379 }
3380 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003381 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003382 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003383 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003384 }
3385}
3386
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003387VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003388{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003389 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003390 if (instance == NULL)
3391 return NULL;
3392
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003393 /* loader uses this to force layer initialization; instance object is wrapped */
3394 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003395 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003396 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003397 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003398 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003399 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003400 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003401 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06003402 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
3403 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
3404 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
3405 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
3406 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
3407 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
3408 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
3409 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003410
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003411 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3412 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003413 if (fptr)
3414 return fptr;
3415
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003416 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003417 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003418 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003419 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003420 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003421 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003422}