blob: 646fff775ce879cf6aa0c678d5944f924a424221 [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++) {
Tobin Ehlis3b341092015-09-30 08:30:20 -0600839 if (pLayout->pTypes[i] != actualType) {
840 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
841 "Descriptor update type of %s has descriptor type %s that does not match overlapping binding descriptor type of %s!",
842 string_VkStructureType(pUpdateStruct->sType), string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->pTypes[i]));
843 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600844 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600845 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600846 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600847}
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600848// Determine the update type, allocate a new struct of that type, shadow the given pUpdate
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600849// struct into the pNewNode param. Return VK_TRUE if error condition encountered and callback signals early exit.
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600850// NOTE : Calls to this function should be wrapped in mutex
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600851static VkBool32 shadowUpdateNode(const VkDevice device, GENERIC_HEADER* pUpdate, GENERIC_HEADER** pNewNode)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600852{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600853 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800854 VkWriteDescriptorSet* pWDS = NULL;
855 VkCopyDescriptorSet* pCDS = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600856 size_t array_size = 0;
857 size_t base_array_size = 0;
858 size_t total_array_size = 0;
859 size_t baseBuffAddr = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600860 switch (pUpdate->sType)
861 {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800862 case VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET:
863 pWDS = new VkWriteDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600864 *pNewNode = (GENERIC_HEADER*)pWDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800865 memcpy(pWDS, pUpdate, sizeof(VkWriteDescriptorSet));
866 pWDS->pDescriptors = new VkDescriptorInfo[pWDS->count];
867 array_size = sizeof(VkDescriptorInfo) * pWDS->count;
868 memcpy((void*)pWDS->pDescriptors, ((VkWriteDescriptorSet*)pUpdate)->pDescriptors, array_size);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600869 break;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800870 case VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET:
871 pCDS = new VkCopyDescriptorSet;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600872 *pNewNode = (GENERIC_HEADER*)pCDS;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800873 memcpy(pCDS, pUpdate, sizeof(VkCopyDescriptorSet));
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600874 break;
875 default:
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600876 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_UPDATE_STRUCT, "DS",
877 "Unexpected UPDATE struct of type %s (value %u) in vkUpdateDescriptors() struct tree", string_VkStructureType(pUpdate->sType), pUpdate->sType))
878 return VK_TRUE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600879 }
880 // Make sure that pNext for the end of shadow copy is NULL
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600881 (*pNewNode)->pNext = NULL;
882 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600883}
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800884// update DS mappings based on ppUpdateArray
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600885static VkBool32 dsUpdate(VkDevice device, VkStructureType type, uint32_t updateCount, const void* pUpdateArray)
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600886{
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800887 const VkWriteDescriptorSet *pWDS = NULL;
888 const VkCopyDescriptorSet *pCDS = NULL;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600889 VkBool32 skipCall = VK_FALSE;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800890
891 if (type == VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
892 pWDS = (const VkWriteDescriptorSet *) pUpdateArray;
893 else
894 pCDS = (const VkCopyDescriptorSet *) pUpdateArray;
895
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600896 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600897 LAYOUT_NODE* pLayout = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600898 VkDescriptorSetLayoutCreateInfo* pLayoutCI = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600899 // TODO : If pCIList is NULL, flag error
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600900 // Perform all updates
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600901 for (uint32_t i = 0; i < updateCount; i++) {
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800902 VkDescriptorSet ds = (pWDS) ? pWDS->destSet : pCDS->destSet;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -0600903 SET_NODE* pSet = setMap[ds.handle]; // getSetNode() without locking
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +0800904 g_lastBoundDescriptorSet = pSet->set;
905 GENERIC_HEADER* pUpdate = (pWDS) ? (GENERIC_HEADER*) &pWDS[i] : (GENERIC_HEADER*) &pCDS[i];
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600906 pLayout = pSet->pLayout;
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600907 // First verify valid update struct
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600908 if ((skipCall = validUpdateStruct(device, pUpdate)) == VK_TRUE) {
Tobin Ehlis0b551cd2015-05-28 12:10:17 -0600909 break;
910 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600911 // Make sure that binding is within bounds
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600912 uint32_t binding = 0, endIndex = 0;
913 skipCall |= getUpdateBinding(device, pUpdate, &binding);
914 if (pLayout->createInfo.count < binding) {
915 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, ds.handle, 0, DRAWSTATE_INVALID_UPDATE_INDEX, "DS",
916 "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 -0600917 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600918 // Next verify that update falls within size of given binding
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600919 skipCall |= getUpdateBinding(device, pUpdate, &binding);
920 skipCall |= getUpdateEndIndex(device, pLayout, pUpdate, &endIndex);
921 if (getBindingEndIndex(pLayout, binding) < endIndex) {
Tony Barbour29b12062015-07-13 13:37:24 -0600922 // TODO : Keep count of layout CI structs and size this string dynamically based on that count
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600923 pLayoutCI = &pLayout->createInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600924 string DSstr = vk_print_vkdescriptorsetlayoutcreateinfo(pLayoutCI, "{DS} ");
Tobin Ehlis48ddcb82015-09-09 11:31:10 -0600925 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",
926 "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 -0600927 } else { // TODO : should we skip update on a type mismatch or force it?
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -0600928 // Layout bindings match w/ update ok, now verify that update is of the right type
Tobin Ehlis3b341092015-09-30 08:30:20 -0600929 if ((skipCall = validateUpdateType(device, pLayout, pUpdate)) == VK_FALSE) {
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) {
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001154 // Account for any dynamic state not set via this PSO
1155 // First consider all state on
1156 // Then unset any state that's noted as dynamic in PSO
1157 // Finally OR that into CB statemask
1158 CBStatusFlags psoDynStateMask = CBSTATUS_ALL;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001159 for (uint32_t i=0; i < pPipe->dynStateCI.dynamicStateCount; i++) {
1160 switch (pPipe->dynStateCI.pDynamicStates[i]) {
1161 case VK_DYNAMIC_STATE_VIEWPORT:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001162 psoDynStateMask &= ~CBSTATUS_VIEWPORT_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001163 break;
1164 case VK_DYNAMIC_STATE_SCISSOR:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001165 psoDynStateMask &= ~CBSTATUS_SCISSOR_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001166 break;
1167 case VK_DYNAMIC_STATE_LINE_WIDTH:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001168 psoDynStateMask &= ~CBSTATUS_LINE_WIDTH_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001169 break;
1170 case VK_DYNAMIC_STATE_DEPTH_BIAS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001171 psoDynStateMask &= ~CBSTATUS_DEPTH_BIAS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001172 break;
1173 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001174 psoDynStateMask &= ~CBSTATUS_BLEND_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001175 break;
1176 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001177 psoDynStateMask &= ~CBSTATUS_DEPTH_BOUNDS_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001178 break;
1179 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001180 psoDynStateMask &= ~CBSTATUS_STENCIL_READ_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001181 break;
1182 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001183 psoDynStateMask &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001184 break;
1185 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001186 psoDynStateMask &= ~CBSTATUS_STENCIL_REFERENCE_SET;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001187 break;
1188 default:
1189 // TODO : Flag error here
1190 break;
1191 }
1192 }
Tobin Ehlis3dec46c2015-10-01 09:24:40 -06001193 pCB->status |= psoDynStateMask;
Tobin Ehlisf6cb4672015-09-29 08:18:34 -06001194 }
Tobin Ehlis97866202015-06-10 12:57:07 -06001195}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001196// Print the last bound Gfx Pipeline
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001197static VkBool32 printPipeline(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001198{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001199 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001200 GLOBAL_CB_NODE* pCB = getCBNode(cb);
1201 if (pCB) {
1202 PIPELINE_NODE *pPipeTrav = getPipeline(pCB->lastBoundPipeline);
1203 if (!pPipeTrav) {
1204 // nothing to print
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001205 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001206 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001207 vk_print_vkgraphicspipelinecreateinfo(&pPipeTrav->graphicsPipelineCI, "{DS}").c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001208 }
1209 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001210 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001211}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001212// Print details of DS config to stdout
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001213static VkBool32 printDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001214{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001215 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001216 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.
1217 GLOBAL_CB_NODE* pCB = getCBNode(cb);
Tobin Ehlis7297f192015-06-09 08:39:32 -06001218 if (pCB && pCB->lastBoundDescriptorSet) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001219 SET_NODE* pSet = getSetNode(pCB->lastBoundDescriptorSet);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001220 POOL_NODE* pPool = getPoolNode(pSet->pool);
1221 // Print out pool details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001222 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001223 "Details for pool %#" PRIxLEAST64 ".", pPool->pool.handle);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001224 string poolStr = vk_print_vkdescriptorpoolcreateinfo(&pPool->createInfo, " ");
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 Ehlisfde4dce2015-06-16 15:50:44 -06001226 "%s", poolStr.c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001227 // Print out set details
1228 char prefix[10];
1229 uint32_t index = 0;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001230 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001231 "Details for descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001232 LAYOUT_NODE* pLayout = pSet->pLayout;
1233 // Print layout details
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001234 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001235 "Layout #%u, (object %#" PRIxLEAST64 ") for DS %#" PRIxLEAST64 ".", index+1, (void*)pLayout->layout.handle, (void*)pSet->set.handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001236 sprintf(prefix, " [L%u] ", index);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001237 string DSLstr = vk_print_vkdescriptorsetlayoutcreateinfo(&pLayout->createInfo, prefix).c_str();
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 Ehlisfde4dce2015-06-16 15:50:44 -06001239 "%s", DSLstr.c_str());
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001240 index++;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001241 GENERIC_HEADER* pUpdate = pSet->pUpdateStructs;
1242 if (pUpdate) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001243 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001244 "Update Chain [UC] for descriptor set %#" PRIxLEAST64 ":", pSet->set.handle);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001245 sprintf(prefix, " [UC] ");
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 Ehlisfde4dce2015-06-16 15:50:44 -06001247 dynamic_display(pUpdate, prefix).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001248 // TODO : If there is a "view" associated with this update, print CI for that view
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001249 } else {
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001250 if (0 != pSet->descriptorCount) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001251 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001252 "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 -06001253 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001254 skipCall |= log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001255 "FYI: No descriptors in descriptor set %#" PRIxLEAST64 ".", pSet->set.handle);
Tobin Ehlis2bca8b02015-06-15 08:41:17 -06001256 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001257 }
1258 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001259 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001260}
1261
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001262static void printCB(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001263{
1264 GLOBAL_CB_NODE* pCB = getCBNode(cb);
David Pinedof5997ab2015-04-27 16:36:17 -06001265 if (pCB && pCB->pCmds.size() > 0) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001266 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NONE, "DS",
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001267 "Cmds in CB %p", (void*)cb);
Courtney Goeltzenleuchtercf2a5362015-04-27 11:16:35 -06001268 vector<CMD_NODE*> pCmds = pCB->pCmds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001269 for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) {
1270 // TODO : Need to pass cb as srcObj here
1271 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 -06001272 " CMD#%lu: %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str());
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001273 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001274 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001275 // Nothing to print
1276 }
1277}
1278
1279
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001280static VkBool32 synchAndPrintDSConfig(const VkCmdBuffer cb)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001281{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001282 VkBool32 skipCall = VK_FALSE;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001283 if (!(mdd(cb)->active_flags & VK_DBG_REPORT_INFO_BIT)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001284 return skipCall;
Mike Stroyanfa2f2222015-08-12 17:11:28 -06001285 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001286 skipCall |= printDSConfig(cb);
1287 skipCall |= printPipeline(cb);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001288 return skipCall;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001289}
1290
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001291static void init_draw_state(layer_data *my_data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001292{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001293 uint32_t report_flags = 0;
1294 uint32_t debug_action = 0;
1295 FILE *log_output = NULL;
1296 const char *option_str;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001297 // initialize DrawState options
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001298 report_flags = getLayerOptionFlags("DrawStateReportFlags", 0);
1299 getLayerOptionEnum("DrawStateDebugAction", (uint32_t *) &debug_action);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001300
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001301 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001302 {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001303 option_str = getLayerOption("DrawStateLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -06001304 log_output = getLayerLogOutput(option_str, "DrawState");
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001305 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 -06001306 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001307
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001308 if (!globalLockInitialized)
1309 {
Mike Stroyand9dd0072015-08-18 15:56:18 -06001310 // This mutex may be deleted by vkDestroyInstance of last instance.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001311 loader_platform_thread_create_mutex(&globalLock);
1312 globalLockInitialized = 1;
1313 }
1314}
1315
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001316VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
1317{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001318 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map,*pInstance);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001319 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
1320
1321 if (result == VK_SUCCESS) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001322 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1323 my_data->report_data = debug_report_create_instance(
1324 pTable,
1325 *pInstance,
1326 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001327 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchterf4a2eba2015-06-08 14:58:39 -06001328
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001329 init_draw_state(my_data);
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06001330 }
1331 return result;
1332}
1333
Jon Ashburne0fa2282015-05-20 09:00:28 -06001334/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001335VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Jon Ashburne0fa2282015-05-20 09:00:28 -06001336{
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001337 dispatch_key key = get_dispatch_key(instance);
1338 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001339 pTable->DestroyInstance(instance);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001340
1341 // Clean up logging callback, if any
1342 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
1343 if (my_data->logging_callback) {
1344 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1345 }
1346
Courtney Goeltzenleuchter2d034fd2015-06-28 13:01:17 -06001347 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001348 layer_data_map.erase(pTable);
1349
1350 draw_state_instance_table_map.erase(key);
Mike Stroyand9dd0072015-08-18 15:56:18 -06001351 if (draw_state_instance_table_map.empty()) {
1352 // Release mutex when destroying last instance.
1353 loader_platform_thread_delete_mutex(&globalLock);
1354 globalLockInitialized = 0;
1355 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06001356}
1357
Jon Ashburnf0615e22015-05-25 14:11:37 -06001358static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1359{
Tony Barbour29b12062015-07-13 13:37:24 -06001360 uint32_t i;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001361 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001362 deviceExtMap[pDisp].debug_marker_enabled = false;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001363
1364 for (i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001365 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001366 /* Found a matching extension name, mark it enabled and init dispatch table*/
1367 initDebugMarkerTable(device);
1368 deviceExtMap[pDisp].debug_marker_enabled = true;
Jon Ashburnf0615e22015-05-25 14:11:37 -06001369 }
1370
1371 }
1372}
1373
Tony Barbour8205d902015-04-16 15:59:00 -06001374VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001375{
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06001376 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1377 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001378 if (result == VK_SUCCESS) {
1379 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
1380 VkLayerDispatchTable *pTable = get_dispatch_table(draw_state_device_table_map, *pDevice);
1381 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1382 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001383 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001384 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001385 return result;
1386}
1387
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001388VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001389{
1390 // Free all the memory
1391 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehliseaf28662015-04-08 10:58:37 -06001392 deletePipelines();
1393 deleteSamplers();
1394 deleteImages();
1395 deleteBuffers();
1396 deleteCmdBuffers();
Tobin Ehliseaf28662015-04-08 10:58:37 -06001397 deletePools();
1398 deleteLayouts();
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001399 loader_platform_thread_unlock_mutex(&globalLock);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001400
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001401 dispatch_key key = get_dispatch_key(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001402 VkLayerDispatchTable *pDisp = get_dispatch_table(draw_state_device_table_map, device);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001403 pDisp->DestroyDevice(device);
Jon Ashburn7e07faf2015-06-18 15:02:58 -06001404 deviceExtMap.erase(pDisp);
Jeremy Hayesea1fef52015-06-19 11:37:38 -06001405 draw_state_device_table_map.erase(key);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06001406 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001407}
1408
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001409static const VkLayerProperties ds_global_layers[] = {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001410 {
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001411 "DrawState",
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001412 VK_API_VERSION,
1413 VK_MAKE_VERSION(0, 1, 0),
1414 "Validation layer: DrawState",
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06001415 }
Jon Ashburneb2728b2015-04-10 14:33:07 -06001416};
1417
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001418VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001419 const char *pLayerName,
1420 uint32_t *pCount,
1421 VkExtensionProperties* pProperties)
Jon Ashburneb2728b2015-04-10 14:33:07 -06001422{
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001423 /* DrawState does not have any global extensions */
1424 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
1425}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001426
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001427VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001428 uint32_t *pCount,
1429 VkLayerProperties* pProperties)
1430{
1431 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
1432 ds_global_layers,
1433 pCount, pProperties);
1434}
Jon Ashburneb2728b2015-04-10 14:33:07 -06001435
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001436static const VkExtensionProperties ds_device_extensions[] = {
1437 {
1438 DEBUG_MARKER_EXTENSION_NAME,
1439 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001440 }
1441};
1442
1443static const VkLayerProperties ds_device_layers[] = {
1444 {
1445 "DrawState",
1446 VK_API_VERSION,
1447 VK_MAKE_VERSION(0, 1, 0),
1448 "Validation layer: DrawState",
1449 }
1450};
1451
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001452VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001453 VkPhysicalDevice physicalDevice,
1454 const char* pLayerName,
1455 uint32_t* pCount,
1456 VkExtensionProperties* pProperties)
1457{
1458 /* Mem tracker does not have any physical device extensions */
1459 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
1460 pCount, pProperties);
1461}
1462
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06001463VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Courtney Goeltzenleuchter73e8bd42015-07-06 22:31:52 -06001464 VkPhysicalDevice physicalDevice,
1465 uint32_t* pCount,
1466 VkLayerProperties* pProperties)
1467{
1468 /* Mem tracker's physical device layers are the same as global */
1469 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
1470 pCount, pProperties);
Jon Ashburneb2728b2015-04-10 14:33:07 -06001471}
1472
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001473VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(VkQueue queue, uint32_t cmdBufferCount, const VkCmdBuffer* pCmdBuffers, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001474{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001475 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001476 GLOBAL_CB_NODE* pCB = NULL;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001477 for (uint32_t i=0; i < cmdBufferCount; i++) {
1478 // Validate that cmd buffers have been updated
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001479 pCB = getCBNode(pCmdBuffers[i]);
1480 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001481 pCB->submitCount++; // increment submit count
1482 if ((pCB->beginInfo.flags & VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001483 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 -06001484 "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 -06001485 }
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001486 if (CB_UPDATE_COMPLETE != pCB->state) {
1487 // Flag error for using CB w/o vkEndCommandBuffer() called
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001488 // TODO : How to pass cb as srcObj?
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001489 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 -06001490 "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 -06001491 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001492 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis28be0be2015-05-22 12:38:16 -06001493 }
Tobin Ehlise9b700e2015-05-26 16:06:50 -06001494 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001495 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001496 if (VK_FALSE == skipCall)
1497 return get_dispatch_table(draw_state_device_table_map, queue)->QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
1498 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001499}
1500
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001501VK_LAYER_EXPORT void VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001502{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001503 get_dispatch_table(draw_state_device_table_map, device)->DestroyFence(device, fence);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001504 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001505}
1506
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001507VK_LAYER_EXPORT void VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001508{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001509 get_dispatch_table(draw_state_device_table_map, device)->DestroySemaphore(device, semaphore);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001510 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001511}
1512
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001513VK_LAYER_EXPORT void VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001514{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001515 get_dispatch_table(draw_state_device_table_map, device)->DestroyEvent(device, event);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001516 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001517}
1518
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001519VK_LAYER_EXPORT void VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001520{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001521 get_dispatch_table(draw_state_device_table_map, device)->DestroyQueryPool(device, queryPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001522 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001523}
1524
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001525VK_LAYER_EXPORT void VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001526{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001527 get_dispatch_table(draw_state_device_table_map, device)->DestroyBuffer(device, buffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001528 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001529}
1530
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001531VK_LAYER_EXPORT void VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001532{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001533 get_dispatch_table(draw_state_device_table_map, device)->DestroyBufferView(device, bufferView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001534 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001535}
1536
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001537VK_LAYER_EXPORT void VKAPI vkDestroyImage(VkDevice device, VkImage image)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001538{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001539 get_dispatch_table(draw_state_device_table_map, device)->DestroyImage(device, image);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001540 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001541}
1542
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001543VK_LAYER_EXPORT void VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001544{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001545 get_dispatch_table(draw_state_device_table_map, device)->DestroyImageView(device, imageView);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001546 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001547}
1548
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001549VK_LAYER_EXPORT void VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001550{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001551 get_dispatch_table(draw_state_device_table_map, device)->DestroyShaderModule(device, shaderModule);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001552 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001553}
1554
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001555VK_LAYER_EXPORT void VKAPI vkDestroyShader(VkDevice device, VkShader shader)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001556{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001557 get_dispatch_table(draw_state_device_table_map, device)->DestroyShader(device, shader);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001558 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001559}
1560
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001561VK_LAYER_EXPORT void VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001562{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001563 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipeline(device, pipeline);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001564 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001565}
1566
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001567VK_LAYER_EXPORT void VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001568{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001569 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001570 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001571}
1572
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001573VK_LAYER_EXPORT void VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001574{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001575 get_dispatch_table(draw_state_device_table_map, device)->DestroySampler(device, sampler);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001576 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001577}
1578
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001579VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001580{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001581 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001582 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001583}
1584
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001585VK_LAYER_EXPORT void VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001586{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001587 get_dispatch_table(draw_state_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001588 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001589}
1590
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001591VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001592{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001593 get_dispatch_table(draw_state_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001594 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001595}
1596
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001597VK_LAYER_EXPORT void VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001598{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001599 get_dispatch_table(draw_state_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001600 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001601}
1602
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001603VK_LAYER_EXPORT void VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001604{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001605 get_dispatch_table(draw_state_device_table_map, device)->DestroyRenderPass(device, renderPass);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001606 // TODO : Clean up any internal data structures using this obj.
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001607}
1608
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001609VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001610{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001611 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001612 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001613 loader_platform_thread_lock_mutex(&globalLock);
1614 BUFFER_NODE* pNewNode = new BUFFER_NODE;
1615 pNewNode->buffer = *pView;
1616 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001617 bufferMap[pView->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001618 loader_platform_thread_unlock_mutex(&globalLock);
1619 }
1620 return result;
1621}
1622
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001623VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001624{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001625 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001626 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001627 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001628 imageMap[pView->handle] = *pCreateInfo;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06001629 loader_platform_thread_unlock_mutex(&globalLock);
1630 }
1631 return result;
1632}
1633
Jon Ashburn0d60d272015-07-09 15:02:25 -06001634//TODO handle pipeline caches
1635VkResult VKAPI vkCreatePipelineCache(
1636 VkDevice device,
1637 const VkPipelineCacheCreateInfo* pCreateInfo,
1638 VkPipelineCache* pPipelineCache)
1639{
1640 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineCache(device, pCreateInfo, pPipelineCache);
1641 return result;
1642}
1643
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001644void VKAPI vkDestroyPipelineCache(
Jon Ashburn0d60d272015-07-09 15:02:25 -06001645 VkDevice device,
1646 VkPipelineCache pipelineCache)
1647{
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001648 get_dispatch_table(draw_state_device_table_map, device)->DestroyPipelineCache(device, pipelineCache);
Jon Ashburn0d60d272015-07-09 15:02:25 -06001649}
1650
1651size_t VKAPI vkGetPipelineCacheSize(
1652 VkDevice device,
1653 VkPipelineCache pipelineCache)
1654{
1655 size_t size = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheSize(device, pipelineCache);
1656 return size;
1657}
1658
1659VkResult VKAPI vkGetPipelineCacheData(
1660 VkDevice device,
1661 VkPipelineCache pipelineCache,
1662 void* pData)
1663{
1664 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->GetPipelineCacheData(device, pipelineCache, pData);
1665 return result;
1666}
1667
1668VkResult VKAPI vkMergePipelineCaches(
1669 VkDevice device,
1670 VkPipelineCache destCache,
1671 uint32_t srcCacheCount,
1672 const VkPipelineCache* pSrcCaches)
1673{
1674 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->MergePipelineCaches(device, destCache, srcCacheCount, pSrcCaches);
1675 return result;
1676}
1677
1678VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001679{
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001680 VkResult result = VK_SUCCESS;
Tobin Ehlise48be202015-09-16 10:33:53 -06001681 //TODO What to do with pipelineCache?
Tobin Ehlisde63c532015-06-18 15:59:33 -06001682 // The order of operations here is a little convoluted but gets the job done
1683 // 1. Pipeline create state is first shadowed into PIPELINE_NODE struct
1684 // 2. Create state is then validated (which uses flags setup during shadowing)
1685 // 3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
Tobin Ehlise48be202015-09-16 10:33:53 -06001686 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis76c18852015-09-17 16:33:58 -06001687 // TODO : Improve this data struct w/ unique_ptrs so cleanup below is automatic
1688 vector<PIPELINE_NODE*> pPipeNode(count);
Tobin Ehlise48be202015-09-16 10:33:53 -06001689 uint32_t i=0;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001690 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001691 for (i=0; i<count; i++) {
1692 pPipeNode[i] = initPipeline(&pCreateInfos[i], NULL);
1693 skipCall |= verifyPipelineCreateState(device, pPipeNode[i]);
1694 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001695 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001696 if (VK_FALSE == skipCall) {
Jon Ashburn0d60d272015-07-09 15:02:25 -06001697 result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Tobin Ehlisde63c532015-06-18 15:59:33 -06001698 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlise48be202015-09-16 10:33:53 -06001699 for (i=0; i<count; i++) {
1700 pPipeNode[i]->pipeline = pPipelines[i];
1701 pipelineMap[pPipeNode[i]->pipeline.handle] = pPipeNode[i];
1702 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001703 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001704 } else {
Tobin Ehlise48be202015-09-16 10:33:53 -06001705 for (i=0; i<count; i++) {
1706 if (pPipeNode[i]) {
1707 // If we allocated a pipeNode, need to clean it up here
1708 delete[] pPipeNode[i]->pVertexBindingDescriptions;
1709 delete[] pPipeNode[i]->pVertexAttributeDescriptions;
1710 delete[] pPipeNode[i]->pAttachments;
1711 delete pPipeNode[i];
1712 }
Tobin Ehlisde63c532015-06-18 15:59:33 -06001713 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001714 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisde63c532015-06-18 15:59:33 -06001715 }
Courtney Goeltzenleuchter9452ac22015-04-13 16:16:04 -06001716 return result;
1717}
1718
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001719VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001720{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001721 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001722 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001723 loader_platform_thread_lock_mutex(&globalLock);
1724 SAMPLER_NODE* pNewNode = new SAMPLER_NODE;
1725 pNewNode->sampler = *pSampler;
1726 pNewNode->createInfo = *pCreateInfo;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001727 sampleMap[pSampler->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001728 loader_platform_thread_unlock_mutex(&globalLock);
1729 }
1730 return result;
1731}
1732
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001733VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayout* pSetLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001734{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001735 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorSetLayout(device, pCreateInfo, pSetLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001736 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001737 LAYOUT_NODE* pNewNode = new LAYOUT_NODE;
1738 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001739 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, (*pSetLayout).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1740 "Out of memory while attempting to allocate LAYOUT_NODE in vkCreateDescriptorSetLayout()"))
1741 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001742 }
1743 memset(pNewNode, 0, sizeof(LAYOUT_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001744 memcpy((void*)&pNewNode->createInfo, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
1745 pNewNode->createInfo.pBinding = new VkDescriptorSetLayoutBinding[pCreateInfo->count];
1746 memcpy((void*)pNewNode->createInfo.pBinding, pCreateInfo->pBinding, sizeof(VkDescriptorSetLayoutBinding)*pCreateInfo->count);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001747 uint32_t totalCount = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001748 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001749 totalCount += pCreateInfo->pBinding[i].arraySize;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001750 if (pCreateInfo->pBinding[i].pImmutableSamplers) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001751 VkSampler** ppIS = (VkSampler**)&pNewNode->createInfo.pBinding[i].pImmutableSamplers;
Chia-I Wud3114a22015-05-25 16:22:52 +08001752 *ppIS = new VkSampler[pCreateInfo->pBinding[i].arraySize];
1753 memcpy(*ppIS, pCreateInfo->pBinding[i].pImmutableSamplers, pCreateInfo->pBinding[i].arraySize*sizeof(VkSampler));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001754 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001755 }
1756 if (totalCount > 0) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001757 pNewNode->pTypes = new VkDescriptorType[totalCount];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001758 uint32_t offset = 0;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001759 uint32_t j = 0;
1760 for (uint32_t i=0; i<pCreateInfo->count; i++) {
Chia-I Wud3114a22015-05-25 16:22:52 +08001761 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001762 pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001763 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001764 offset += j;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001765 }
1766 }
1767 pNewNode->layout = *pSetLayout;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001768 pNewNode->startIndex = 0;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001769 pNewNode->endIndex = pNewNode->startIndex + totalCount - 1;
1770 assert(pNewNode->endIndex >= pNewNode->startIndex);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001771 // Put new node at Head of global Layer list
1772 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001773 layoutMap[pSetLayout->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001774 loader_platform_thread_unlock_mutex(&globalLock);
1775 }
1776 return result;
1777}
1778
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001779VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, VkPipelineLayout* pPipelineLayout)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001780{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001781 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001782 if (VK_SUCCESS == result) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001783 // TODO : Need to capture the pipeline layout
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001784 }
1785 return result;
1786}
1787
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001788VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, VkDescriptorPool* pDescriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001789{
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001790 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateDescriptorPool(device, pCreateInfo, pDescriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001791 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001792 // Insert this pool into Global Pool LL at head
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001793 if (log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1794 "Created Descriptor Pool %#" PRIxLEAST64, (*pDescriptorPool).handle))
1795 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001796 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001797 POOL_NODE* pNewNode = new POOL_NODE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001798 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001799 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (*pDescriptorPool).handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1800 "Out of memory while attempting to allocate POOL_NODE in vkCreateDescriptorPool()"))
1801 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001802 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001803 memset(pNewNode, 0, sizeof(POOL_NODE));
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001804 VkDescriptorPoolCreateInfo* pCI = (VkDescriptorPoolCreateInfo*)&pNewNode->createInfo;
1805 memcpy((void*)pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001806 if (pNewNode->createInfo.count) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001807 size_t typeCountSize = pNewNode->createInfo.count * sizeof(VkDescriptorTypeCount);
1808 pNewNode->createInfo.pTypeCount = new VkDescriptorTypeCount[typeCountSize];
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001809 memcpy((void*)pNewNode->createInfo.pTypeCount, pCreateInfo->pTypeCount, typeCountSize);
1810 }
Courtney Goeltzenleuchterd9e966a2015-09-16 16:12:45 -06001811 pNewNode->poolUsage = pCreateInfo->poolUsage;
1812 pNewNode->maxSets = pCreateInfo->maxSets;
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001813 pNewNode->pool = *pDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001814 poolMap[pDescriptorPool->handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001815 }
1816 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001817 } else {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001818 // Need to do anything if pool create fails?
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001819 }
1820 return result;
1821}
1822
Mike Stroyan230e6252015-04-17 12:36:38 -06001823VK_LAYER_EXPORT VkResult VKAPI vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001824{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001825 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->ResetDescriptorPool(device, descriptorPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001826 if (VK_SUCCESS == result) {
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06001827 clearDescriptorPool(device, descriptorPool);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001828 }
1829 return result;
1830}
1831
Cody Northropc8aa4a52015-08-03 12:47:29 -06001832VK_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 -06001833{
Cody Northropc8aa4a52015-08-03 12:47:29 -06001834 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->AllocDescriptorSets(device, descriptorPool, setUsage, count, pSetLayouts, pDescriptorSets);
1835 if (VK_SUCCESS == result) {
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001836 POOL_NODE *pPoolNode = getPoolNode(descriptorPool);
1837 if (!pPoolNode) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001838 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_POOL, descriptorPool.handle, 0, DRAWSTATE_INVALID_POOL, "DS",
1839 "Unable to find pool node for pool %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", descriptorPool.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001840 } else {
Cody Northropc8aa4a52015-08-03 12:47:29 -06001841 if (count == 0) {
1842 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, count, 0, DRAWSTATE_NONE, "DS",
1843 "AllocDescriptorSets called with 0 count");
1844 }
1845 for (uint32_t i = 0; i < count; i++) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001846 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_NONE, "DS",
1847 "Created Descriptor Set %#" PRIxLEAST64, pDescriptorSets[i].handle);
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001848 // Create new set node and add to head of pool nodes
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001849 SET_NODE* pNewNode = new SET_NODE;
1850 if (NULL == pNewNode) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001851 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET, pDescriptorSets[i].handle, 0, DRAWSTATE_OUT_OF_MEMORY, "DS",
1852 "Out of memory while attempting to allocate SET_NODE in vkAllocDescriptorSets()"))
1853 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06001854 } else {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001855 memset(pNewNode, 0, sizeof(SET_NODE));
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001856 // Insert set at head of Set LL for this pool
1857 pNewNode->pNext = pPoolNode->pSets;
1858 pPoolNode->pSets = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001859 LAYOUT_NODE* pLayout = getLayoutNode(pSetLayouts[i]);
1860 if (NULL == pLayout) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001861 if (log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, pSetLayouts[i].handle, 0, DRAWSTATE_INVALID_LAYOUT, "DS",
1862 "Unable to find set layout node for layout %#" PRIxLEAST64 " specified in vkAllocDescriptorSets() call", pSetLayouts[i].handle))
1863 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001864 }
Tobin Ehlisdd82f6b2015-04-03 12:01:11 -06001865 pNewNode->pLayout = pLayout;
1866 pNewNode->pool = descriptorPool;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001867 pNewNode->set = pDescriptorSets[i];
1868 pNewNode->setUsage = setUsage;
1869 pNewNode->descriptorCount = pLayout->endIndex + 1;
1870 if (pNewNode->descriptorCount) {
1871 size_t descriptorArraySize = sizeof(GENERIC_HEADER*)*pNewNode->descriptorCount;
1872 pNewNode->ppDescriptors = new GENERIC_HEADER*[descriptorArraySize];
1873 memset(pNewNode->ppDescriptors, 0, descriptorArraySize);
1874 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06001875 setMap[pDescriptorSets[i].handle] = pNewNode;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001876 }
1877 }
1878 }
1879 }
1880 return result;
1881}
1882
Tony Barbourb857d312015-07-10 10:50:45 -06001883VK_LAYER_EXPORT VkResult VKAPI vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count, const VkDescriptorSet* pDescriptorSets)
1884{
1885 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->FreeDescriptorSets(device, descriptorPool, count, pDescriptorSets);
1886 // TODO : Clean up any internal data structures using this obj.
1887 return result;
1888}
1889
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001890VK_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 -06001891{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001892 // dsUpdate will return VK_TRUE only if a bailout error occurs, so we want to call down tree when both updates return VK_FALSE
1893 if (!dsUpdate(device, VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, writeCount, pDescriptorWrites) &&
1894 !dsUpdate(device, VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET, copyCount, pDescriptorCopies)) {
Mark Lobodzinski67b42b72015-09-07 13:59:43 -06001895 get_dispatch_table(draw_state_device_table_map, device)->UpdateDescriptorSets(device, writeCount, pDescriptorWrites, copyCount, pDescriptorCopies);
Jon Ashburne0fa2282015-05-20 09:00:28 -06001896 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001897}
1898
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001899VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001900{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001901 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001902 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001903 loader_platform_thread_lock_mutex(&globalLock);
1904 GLOBAL_CB_NODE* pCB = new GLOBAL_CB_NODE;
1905 memset(pCB, 0, sizeof(GLOBAL_CB_NODE));
1906 pCB->cmdBuffer = *pCmdBuffer;
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001907 pCB->createInfo = *pCreateInfo;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001908 pCB->lastVtxBinding = MAX_BINDING;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001909 pCB->level = pCreateInfo->level;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001910 cmdBufferMap[*pCmdBuffer] = pCB;
1911 loader_platform_thread_unlock_mutex(&globalLock);
1912 updateCBTracking(*pCmdBuffer);
1913 }
1914 return result;
1915}
1916
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001917VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001918{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001919 VkBool32 skipCall = false;
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001920 // Validate command buffer level
1921 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1922 if (pCB) {
1923 if (pCB->level == VK_CMD_BUFFER_LEVEL_PRIMARY) {
1924 if (pBeginInfo->renderPass.handle || pBeginInfo->framebuffer.handle) {
1925 // These should be NULL for a Primary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001926 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 -06001927 "vkCreateCommandBuffer(): Primary Command Buffer (%p) may not specify framebuffer or renderpass parameters", (void*)cmdBuffer);
1928 }
1929 } else {
1930 if (!pBeginInfo->renderPass.handle || !pBeginInfo->framebuffer.handle) {
1931 // These should NOT be null for an Secondary CB
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001932 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 -06001933 "vkCreateCommandBuffer(): Secondary Command Buffers (%p) must specify framebuffer and renderpass parameters", (void*)cmdBuffer);
1934 }
1935 }
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001936 pCB->beginInfo = *pBeginInfo;
1937 } else {
1938 // TODO : Need to pass cmdBuffer as objType here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001939 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 -06001940 "In vkBeginCommandBuffer() and unable to find CmdBuffer Node for CB %p!", (void*)cmdBuffer);
Mark Lobodzinski90bf5b02015-08-04 16:24:20 -06001941 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001942 if (skipCall) {
1943 return VK_ERROR_VALIDATION_FAILED;
Courtney Goeltzenleuchter3abd86e2015-09-04 15:03:52 -06001944 }
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06001945 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001946 if (VK_SUCCESS == result) {
Tobin Ehlis0cea4082015-08-18 07:10:58 -06001947 if (CB_NEW != pCB->state)
1948 resetCB(cmdBuffer);
1949 pCB->state = CB_UPDATE_ACTIVE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001950 updateCBTracking(cmdBuffer);
1951 }
1952 return result;
1953}
1954
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001955VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001956{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001957 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001958 VkResult result = VK_SUCCESS;
Tobin Ehlise42007c2015-06-19 13:00:59 -06001959 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06001960 /* TODO: preference is to always call API function after reporting any validation errors */
Tobin Ehlise42007c2015-06-19 13:00:59 -06001961 if (pCB) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001962 if (pCB->state != CB_UPDATE_ACTIVE) {
1963 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkEndCommandBuffer()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001964 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001965 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001966 if (VK_FALSE == skipCall) {
1967 result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
1968 if (VK_SUCCESS == result) {
1969 updateCBTracking(cmdBuffer);
1970 pCB->state = CB_UPDATE_COMPLETE;
1971 // Reset CB status flags
1972 pCB->status = 0;
1973 printCB(cmdBuffer);
1974 }
1975 } else {
1976 result = VK_ERROR_VALIDATION_FAILED;
1977 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001978 return result;
1979}
1980
Cody Northropf02f9f82015-07-09 18:08:05 -06001981VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer, VkCmdBufferResetFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001982{
Cody Northropf02f9f82015-07-09 18:08:05 -06001983 VkResult result = get_dispatch_table(draw_state_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001984 if (VK_SUCCESS == result) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001985 resetCB(cmdBuffer);
1986 updateCBTracking(cmdBuffer);
1987 }
1988 return result;
1989}
1990
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001991VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001992{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001993 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06001994 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
1995 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06001996 if (pCB->state == CB_UPDATE_ACTIVE) {
1997 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06001998 skipCall |= addCmd(pCB, CMD_BINDPIPELINE);
Tobin Ehlis642d5a52015-06-23 08:46:18 -06001999 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002000 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 -06002001 "Incorrectly binding compute pipeline (%#" PRIxLEAST64 ") during active RenderPass (%#" PRIxLEAST64 ")", pipeline.handle, pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002002 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002003 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 -06002004 "Incorrectly binding graphics pipeline (%#" PRIxLEAST64 ") without an active RenderPass", pipeline.handle);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002005 } else {
Tobin Ehlise4076782015-06-24 15:53:07 -06002006 PIPELINE_NODE* pPN = getPipeline(pipeline);
2007 if (pPN) {
2008 pCB->lastBoundPipeline = pipeline;
2009 loader_platform_thread_lock_mutex(&globalLock);
2010 set_cb_pso_status(pCB, pPN);
2011 g_lastBoundPipeline = pPN;
2012 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002013 skipCall |= validatePipelineState(pCB, pipelineBindPoint, pipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06002014 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002015 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 -06002016 "Attempt to bind Pipeline %#" PRIxLEAST64 " that doesn't exist!", (void*)pipeline.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002017 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002018 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002019 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002020 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindPipeline()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002021 }
2022 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002023 if (VK_FALSE == skipCall)
2024 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002025}
2026
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002027VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
2028 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002029 uint32_t viewportCount,
2030 const VkViewport* pViewports)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002031{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002032 VkBool32 skipCall = VK_FALSE;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002033 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2034 if (pCB) {
2035 if (pCB->state == CB_UPDATE_ACTIVE) {
2036 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002037 skipCall |= addCmd(pCB, CMD_SETVIEWPORTSTATE);
Tobin Ehlise4076782015-06-24 15:53:07 -06002038 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002039 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 -06002040 "Incorrect call to vkCmdSetViewport() without an active RenderPass.");
Tobin Ehlise4076782015-06-24 15:53:07 -06002041 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002042 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002043 pCB->status |= CBSTATUS_VIEWPORT_SET;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002044 pCB->viewports.resize(viewportCount);
2045 memcpy(pCB->viewports.data(), pViewports, viewportCount);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002046 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002047 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002048 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetViewport()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002049 }
2050 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002051 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002052 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
2053}
2054
2055VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
2056 VkCmdBuffer cmdBuffer,
2057 uint32_t scissorCount,
2058 const VkRect2D* pScissors)
2059{
2060 VkBool32 skipCall = VK_FALSE;
2061 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2062 if (pCB) {
2063 if (pCB->state == CB_UPDATE_ACTIVE) {
2064 updateCBTracking(cmdBuffer);
2065 skipCall |= addCmd(pCB, CMD_SETSCISSORSTATE);
2066 if (!pCB->activeRenderPass) {
2067 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2068 "Incorrect call to vkCmdSetScissor() without an active RenderPass.");
2069 }
2070 loader_platform_thread_lock_mutex(&globalLock);
2071 pCB->status |= CBSTATUS_SCISSOR_SET;
2072 pCB->scissors.resize(scissorCount);
2073 memcpy(pCB->scissors.data(), pScissors, scissorCount);
2074 loader_platform_thread_unlock_mutex(&globalLock);
2075 } else {
2076 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetScissor()");
2077 }
2078 }
2079 if (VK_FALSE == skipCall)
2080 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002081}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002082
2083VK_LAYER_EXPORT void VKAPI vkCmdSetLineWidth(VkCmdBuffer cmdBuffer, float lineWidth)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002084{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002085 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002086 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2087 if (pCB) {
2088 if (pCB->state == CB_UPDATE_ACTIVE) {
2089 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002090 skipCall |= addCmd(pCB, CMD_SETLINEWIDTHSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002091 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002092 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 -06002093 "Incorrect call to vkCmdSetLineWidth() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002094 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002095 /* TODO: Do we still need this lock? */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002096 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002097 pCB->status |= CBSTATUS_LINE_WIDTH_SET;
2098 pCB->lineWidth = lineWidth;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002099 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002100 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002101 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDynamicLineWidthState()");
Cody Northropf5bd2252015-08-17 11:10:49 -06002102 }
2103 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002104 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002105 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetLineWidth(cmdBuffer, lineWidth);
Cody Northropf5bd2252015-08-17 11:10:49 -06002106}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002107
2108VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBias(
2109 VkCmdBuffer cmdBuffer,
2110 float depthBias,
2111 float depthBiasClamp,
2112 float slopeScaledDepthBias)
Cody Northropf5bd2252015-08-17 11:10:49 -06002113{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002114 VkBool32 skipCall = VK_FALSE;
Cody Northropf5bd2252015-08-17 11:10:49 -06002115 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2116 if (pCB) {
2117 if (pCB->state == CB_UPDATE_ACTIVE) {
2118 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002119 skipCall |= addCmd(pCB, CMD_SETDEPTHBIASSTATE);
Cody Northropf5bd2252015-08-17 11:10:49 -06002120 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002121 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 -06002122 "Incorrect call to vkCmdSetDepthBias() without an active RenderPass.");
Cody Northropf5bd2252015-08-17 11:10:49 -06002123 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002124 pCB->status |= CBSTATUS_DEPTH_BIAS_SET;
2125 pCB->depthBias = depthBias;
2126 pCB->depthBiasClamp = depthBiasClamp;
2127 pCB->slopeScaledDepthBias = slopeScaledDepthBias;
Cody Northropf5bd2252015-08-17 11:10:49 -06002128 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002129 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBias()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002130 }
2131 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002132 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002133 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBias(cmdBuffer, depthBias, depthBiasClamp, slopeScaledDepthBias);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002134}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002135
2136VK_LAYER_EXPORT void VKAPI vkCmdSetBlendConstants(VkCmdBuffer cmdBuffer, const float blendConst[4])
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002137{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002138 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002139 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2140 if (pCB) {
2141 if (pCB->state == CB_UPDATE_ACTIVE) {
2142 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002143 skipCall |= addCmd(pCB, CMD_SETBLENDSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002144 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002145 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 -06002146 "Incorrect call to vkSetBlendConstants() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002147 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002148 pCB->status |= CBSTATUS_BLEND_SET;
2149 memcpy(pCB->blendConst, blendConst, 4 * sizeof(float));
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002150 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002151 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetBlendConstants()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002152 }
2153 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002154 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002155 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetBlendConstants(cmdBuffer, blendConst);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002156}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002157
2158VK_LAYER_EXPORT void VKAPI vkCmdSetDepthBounds(
2159 VkCmdBuffer cmdBuffer,
2160 float minDepthBounds,
2161 float maxDepthBounds)
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002162{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002163 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002164 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2165 if (pCB) {
2166 if (pCB->state == CB_UPDATE_ACTIVE) {
2167 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002168 skipCall |= addCmd(pCB, CMD_SETDEPTHBOUNDSSTATE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002169 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002170 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 -06002171 "Incorrect call to vkCmdSetDepthBounds() without an active RenderPass.");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002172 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002173 pCB->status |= CBSTATUS_DEPTH_BOUNDS_SET;
2174 pCB->minDepthBounds = minDepthBounds;
2175 pCB->maxDepthBounds = maxDepthBounds;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002176 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002177 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetDepthBounds()");
Cody Northrop2605cb02015-08-18 15:21:16 -06002178 }
2179 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002180 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002181 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetDepthBounds(cmdBuffer, minDepthBounds, maxDepthBounds);
Cody Northrop2605cb02015-08-18 15:21:16 -06002182}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002183
2184VK_LAYER_EXPORT void VKAPI vkCmdSetStencilCompareMask(
2185 VkCmdBuffer cmdBuffer,
2186 VkStencilFaceFlags faceMask,
2187 uint32_t stencilCompareMask)
Cody Northrop2605cb02015-08-18 15:21:16 -06002188{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002189 VkBool32 skipCall = VK_FALSE;
Cody Northrop2605cb02015-08-18 15:21:16 -06002190 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2191 if (pCB) {
2192 if (pCB->state == CB_UPDATE_ACTIVE) {
2193 updateCBTracking(cmdBuffer);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002194 skipCall |= addCmd(pCB, CMD_SETSTENCILREADMASKSTATE);
Cody Northrop2605cb02015-08-18 15:21:16 -06002195 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002196 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 -06002197 "Incorrect call to vkCmdSetStencilCompareMask() without an active RenderPass.");
Cody Northrop2605cb02015-08-18 15:21:16 -06002198 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002199 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2200 pCB->front.stencilCompareMask = stencilCompareMask;
Cody Northrop2605cb02015-08-18 15:21:16 -06002201 }
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002202 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2203 pCB->back.stencilCompareMask = stencilCompareMask;
2204 }
2205 /* TODO: Do we need to track front and back separately? */
2206 /* TODO: We aren't capturing the faceMask, do we need to? */
2207 pCB->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Cody Northrop2605cb02015-08-18 15:21:16 -06002208 } else {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002209 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilCompareMask()");
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002210 }
2211 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002212 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002213 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilCompareMask(cmdBuffer, faceMask, stencilCompareMask);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002214}
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06002215
2216VK_LAYER_EXPORT void VKAPI vkCmdSetStencilWriteMask(
2217 VkCmdBuffer cmdBuffer,
2218 VkStencilFaceFlags faceMask,
2219 uint32_t stencilWriteMask)
2220{
2221 VkBool32 skipCall = VK_FALSE;
2222 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2223 if (pCB) {
2224 if (pCB->state == CB_UPDATE_ACTIVE) {
2225 updateCBTracking(cmdBuffer);
2226 skipCall |= addCmd(pCB, CMD_SETSTENCILWRITEMASKSTATE);
2227 if (!pCB->activeRenderPass) {
2228 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2229 "Incorrect call to vkCmdSetStencilWriteMask() without an active RenderPass.");
2230 }
2231 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2232 pCB->front.stencilWriteMask = stencilWriteMask;
2233 }
2234 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2235 pCB->back.stencilWriteMask = stencilWriteMask;
2236 }
2237 pCB->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
2238 } else {
2239 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilWriteMask()");
2240 }
2241 }
2242 if (VK_FALSE == skipCall)
2243 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilWriteMask(cmdBuffer, faceMask, stencilWriteMask);
2244}
2245
2246VK_LAYER_EXPORT void VKAPI vkCmdSetStencilReference(
2247 VkCmdBuffer cmdBuffer,
2248 VkStencilFaceFlags faceMask,
2249 uint32_t stencilReference)
2250{
2251 VkBool32 skipCall = VK_FALSE;
2252 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2253 if (pCB) {
2254 if (pCB->state == CB_UPDATE_ACTIVE) {
2255 updateCBTracking(cmdBuffer);
2256 skipCall |= addCmd(pCB, CMD_SETSTENCILREFERENCESTATE);
2257 if (!pCB->activeRenderPass) {
2258 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2259 "Incorrect call to vkCmdSetStencilReference() without an active RenderPass.");
2260 }
2261 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2262 pCB->front.stencilReference = stencilReference;
2263 }
2264 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2265 pCB->back.stencilReference = stencilReference;
2266 }
2267 pCB->status |= CBSTATUS_STENCIL_REFERENCE_SET;
2268 } else {
2269 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdSetStencilReference()");
2270 }
2271 }
2272 if (VK_FALSE == skipCall)
2273 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetStencilReference(cmdBuffer, faceMask, stencilReference);
2274}
2275
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06002276VK_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 -06002277{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002278 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002279 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2280 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002281 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002282 if ((VK_PIPELINE_BIND_POINT_COMPUTE == pipelineBindPoint) && (pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002283 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 -06002284 "Incorrectly binding compute DescriptorSets during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06002285 } else if ((VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) && (!pCB->activeRenderPass)) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002286 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 -06002287 "Incorrectly binding graphics DescriptorSets without an active RenderPass");
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002288 } else {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002289 for (uint32_t i=0; i<setCount; i++) {
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002290 SET_NODE* pSet = getSetNode(pDescriptorSets[i]);
2291 if (pSet) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002292 loader_platform_thread_lock_mutex(&globalLock);
2293 pCB->lastBoundDescriptorSet = pDescriptorSets[i];
Tobin Ehlisc6c3d6d2015-06-22 17:20:50 -06002294 pCB->lastBoundPipelineLayout = layout;
Tobin Ehlise42007c2015-06-19 13:00:59 -06002295 pCB->boundDescriptorSets.push_back(pDescriptorSets[i]);
2296 g_lastBoundDescriptorSet = pDescriptorSets[i];
2297 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002298 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 -06002299 "DS %#" PRIxLEAST64 " bound on pipeline %s", pDescriptorSets[i].handle, string_VkPipelineBindPoint(pipelineBindPoint));
Tobin Ehlis55c1c602015-06-24 17:27:33 -06002300 if (!pSet->pUpdateStructs)
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002301 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 -06002302 "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 -06002303 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002304 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 -06002305 "Attempt to bind DS %#" PRIxLEAST64 " that doesn't exist!", pDescriptorSets[i].handle);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002306 }
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002307 }
Tobin Ehlis59db5712015-07-13 13:14:24 -06002308 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002309 skipCall |= addCmd(pCB, CMD_BINDDESCRIPTORSETS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002310 }
Tobin Ehlise42007c2015-06-19 13:00:59 -06002311 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002312 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindDescriptorSets()");
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002313 }
2314 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002315 if (VK_FALSE == skipCall)
2316 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 -06002317}
2318
Tony Barbour8205d902015-04-16 15:59:00 -06002319VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002320{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002321 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002322 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2323 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002324 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002325 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002326 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 -06002327 "Incorrect call to vkCmdBindIndexBuffer() without an active RenderPass.");
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002328 }
2329 VkDeviceSize offset_align = 0;
2330 switch (indexType) {
2331 case VK_INDEX_TYPE_UINT16:
2332 offset_align = 2;
2333 break;
2334 case VK_INDEX_TYPE_UINT32:
2335 offset_align = 4;
2336 break;
2337 default:
2338 // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
2339 break;
2340 }
2341 if (!offset_align || (offset % offset_align)) {
2342 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
2343 "vkCmdBindIndexBuffer() offset (%#" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset, string_VkIndexType(indexType));
Tobin Ehlise4076782015-06-24 15:53:07 -06002344 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002345 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002346 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002347 }
Tobin Ehlis8d199e52015-09-17 12:24:13 -06002348 pCB->status |= CBSTATUS_INDEX_BUFFER_BOUND;
2349 updateCBTracking(cmdBuffer);
2350 skipCall |= addCmd(pCB, CMD_BINDINDEXBUFFER);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002351 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002352 if (VK_FALSE == skipCall)
2353 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002354}
2355
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002356VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
2357 VkCmdBuffer cmdBuffer,
2358 uint32_t startBinding,
2359 uint32_t bindingCount,
2360 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06002361 const VkDeviceSize* pOffsets)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002362{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002363 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002364 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2365 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002366 if (pCB->state == CB_UPDATE_ACTIVE) {
2367 /* TODO: Need to track all the vertex buffers, not just last one */
Tobin Ehlise4076782015-06-24 15:53:07 -06002368 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002369 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 -06002370 "Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.");
2371 } else {
2372 pCB->lastVtxBinding = startBinding + bindingCount -1;
Tobin Ehlisd28acef2015-09-09 15:12:35 -06002373 updateCBTracking(cmdBuffer);
2374 addCmd(pCB, CMD_BINDVERTEXBUFFER);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002375 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002376 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002377 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis0b551cd2015-05-28 12:10:17 -06002378 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002379 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002380 if (VK_FALSE == skipCall)
2381 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002382}
2383
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002384VK_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 -06002385{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002386 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002387 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2388 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002389 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002390 pCB->drawCount[DRAW]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002391 skipCall |= validate_draw_state(pCB, VK_FALSE);
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -06002392 /* TODOVV: Check that scissor and viewport counts are the same */
2393 /* TODOVV: Do we need to check that viewportCount given in pipeline's
2394 * VkPipelineViewportStateCreateInfo matches scissor & viewport counts
2395 * given as dynamic state? Or is the count given in VkPipelineViewportStateCreateInfo
2396 * simply indicate the number of viewport / scissor to use at this time?
2397 */
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002398 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002399 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 -06002400 "vkCmdDraw() call #%lu, reporting DS state:", g_drawCount[DRAW]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002401 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2402 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002403 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002404 skipCall |= addCmd(pCB, CMD_DRAW);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002405 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002406 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002407 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002408 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002409 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002410 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002411 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDraw(cmdBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002412}
2413
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002414VK_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 -06002415{
2416 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002417 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002418 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002419 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002420 pCB->drawCount[DRAW_INDEXED]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002421 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002422 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002423 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 -06002424 "vkCmdDrawIndexed() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002425 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2426 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002427 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002428 skipCall |= addCmd(pCB, CMD_DRAWINDEXED);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002429 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002430 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002431 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002432 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002433 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002434 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06002435 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexed(cmdBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002436}
2437
Tony Barbour8205d902015-04-16 15:59:00 -06002438VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002439{
2440 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002441 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002442 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002443 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002444 pCB->drawCount[DRAW_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002445 skipCall |= validate_draw_state(pCB, VK_FALSE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002446 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002447 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 -06002448 "vkCmdDrawIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002449 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2450 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002451 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002452 skipCall |= addCmd(pCB, CMD_DRAWINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002453 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002454 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002455 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002456 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002457 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002458 if (VK_FALSE == skipCall)
2459 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002460}
2461
Tony Barbour8205d902015-04-16 15:59:00 -06002462VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002463{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002464 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002465 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2466 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002467 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002468 pCB->drawCount[DRAW_INDEXED_INDIRECT]++;
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002469 skipCall |= validate_draw_state(pCB, VK_TRUE);
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002470 // TODO : Need to pass cmdBuffer as srcObj here
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002471 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 -06002472 "vkCmdDrawIndexedIndirect() call #%lu, reporting DS state:", g_drawCount[DRAW_INDEXED_INDIRECT]++);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002473 skipCall |= synchAndPrintDSConfig(cmdBuffer);
2474 if (VK_FALSE == skipCall) {
Tobin Ehlis59db5712015-07-13 13:14:24 -06002475 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002476 skipCall |= addCmd(pCB, CMD_DRAWINDEXEDINDIRECT);
Tobin Ehlise42007c2015-06-19 13:00:59 -06002477 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002478 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002479 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002480 }
Jon Ashburne0fa2282015-05-20 09:00:28 -06002481 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002482 if (VK_FALSE == skipCall)
2483 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002484}
2485
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002486VK_LAYER_EXPORT void VKAPI vkCmdDispatch(VkCmdBuffer cmdBuffer, uint32_t x, uint32_t y, uint32_t z)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002487{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002488 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002489 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2490 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002491 if (pCB->state == CB_UPDATE_ACTIVE) {
2492 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002493 skipCall |= addCmd(pCB, CMD_DISPATCH);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002494 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002495 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002496 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002497 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002498 if (VK_FALSE == skipCall)
2499 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatch(cmdBuffer, x, y, z);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002500}
2501
Tony Barbour8205d902015-04-16 15:59:00 -06002502VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002503{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002504 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002505 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2506 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002507 if (pCB->state == CB_UPDATE_ACTIVE) {
2508 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002509 skipCall |= addCmd(pCB, CMD_DISPATCHINDIRECT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002510 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002511 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002512 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002513 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002514 if (VK_FALSE == skipCall)
2515 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002516}
2517
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002518VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer, uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002519{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002520 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002521 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2522 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002523 if (pCB->state == CB_UPDATE_ACTIVE) {
2524 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002525 skipCall |= addCmd(pCB, CMD_COPYBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002526 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002527 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002528 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002529 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002530 if (VK_FALSE == skipCall)
2531 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002532}
2533
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002534VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
2535 VkImage srcImage,
2536 VkImageLayout srcImageLayout,
2537 VkImage destImage,
2538 VkImageLayout destImageLayout,
2539 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002540{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002541 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002542 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2543 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002544 if (pCB->state == CB_UPDATE_ACTIVE) {
2545 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002546 skipCall |= addCmd(pCB, CMD_COPYIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002547 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002548 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002549 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002550 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002551 if (VK_FALSE == skipCall)
2552 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002553}
2554
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002555VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
2556 VkImage srcImage, VkImageLayout srcImageLayout,
2557 VkImage destImage, VkImageLayout destImageLayout,
Mark Lobodzinski20f68592015-05-22 14:43:25 -05002558 uint32_t regionCount, const VkImageBlit* pRegions,
2559 VkTexFilter filter)
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002560{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002561 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002562 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2563 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002564 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis054bd872015-06-23 10:41:13 -06002565 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002566 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 -06002567 "Incorrectly issuing CmdBlitImage during active RenderPass (%#" PRIxLEAST64 ")", pCB->activeRenderPass.handle);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002568 } else {
2569 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002570 skipCall |= addCmd(pCB, CMD_BLITIMAGE);
Tobin Ehlis59db5712015-07-13 13:14:24 -06002571 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002572 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002573 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002574 }
Courtney Goeltzenleuchter6ff8ebc2015-04-03 14:42:51 -06002575 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002576 if (VK_FALSE == skipCall)
2577 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 -06002578}
2579
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002580VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
2581 VkBuffer srcBuffer,
2582 VkImage destImage, VkImageLayout destImageLayout,
2583 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002584{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002585 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002586 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2587 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002588 if (pCB->state == CB_UPDATE_ACTIVE) {
2589 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002590 skipCall |= addCmd(pCB, CMD_COPYBUFFERTOIMAGE);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002591 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002592 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002593 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002594 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002595 if (VK_FALSE == skipCall)
2596 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002597}
2598
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002599VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
2600 VkImage srcImage, VkImageLayout srcImageLayout,
2601 VkBuffer destBuffer,
2602 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002603{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002604 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002605 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2606 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002607 if (pCB->state == CB_UPDATE_ACTIVE) {
2608 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002609 skipCall |= addCmd(pCB, CMD_COPYIMAGETOBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002610 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002611 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002612 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002613 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002614 if (VK_FALSE == skipCall)
2615 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002616}
2617
Tony Barbour8205d902015-04-16 15:59:00 -06002618VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002619{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002620 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002621 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2622 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002623 if (pCB->state == CB_UPDATE_ACTIVE) {
2624 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002625 skipCall |= addCmd(pCB, CMD_UPDATEBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002626 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002627 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002628 }
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002629 if (pCB->activeRenderPass) {
2630 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2631 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2632 "CmdUpdateBuffer cmd issued within an active RenderPass -- vkCmdUpdateBuffer "
2633 "may only be called outside of a RenderPass.");
2634 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002635 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002636 if (VK_FALSE == skipCall)
2637 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002638}
2639
Tony Barbour8205d902015-04-16 15:59:00 -06002640VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002641{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002642 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002643 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2644 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002645 if (pCB->state == CB_UPDATE_ACTIVE) {
2646 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002647 skipCall |= addCmd(pCB, CMD_FILLBUFFER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002648 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002649 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002650 }
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002651 if (pCB->activeRenderPass) {
2652 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2653 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2654 "CmdFillBuffer cmd issued within an active RenderPass -- vkCmdFillBuffer "
2655 "may only be called outside of a RenderPass.");
2656 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002657 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002658 if (VK_FALSE == skipCall)
2659 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002660}
2661
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002662VK_LAYER_EXPORT void VKAPI vkCmdClearColorAttachment(
2663 VkCmdBuffer cmdBuffer,
2664 uint32_t colorAttachment,
2665 VkImageLayout imageLayout,
2666 const VkClearColorValue* pColor,
2667 uint32_t rectCount,
2668 const VkRect3D* pRects)
2669{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002670 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002671 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2672 if (pCB) {
2673 if (pCB->state == CB_UPDATE_ACTIVE) {
2674 // Warn if this is issued prior to Draw Cmd
2675 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002676 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002677 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 -06002678 "vkCmdClearColorAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002679 " 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 -06002680 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002681 if (!pCB->activeRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002682 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2683 (uint64_t)cmdBuffer, 0, DRAWSTATE_NO_ACTIVE_RENDERPASS, "DS",
2684 "CmdClearColorAttachment cmd issued outside of an active RenderPass. "
2685 "vkCmdClearColorAttachment() must only be called inside of a RenderPass."
Tobin Ehlis92a89912015-06-23 11:34:28 -06002686 " vkCmdClearColorImage() should be used outside of a RenderPass.");
2687 } else {
2688 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002689 skipCall |= addCmd(pCB, CMD_CLEARCOLORATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002690 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002691 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002692 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002693 }
2694 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002695 if (VK_FALSE == skipCall)
2696 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorAttachment(cmdBuffer, colorAttachment, imageLayout, pColor, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002697}
2698
2699VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilAttachment(
2700 VkCmdBuffer cmdBuffer,
2701 VkImageAspectFlags imageAspectMask,
2702 VkImageLayout imageLayout,
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002703 const VkClearDepthStencilValue* pDepthStencil,
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002704 uint32_t rectCount,
2705 const VkRect3D* pRects)
2706{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002707 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002708 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2709 if (pCB) {
2710 if (pCB->state == CB_UPDATE_ACTIVE) {
2711 // Warn if this is issued prior to Draw Cmd
2712 if (!hasDrawCmd(pCB)) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002713 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002714 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 -06002715 "vkCmdClearDepthStencilAttachment() issued on CB object 0x%" PRIxLEAST64 " prior to any Draw Cmds."
Courtney Goeltzenleuchter0f2b9e22015-08-26 15:09:25 -06002716 " 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 -06002717 }
Tobin Ehlis92a89912015-06-23 11:34:28 -06002718 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002719 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 -06002720 "Clear*Attachment cmd issued without an active RenderPass. vkCmdClearDepthStencilAttachment() must only be called inside of a RenderPass."
2721 " vkCmdClearDepthStencilImage() should be used outside of a RenderPass.");
2722 } else {
2723 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002724 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILATTACHMENT);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002725 }
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002726 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002727 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002728 }
2729 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002730 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002731 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilAttachment(cmdBuffer, imageAspectMask, imageLayout, pDepthStencil, rectCount, pRects);
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06002732}
2733
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002734VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2735 VkCmdBuffer cmdBuffer,
2736 VkImage image, VkImageLayout imageLayout,
Chris Forbese3105972015-06-24 14:34:53 +12002737 const VkClearColorValue *pColor,
Courtney Goeltzenleuchterda4a99e2015-04-23 17:49:22 -06002738 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002739{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002740 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002741 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2742 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002743 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002744 if (pCB->activeRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002745 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2746 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2747 "CmdClearColorImage cmd issued within an active RenderPass. "
2748 "vkCmdClearColorImage() must only be called outside of a RenderPass. "
2749 "vkCmdClearColorAttachment() should be used within a RenderPass.");
Tobin Ehlis92a89912015-06-23 11:34:28 -06002750 } else {
2751 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002752 skipCall |= addCmd(pCB, CMD_CLEARCOLORIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002753 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002754 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002755 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002756 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002757 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002758 if (VK_FALSE == skipCall)
2759 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002760}
2761
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002762VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(
2763 VkCmdBuffer cmdBuffer,
2764 VkImage image, VkImageLayout imageLayout,
2765 const VkClearDepthStencilValue *pDepthStencil,
2766 uint32_t rangeCount,
2767 const VkImageSubresourceRange* pRanges)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002768{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002769 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002770 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2771 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002772 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlis92a89912015-06-23 11:34:28 -06002773 if (pCB->activeRenderPass) {
Mark Lobodzinskif5b3cc12015-09-24 09:51:47 -06002774 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER,
2775 (uint64_t)cmdBuffer, 0, DRAWSTATE_INVALID_RENDERPASS_CMD, "DS",
2776 "CmdClearDepthStencilImage cmd issued within an active RenderPass. "
2777 "vkCmdClearDepthStencilImage() must only be called outside of a RenderPass."
Tobin Ehlis92a89912015-06-23 11:34:28 -06002778 " vkCmdClearDepthStencilAttachment() should be used within a RenderPass.");
2779 } else {
2780 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002781 skipCall |= addCmd(pCB, CMD_CLEARDEPTHSTENCILIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002782 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002783 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002784 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002785 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002786 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002787 if (VK_FALSE == skipCall)
Courtney Goeltzenleuchter315ad992015-09-15 18:03:22 -06002788 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(cmdBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002789}
2790
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002791VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
2792 VkImage srcImage, VkImageLayout srcImageLayout,
2793 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06002794 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002795{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002796 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002797 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2798 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002799 if (pCB->state == CB_UPDATE_ACTIVE) {
Tobin Ehlise4076782015-06-24 15:53:07 -06002800 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002801 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 -06002802 "Cannot call vkCmdResolveImage() during an active RenderPass (%#" PRIxLEAST64 ").", pCB->activeRenderPass.handle);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002803 } else {
2804 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002805 skipCall |= addCmd(pCB, CMD_RESOLVEIMAGE);
Tobin Ehlis92a89912015-06-23 11:34:28 -06002806 }
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002807 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002808 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002809 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002810 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002811 if (VK_FALSE == skipCall)
2812 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002813}
2814
Tony Barbourc2e987e2015-06-29 16:20:35 -06002815VK_LAYER_EXPORT void VKAPI vkCmdSetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002816{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002817 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002818 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2819 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002820 if (pCB->state == CB_UPDATE_ACTIVE) {
2821 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002822 skipCall |= addCmd(pCB, CMD_SETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002823 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002824 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002825 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002826 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002827 if (VK_FALSE == skipCall)
2828 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdSetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002829}
2830
Tony Barbourc2e987e2015-06-29 16:20:35 -06002831VK_LAYER_EXPORT void VKAPI vkCmdResetEvent(VkCmdBuffer cmdBuffer, VkEvent event, VkPipelineStageFlags stageMask)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002832{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002833 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002834 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2835 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002836 if (pCB->state == CB_UPDATE_ACTIVE) {
2837 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002838 skipCall |= addCmd(pCB, CMD_RESETEVENT);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002839 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002840 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002841 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002842 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002843 if (VK_FALSE == skipCall)
2844 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetEvent(cmdBuffer, event, stageMask);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002845}
2846
Courtney Goeltzenleuchterd9ba3422015-07-12 12:58:58 -06002847VK_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 -06002848{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002849 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002850 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2851 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002852 if (pCB->state == CB_UPDATE_ACTIVE) {
2853 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002854 skipCall |= addCmd(pCB, CMD_WAITEVENTS);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002855 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002856 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBindIndexBuffer()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002857 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002858 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002859 if (VK_FALSE == skipCall)
2860 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWaitEvents(cmdBuffer, eventCount, pEvents, sourceStageMask, destStageMask, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002861}
2862
Courtney Goeltzenleuchter82b348f2015-07-12 13:07:46 -06002863VK_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 -06002864{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002865 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002866 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2867 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002868 if (pCB->state == CB_UPDATE_ACTIVE) {
2869 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002870 skipCall |= addCmd(pCB, CMD_PIPELINEBARRIER);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002871 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002872 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdPipelineBarrier()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002873 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002874 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002875 if (VK_FALSE == skipCall)
2876 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdPipelineBarrier(cmdBuffer, srcStageMask, destStageMask, byRegion, memBarrierCount, ppMemBarriers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002877}
2878
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002879VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002880{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002881 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002882 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2883 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002884 if (pCB->state == CB_UPDATE_ACTIVE) {
2885 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002886 skipCall |= addCmd(pCB, CMD_BEGINQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002887 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002888 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdBeginQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002889 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002890 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002891 if (VK_FALSE == skipCall)
2892 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002893}
2894
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002895VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002896{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002897 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002898 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2899 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002900 if (pCB->state == CB_UPDATE_ACTIVE) {
2901 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002902 skipCall |= addCmd(pCB, CMD_ENDQUERY);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002903 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002904 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdEndQuery()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002905 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002906 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002907 if (VK_FALSE == skipCall)
2908 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002909}
2910
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002911VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002912{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002913 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002914 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2915 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002916 if (pCB->state == CB_UPDATE_ACTIVE) {
2917 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002918 skipCall |= addCmd(pCB, CMD_RESETQUERYPOOL);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002919 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002920 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdResetQueryPool()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002921 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002922 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002923 if (VK_FALSE == skipCall)
2924 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002925}
2926
Tony Barbour8205d902015-04-16 15:59:00 -06002927VK_LAYER_EXPORT void VKAPI vkCmdWriteTimestamp(VkCmdBuffer cmdBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002928{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002929 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002930 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
2931 if (pCB) {
Tobin Ehlise42007c2015-06-19 13:00:59 -06002932 if (pCB->state == CB_UPDATE_ACTIVE) {
2933 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002934 skipCall |= addCmd(pCB, CMD_WRITETIMESTAMP);
Tobin Ehlisa366ca22015-06-19 15:07:05 -06002935 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002936 skipCall |= report_error_no_cb_begin(cmdBuffer, "vkCmdWriteTimestamp()");
Tobin Ehlise42007c2015-06-19 13:00:59 -06002937 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002938 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06002939 if (VK_FALSE == skipCall)
2940 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdWriteTimestamp(cmdBuffer, timestampType, destBuffer, destOffset);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06002941}
2942
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002943VK_LAYER_EXPORT VkResult VKAPI vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, VkFramebuffer* pFramebuffer)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002944{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002945 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateFramebuffer(device, pCreateInfo, pFramebuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002946 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002947 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002948 VkFramebufferCreateInfo* localFBCI = new VkFramebufferCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002949 if (pCreateInfo->pAttachments) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06002950 localFBCI->pAttachments = new VkImageView[localFBCI->attachmentCount];
2951 memcpy((void*)localFBCI->pAttachments, pCreateInfo->pAttachments, localFBCI->attachmentCount*sizeof(VkImageView));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002952 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06002953 frameBufferMap[pFramebuffer->handle] = localFBCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06002954 }
2955 return result;
2956}
2957
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002958VK_LAYER_EXPORT VkResult VKAPI vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, VkRenderPass* pRenderPass)
Tobin Ehlis2464b882015-04-01 08:40:34 -06002959{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06002960 VkResult result = get_dispatch_table(draw_state_device_table_map, device)->CreateRenderPass(device, pCreateInfo, pRenderPass);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002961 if (VK_SUCCESS == result) {
Tobin Ehlis2464b882015-04-01 08:40:34 -06002962 // Shadow create info and store in map
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002963 VkRenderPassCreateInfo* localRPCI = new VkRenderPassCreateInfo(*pCreateInfo);
Chia-I Wuc278df82015-07-07 11:50:03 +08002964 if (pCreateInfo->pAttachments) {
2965 localRPCI->pAttachments = new VkAttachmentDescription[localRPCI->attachmentCount];
2966 memcpy((void*)localRPCI->pAttachments, pCreateInfo->pAttachments, localRPCI->attachmentCount*sizeof(VkAttachmentDescription));
Tobin Ehlis2464b882015-04-01 08:40:34 -06002967 }
Chia-I Wuc278df82015-07-07 11:50:03 +08002968 if (pCreateInfo->pSubpasses) {
2969 localRPCI->pSubpasses = new VkSubpassDescription[localRPCI->subpassCount];
2970 memcpy((void*)localRPCI->pSubpasses, pCreateInfo->pSubpasses, localRPCI->subpassCount*sizeof(VkSubpassDescription));
2971
2972 for (uint32_t i = 0; i < localRPCI->subpassCount; i++) {
2973 VkSubpassDescription *subpass = (VkSubpassDescription *) &localRPCI->pSubpasses[i];
2974 const uint32_t attachmentCount = subpass->inputCount +
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002975 subpass->colorCount * (1 + (subpass->pResolveAttachments?1:0)) +
Chia-I Wuc278df82015-07-07 11:50:03 +08002976 subpass->preserveCount;
2977 VkAttachmentReference *attachments = new VkAttachmentReference[attachmentCount];
2978
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002979 memcpy(attachments, subpass->pInputAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002980 sizeof(attachments[0]) * subpass->inputCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002981 subpass->pInputAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002982 attachments += subpass->inputCount;
2983
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002984 memcpy(attachments, subpass->pColorAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002985 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002986 subpass->pColorAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002987 attachments += subpass->colorCount;
2988
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002989 if (subpass->pResolveAttachments) {
2990 memcpy(attachments, subpass->pResolveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002991 sizeof(attachments[0]) * subpass->colorCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002992 subpass->pResolveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002993 attachments += subpass->colorCount;
2994 }
2995
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002996 memcpy(attachments, subpass->pPreserveAttachments,
Chia-I Wuc278df82015-07-07 11:50:03 +08002997 sizeof(attachments[0]) * subpass->preserveCount);
Cody Northrop6de6b0b2015-08-04 11:16:41 -06002998 subpass->pPreserveAttachments = attachments;
Chia-I Wuc278df82015-07-07 11:50:03 +08002999 }
Tobin Ehlis2464b882015-04-01 08:40:34 -06003000 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003001 if (pCreateInfo->pDependencies) {
3002 localRPCI->pDependencies = new VkSubpassDependency[localRPCI->dependencyCount];
3003 memcpy((void*)localRPCI->pDependencies, pCreateInfo->pDependencies, localRPCI->dependencyCount*sizeof(VkSubpassDependency));
Tobin Ehlis2464b882015-04-01 08:40:34 -06003004 }
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003005 renderPassMap[pRenderPass->handle] = localRPCI;
Tobin Ehlis2464b882015-04-01 08:40:34 -06003006 }
3007 return result;
3008}
3009
Chia-I Wuc278df82015-07-07 11:50:03 +08003010VK_LAYER_EXPORT void VKAPI vkCmdBeginRenderPass(VkCmdBuffer cmdBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkRenderPassContents contents)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003011{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003012 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003013 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3014 if (pCB) {
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003015 if (pRenderPassBegin && pRenderPassBegin->renderPass) {
Tobin Ehlise4076782015-06-24 15:53:07 -06003016 if (pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003017 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 -06003018 "Cannot call vkCmdBeginRenderPass() during an active RenderPass (%#" PRIxLEAST64 "). You must first call vkCmdEndRenderPass().", pCB->activeRenderPass.handle);
Tobin Ehlise4076782015-06-24 15:53:07 -06003019 } else {
3020 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003021 skipCall |= addCmd(pCB, CMD_BEGINRENDERPASS);
Tobin Ehlise4076782015-06-24 15:53:07 -06003022 pCB->activeRenderPass = pRenderPassBegin->renderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003023 pCB->activeSubpass = 0;
Tobin Ehlise4076782015-06-24 15:53:07 -06003024 pCB->framebuffer = pRenderPassBegin->framebuffer;
3025 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003026 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Tobin Ehlise4076782015-06-24 15:53:07 -06003027 }
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003028 }
Tobin Ehlise4076782015-06-24 15:53:07 -06003029 } else {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003030 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 -06003031 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tony Barbourb9f82ba2015-04-06 11:09:26 -06003032 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003033 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003034 if (VK_FALSE == skipCall)
3035 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdBeginRenderPass(cmdBuffer, pRenderPassBegin, contents);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003036}
3037
Chia-I Wuc278df82015-07-07 11:50:03 +08003038VK_LAYER_EXPORT void VKAPI vkCmdNextSubpass(VkCmdBuffer cmdBuffer, VkRenderPassContents contents)
3039{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003040 VkBool32 skipCall = VK_FALSE;
Chia-I Wuc278df82015-07-07 11:50:03 +08003041 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3042 if (pCB) {
3043 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003044 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 +08003045 "Incorrect call to vkCmdNextSubpass() without an active RenderPass.");
3046 } else {
3047 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003048 skipCall |= addCmd(pCB, CMD_NEXTSUBPASS);
Chia-I Wuc278df82015-07-07 11:50:03 +08003049 pCB->activeSubpass++;
3050 if (pCB->lastBoundPipeline) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003051 skipCall |= validatePipelineState(pCB, VK_PIPELINE_BIND_POINT_GRAPHICS, pCB->lastBoundPipeline);
Chia-I Wuc278df82015-07-07 11:50:03 +08003052 }
Chia-I Wuc278df82015-07-07 11:50:03 +08003053 }
3054 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003055 if (VK_FALSE == skipCall)
3056 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdNextSubpass(cmdBuffer, contents);
Chia-I Wuc278df82015-07-07 11:50:03 +08003057}
3058
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003059VK_LAYER_EXPORT void VKAPI vkCmdEndRenderPass(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003060{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003061 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003062 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3063 if (pCB) {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003064 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003065 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 +08003066 "Incorrect call to vkCmdEndRenderPass() without an active RenderPass.");
Tobin Ehlis536cfe42015-06-23 16:13:03 -06003067 } else {
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003068 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003069 skipCall |= addCmd(pCB, CMD_ENDRENDERPASS);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003070 pCB->activeRenderPass = 0;
Chia-I Wuc278df82015-07-07 11:50:03 +08003071 pCB->activeSubpass = 0;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003072 }
3073 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003074 if (VK_FALSE == skipCall)
3075 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdEndRenderPass(cmdBuffer);
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003076}
3077
3078VK_LAYER_EXPORT void VKAPI vkCmdExecuteCommands(VkCmdBuffer cmdBuffer, uint32_t cmdBuffersCount, const VkCmdBuffer* pCmdBuffers)
3079{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003080 VkBool32 skipCall = VK_FALSE;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003081 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
3082 if (pCB) {
3083 if (!pCB->activeRenderPass) {
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003084 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 +08003085 "Incorrect call to vkCmdExecuteCommands() without an active RenderPass.");
Tobin Ehlis8b6c2352015-06-23 16:13:03 -06003086 }
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003087 GLOBAL_CB_NODE* pSubCB = NULL;
3088 for (uint32_t i=0; i<cmdBuffersCount; i++) {
3089 pSubCB = getCBNode(pCmdBuffers[i]);
3090 if (!pSubCB) {
3091 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3092 "vkCmdExecuteCommands() called w/ invalid Cmd Buffer %p in element %u of pCmdBuffers array.", (void*)pCmdBuffers[i], i);
3093 } else if (VK_CMD_BUFFER_LEVEL_PRIMARY == pSubCB->createInfo.level) {
3094 skipCall |= log_msg(mdd(pCB->cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_INVALID_SECONDARY_CMD_BUFFER, "DS",
3095 "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);
3096 }
3097 }
3098 updateCBTracking(cmdBuffer);
3099 skipCall |= addCmd(pCB, CMD_EXECUTECOMMANDS);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003100 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003101 if (VK_FALSE == skipCall)
3102 get_dispatch_table(draw_state_device_table_map, cmdBuffer)->CmdExecuteCommands(cmdBuffer, cmdBuffersCount, pCmdBuffers);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003103}
3104
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003105VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
3106 VkInstance instance,
3107 VkFlags msgFlags,
3108 const PFN_vkDbgMsgCallback pfnMsgCallback,
3109 void* pUserData,
3110 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003111{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003112 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003113 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3114 if (VK_SUCCESS == res) {
3115 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3116 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
3117 }
3118 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003119}
3120
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -06003121VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
3122 VkInstance instance,
3123 VkDbgMsgCallback msgCallback)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003124{
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003125 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Tobin Ehlisc91330b2015-06-16 09:04:30 -06003126 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
3127 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3128 layer_destroy_msg_callback(my_data->report_data, msgCallback);
3129 return res;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003130}
3131
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003132VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003133{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003134 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003135 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003136 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3137 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003138 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003139 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 -06003140 "Attempt to use CmdDbgMarkerBegin but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003141 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003142 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003143 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003144 skipCall |= addCmd(pCB, CMD_DBGMARKERBEGIN);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003145 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003146 if (VK_FALSE == skipCall)
3147 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerBegin(cmdBuffer, pMarker);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003148}
3149
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003150VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003151{
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003152 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003153 GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003154 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) cmdBuffer;
3155 if (!deviceExtMap[pDisp].debug_marker_enabled) {
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003156 // TODO : cmdBuffer should be srcObj
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003157 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 -06003158 "Attempt to use CmdDbgMarkerEnd but extension disabled!");
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003159 return;
Tobin Ehlisa366ca22015-06-19 15:07:05 -06003160 } else if (pCB) {
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003161 updateCBTracking(cmdBuffer);
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003162 skipCall |= addCmd(pCB, CMD_DBGMARKEREND);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003163 }
Tobin Ehlis48ddcb82015-09-09 11:31:10 -06003164 if (VK_FALSE == skipCall)
3165 debug_marker_dispatch_table(cmdBuffer)->CmdDbgMarkerEnd(cmdBuffer);
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003166}
3167
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003168//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType objType, VkObject object, size_t tagSize, const void* pTag)
3169//{
3170// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3171// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3172// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3173// "Attempt to use DbgSetObjectTag but extension disabled!");
3174// return VK_ERROR_UNAVAILABLE;
3175// }
3176// debug_marker_dispatch_table(device)->DbgSetObjectTag(device, objType, object, tagSize, pTag);
3177//}
3178//
3179//VK_LAYER_EXPORT VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType objType, VkObject object, size_t nameSize, const char* pName)
3180//{
3181// VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
3182// if (!deviceExtMap[pDisp].debug_marker_enabled) {
3183// log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, objType, object, 0, DRAWSTATE_INVALID_EXTENSION, "DS",
3184// "Attempt to use DbgSetObjectName but extension disabled!");
3185// return VK_ERROR_UNAVAILABLE;
3186// }
3187// debug_marker_dispatch_table(device)->DbgSetObjectName(device, objType, object, nameSize, pName);
3188//}
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003189
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003190VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003191{
Jon Ashburn1245cec2015-05-18 13:20:15 -06003192 if (dev == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003193 return NULL;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003194
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003195 /* loader uses this to force layer initialization; device object is wrapped */
3196 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003197 initDeviceTable(draw_state_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003198 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003199 }
Courtney Goeltzenleuchterbe637992015-06-25 18:01:43 -06003200 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003201 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003202 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003203 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003204 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003205 return (PFN_vkVoidFunction) vkQueueSubmit;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003206 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003207 return (PFN_vkVoidFunction) vkDestroyInstance;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003208 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003209 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003210 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003211 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003212 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003213 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003214 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003215 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003216 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003217 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003218 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003219 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003220 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003221 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003222 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003223 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003224 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003225 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003226 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003227 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003228 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003229 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003230 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003231 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003232 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003233 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003234 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003235 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003236 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003237 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003238 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003239 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003240 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003241 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003242 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003243 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003244 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003245 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003246 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003247 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003248 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003249 return (PFN_vkVoidFunction) vkCreateImageView;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003250 if (!strcmp(funcName, "CreatePipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003251 return (PFN_vkVoidFunction) vkCreatePipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003252 if (!strcmp(funcName, "DestroyPipelineCache"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003253 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003254 if (!strcmp(funcName, "GetPipelineCacheSize"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003255 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003256 if (!strcmp(funcName, "GetPipelineCacheData"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003257 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003258 if (!strcmp(funcName, "MergePipelineCaches"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003259 return (PFN_vkVoidFunction) vkMergePipelineCaches;
Jon Ashburn0d60d272015-07-09 15:02:25 -06003260 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003261 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003262 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003263 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003264 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003265 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003266 if (!strcmp(funcName, "vkCreatePipelineLayout"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003267 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003268 if (!strcmp(funcName, "vkCreateDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003269 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003270 if (!strcmp(funcName, "vkResetDescriptorPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003271 return (PFN_vkVoidFunction) vkResetDescriptorPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003272 if (!strcmp(funcName, "vkAllocDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003273 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
Chia-I Wu8cd8ecd2015-05-25 16:27:55 +08003274 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003275 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003276 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003277 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003278 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003279 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003280 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003281 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003282 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003283 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003284 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003285 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003286 if (!strcmp(funcName, "vkCmdSetViewport"))
3287 return (PFN_vkVoidFunction) vkCmdSetViewport;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06003288 if (!strcmp(funcName, "vkCmdSetScissor"))
3289 return (PFN_vkVoidFunction) vkCmdSetScissor;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06003290 if (!strcmp(funcName, "vkCmdSetLineWidth"))
3291 return (PFN_vkVoidFunction) vkCmdSetLineWidth;
3292 if (!strcmp(funcName, "vkCmdSetDepthBias"))
3293 return (PFN_vkVoidFunction) vkCmdSetDepthBias;
3294 if (!strcmp(funcName, "vkCmdSetBlendConstants"))
3295 return (PFN_vkVoidFunction) vkCmdSetBlendConstants;
3296 if (!strcmp(funcName, "vkCmdSetDepthBounds"))
3297 return (PFN_vkVoidFunction) vkCmdSetDepthBounds;
3298 if (!strcmp(funcName, "vkCmdSetStencilCompareMask"))
3299 return (PFN_vkVoidFunction) vkCmdSetStencilCompareMask;
3300 if (!strcmp(funcName, "vkCmdSetStencilWriteMask"))
3301 return (PFN_vkVoidFunction) vkCmdSetStencilWriteMask;
3302 if (!strcmp(funcName, "vkCmdSetStencilReference"))
3303 return (PFN_vkVoidFunction) vkCmdSetStencilReference;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003304 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003305 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003306 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003307 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003308 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003309 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003310 if (!strcmp(funcName, "vkCmdDraw"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003311 return (PFN_vkVoidFunction) vkCmdDraw;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003312 if (!strcmp(funcName, "vkCmdDrawIndexed"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003313 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003314 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003315 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003316 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003317 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003318 if (!strcmp(funcName, "vkCmdDispatch"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003319 return (PFN_vkVoidFunction) vkCmdDispatch;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003320 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003321 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003322 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003323 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003324 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003325 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003326 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003327 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003328 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003329 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003330 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003331 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003332 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003333 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003334 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003335 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbes2951d7d2015-06-22 17:21:59 +12003336 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003337 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003338 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003339 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
Tobin Ehlis8cd650e2015-07-01 16:46:13 -06003340 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003341 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003342 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003343 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003344 if (!strcmp(funcName, "vkCmdSetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003345 return (PFN_vkVoidFunction) vkCmdSetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003346 if (!strcmp(funcName, "vkCmdResetEvent"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003347 return (PFN_vkVoidFunction) vkCmdResetEvent;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003348 if (!strcmp(funcName, "vkCmdWaitEvents"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003349 return (PFN_vkVoidFunction) vkCmdWaitEvents;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003350 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003351 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003352 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003353 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003354 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003355 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003356 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003357 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003358 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003359 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003360 if (!strcmp(funcName, "vkCreateFramebuffer"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003361 return (PFN_vkVoidFunction) vkCreateFramebuffer;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003362 if (!strcmp(funcName, "vkCreateRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003363 return (PFN_vkVoidFunction) vkCreateRenderPass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003364 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003365 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
Chia-I Wuc278df82015-07-07 11:50:03 +08003366 if (!strcmp(funcName, "vkCmdNextSubpass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003367 return (PFN_vkVoidFunction) vkCmdNextSubpass;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003368 if (!strcmp(funcName, "vkCmdEndRenderPass"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003369 return (PFN_vkVoidFunction) vkCmdEndRenderPass;
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003370 if (!strcmp(funcName, "vkCmdExecuteCommands"))
3371 return (PFN_vkVoidFunction) vkCmdExecuteCommands;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003372
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003373 VkLayerDispatchTable* pTable = get_dispatch_table(draw_state_device_table_map, dev);
3374 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003375 {
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003376 if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003377 return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
Jon Ashburn7e07faf2015-06-18 15:02:58 -06003378 if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003379 return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
Tobin Ehlis1dce5f12015-07-07 10:42:20 -06003380// if (!strcmp(funcName, "vkDbgSetObjectTag"))
3381// return (void*) vkDbgSetObjectTag;
3382// if (!strcmp(funcName, "vkDbgSetObjectName"))
3383// return (void*) vkDbgSetObjectName;
Jon Ashburn6f8cd632015-06-01 09:37:38 -06003384 }
3385 {
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003386 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003387 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003388 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003389 }
3390}
3391
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003392VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003393{
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003394 PFN_vkVoidFunction fptr;
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003395 if (instance == NULL)
3396 return NULL;
3397
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003398 /* loader uses this to force layer initialization; instance object is wrapped */
3399 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003400 initInstanceTable(draw_state_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003401 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003402 }
Courtney Goeltzenleuchter3c9f6ec2015-06-01 14:29:58 -06003403 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003404 return (PFN_vkVoidFunction) vkCreateInstance;
Jon Ashburne0fa2282015-05-20 09:00:28 -06003405 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchtera4c8c712015-07-12 14:35:22 -06003406 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -06003407 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
3408 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
3409 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
3410 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
3411 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
3412 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
3413 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
3414 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003415
Tobin Ehlisfde4dce2015-06-16 15:50:44 -06003416 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3417 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchtercc899fe2015-06-01 14:33:14 -06003418 if (fptr)
3419 return fptr;
3420
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003421 {
Courtney Goeltzenleuchterc280adc2015-06-13 21:23:09 -06003422 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(draw_state_instance_table_map, instance);
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003423 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburn79b78ac2015-05-05 14:22:52 -06003424 return NULL;
Jon Ashburn4f2575f2015-05-28 16:25:02 -06003425 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003426 }
Tobin Ehlis63bb9482015-03-17 16:24:32 -06003427}