blob: 32f7712791c1e47a769124653bef725afc623a81 [file] [log] [blame]
Tobin Ehlis6663f492014-11-10 12:29:12 -07001/*
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05002 * Vulkan
Tobin Ehlis6663f492014-11-10 12:29:12 -07003 *
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05004 * Copyright (C) 2015 LunarG, Inc.
Tobin Ehlis6663f492014-11-10 12:29:12 -07005 *
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
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050017* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Tobin Ehlis6663f492014-11-10 12:29:12 -070018 * 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
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -050025#include <inttypes.h>
Tobin Ehlis6663f492014-11-10 12:29:12 -070026#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050030#include <list>
Mark Lobodzinski76c991d2015-05-20 16:16:37 -050031#include <map>
Chia-I Wuf8693382015-04-16 22:02:10 +080032#include <vector>
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050033using namespace std;
34
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060035#include "vk_loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036#include "vk_dispatch_table_helper.h"
37#include "vk_struct_string_helper_cpp.h"
Tobin Ehliscd9223b2014-11-19 16:19:28 -070038#include "mem_tracker.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060039#include "vk_layer_config.h"
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060040#include "vk_layer_extension_utils.h"
Ian Elliott655cad72015-02-12 17:08:34 -070041// The following is #included again to catch certain OS-specific functions
42// being used:
Tobin Ehlisb835d1b2015-07-03 10:34:49 -060043#include "vk_loader_platform.h"
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060044#include "vk_layer_table.h"
45#include "vk_layer_data.h"
46#include "vk_layer_logging.h"
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -060047static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -050048
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060049typedef struct _layer_data {
50 debug_report_data *report_data;
51 // TODO: put instance data here
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -060052 VkDbgMsgCallback logging_callback;
Ian Elliott1064fe32015-07-06 14:31:32 -060053 bool wsi_enabled;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060054} layer_data;
Mark Lobodzinski76c991d2015-05-20 16:16:37 -050055
Tobin Ehlis257d9742015-07-08 17:08:02 -060056static unordered_map<void *, layer_data *> layer_data_map;
57
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060058static device_table_map mem_tracker_device_table_map;
59static instance_table_map mem_tracker_instance_table_map;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -060060static VkPhysicalDeviceMemoryProperties memProps;
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060061
Mark Lobodzinski93f494b2015-03-02 20:23:52 -060062// TODO : This can be much smarter, using separate locks for separate global data
63static int globalLockInitialized = 0;
64static loader_platform_thread_mutex globalLock;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070065
Tobin Ehlisc145be82015-01-08 15:22:32 -070066#define MAX_BINDING 0xFFFFFFFF
Tobin Ehlisc145be82015-01-08 15:22:32 -070067
Tobin Ehlis257d9742015-07-08 17:08:02 -060068// Maps for tracking key structs related to MemTracker state
Mike Stroyandd7aed72015-05-19 17:03:40 -060069unordered_map<VkCmdBuffer, MT_CB_INFO> cbMap;
Tobin Ehlis257d9742015-07-08 17:08:02 -060070unordered_map<uint64_t, MT_MEM_OBJ_INFO> memObjMap;
71unordered_map<uint64_t, MT_FENCE_INFO> fenceMap; // Map fence to fence info
Mike Stroyandd7aed72015-05-19 17:03:40 -060072unordered_map<VkQueue, MT_QUEUE_INFO> queueMap;
Ian Elliott1064fe32015-07-06 14:31:32 -060073unordered_map<uint64_t, MT_SWAP_CHAIN_INFO*> swapChainMap;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050074
Tobin Ehlis257d9742015-07-08 17:08:02 -060075// Images and Buffers are 2 objects that can have memory bound to them so they get special treatment
76unordered_map<uint64_t, MT_OBJ_BINDING_INFO> imageMap;
77unordered_map<uint64_t, MT_OBJ_BINDING_INFO> bufferMap;
78
79// Maps for non-dispatchable objects that store createInfo based on handle
80unordered_map<uint64_t, VkAttachmentViewCreateInfo> attachmentViewMap;
81unordered_map<uint64_t, VkImageViewCreateInfo> imageViewMap;
82// TODO : If we ever really care about Compute pipelines, split them into own map
83unordered_map<uint64_t, VkGraphicsPipelineCreateInfo> pipelineMap;
84unordered_map<uint64_t, VkSamplerCreateInfo> samplerMap;
85unordered_map<uint64_t, VkSemaphoreCreateInfo> semaphoreMap;
86unordered_map<uint64_t, VkEventCreateInfo> eventMap;
87unordered_map<uint64_t, VkQueryPoolCreateInfo> queryPoolMap;
88unordered_map<uint64_t, VkBufferViewCreateInfo> bufferViewMap;
89unordered_map<uint64_t, VkShaderModuleCreateInfo> shaderModuleMap;
90unordered_map<uint64_t, VkShaderCreateInfo> shaderMap;
91unordered_map<uint64_t, VkPipelineLayoutCreateInfo> pipelineLayoutMap;
92unordered_map<uint64_t, VkDescriptorSetLayoutCreateInfo> descriptorSetLayoutMap;
93unordered_map<uint64_t, VkDescriptorPoolCreateInfo> descriptorPoolMap;
94unordered_map<uint64_t, VkRenderPassCreateInfo> renderPassMap;
95unordered_map<uint64_t, VkFramebufferCreateInfo> framebufferMap;
96//unordered_map<uint64_t, VkDescriptorSetCreateInfo> descriptorSetMap;
97unordered_map<uint64_t, VkDynamicViewportStateCreateInfo> dynamicViewportStateMap;
98unordered_map<uint64_t, VkDynamicRasterStateCreateInfo> dynamicRasterStateMap;
99unordered_map<uint64_t, VkDynamicColorBlendStateCreateInfo> dynamicColorBlendStateMap;
100unordered_map<uint64_t, VkDynamicDepthStencilStateCreateInfo> dynamicDepthStencilStateMap;
101
102// For a given handle and object type, return a ptr to its CreateInfo struct, or NULL if not found
103static void* get_object_create_info(uint64_t handle, VkDbgObjectType type)
104{
105 void* retValue = NULL;
106 switch (type)
107 {
108 case VK_OBJECT_TYPE_ATTACHMENT_VIEW:
109 {
110 auto it = attachmentViewMap.find(handle);
111 if (it != attachmentViewMap.end())
112 return (void*)&(*it).second;
113 break;
114 }
115 case VK_OBJECT_TYPE_IMAGE_VIEW:
116 {
117 auto it = imageViewMap.find(handle);
118 if (it != imageViewMap.end())
119 return (void*)&(*it).second;
120 break;
121 }
122 case VK_OBJECT_TYPE_IMAGE:
123 {
124 auto it = imageMap.find(handle);
125 if (it != imageMap.end())
126 return (void*)&(*it).second;
127 break;
128 }
129 case VK_OBJECT_TYPE_PIPELINE:
130 {
131 auto it = pipelineMap.find(handle);
132 if (it != pipelineMap.end())
133 return (void*)&(*it).second;
134 break;
135 }
136 case VK_OBJECT_TYPE_SAMPLER:
137 {
138 auto it = samplerMap.find(handle);
139 if (it != samplerMap.end())
140 return (void*)&(*it).second;
141 break;
142 }
143 case VK_OBJECT_TYPE_BUFFER:
144 {
145 auto it = bufferMap.find(handle);
146 if (it != bufferMap.end())
147 return (void*)&(*it).second;
148 break;
149 }
150 case VK_OBJECT_TYPE_SEMAPHORE:
151 {
152 auto it = semaphoreMap.find(handle);
153 if (it != semaphoreMap.end())
154 return (void*)&(*it).second;
155 break;
156 }
157 case VK_OBJECT_TYPE_EVENT:
158 {
159 auto it = eventMap.find(handle);
160 if (it != eventMap.end())
161 return (void*)&(*it).second;
162 break;
163 }
164 case VK_OBJECT_TYPE_QUERY_POOL:
165 {
166 auto it = queryPoolMap.find(handle);
167 if (it != queryPoolMap.end())
168 return (void*)&(*it).second;
169 break;
170 }
171 case VK_OBJECT_TYPE_BUFFER_VIEW:
172 {
173 auto it = bufferViewMap.find(handle);
174 if (it != bufferViewMap.end())
175 return (void*)&(*it).second;
176 break;
177 }
178 case VK_OBJECT_TYPE_SHADER_MODULE:
179 {
180 auto it = shaderModuleMap.find(handle);
181 if (it != shaderModuleMap.end())
182 return (void*)&(*it).second;
183 break;
184 }
185 case VK_OBJECT_TYPE_SHADER:
186 {
187 auto it = shaderMap.find(handle);
188 if (it != shaderMap.end())
189 return (void*)&(*it).second;
190 break;
191 }
192 case VK_OBJECT_TYPE_PIPELINE_LAYOUT:
193 {
194 auto it = pipelineLayoutMap.find(handle);
195 if (it != pipelineLayoutMap.end())
196 return (void*)&(*it).second;
197 break;
198 }
199 case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
200 {
201 auto it = descriptorSetLayoutMap.find(handle);
202 if (it != descriptorSetLayoutMap.end())
203 return (void*)&(*it).second;
204 break;
205 }
206 case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
207 {
208 auto it = descriptorPoolMap.find(handle);
209 if (it != descriptorPoolMap.end())
210 return (void*)&(*it).second;
211 break;
212 }
213// case VK_OBJECT_TYPE_DESCRIPTOR_SET:
214// {
215// auto it = descriptorSetMap.find(handle);
216// if (it != descriptorSetMap.end())
217// return (void*)&(*it).second;
218// break;
219// }
220 case VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE:
221 {
222 auto it = dynamicViewportStateMap.find(handle);
223 if (it != dynamicViewportStateMap.end())
224 return (void*)&(*it).second;
225 break;
226 }
227 case VK_OBJECT_TYPE_DYNAMIC_RASTER_STATE:
228 {
229 auto it = dynamicRasterStateMap.find(handle);
230 if (it != dynamicRasterStateMap.end())
231 return (void*)&(*it).second;
232 break;
233 }
234 case VK_OBJECT_TYPE_DYNAMIC_COLOR_BLEND_STATE:
235 {
236 auto it = dynamicColorBlendStateMap.find(handle);
237 if (it != dynamicColorBlendStateMap.end())
238 return (void*)&(*it).second;
239 break;
240 }
241 case VK_OBJECT_TYPE_DYNAMIC_DEPTH_STENCIL_STATE:
242 {
243 auto it = dynamicDepthStencilStateMap.find(handle);
244 if (it != dynamicDepthStencilStateMap.end())
245 return (void*)&(*it).second;
246 break;
247 }
248 case VK_OBJECT_TYPE_RENDER_PASS:
249 {
250 auto it = renderPassMap.find(handle);
251 if (it != renderPassMap.end())
252 return (void*)&(*it).second;
253 break;
254 }
255 case VK_OBJECT_TYPE_FRAMEBUFFER:
256 {
257 auto it = framebufferMap.find(handle);
258 if (it != framebufferMap.end())
259 return (void*)&(*it).second;
260 break;
261 }
262 default:
263 {
264 // NULL will be returned below by default
265 break;
266 }
267 }
268 return retValue;
269}
270
271static MT_OBJ_BINDING_INFO* get_object_binding_info(uint64_t handle, VkDbgObjectType type)
272{
273 MT_OBJ_BINDING_INFO* retValue = NULL;
274 switch (type)
275 {
276 case VK_OBJECT_TYPE_IMAGE:
277 {
278 auto it = imageMap.find(handle);
279 if (it != imageMap.end())
280 return &(*it).second;
281 break;
282 }
283 case VK_OBJECT_TYPE_BUFFER:
284 {
285 auto it = bufferMap.find(handle);
286 if (it != bufferMap.end())
287 return &(*it).second;
288 break;
289 }
290 }
291 return retValue;
292}
Mark Lobodzinski50932972015-04-02 20:49:09 -0500293// TODO : Add per-device fence completion
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600294static uint64_t g_currentFenceId = 1;
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600295
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600296template layer_data *get_my_data_ptr<layer_data>(
297 void *data_key,
298 std::unordered_map<void *, layer_data *> &data_map);
299
Tobin Ehlis257d9742015-07-08 17:08:02 -0600300debug_report_data *mdd(void* object)
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600301{
Courtney Goeltzenleuchter62110862015-06-13 21:39:35 -0600302 dispatch_key key = get_dispatch_key(object);
303 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Courtney Goeltzenleuchter89d68442015-06-13 21:40:22 -0600304#if DISPATCH_MAP_DEBUG
305 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
306#endif
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600307 return my_data->report_data;
308}
309
310debug_report_data *mid(VkInstance object)
311{
Courtney Goeltzenleuchter62110862015-06-13 21:39:35 -0600312 dispatch_key key = get_dispatch_key(object);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600313 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
Courtney Goeltzenleuchter89d68442015-06-13 21:40:22 -0600314#if DISPATCH_MAP_DEBUG
315 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
316#endif
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600317 return my_data->report_data;
318}
319
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500320// Add new queue for this device to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500321static void add_queue_info(const VkQueue queue)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500322{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600323 MT_QUEUE_INFO* pInfo = &queueMap[queue];
Mark Lobodzinski50932972015-04-02 20:49:09 -0500324 pInfo->lastRetiredId = 0;
325 pInfo->lastSubmittedId = 0;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500326}
327
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500328static void delete_queue_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600329 void)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500330{
331 // Process queue list, cleaning up each entry before deleting
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500332 queueMap.clear();
333}
334
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500335static void add_swap_chain_info(
Tobin Ehlis41376e12015-07-03 08:45:14 -0600336 const VkSwapChainWSI swapChain, const VkSwapChainCreateInfoWSI* pCI)
Chia-I Wuf8693382015-04-16 22:02:10 +0800337{
338 MT_SWAP_CHAIN_INFO* pInfo = new MT_SWAP_CHAIN_INFO;
Tobin Ehlis41376e12015-07-03 08:45:14 -0600339 memcpy(&pInfo->createInfo, pCI, sizeof(VkSwapChainCreateInfoWSI));
Ian Elliott1064fe32015-07-06 14:31:32 -0600340 swapChainMap[swapChain.handle] = pInfo;
Chia-I Wuf8693382015-04-16 22:02:10 +0800341}
342
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500343// Add new CBInfo for this cb to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500344static void add_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600345 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700346{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600347 cbMap[cb].cmdBuffer = cb;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700348}
349
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500350// Return ptr to Info in CB map, or NULL if not found
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500351static MT_CB_INFO* get_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600352 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700353{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600354 auto item = cbMap.find(cb);
Mike Stroyan950496e2015-05-19 15:16:08 -0600355 if (item != cbMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600356 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600357 } else {
358 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600359 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700360}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600361
Tobin Ehlis257d9742015-07-08 17:08:02 -0600362static void add_object_binding_info(const uint64_t handle, const VkDbgObjectType type, const VkDeviceMemory mem)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500363{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600364 switch (type)
365 {
366 // Buffers and images are unique as their CreateInfo is in container struct
367 case VK_OBJECT_TYPE_BUFFER:
368 {
369 auto pCI = &bufferMap[handle];
370 pCI->mem = mem;
371 break;
372 }
373 case VK_OBJECT_TYPE_IMAGE:
374 {
375 auto pCI = &imageMap[handle];
376 pCI->mem = mem;
377 break;
378 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500379 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500380}
381
Tobin Ehlis257d9742015-07-08 17:08:02 -0600382static void add_object_create_info(const uint64_t handle, const VkDbgObjectType type, const void* pCreateInfo)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500383{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600384 // TODO : For any CreateInfo struct that has ptrs, need to deep copy them and appropriately clean up on Destroy
385 switch (type)
386 {
387 // Buffers and images are unique as their CreateInfo is in container struct
388 case VK_OBJECT_TYPE_BUFFER:
389 {
390 auto pCI = &bufferMap[handle];
391 memset(pCI, 0, sizeof(MT_OBJ_BINDING_INFO));
392 memcpy(&pCI->create_info.buffer, pCreateInfo, sizeof(VkBufferCreateInfo));
393 break;
394 }
395 case VK_OBJECT_TYPE_IMAGE:
396 {
397 auto pCI = &imageMap[handle];
398 memset(pCI, 0, sizeof(MT_OBJ_BINDING_INFO));
399 memcpy(&pCI->create_info.image, pCreateInfo, sizeof(VkImageCreateInfo));
400 break;
401 }
402 // Swap Chain is very unique, use imageMap, but copy in SwapChainCreatInfo
403 // This is used by vkCreateAttachmentView to distinguish swap chain images
404 case VK_OBJECT_TYPE_SWAP_CHAIN_WSI:
405 {
406 auto pCI = &imageMap[handle];
407 memset(pCI, 0, sizeof(MT_OBJ_BINDING_INFO));
Tony Barbour791646c2015-07-13 16:37:21 -0600408 // memcpy(&pCI->create_info.swapchain, pCreateInfo, sizeof(VkSwapChainCreateInfoWSI));
Tobin Ehlis257d9742015-07-08 17:08:02 -0600409 break;
410 }
411 // All other non-disp objects store their Create info struct as map value
412 case VK_OBJECT_TYPE_ATTACHMENT_VIEW:
413 {
414 auto pCI = &attachmentViewMap[handle];
415 memcpy(pCI, pCreateInfo, sizeof(VkAttachmentViewCreateInfo));
416 break;
417 }
418 case VK_OBJECT_TYPE_IMAGE_VIEW:
419 {
420 auto pCI = &imageViewMap[handle];
421 memcpy(pCI, pCreateInfo, sizeof(VkImageViewCreateInfo));
422 break;
423 }
424 case VK_OBJECT_TYPE_PIPELINE:
425 {
426 auto pCI = &pipelineMap[handle];
427 memcpy(pCI, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo));
428 break;
429 }
430 case VK_OBJECT_TYPE_SAMPLER:
431 {
432 auto pCI = &samplerMap[handle];
433 memcpy(pCI, pCreateInfo, sizeof(VkSamplerCreateInfo));
434 break;
435 }
436 case VK_OBJECT_TYPE_SEMAPHORE:
437 {
438 auto pCI = &semaphoreMap[handle];
439 memcpy(pCI, pCreateInfo, sizeof(VkSemaphoreCreateInfo));
440 break;
441 }
442 case VK_OBJECT_TYPE_EVENT:
443 {
444 auto pCI = &eventMap[handle];
445 memcpy(pCI, pCreateInfo, sizeof(VkEventCreateInfo));
446 break;
447 }
448 case VK_OBJECT_TYPE_QUERY_POOL:
449 {
450 auto pCI = &queryPoolMap[handle];
451 memcpy(pCI, pCreateInfo, sizeof(VkQueryPoolCreateInfo));
452 break;
453 }
454 case VK_OBJECT_TYPE_BUFFER_VIEW:
455 {
456 auto pCI = &bufferViewMap[handle];
457 memcpy(pCI, pCreateInfo, sizeof(VkBufferViewCreateInfo));
458 break;
459 }
460 case VK_OBJECT_TYPE_SHADER_MODULE:
461 {
462 auto pCI = &shaderModuleMap[handle];
463 memcpy(pCI, pCreateInfo, sizeof(VkShaderModuleCreateInfo));
464 break;
465 }
466 case VK_OBJECT_TYPE_SHADER:
467 {
468 auto pCI = &shaderMap[handle];
469 memcpy(pCI, pCreateInfo, sizeof(VkShaderCreateInfo));
470 break;
471 }
472 case VK_OBJECT_TYPE_PIPELINE_LAYOUT:
473 {
474 auto pCI = &pipelineLayoutMap[handle];
475 memcpy(pCI, pCreateInfo, sizeof(VkPipelineLayoutCreateInfo));
476 break;
477 }
478 case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
479 {
480 auto pCI = &descriptorSetLayoutMap[handle];
481 memcpy(pCI, pCreateInfo, sizeof(VkDescriptorSetLayoutCreateInfo));
482 break;
483 }
484 case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
485 {
486 auto pCI = &descriptorPoolMap[handle];
487 memcpy(pCI, pCreateInfo, sizeof(VkDescriptorPoolCreateInfo));
488 break;
489 }
490// case VK_OBJECT_TYPE_DESCRIPTOR_SET:
491// {
492// auto pCI = &descriptorSetMap[handle];
493// memcpy(pCI, pCreateInfo, sizeof(VkDescriptorSetCreateInfo));
494// break;
495// }
496 case VK_OBJECT_TYPE_RENDER_PASS:
497 {
498 auto pCI = &renderPassMap[handle];
499 memcpy(pCI, pCreateInfo, sizeof(VkRenderPassCreateInfo));
500 break;
501 }
502 case VK_OBJECT_TYPE_FRAMEBUFFER:
503 {
504 auto pCI = &framebufferMap[handle];
505 memcpy(pCI, pCreateInfo, sizeof(VkFramebufferCreateInfo));
506 break;
507 }
508 case VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE:
509 {
510 auto pCI = &dynamicViewportStateMap[handle];
511 memcpy(pCI, pCreateInfo, sizeof(VkDynamicViewportStateCreateInfo));
512 break;
513 }
514 case VK_OBJECT_TYPE_DYNAMIC_RASTER_STATE:
515 {
516 auto pCI = &dynamicRasterStateMap[handle];
517 memcpy(pCI, pCreateInfo, sizeof(VkDynamicRasterStateCreateInfo));
518 break;
519 }
520 case VK_OBJECT_TYPE_DYNAMIC_COLOR_BLEND_STATE:
521 {
522 auto pCI = &dynamicColorBlendStateMap[handle];
523 memcpy(pCI, pCreateInfo, sizeof(VkDynamicColorBlendStateCreateInfo));
524 break;
525 }
526 case VK_OBJECT_TYPE_DYNAMIC_DEPTH_STENCIL_STATE:
527 {
528 auto pCI = &dynamicDepthStencilStateMap[handle];
529 memcpy(pCI, pCreateInfo, sizeof(VkDynamicDepthStencilStateCreateInfo));
530 break;
531 }
532 default:
533 {
534 // NULL will be returned below by default
535 break;
536 }
537 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500538}
539
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500540// Add a fence, creating one if necessary to our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500541static uint64_t add_fence_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600542 VkFence fence,
543 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500544{
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500545 // Create fence object
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500546 uint64_t fenceId = g_currentFenceId++;
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500547 // If no fence, create an internal fence to track the submissions
Tobin Ehlis257d9742015-07-08 17:08:02 -0600548 if (fence.handle != 0) {
549 fenceMap[fence.handle].fenceId = fenceId;
550 fenceMap[fence.handle].queue = queue;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500551 // Validate that fence is in UNSIGNALED state
Tobin Ehlis257d9742015-07-08 17:08:02 -0600552 VkFenceCreateInfo* pFenceCI = &(fenceMap[fence.handle].createInfo);
553 if (pFenceCI->flags & VK_FENCE_CREATE_SIGNALED_BIT) {
554 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, fence.handle, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM",
555 "Fence %#" PRIxLEAST64 " submitted in SIGNALED state. Fences must be reset before being submitted", fence.handle);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500556 }
Tobin Ehlis257d9742015-07-08 17:08:02 -0600557 } else {
558 // TODO : Do we need to create an internal fence here for tracking purposes?
Tobin Ehlis6663f492014-11-10 12:29:12 -0700559 }
Mike Stroyan950496e2015-05-19 15:16:08 -0600560 // Update most recently submitted fence and fenceId for Queue
Mike Stroyandd7aed72015-05-19 17:03:40 -0600561 queueMap[queue].lastSubmittedId = fenceId;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500562 return fenceId;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500563}
564
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500565// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500566static void delete_fence_info(
Mike Stroyan950496e2015-05-19 15:16:08 -0600567 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500568{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600569 fenceMap.erase(fence.handle);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500570}
571
Mike Stroyan950496e2015-05-19 15:16:08 -0600572// Record information when a fence is known to be signalled
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500573static void update_fence_tracking(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600574 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500575{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600576 auto fence_item = fenceMap.find(fence.handle);
Mike Stroyan950496e2015-05-19 15:16:08 -0600577 if (fence_item != fenceMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600578 MT_FENCE_INFO *pCurFenceInfo = &(*fence_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600579 VkQueue queue = pCurFenceInfo->queue;
Tobin Ehlis257d9742015-07-08 17:08:02 -0600580 auto queue_item = queueMap.find(queue);
Mike Stroyan950496e2015-05-19 15:16:08 -0600581 if (queue_item != queueMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600582 MT_QUEUE_INFO *pQueueInfo = &(*queue_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600583 if (pQueueInfo->lastRetiredId < pCurFenceInfo->fenceId) {
584 pQueueInfo->lastRetiredId = pCurFenceInfo->fenceId;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500585 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500586 }
587 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500588
Mike Stroyan950496e2015-05-19 15:16:08 -0600589 // Update fence state in fenceCreateInfo structure
Tobin Ehlis257d9742015-07-08 17:08:02 -0600590 auto pFCI = &(fenceMap[fence.handle].createInfo);
591 pFCI->flags = static_cast<VkFenceCreateFlags>(pFCI->flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500592}
593
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500594// Helper routine that updates the fence list for a specific queue to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500595static void retire_queue_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600596 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500597{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600598 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
599 // Set queue's lastRetired to lastSubmitted indicating all fences completed
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600600 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700601}
602
Mike Stroyandd7aed72015-05-19 17:03:40 -0600603// Helper routine that updates all queues to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500604static void retire_device_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600605 VkDevice device)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500606{
607 // Process each queue for device
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600608 // TODO: Add multiple device support
Tobin Ehlis257d9742015-07-08 17:08:02 -0600609 for (auto ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600610 // Set queue's lastRetired to lastSubmitted indicating all fences completed
611 MT_QUEUE_INFO *pQueueInfo = &(*ii).second;
612 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500613 }
614}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600615// Helper function to validate correct usage bits set for buffers or images
616// Verify that (actual & desired) flags != 0 or,
617// if strict is true, verify that (actual & desired) flags == desired
618// In case of error, report it via dbg callbacks
David Pinedo38310942015-07-09 16:23:44 -0600619static void validate_usage_flags(void* disp_obj, VkFlags actual, VkFlags desired,
Tobin Ehlis257d9742015-07-08 17:08:02 -0600620 VkBool32 strict, uint64_t obj_handle, VkDbgObjectType obj_type,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600621 char const* ty_str, char const* func_name, char const* usage_str)
622{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600623 VkBool32 correct_usage = VK_FALSE;
Tobin Ehlis41376e12015-07-03 08:45:14 -0600624 if (strict)
625 correct_usage = ((actual & desired) == desired);
626 else
627 correct_usage = ((actual & desired) != 0);
628 if (!correct_usage) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600629 log_msg(mdd(disp_obj), VK_DBG_REPORT_ERROR_BIT, obj_type, obj_handle, 0, MEMTRACK_INVALID_USAGE_FLAG, "MEM",
630 "Invalid usage flag for %s %#" PRIxLEAST64 " used by %s. In this case, %s should have %s set during creation.",
631 ty_str, obj_handle, func_name, ty_str, usage_str);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600632 }
633}
634// Helper function to validate usage flags for images
635// Pulls image info and then sends actual vs. desired usage off to helper above where
636// an error will be flagged if usage is not correct
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600637static void validate_image_usage_flags(void* disp_obj, VkImage image, VkFlags desired, VkBool32 strict,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600638 char const* func_name, char const* usage_string)
639{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600640 MT_OBJ_BINDING_INFO* pBindInfo = get_object_binding_info(image.handle, VK_OBJECT_TYPE_IMAGE);
641 if (pBindInfo) {
642 validate_usage_flags(disp_obj, pBindInfo->create_info.image.usage, desired, strict,
643 image.handle, VK_OBJECT_TYPE_IMAGE, "image", func_name, usage_string);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600644 }
645}
646// Helper function to validate usage flags for buffers
647// Pulls buffer info and then sends actual vs. desired usage off to helper above where
648// an error will be flagged if usage is not correct
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600649static void validate_buffer_usage_flags(void* disp_obj, VkBuffer buffer, VkFlags desired, VkBool32 strict,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600650 char const* func_name, char const* usage_string)
651{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600652 MT_OBJ_BINDING_INFO* pBindInfo = get_object_binding_info(buffer.handle, VK_OBJECT_TYPE_BUFFER);
653 if (pBindInfo) {
654 validate_usage_flags(disp_obj, pBindInfo->create_info.buffer.usage, desired, strict,
655 buffer.handle, VK_OBJECT_TYPE_BUFFER, "buffer", func_name, usage_string);
Tobin Ehlis41376e12015-07-03 08:45:14 -0600656 }
657}
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500658// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700659// Calls to this function should be wrapped in mutex
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500660static MT_MEM_OBJ_INFO* get_mem_obj_info(
Tobin Ehlis257d9742015-07-08 17:08:02 -0600661 const uint64_t device_mem_handle)
Tobin Ehlisc145be82015-01-08 15:22:32 -0700662{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600663 auto item = memObjMap.find(device_mem_handle);
Mike Stroyan950496e2015-05-19 15:16:08 -0600664 if (item != memObjMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600665 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600666 } else {
667 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600668 }
Tobin Ehlisc145be82015-01-08 15:22:32 -0700669}
670
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500671static void add_mem_obj_info(
Tobin Ehlis257d9742015-07-08 17:08:02 -0600672 void* object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600673 const VkDeviceMemory mem,
Tobin Ehlis257d9742015-07-08 17:08:02 -0600674 const VkMemoryAllocInfo* pAllocInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700675{
Courtney Goeltzenleuchter17fd5ce2015-06-13 21:29:26 -0600676 assert(object != NULL);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600677
Ian Elliott1064fe32015-07-06 14:31:32 -0600678 memcpy(&memObjMap[mem.handle].allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
679 // TODO: Update for real hardware, actually process allocation info structures
680 memObjMap[mem.handle].allocInfo.pNext = NULL;
Tobin Ehlis257d9742015-07-08 17:08:02 -0600681 memObjMap[mem.handle].object = object;
682 memObjMap[mem.handle].refCount = 0;
683 memObjMap[mem.handle].mem = mem;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700684}
685
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500686// Find CB Info and add mem reference to list container
687// Find Mem Obj Info and add CB reference to list container
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600688static VkBool32 update_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600689 const VkCmdBuffer cb,
690 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700691{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600692 VkBool32 result = VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700693 // First update CB binding in MemObj mini CB list
Tobin Ehlis257d9742015-07-08 17:08:02 -0600694 MT_MEM_OBJ_INFO* pMemInfo = get_mem_obj_info(mem.handle);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500695 if (!pMemInfo) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600696 // TODO : cb should be srcObj
697 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
698 "Trying to bind mem obj %#" PRIxLEAST64 " to CB %p but no info for that mem obj.\n "
699 "Was it correctly allocated? Did it already get freed?", mem.handle, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600700 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600701 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500702 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600703 VkBool32 found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600704 if (pMemInfo->pCmdBufferBindings.size() > 0) {
705 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
706 if ((*it) == cb) {
707 found = VK_TRUE;
708 break;
709 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500710 }
711 }
712 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600713 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500714 pMemInfo->pCmdBufferBindings.push_front(cb);
715 pMemInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500716 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500717 // Now update CBInfo's Mem reference list
718 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
719 // TODO: keep track of all destroyed CBs so we know if this is a stale or simply invalid object
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500720 if (!pCBInfo) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600721 // TODO : cb should be srcObj
722 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
723 "Trying to bind mem obj %#" PRIxLEAST64 " to CB %p but no info for that CB. Was CB incorrectly destroyed?", mem.handle, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600724 result = VK_FALSE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500725 } else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500726 // Search for memory object in cmd buffer's reference list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600727 VkBool32 found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600728 if (pCBInfo->pMemObjList.size() > 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600729 for (auto it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
David Pinedod8f83d82015-04-27 16:36:17 -0600730 if ((*it) == mem) {
731 found = VK_TRUE;
732 break;
733 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500734 }
735 }
736 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600737 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500738 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600739 }
740 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700741 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600742 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700743}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600744
Tobin Ehlis6663f492014-11-10 12:29:12 -0700745// Clear the CB Binding for mem
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500746// Calls to this function should be wrapped in mutex
747static void remove_cmd_buf_and_mem_reference(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600748 const VkCmdBuffer cb,
749 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700750{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600751 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem.handle);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500752 // TODO : Having this check is not ideal, really if memInfo was deleted,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500753 // its CB bindings should be cleared and then clear_cmd_buf_and_mem_references wouldn't call
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700754 // us here with stale mem objs
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500755 if (pInfo) {
756 pInfo->pCmdBufferBindings.remove(cb);
757 pInfo->refCount--;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700758 }
759}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600760
Tobin Ehlis6663f492014-11-10 12:29:12 -0700761// Free bindings related to CB
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600762static VkBool32 clear_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600763 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700764{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600765 VkBool32 result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500766 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500767 if (!pCBInfo) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600768 // TODO : cb should be srcObj
769 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_CB, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600770 "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600771 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600772 } else {
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600773 if (pCBInfo->pMemObjList.size() > 0) {
774 list<VkDeviceMemory> mem_obj_list = pCBInfo->pMemObjList;
775 for (list<VkDeviceMemory>::iterator it=mem_obj_list.begin(); it!=mem_obj_list.end(); ++it) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500776 remove_cmd_buf_and_mem_reference(cb, (*it));
David Pinedod8f83d82015-04-27 16:36:17 -0600777 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600778 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500779 pCBInfo->pMemObjList.clear();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700780 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600781 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700782}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600783
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500784// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500785// and also clear mem references to CB
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600786static VkBool32 delete_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600787 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700788{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600789 VkBool32 result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500790 result = clear_cmd_buf_and_mem_references(cb);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500791 // Delete the CBInfo info
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600792 if (result == VK_TRUE) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600793 cbMap.erase(cb);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700794 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600795 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700796}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600797
Tobin Ehlis6663f492014-11-10 12:29:12 -0700798// Delete the entire CB list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600799static VkBool32 delete_cmd_buf_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600800 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700801{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600802 for (unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500803 clear_cmd_buf_and_mem_references((*ii).first);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700804 }
Mike Stroyandd7aed72015-05-19 17:03:40 -0600805 cbMap.clear();
806 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700807}
808
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500809// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600810static void reportMemReferencesAndCleanUp(
811 MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700812{
Tony Barbour18f71552015-04-22 11:36:22 -0600813 size_t cmdBufRefCount = pMemObjInfo->pCmdBufferBindings.size();
814 size_t objRefCount = pMemObjInfo->pObjBindings.size();
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500815
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500816 if ((pMemObjInfo->pCmdBufferBindings.size() + pMemObjInfo->pObjBindings.size()) != 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600817 log_msg(mdd(pMemObjInfo->object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pMemObjInfo->mem.handle, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
818 "Attempting to free memory object %#" PRIxLEAST64 " which still contains %lu references",
819 pMemObjInfo->mem.handle, (cmdBufRefCount + objRefCount));
Tobin Ehlis6663f492014-11-10 12:29:12 -0700820 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500821
David Pinedod8f83d82015-04-27 16:36:17 -0600822 if (cmdBufRefCount > 0 && pMemObjInfo->pCmdBufferBindings.size() > 0) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500823 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600824 // TODO : cmdBuffer should be source Obj here
825 log_msg(mdd(pMemObjInfo->object), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_NONE, "MEM",
826 "Command Buffer %p still has a reference to mem obj %#" PRIxLEAST64, (*it), pMemObjInfo->mem.handle);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500827 }
828 // Clear the list of hanging references
829 pMemObjInfo->pCmdBufferBindings.clear();
830 }
831
David Pinedod8f83d82015-04-27 16:36:17 -0600832 if (objRefCount > 0 && pMemObjInfo->pObjBindings.size() > 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600833 for (auto it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
834 log_msg(mdd(pMemObjInfo->object), VK_DBG_REPORT_INFO_BIT, it->type, it->handle, 0, MEMTRACK_NONE, "MEM",
835 "VK Object %#" PRIxLEAST64 " still has a reference to mem obj %#" PRIxLEAST64, it->handle, pMemObjInfo->mem.handle);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500836 }
837 // Clear the list of hanging references
838 pMemObjInfo->pObjBindings.clear();
839 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500840
Tobin Ehlis6663f492014-11-10 12:29:12 -0700841}
842
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600843static void deleteMemObjInfo(
Tobin Ehlis257d9742015-07-08 17:08:02 -0600844 void* object,
845 const uint64_t device_mem_handle)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700846{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600847 auto item = memObjMap.find(device_mem_handle);
Mike Stroyan950496e2015-05-19 15:16:08 -0600848 if (item != memObjMap.end()) {
Mike Stroyan950496e2015-05-19 15:16:08 -0600849 memObjMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700850 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500851 else {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600852 log_msg(mdd(object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, device_mem_handle, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
853 "Request to delete memory object %#" PRIxLEAST64 " not present in memory Object Map", device_mem_handle);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500854 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700855}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500856
Tobin Ehlis6663f492014-11-10 12:29:12 -0700857// Check if fence for given CB is completed
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600858static VkBool32 checkCBCompleted(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600859 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700860{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600861 VkBool32 result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500862 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500863 if (!pCBInfo) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600864 // TODO : cb should be srcObj
865 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_CB, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600866 "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600867 result = VK_FALSE;
Mike Stroyan950496e2015-05-19 15:16:08 -0600868 } else if (pCBInfo->lastSubmittedQueue != NULL) {
869 VkQueue queue = pCBInfo->lastSubmittedQueue;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600870 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
Mike Stroyan950496e2015-05-19 15:16:08 -0600871 if (pCBInfo->fenceId > pQueueInfo->lastRetiredId) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600872 // TODO : cb should be srcObj and print cb handle
873 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_NONE, "MEM",
874 "fence %#" PRIxLEAST64 " for CB %p has not been checked for completion",
875 pCBInfo->lastSubmittedFence.handle, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600876 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600877 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700878 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600879 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700880}
881
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600882static VkBool32 freeMemObjInfo(
Tobin Ehlis257d9742015-07-08 17:08:02 -0600883 void* object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600884 VkDeviceMemory mem,
885 bool internal)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700886{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600887 VkBool32 result = VK_TRUE;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500888 // Parse global list to find info w/ mem
Tobin Ehlis257d9742015-07-08 17:08:02 -0600889 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem.handle);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500890 if (!pInfo) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600891 log_msg(mdd(object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem.handle, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
892 "Couldn't find mem info object for %#" PRIxLEAST64 "\n Was %#" PRIxLEAST64 " never allocated or previously freed?",
893 mem.handle, mem.handle);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600894 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600895 } else {
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -0600896 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600897 log_msg(mdd(pInfo->object), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem.handle, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
898 "Attempting to free memory associated with a Persistent Image, %#" PRIxLEAST64 ", "
899 "this should not be explicitly freed\n", mem.handle);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600900 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600901 } else {
902 // Clear any CB bindings for completed CBs
903 // TODO : Is there a better place to do this?
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500904
Courtney Goeltzenleuchter10100442015-06-13 21:36:49 -0600905 assert(pInfo->object != VK_NULL_HANDLE);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600906 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
907 list<VkCmdBuffer>::iterator temp;
David Pinedod8f83d82015-04-27 16:36:17 -0600908 while (pInfo->pCmdBufferBindings.size() > 0 && it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600909 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500910 temp = it;
911 ++temp;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500912 clear_cmd_buf_and_mem_references(*it);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500913 it = temp;
914 } else {
915 ++it;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600916 }
917 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500918
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600919 // Now verify that no references to this mem obj remain
Tobin Ehlis2717d132015-07-10 18:25:07 -0600920 // TODO : Is this check still valid? I don't think so
921 // Even if not, we still need to remove binding from obj
922// if (0 != pInfo->refCount) {
923// reportMemReferencesAndCleanUp(pInfo);
924// result = VK_FALSE;
925// }
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600926 // Delete mem obj info
Tobin Ehlis257d9742015-07-08 17:08:02 -0600927 deleteMemObjInfo(object, mem.handle);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700928 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700929 }
930 return result;
931}
932
Tobin Ehlis6663f492014-11-10 12:29:12 -0700933// Remove object binding performs 3 tasks:
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500934// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
935// 2. Decrement refCount for MemObjInfo
Tobin Ehlis257d9742015-07-08 17:08:02 -0600936// 3. Clear mem binding for image/buffer by setting its handle to 0
937// TODO : This only applied to Buffer and Image objects now, how should it be updated/customized?
938static VkBool32 clear_object_binding(void* dispObj, uint64_t handle, VkDbgObjectType type)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700939{
Tobin Ehlis257d9742015-07-08 17:08:02 -0600940 // TODO : Need to customize images/buffers to track mem binding and clear it here appropriately
941 VkBool32 result = VK_TRUE;
942 MT_OBJ_BINDING_INFO* pObjBindInfo = get_object_binding_info(handle, type);
943 if (pObjBindInfo) {
944 MT_MEM_OBJ_INFO* pMemObjInfo = get_mem_obj_info(pObjBindInfo->mem.handle);
945 if (!pMemObjInfo) {
946 log_msg(mdd(dispObj), VK_DBG_REPORT_WARN_BIT, type, handle, 0, MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, "MEM",
947 "Attempting to clear mem binding on %s obj %#" PRIxLEAST64 " but it has no binding.",
948 (VK_OBJECT_TYPE_IMAGE == type) ? "image" : "buffer", handle);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600949 } else {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600950 // This obj is bound to a memory object. Remove the reference to this object in that memory object's list, decrement the memObj's refcount
951 // and set the objects memory binding pointer to NULL.
952 for (auto it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
953 if ((it->handle == handle) && (it->type == type)) {
954 pMemObjInfo->refCount--;
955 pMemObjInfo->pObjBindings.erase(it);
956 // TODO : Make sure this is a reasonable way to reset mem binding
957 pObjBindInfo->mem.handle = 0;
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500958 result = VK_TRUE;
959 break;
960 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600961 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600962 if (result == VK_FALSE) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600963 log_msg(mdd(dispObj), VK_DBG_REPORT_ERROR_BIT, type, handle, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
964 "While trying to clear mem binding for %s obj %#" PRIxLEAST64 ", unable to find that object referenced by mem obj %#" PRIxLEAST64,
965 (VK_OBJECT_TYPE_IMAGE == type) ? "image" : "buffer", handle, pMemObjInfo->mem.handle);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600966 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700967 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700968 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600969 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700970}
971
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500972// For NULL mem case, output warning
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500973// Make sure given object is in global object map
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500974// IF a previous binding existed, output validation error
975// Otherwise, add reference from objectInfo to memoryInfo
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500976// Add reference off of objInfo
Courtney Goeltzenleuchter540d3492015-06-13 21:37:34 -0600977// device is required for error logging, need a dispatchable
978// object for that.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600979// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Tobin Ehlis257d9742015-07-08 17:08:02 -0600980static VkBool32 set_mem_binding(
981 void* dispatch_object,
982 VkDeviceMemory mem,
983 uint64_t handle,
984 VkDbgObjectType type)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700985{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600986 VkBool32 result = VK_FALSE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700987 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600988 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600989 log_msg(mdd(dispatch_object), VK_DBG_REPORT_WARN_BIT, type, handle, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
990 "Attempting to Bind Obj(%#" PRIxLEAST64 ") to NULL", handle);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500991 return VK_TRUE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600992 } else {
Tobin Ehlis257d9742015-07-08 17:08:02 -0600993 MT_OBJ_BINDING_INFO* pObjBindInfo = get_object_binding_info(handle, type);
994 if (!pObjBindInfo) {
995 log_msg(mdd(dispatch_object), VK_DBG_REPORT_ERROR_BIT, type, handle, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
996 "Attempting to update Binding of %s Obj(%#" PRIxLEAST64 ") that's not in global list()", (VK_OBJECT_TYPE_IMAGE == type) ? "image" : "buffer", handle);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600997 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600998 }
999 // non-null case so should have real mem obj
Tobin Ehlis257d9742015-07-08 17:08:02 -06001000 MT_MEM_OBJ_INFO* pMemInfo = get_mem_obj_info(mem.handle);
1001 if (!pMemInfo) {
1002 log_msg(mdd(dispatch_object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem.handle, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
1003 "While trying to bind mem for %s obj %#" PRIxLEAST64 ", couldn't find info for mem obj %#" PRIxLEAST64, (VK_OBJECT_TYPE_IMAGE == type) ? "image" : "buffer", handle, mem.handle);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001004 return VK_FALSE;
1005 } else {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001006 // TODO : Need to track mem binding for obj and report conflict here
1007 MT_MEM_OBJ_INFO* pPrevBinding = get_mem_obj_info(pObjBindInfo->mem.handle);
1008 if (pPrevBinding != NULL) {
1009 log_msg(mdd(dispatch_object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem.handle, 0, MEMTRACK_REBIND_OBJECT, "MEM",
1010 "Attempting to bind memory (%#" PRIxLEAST64 ") to object (%#" PRIxLEAST64 ") which has already been bound to mem object %#" PRIxLEAST64,
1011 mem.handle, handle, pPrevBinding->mem.handle);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001012 return VK_FALSE;
1013 }
1014 else {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001015 MT_OBJ_HANDLE_TYPE oht;
1016 oht.handle = handle;
1017 oht.type = type;
1018 pMemInfo->pObjBindings.push_front(oht);
1019 pMemInfo->refCount++;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001020 // For image objects, make sure default memory state is correctly set
1021 // TODO : What's the best/correct way to handle this?
Tobin Ehlis257d9742015-07-08 17:08:02 -06001022 if (VK_OBJECT_TYPE_IMAGE == type) {
1023 VkImageCreateInfo ici = pObjBindInfo->create_info.image;
1024 if (ici.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
1025 VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001026 // TODO:: More memory state transition stuff.
1027 }
1028 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06001029 pObjBindInfo->mem = mem;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001030 }
1031 }
1032 }
1033 return VK_TRUE;
1034}
1035
1036// For NULL mem case, clear any previous binding Else...
Tobin Ehlis257d9742015-07-08 17:08:02 -06001037// Make sure given object is in its object map
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001038// IF a previous binding existed, update binding
1039// Add reference from objectInfo to memoryInfo
Tobin Ehlis257d9742015-07-08 17:08:02 -06001040// Add reference off of object's binding info
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001041// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Tobin Ehlis257d9742015-07-08 17:08:02 -06001042static VkBool32 set_sparse_mem_binding(
1043 void* dispObject,
1044 VkDeviceMemory mem,
1045 uint64_t handle,
1046 VkDbgObjectType type)
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001047{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001048 VkBool32 result = VK_FALSE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001049 // Handle NULL case separately, just clear previous binding & decrement reference
1050 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001051 clear_object_binding(dispObject, handle, type);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001052 return VK_TRUE;
1053 } else {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001054 MT_OBJ_BINDING_INFO* pObjBindInfo = get_object_binding_info(handle, type);
1055 if (!pObjBindInfo) {
1056 log_msg(mdd(dispObject), VK_DBG_REPORT_ERROR_BIT, type, handle, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
1057 "Attempting to update Binding of Obj(%#" PRIxLEAST64 ") that's not in global list()", handle);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001058 return VK_FALSE;
1059 }
1060 // non-null case so should have real mem obj
Tobin Ehlis257d9742015-07-08 17:08:02 -06001061 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem.handle);
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -06001062 if (!pInfo) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001063 log_msg(mdd(dispObject), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem.handle, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
1064 "While trying to bind mem for obj %#" PRIxLEAST64 ", couldn't find info for mem obj %#" PRIxLEAST64, handle, mem.handle);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001065 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001066 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001067 // Search for object in memory object's binding list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001068 VkBool32 found = VK_FALSE;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -06001069 if (pInfo->pObjBindings.size() > 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001070 for (auto it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
1071 if (((*it).handle == handle) && ((*it).type == type)) {
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -06001072 found = VK_TRUE;
1073 break;
1074 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001075 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001076 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001077 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001078 if (found == VK_FALSE) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001079 MT_OBJ_HANDLE_TYPE oht;
1080 oht.handle = handle;
1081 oht.type = type;
1082 pInfo->pObjBindings.push_front(oht);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001083 pInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001084 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06001085 // Need to set mem binding for this object
1086 // TODO : Do we still need to check for previous binding?
1087 MT_MEM_OBJ_INFO* pPrevBinding = get_mem_obj_info(pObjBindInfo->mem.handle);
1088 if (pPrevBinding) {
1089 clear_object_binding(dispObject, handle, type); // Need to clear the previous object binding before setting new binding
1090 log_msg(mdd(dispObject), VK_DBG_REPORT_INFO_BIT, type, handle, 0, MEMTRACK_NONE, "MEM",
1091 "Updating memory binding for object %#" PRIxLEAST64 " from mem obj %#" PRIxLEAST64 " to %#" PRIxLEAST64, handle, pPrevBinding->mem.handle, mem.handle);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001092 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06001093 pObjBindInfo->mem = mem;
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001094 }
1095 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001096 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -07001097}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001098
Tobin Ehlis6663f492014-11-10 12:29:12 -07001099// Print details of global Obj tracking list
Tobin Ehlis257d9742015-07-08 17:08:02 -06001100//static void print_object_list(
1101// VkObject object)
1102//{
1103// MT_OBJ_INFO* pInfo = NULL;
1104// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1105// "Details of Object list of size %lu elements", objectMap.size());
1106// if (objectMap.size() <= 0)
1107// return;
1108// for (unordered_map<VkObject, MT_OBJ_INFO>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
1109// pInfo = &(*ii).second;
1110// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, pInfo->object, 0, MEMTRACK_NONE, "MEM",
1111// " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
1112// }
1113//}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001114
Tobin Ehlis6663f492014-11-10 12:29:12 -07001115// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001116static VkDeviceMemory get_mem_binding_from_object(
Tobin Ehlis257d9742015-07-08 17:08:02 -06001117 void* dispObj, const uint64_t handle, const VkDbgObjectType type)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001118{
Tobin Ehlis257d9742015-07-08 17:08:02 -06001119 VkDeviceMemory mem;
1120 mem.handle = 0;
1121 MT_OBJ_BINDING_INFO* pObjBindInfo = get_object_binding_info(handle, type);
1122 if (pObjBindInfo) {
1123 if (pObjBindInfo->mem) {
1124 mem = pObjBindInfo->mem;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -06001125 } else {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001126 log_msg(mdd(dispObj), VK_DBG_REPORT_ERROR_BIT, type, handle, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM",
1127 "Trying to get mem binding for object %#" PRIxLEAST64 " but object has no mem binding", handle);
1128 //print_object_list(object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001129 }
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -06001130 } else {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001131 log_msg(mdd(dispObj), VK_DBG_REPORT_ERROR_BIT, type, handle, 0, MEMTRACK_INVALID_OBJECT, "MEM",
1132 "Trying to get mem binding for object %#" PRIxLEAST64 " but no such object in %s list", handle, (VK_OBJECT_TYPE_IMAGE == type) ? "image" : "buffer");
1133 //print_object_list(object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001134 }
1135 return mem;
1136}
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001137
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001138// Print details of MemObjInfo list
Tobin Ehlis257d9742015-07-08 17:08:02 -06001139//static void print_mem_list(
1140// VkObject object)
1141//{
1142// MT_MEM_OBJ_INFO* pInfo = NULL;
1143// // Just printing each msg individually for now, may want to package these into single large print
1144// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1145// "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
1146//
1147// if (memObjMap.size() <= 0)
1148// return;
1149//
1150// for (auto ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
1151// pInfo = &(*ii).second;
1152//
1153// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1154// " ===MemObjInfo at %p===", (void*)pInfo);
1155// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1156// " Mem object: %#" PRIxLEAST64, (void*)pInfo->mem.handle);
1157// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1158// " Ref Count: %u", pInfo->refCount);
1159// if (0 != pInfo->allocInfo.allocationSize) {
1160// string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
1161// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1162// " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
1163// } else {
1164// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1165// " Mem Alloc info is NULL (alloc done by vkCreateSwapChainWSI())");
1166// }
1167//
1168// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1169// " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
1170// if (pInfo->pObjBindings.size() > 0) {
1171// for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
1172// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1173// " VK OBJECT %p", (*it));
1174// }
1175// }
1176//
1177// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1178// " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
1179// if (pInfo->pCmdBufferBindings.size() > 0)
1180// {
1181// for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
1182// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1183// " VK CB %p", (*it));
1184// }
1185// }
1186// }
1187//}
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001188
Tobin Ehlis257d9742015-07-08 17:08:02 -06001189//static void printCBList(
1190// VkObject object)
1191//{
1192// MT_CB_INFO* pCBInfo = NULL;
1193// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1194// "Details of CB list of size %lu elements", cbMap.size());
1195//
1196// if (cbMap.size() <= 0)
1197// return;
1198//
1199// for (auto ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
1200// pCBInfo = &(*ii).second;
1201//
1202// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1203// " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %#" PRIxLEAST64,
1204// (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
1205// pCBInfo->lastSubmittedFence.handle);
1206//
1207// if (pCBInfo->pMemObjList.size() <= 0)
1208// continue;
1209// for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
1210// log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
1211// " Mem obj %p", (*it));
1212// }
1213// }
1214//}
Tobin Ehlis6663f492014-11-10 12:29:12 -07001215
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001216static void init_mem_tracker(
1217 layer_data *my_data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001218{
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001219 uint32_t report_flags = 0;
1220 uint32_t debug_action = 0;
1221 FILE *log_output = NULL;
1222 const char *option_str;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -07001223 // initialize MemTracker options
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001224 report_flags = getLayerOptionFlags("MemTrackerReportFlags", 0);
1225 getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &debug_action);
Tobin Ehlisee702232015-01-08 14:26:53 -07001226
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001227 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -07001228 {
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001229 option_str = getLayerOption("MemTrackerLogFilename");
1230 if (option_str) {
1231 log_output = fopen(option_str, "w");
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -07001232 }
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001233 if (log_output == NULL) {
1234 log_output = stdout;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001235 }
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001236
1237 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -07001238 }
1239
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001240 if (!globalLockInitialized)
1241 {
1242 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001243 // suggestion is to call this during vkCreateInstance(), and then we
1244 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001245 // that the layer have per-instance locks. We need to come back and
1246 // address this soon.
1247 loader_platform_thread_create_mutex(&globalLock);
1248 globalLockInitialized = 1;
1249 }
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -06001250
1251 // Zero out memory property data
1252 memset(&memProps, 0, sizeof(VkPhysicalDeviceMemoryProperties));
Tobin Ehlis6663f492014-11-10 12:29:12 -07001253}
1254
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001255// hook DestroyInstance to remove tableInstanceMap entry
1256VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
1257{
Jeremy Hayes35f8afc2015-06-18 10:25:55 -06001258 // Grab the key before the instance is destroyed.
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001259 dispatch_key key = get_dispatch_key(instance);
1260 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, instance);
1261 VkResult res = pTable->DestroyInstance(instance);
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001262
1263 // Clean up logging callback, if any
Courtney Goeltzenleuchter095e6772015-06-16 16:58:52 -06001264 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001265 if (my_data->logging_callback) {
1266 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
1267 }
1268
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001269 layer_debug_report_destroy_instance(mid(instance));
1270 layer_data_map.erase(pTable);
1271
1272 mem_tracker_instance_table_map.erase(key);
1273 assert(mem_tracker_instance_table_map.size() == 0 && "Should not have any instance mappings hanging around");
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001274 return res;
1275}
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001276
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001277VkResult VKAPI vkCreateInstance(
1278 const VkInstanceCreateInfo* pCreateInfo,
1279 VkInstance* pInstance)
1280{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001281 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, *pInstance);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -06001282 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001283
1284 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001285 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
1286 my_data->report_data = debug_report_create_instance(
1287 pTable,
1288 *pInstance,
1289 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001290 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -06001291
1292 init_mem_tracker(my_data);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001293 }
1294 return result;
1295}
1296
Jon Ashburn747f2b62015-06-18 15:02:58 -06001297static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
1298{
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -06001299 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Ian Elliott1064fe32015-07-06 14:31:32 -06001300 my_device_data->wsi_enabled = false;
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -06001301 for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
Ian Elliott1064fe32015-07-06 14:31:32 -06001302 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_WSI_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)
1303 my_device_data->wsi_enabled = true;
Jon Ashburn747f2b62015-06-18 15:02:58 -06001304 }
1305}
1306
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001307VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
1308 VkPhysicalDevice gpu,
1309 const VkDeviceCreateInfo *pCreateInfo,
1310 VkDevice *pDevice)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001311{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06001312 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(mem_tracker_device_table_map, *pDevice);
1313 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001314 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001315 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001316 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
1317 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -06001318 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001319 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001320 return result;
1321}
1322
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001323VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(
1324 VkDevice device)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001325{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001326 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001327 // TODO : Need to set device as srcObj
1328// log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DEVICE, 0, 0, MEMTRACK_NONE, "MEM",
1329// "Printing List details prior to vkDestroyDevice()");
1330// print_mem_list(device);
1331// printCBList(device);
1332// print_object_list(device);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001333 if (VK_FALSE == delete_cmd_buf_info_list()) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001334 // TODO : Need to set device as srcObj
1335 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, 0, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001336 "Issue deleting global CB list in vkDestroyDevice()");
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001337 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -07001338 // Report any memory leaks
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001339 MT_MEM_OBJ_INFO* pInfo = NULL;
David Pinedod8f83d82015-04-27 16:36:17 -06001340 if (memObjMap.size() > 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001341 for (auto ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mike Stroyandd7aed72015-05-19 17:03:40 -06001342 pInfo = &(*ii).second;
David Pinedod8f83d82015-04-27 16:36:17 -06001343 if (pInfo->allocInfo.allocationSize != 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001344 log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pInfo->mem.handle, 0, MEMTRACK_MEMORY_LEAK, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001345 "Mem Object %p has not been freed. You should clean up this memory by calling "
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001346 "vkFreeMemory(%p) prior to vkDestroyDevice().", pInfo->mem, pInfo->mem);
David Pinedod8f83d82015-04-27 16:36:17 -06001347 }
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -06001348 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -07001349 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001350 // Queues persist until device is destroyed
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001351 delete_queue_info_list();
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001352 layer_debug_report_destroy_device(device);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001353 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001354
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001355 dispatch_key key = get_dispatch_key(device);
Courtney Goeltzenleuchter89d68442015-06-13 21:40:22 -06001356#if DISPATCH_MAP_DEBUG
1357 fprintf(stderr, "Device: %p, key: %p\n", device, key);
1358#endif
Jon Ashburn747f2b62015-06-18 15:02:58 -06001359 VkLayerDispatchTable *pDisp = get_dispatch_table(mem_tracker_device_table_map, device);
1360 VkResult result = pDisp->DestroyDevice(device);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001361 mem_tracker_device_table_map.erase(key);
Courtney Goeltzenleuchter10100442015-06-13 21:36:49 -06001362 assert(mem_tracker_device_table_map.size() == 0 && "Should not have any instance mappings hanging around");
Jon Ashburn747f2b62015-06-18 15:02:58 -06001363
Tobin Ehlis6663f492014-11-10 12:29:12 -07001364 return result;
1365}
1366
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -06001367VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(
1368 VkPhysicalDevice physicalDevice,
1369 VkPhysicalDeviceMemoryProperties *pMemoryProperties)
1370{
1371 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(mem_tracker_instance_table_map, physicalDevice);
1372 VkResult result = pInstanceTable->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
1373 if (result == VK_SUCCESS) {
1374 // copy mem props to local var...
1375 memcpy(&memProps, pMemoryProperties, sizeof(VkPhysicalDeviceMemoryProperties));
1376 }
1377 return result;
1378}
1379
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001380static const VkLayerProperties mtGlobalLayers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001381 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001382 "MemTracker",
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001383 VK_API_VERSION,
1384 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001385 "Validation layer: MemTracker",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001386 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001387};
1388
Tony Barbour59a47322015-06-24 16:06:58 -06001389VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001390 const char *pLayerName,
1391 uint32_t *pCount,
1392 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001393{
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001394 /* Mem tracker does not have any global extensions */
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001395 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -06001396}
1397
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001398VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1399 uint32_t *pCount,
1400 VkLayerProperties* pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -06001401{
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001402 return util_GetLayerProperties(ARRAY_SIZE(mtGlobalLayers),
1403 mtGlobalLayers,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001404 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001405}
1406
Tony Barbour59a47322015-06-24 16:06:58 -06001407VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001408 VkPhysicalDevice physicalDevice,
1409 const char* pLayerName,
1410 uint32_t* pCount,
1411 VkExtensionProperties* pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -06001412{
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001413 /* Mem tracker does not have any physical device extensions */
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001414 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001415}
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001416
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001417VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1418 VkPhysicalDevice physicalDevice,
1419 uint32_t* pCount,
1420 VkLayerProperties* pProperties)
1421{
1422 /* Mem tracker's physical device layers are the same as global */
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001423 return util_GetLayerProperties(ARRAY_SIZE(mtGlobalLayers), mtGlobalLayers,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001424 pCount, pProperties);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001425}
1426
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001427VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(
1428 VkDevice device,
1429 uint32_t queueNodeIndex,
1430 uint32_t queueIndex,
1431 VkQueue *pQueue)
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001432{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001433 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001434 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001435 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001436 add_queue_info(*pQueue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001437 loader_platform_thread_unlock_mutex(&globalLock);
1438 }
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001439 return result;
1440}
1441
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001442VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1443 VkQueue queue,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001444 uint32_t cmdBufferCount,
1445 const VkCmdBuffer *pCmdBuffers,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001446 VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001447{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001448 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001449 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001450 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001451 uint64_t fenceId = add_fence_info(fence, queue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001452
Tobin Ehlis257d9742015-07-08 17:08:02 -06001453 //print_mem_list(queue);
1454 //printCBList(queue);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001455 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001456 pCBInfo = get_cmd_buf_info(pCmdBuffers[i]);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001457 pCBInfo->fenceId = fenceId;
Mike Stroyan950496e2015-05-19 15:16:08 -06001458 pCBInfo->lastSubmittedFence = fence;
1459 pCBInfo->lastSubmittedQueue = queue;
Tobin Ehlis6663f492014-11-10 12:29:12 -07001460 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001461
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001462 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001463 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueSubmit(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001464 queue, cmdBufferCount, pCmdBuffers, fence);
Courtney Goeltzenleuchterd3fb9552015-04-02 13:39:07 -06001465 return result;
1466}
1467
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001468VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(
1469 VkDevice device,
1470 const VkMemoryAllocInfo *pAllocInfo,
1471 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001472{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001473 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001474 // TODO : Track allocations and overall size here
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001475 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001476 add_mem_obj_info(device, *pMem, pAllocInfo);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001477 //print_mem_list(device);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001478 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001479 return result;
1480}
1481
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001482VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(
1483 VkDevice device,
1484 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001485{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001486 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisc0418f92014-11-25 14:47:20 -07001487 * freeing a memory object, an application must ensure the memory object is unbound from
1488 * all API objects referencing it and that it is not referenced by any queued command buffers
1489 */
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001490 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001491 VkBool32 noerror = freeMemObjInfo(device, mem, false);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001492 //print_mem_list(device);
1493 //print_object_list(device);
1494 //printCBList(device);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001495 // Output an warning message for proper error/warning handling
1496 if (noerror == VK_FALSE) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001497 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem.handle, 0, MEMTRACK_FREED_MEM_REF, "MEM",
1498 "Freeing memory object while it still has references: mem obj %#" PRIxLEAST64, mem.handle);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001499 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001500 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001501 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->FreeMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001502 return result;
1503}
1504
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001505VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(
1506 VkDevice device,
1507 VkDeviceMemory mem,
1508 VkDeviceSize offset,
1509 VkDeviceSize size,
1510 VkFlags flags,
1511 void **ppData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001512{
1513 // TODO : Track when memory is mapped
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001514 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001515 MT_MEM_OBJ_INFO *pMemObj = get_mem_obj_info(mem.handle);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -06001516 if ((memProps.memoryTypes[pMemObj->allocInfo.memoryTypeIndex].propertyFlags &
1517 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001518 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem.handle, 0, MEMTRACK_INVALID_STATE, "MEM",
1519 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set: mem obj %#" PRIxLEAST64, mem.handle);
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001520 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001521 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001522 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->MapMemory(device, mem, offset, size, flags, ppData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001523 return result;
1524}
1525
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001526VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(
1527 VkDevice device,
1528 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001529{
1530 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1531 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001532 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->UnmapMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001533 return result;
1534}
1535
Tobin Ehlis257d9742015-07-08 17:08:02 -06001536VK_LAYER_EXPORT VkResult VKAPI vkDestroyFence(VkDevice device, VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001537{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001538 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001539 delete_fence_info(fence);
1540 auto item = fenceMap.find(fence.handle);
1541 if (item != fenceMap.end()) {
1542 fenceMap.erase(item);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001543 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001544 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001545 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyFence(device, fence);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001546 return result;
1547}
1548
Tobin Ehlis257d9742015-07-08 17:08:02 -06001549VK_LAYER_EXPORT VkResult VKAPI vkDestroyBuffer(VkDevice device, VkBuffer buffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001550{
Tobin Ehlis257d9742015-07-08 17:08:02 -06001551 loader_platform_thread_lock_mutex(&globalLock);
1552 auto item = bufferMap.find(buffer.handle);
1553 if (item != bufferMap.end()) {
1554 bufferMap.erase(item);
1555 }
1556 loader_platform_thread_unlock_mutex(&globalLock);
1557 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyBuffer(device, buffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001558 return result;
1559}
1560
Tobin Ehlis257d9742015-07-08 17:08:02 -06001561VK_LAYER_EXPORT VkResult VKAPI vkDestroyImage(VkDevice device, VkImage image)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001562{
Tobin Ehlis257d9742015-07-08 17:08:02 -06001563 loader_platform_thread_lock_mutex(&globalLock);
1564 auto item = imageMap.find(image.handle);
1565 if (item != imageMap.end()) {
1566 imageMap.erase(item);
1567 }
1568 loader_platform_thread_unlock_mutex(&globalLock);
1569 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyImage(device, image);
1570 return result;
1571}
1572
1573VK_LAYER_EXPORT VkResult VKAPI vkDestroyAttachmentView(VkDevice device, VkAttachmentView attachmentView)
1574{
1575 loader_platform_thread_lock_mutex(&globalLock);
1576 auto item = attachmentViewMap.find(attachmentView.handle);
1577 if (item != attachmentViewMap.end()) {
1578 attachmentViewMap.erase(item);
1579 }
1580 loader_platform_thread_unlock_mutex(&globalLock);
1581 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyAttachmentView(device, attachmentView);
1582 return result;
1583}
1584
1585VK_LAYER_EXPORT VkResult VKAPI vkDestroyImageView(VkDevice device, VkImageView imageView)
1586{
1587 loader_platform_thread_lock_mutex(&globalLock);
1588 auto item = imageViewMap.find(imageView.handle);
1589 if (item != imageViewMap.end()) {
1590 imageViewMap.erase(item);
1591 }
1592 loader_platform_thread_unlock_mutex(&globalLock);
1593 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyImageView(device, imageView);
1594 return result;
1595}
1596
1597VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipeline(VkDevice device, VkPipeline pipeline)
1598{
1599 loader_platform_thread_lock_mutex(&globalLock);
1600 auto item = pipelineMap.find(pipeline.handle);
1601 if (item != pipelineMap.end()) {
1602 pipelineMap.erase(item);
1603 }
1604 loader_platform_thread_unlock_mutex(&globalLock);
1605 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyPipeline(device, pipeline);
1606 return result;
1607}
1608
1609VK_LAYER_EXPORT VkResult VKAPI vkDestroySampler(VkDevice device, VkSampler sampler)
1610{
1611 loader_platform_thread_lock_mutex(&globalLock);
1612 auto item = samplerMap.find(sampler.handle);
1613 if (item != samplerMap.end()) {
1614 samplerMap.erase(item);
1615 }
1616 loader_platform_thread_unlock_mutex(&globalLock);
1617 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroySampler(device, sampler);
1618 return result;
1619}
1620
1621VK_LAYER_EXPORT VkResult VKAPI vkDestroySemaphore(VkDevice device, VkSemaphore semaphore)
1622{
1623 loader_platform_thread_lock_mutex(&globalLock);
1624 auto item = semaphoreMap.find(semaphore.handle);
1625 if (item != semaphoreMap.end()) {
1626 semaphoreMap.erase(item);
1627 }
1628 loader_platform_thread_unlock_mutex(&globalLock);
1629 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroySemaphore(device, semaphore);
1630 return result;
1631}
1632
1633VK_LAYER_EXPORT VkResult VKAPI vkDestroyEvent(VkDevice device, VkEvent event)
1634{
1635 loader_platform_thread_lock_mutex(&globalLock);
1636 auto item = eventMap.find(event.handle);
1637 if (item != eventMap.end()) {
1638 eventMap.erase(item);
1639 }
1640 loader_platform_thread_unlock_mutex(&globalLock);
1641 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyEvent(device, event);
1642 return result;
1643}
1644
1645VK_LAYER_EXPORT VkResult VKAPI vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool)
1646{
1647 loader_platform_thread_lock_mutex(&globalLock);
1648 auto item = queryPoolMap.find(queryPool.handle);
1649 if (item != queryPoolMap.end()) {
1650 queryPoolMap.erase(item);
1651 }
1652 loader_platform_thread_unlock_mutex(&globalLock);
1653 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyQueryPool(device, queryPool);
1654 return result;
1655}
1656
1657VK_LAYER_EXPORT VkResult VKAPI vkDestroyBufferView(VkDevice device, VkBufferView bufferView)
1658{
1659 loader_platform_thread_lock_mutex(&globalLock);
1660 auto item = bufferViewMap.find(bufferView.handle);
1661 if (item != bufferViewMap.end()) {
1662 bufferViewMap.erase(item);
1663 }
1664 loader_platform_thread_unlock_mutex(&globalLock);
1665 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyBufferView(device, bufferView);
1666 return result;
1667}
1668
1669VK_LAYER_EXPORT VkResult VKAPI vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule)
1670{
1671 loader_platform_thread_lock_mutex(&globalLock);
1672 auto item = shaderModuleMap.find(shaderModule.handle);
1673 if (item != shaderModuleMap.end()) {
1674 shaderModuleMap.erase(item);
1675 }
1676 loader_platform_thread_unlock_mutex(&globalLock);
1677 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyShaderModule(device, shaderModule);
1678 return result;
1679}
1680
1681VK_LAYER_EXPORT VkResult VKAPI vkDestroyShader(VkDevice device, VkShader shader)
1682{
1683 loader_platform_thread_lock_mutex(&globalLock);
1684 auto item = shaderMap.find(shader.handle);
1685 if (item != shaderMap.end()) {
1686 shaderMap.erase(item);
1687 }
1688 loader_platform_thread_unlock_mutex(&globalLock);
1689 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyShader(device, shader);
1690 return result;
1691}
1692
1693VK_LAYER_EXPORT VkResult VKAPI vkDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout)
1694{
1695 loader_platform_thread_lock_mutex(&globalLock);
1696 auto item = pipelineLayoutMap.find(pipelineLayout.handle);
1697 if (item != pipelineLayoutMap.end()) {
1698 pipelineLayoutMap.erase(item);
1699 }
1700 loader_platform_thread_unlock_mutex(&globalLock);
1701 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyPipelineLayout(device, pipelineLayout);
1702 return result;
1703}
1704
1705VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout)
1706{
1707 loader_platform_thread_lock_mutex(&globalLock);
1708 auto item = descriptorSetLayoutMap.find(descriptorSetLayout.handle);
1709 if (item != descriptorSetLayoutMap.end()) {
1710 descriptorSetLayoutMap.erase(item);
1711 }
1712 loader_platform_thread_unlock_mutex(&globalLock);
1713 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyDescriptorSetLayout(device, descriptorSetLayout);
1714 return result;
1715}
1716
1717VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool)
1718{
1719 loader_platform_thread_lock_mutex(&globalLock);
1720 auto item = descriptorPoolMap.find(descriptorPool.handle);
1721 if (item != descriptorPoolMap.end()) {
1722 descriptorPoolMap.erase(item);
1723 }
1724 loader_platform_thread_unlock_mutex(&globalLock);
1725 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyDescriptorPool(device, descriptorPool);
1726 return result;
1727}
1728
1729//VK_LAYER_EXPORT VkResult VKAPI vkDestroyDescriptorSet(VkDevice device, VkDescriptorSet descriptorSet)
1730//{
1731// loader_platform_thread_lock_mutex(&globalLock);
1732// auto item = descriptorSetMap.find(descriptorSet.handle);
1733// if (item != descriptorSetMap.end()) {
1734// descriptorSetMap.erase(item);
1735// }
1736// loader_platform_thread_unlock_mutex(&globalLock);
1737// VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyDescriptorSet(device, descriptorSet);
1738// return result;
1739//}
1740
1741VK_LAYER_EXPORT VkResult VKAPI vkDestroyRenderPass(VkDevice device, VkRenderPass renderPass)
1742{
1743 loader_platform_thread_lock_mutex(&globalLock);
1744 auto item = renderPassMap.find(renderPass.handle);
1745 if (item != renderPassMap.end()) {
1746 renderPassMap.erase(item);
1747 }
1748 loader_platform_thread_unlock_mutex(&globalLock);
1749 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyRenderPass(device, renderPass);
1750 return result;
1751}
1752
1753VK_LAYER_EXPORT VkResult VKAPI vkDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer)
1754{
1755 loader_platform_thread_lock_mutex(&globalLock);
1756 auto item = framebufferMap.find(framebuffer.handle);
1757 if (item != framebufferMap.end()) {
1758 framebufferMap.erase(item);
1759 }
1760 loader_platform_thread_unlock_mutex(&globalLock);
1761 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyFramebuffer(device, framebuffer);
Tony Barbour343d6212015-07-10 18:32:33 -06001762 return result;
Tobin Ehlis257d9742015-07-08 17:08:02 -06001763}
1764
1765VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicViewportState(VkDevice device, VkDynamicViewportState dynamicViewportState)
1766{
1767 loader_platform_thread_lock_mutex(&globalLock);
1768 auto item = dynamicViewportStateMap.find(dynamicViewportState.handle);
1769 if (item != dynamicViewportStateMap.end()) {
1770 dynamicViewportStateMap.erase(item);
1771 }
1772 loader_platform_thread_unlock_mutex(&globalLock);
1773 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyDynamicViewportState(device, dynamicViewportState);
1774 return result;
1775}
1776
1777VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicRasterState(VkDevice device, VkDynamicRasterState dynamicRasterState)
1778{
1779 loader_platform_thread_lock_mutex(&globalLock);
1780 auto item = dynamicRasterStateMap.find(dynamicRasterState.handle);
1781 if (item != dynamicRasterStateMap.end()) {
1782 dynamicRasterStateMap.erase(item);
1783 }
1784 loader_platform_thread_unlock_mutex(&globalLock);
1785 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyDynamicRasterState(device, dynamicRasterState);
1786 return result;
1787}
1788
1789VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicColorBlendState(VkDevice device, VkDynamicColorBlendState dynamicColorBlendState)
1790{
1791 loader_platform_thread_lock_mutex(&globalLock);
1792 auto item = dynamicColorBlendStateMap.find(dynamicColorBlendState.handle);
1793 if (item != dynamicColorBlendStateMap.end()) {
1794 dynamicColorBlendStateMap.erase(item);
1795 }
1796 loader_platform_thread_unlock_mutex(&globalLock);
1797 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyDynamicColorBlendState(device, dynamicColorBlendState);
1798 return result;
1799}
1800
1801VK_LAYER_EXPORT VkResult VKAPI vkDestroyDynamicDepthStencilState(VkDevice device, VkDynamicDepthStencilState dynamicDepthStencilState)
1802{
1803 loader_platform_thread_lock_mutex(&globalLock);
1804 auto item = dynamicDepthStencilStateMap.find(dynamicDepthStencilState.handle);
1805 if (item != dynamicDepthStencilStateMap.end()) {
1806 dynamicDepthStencilStateMap.erase(item);
1807 }
1808 loader_platform_thread_unlock_mutex(&globalLock);
1809 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyDynamicDepthStencilState(device, dynamicDepthStencilState);
1810 return result;
1811}
1812
1813VkResult VKAPI vkBindBufferMemory(
1814 VkDevice device,
1815 VkBuffer buffer,
1816 VkDeviceMemory mem,
1817 VkDeviceSize memOffset)
1818{
1819 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->BindBufferMemory(device, buffer, mem, memOffset);
Mike Stroyanb050c682015-04-17 12:36:38 -06001820 loader_platform_thread_lock_mutex(&globalLock);
1821 // Track objects tied to memory
Tobin Ehlis257d9742015-07-08 17:08:02 -06001822 set_mem_binding(device, mem, buffer.handle, VK_OBJECT_TYPE_BUFFER);
Tobin Ehlis2717d132015-07-10 18:25:07 -06001823 add_object_binding_info(buffer.handle, VK_OBJECT_TYPE_BUFFER, mem);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001824 //print_object_list(device);
1825 //print_mem_list(device);
1826 loader_platform_thread_unlock_mutex(&globalLock);
1827 return result;
1828}
1829
1830VkResult VKAPI vkBindImageMemory(
1831 VkDevice device,
1832 VkImage image,
1833 VkDeviceMemory mem,
1834 VkDeviceSize memOffset)
1835{
1836 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->BindImageMemory(device, image, mem, memOffset);
1837 loader_platform_thread_lock_mutex(&globalLock);
1838 // Track objects tied to memory
Tobin Ehlis257d9742015-07-08 17:08:02 -06001839 set_mem_binding(device, mem, image.handle, VK_OBJECT_TYPE_IMAGE);
Tobin Ehlis2717d132015-07-10 18:25:07 -06001840 add_object_binding_info(image.handle, VK_OBJECT_TYPE_IMAGE, mem);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001841 //print_object_list(device);
1842 //print_mem_list(device);
1843 loader_platform_thread_unlock_mutex(&globalLock);
1844 return result;
1845}
1846
1847VkResult VKAPI vkGetBufferMemoryRequirements(
1848 VkDevice device,
1849 VkBuffer buffer,
1850 VkMemoryRequirements* pMemoryRequirements)
1851{
1852 // TODO : What to track here?
1853 // Could potentially save returned mem requirements and validate values passed into BindBufferMemory
1854 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetBufferMemoryRequirements(device, buffer, pMemoryRequirements);
1855 return result;
1856}
1857
1858VkResult VKAPI vkGetImageMemoryRequirements(
1859 VkDevice device,
1860 VkImage image,
1861 VkMemoryRequirements* pMemoryRequirements)
1862{
1863 // TODO : What to track here?
1864 // Could potentially save returned mem requirements and validate values passed into BindImageMemory
1865 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetImageMemoryRequirements(device, image, pMemoryRequirements);
1866 return result;
1867}
1868
1869VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseImageOpaqueMemory(
1870 VkQueue queue,
1871 VkImage image,
1872 uint32_t numBindings,
1873 const VkSparseMemoryBindInfo* pBindInfo)
1874{
1875 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueBindSparseImageOpaqueMemory(
1876 queue, image, numBindings, pBindInfo);
1877 loader_platform_thread_lock_mutex(&globalLock);
1878 // Track objects tied to memory
1879 if (VK_FALSE == set_sparse_mem_binding(queue, pBindInfo->mem, image.handle, VK_OBJECT_TYPE_IMAGE)) {
1880 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, image.handle, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1881 "In vkQueueBindSparseImageOpaqueMemory(), unable to set image %#" PRIxLEAST64 " binding to mem obj %#" PRIxLEAST64, image.handle, pBindInfo->mem.handle);
1882 }
1883 //print_object_list(queue);
1884 //print_mem_list(queue);
1885 loader_platform_thread_unlock_mutex(&globalLock);
1886 return result;
1887}
1888
1889VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseImageMemory(
1890 VkQueue queue,
1891 VkImage image,
1892 uint32_t numBindings,
1893 const VkSparseImageMemoryBindInfo* pBindInfo)
1894{
1895 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueBindSparseImageMemory(
1896 queue, image, numBindings, pBindInfo);
1897 loader_platform_thread_lock_mutex(&globalLock);
1898 // Track objects tied to memory
1899 if (VK_FALSE == set_sparse_mem_binding(queue, pBindInfo->mem, image.handle, VK_OBJECT_TYPE_IMAGE)) {
1900 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, image.handle, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1901 "In vkQueueBindSparseImageMemory(), unable to set image %#" PRIxLEAST64 " binding to mem obj %#" PRIxLEAST64, image.handle, pBindInfo->mem.handle);
1902 }
1903 //print_object_list(queue);
1904 //print_mem_list(queue);
Mike Stroyanb050c682015-04-17 12:36:38 -06001905 loader_platform_thread_unlock_mutex(&globalLock);
1906 return result;
1907}
1908
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001909VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -06001910 VkQueue queue,
1911 VkBuffer buffer,
1912 uint32_t numBindings,
1913 const VkSparseMemoryBindInfo* pBindInfo)
Mike Stroyanb050c682015-04-17 12:36:38 -06001914{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001915 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueBindSparseBufferMemory(
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -06001916 queue, buffer, numBindings, pBindInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001917 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001918 // Track objects tied to memory
Tobin Ehlis257d9742015-07-08 17:08:02 -06001919 if (VK_FALSE == set_sparse_mem_binding(queue, pBindInfo->mem, buffer.handle, VK_OBJECT_TYPE_BUFFER)) {
1920 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_BUFFER, buffer.handle, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1921 "Unable to set object %#" PRIxLEAST64 " binding to mem obj %#" PRIxLEAST64, buffer.handle, pBindInfo->mem.handle);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001922 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06001923 //print_object_list(queue);
1924 //print_mem_list(queue);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001925 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001926 return result;
1927}
1928
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001929VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(
1930 VkDevice device,
1931 const VkFenceCreateInfo *pCreateInfo,
1932 VkFence *pFence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001933{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001934 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001935 if (VK_SUCCESS == result) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001936 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06001937 MT_FENCE_INFO* pFI = &fenceMap[pFence->handle];
1938 memset(pFI, 0, sizeof(MT_FENCE_INFO));
1939 memcpy(&(pFI->createInfo), pCreateInfo, sizeof(VkFenceCreateInfo));
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001940 loader_platform_thread_unlock_mutex(&globalLock);
1941 }
1942 return result;
1943}
1944
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001945VK_LAYER_EXPORT VkResult VKAPI vkResetFences(
1946 VkDevice device,
1947 uint32_t fenceCount,
Courtney Goeltzenleuchter2bf8f902015-06-18 17:28:20 -06001948 const VkFence *pFences)
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001949{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001950 /*
1951 * TODO: Shouldn't we check for error conditions before passing down the chain?
1952 * What if reason result is not VK_SUCCESS is something we could report as a validation error?
1953 */
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001954 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001955 if (VK_SUCCESS == result) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001956 loader_platform_thread_lock_mutex(&globalLock);
1957 // Reset fence state in fenceCreateInfo structure
1958 for (uint32_t i = 0; i < fenceCount; i++) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001959 //MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i].handle);
1960 auto fence_item = fenceMap.find(pFences[i].handle);
1961 if (fence_item != fenceMap.end()) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001962 // Validate fences in SIGNALED state
Tobin Ehlis257d9742015-07-08 17:08:02 -06001963 if (!(fence_item->second.createInfo.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
1964 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, pFences[i].handle, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM",
1965 "Fence %#" PRIxLEAST64 " submitted to VkResetFences in UNSIGNALED STATE", pFences[i].handle);
1966 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001967 }
1968 else {
Tobin Ehlis257d9742015-07-08 17:08:02 -06001969 fence_item->second.createInfo.flags =
1970 static_cast<VkFenceCreateFlags>(fence_item->second.createInfo.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001971 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001972 }
1973 }
1974 loader_platform_thread_unlock_mutex(&globalLock);
1975 }
1976 return result;
1977}
1978
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001979VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(
1980 VkDevice device,
1981 VkFence fence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001982{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001983 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetFenceStatus(device, fence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001984 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001985 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001986 update_fence_tracking(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001987 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001988 }
1989 return result;
1990}
1991
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001992VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(
1993 VkDevice device,
1994 uint32_t fenceCount,
1995 const VkFence *pFences,
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001996 VkBool32 waitAll,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001997 uint64_t timeout)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001998{
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001999 // Verify fence status of submitted fences
2000 for(uint32_t i = 0; i < fenceCount; i++) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002001 auto pFenceInfo = fenceMap.find(pFences[i].handle);
2002 if (pFenceInfo != fenceMap.end()) {
2003 if (pFenceInfo->second.createInfo.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
2004 log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_FENCE, pFences[i].handle, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM",
2005 "VkWaitForFences specified fence %#" PRIxLEAST64 " already in SIGNALED state.", pFences[i].handle);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05002006 }
2007 }
2008 }
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002009 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002010 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05002011
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002012 if (VK_SUCCESS == result) {
Mark Lobodzinski50932972015-04-02 20:49:09 -05002013 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002014 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002015 update_fence_tracking(pFences[i]);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002016 }
2017 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002018 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002019 loader_platform_thread_unlock_mutex(&globalLock);
2020 return result;
2021}
2022
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002023VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(
2024 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002025{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002026 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueWaitIdle(queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002027 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002028 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002029 retire_queue_fences(queue);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002030 loader_platform_thread_unlock_mutex(&globalLock);
2031 }
2032 return result;
2033}
2034
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002035VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(
2036 VkDevice device)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002037{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002038 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DeviceWaitIdle(device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002039 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002040 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002041 retire_device_fences(device);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002042 loader_platform_thread_unlock_mutex(&globalLock);
2043 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002044 return result;
2045}
2046
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002047VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(
2048 VkDevice device,
2049 const VkEventCreateInfo *pCreateInfo,
2050 VkEvent *pEvent)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002051{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002052 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002053 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002054 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002055 add_object_create_info(pEvent->handle, VK_OBJECT_TYPE_EVENT, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002056 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06002057 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002058 return result;
2059}
2060
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002061VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(
2062 VkDevice device,
2063 const VkQueryPoolCreateInfo *pCreateInfo,
2064 VkQueryPool *pQueryPool)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002065{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002066 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002067 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002068 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002069 add_object_create_info(pQueryPool->handle, VK_OBJECT_TYPE_QUERY_POOL, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002070 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06002071 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002072 return result;
2073}
2074
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002075VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(
2076 VkDevice device,
2077 const VkBufferCreateInfo *pCreateInfo,
2078 VkBuffer *pBuffer)
Tobin Ehlis7265e832015-01-19 08:42:29 -07002079{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002080 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002081 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002082 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002083 add_object_create_info(pBuffer->handle, VK_OBJECT_TYPE_BUFFER, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002084 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06002085 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07002086 return result;
2087}
2088
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002089VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(
2090 VkDevice device,
2091 const VkBufferViewCreateInfo *pCreateInfo,
2092 VkBufferView *pView)
Tobin Ehlis7265e832015-01-19 08:42:29 -07002093{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002094 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002095 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002096 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002097 add_object_create_info(pView->handle, VK_OBJECT_TYPE_BUFFER_VIEW, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002098 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06002099 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07002100 return result;
2101}
2102
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002103VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
2104 VkDevice device,
2105 const VkImageCreateInfo *pCreateInfo,
2106 VkImage *pImage)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002107{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002108 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002109 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002110 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002111 add_object_create_info(pImage->handle, VK_OBJECT_TYPE_IMAGE, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002112 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002113 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002114 return result;
2115}
2116
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002117VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(
2118 VkDevice device,
2119 const VkImageViewCreateInfo *pCreateInfo,
2120 VkImageView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002121{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002122 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002123 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002124 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002125 add_object_create_info(pView->handle, VK_OBJECT_TYPE_IMAGE_VIEW, pCreateInfo);
Tobin Ehlis41376e12015-07-03 08:45:14 -06002126 // Validate that img has correct usage flags set
2127 validate_image_usage_flags(device, pCreateInfo->image, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
2128 false, "vkCreateImageView()", "VK_IMAGE_USAGE_[SAMPLED|STORAGE]_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002129 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002130 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002131 return result;
2132}
2133
Chia-I Wu08accc62015-07-07 11:50:03 +08002134VK_LAYER_EXPORT VkResult VKAPI vkCreateAttachmentView(
Tobin Ehlisc0ff3e02015-07-13 13:42:25 -06002135 VkDevice device,
Chia-I Wu08accc62015-07-07 11:50:03 +08002136 const VkAttachmentViewCreateInfo *pCreateInfo,
2137 VkAttachmentView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002138{
Chia-I Wu08accc62015-07-07 11:50:03 +08002139 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002140 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002141 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002142 add_object_create_info(pView->handle, VK_OBJECT_TYPE_ATTACHMENT_VIEW, pCreateInfo);
Tobin Ehlis41376e12015-07-03 08:45:14 -06002143 // Validate that img has correct usage flags set
2144 // We don't use the image helper function here as it's a special case that checks struct type
Tobin Ehlis257d9742015-07-08 17:08:02 -06002145 MT_OBJ_BINDING_INFO* pInfo = get_object_binding_info(pCreateInfo->image.handle, VK_OBJECT_TYPE_IMAGE);
Tobin Ehlis41376e12015-07-03 08:45:14 -06002146 if (pInfo) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002147 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pInfo->create_info.image.sType) {
Tobin Ehlisc0ff3e02015-07-13 13:42:25 -06002148 // TODO : Now that this is generalized for all Attachments, need to only check COLOR or DS USAGE bits
2149 // if/when we know that Image being attached to is Color or DS. Can probably do this for DS based on format
2150// validate_usage_flags(device, pInfo->create_info.image.usage, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, true,
2151// pCreateInfo->image.handle, VK_OBJECT_TYPE_IMAGE, "image", "vkCreateAttachmentView()", "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT");
Tony Barbour791646c2015-07-13 16:37:21 -06002152 }// else if (VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI == pInfo->create_info.swapchain.sType) {
2153 // validate_usage_flags(device, pInfo->create_info.swapchain.imageUsageFlags, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, true,
2154 // pCreateInfo->image.handle, VK_OBJECT_TYPE_IMAGE, "image", "vkCreateAttachmentView()", "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT");
2155 //}
Tobin Ehlis41376e12015-07-03 08:45:14 -06002156 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002157 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002158 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002159 return result;
2160}
2161
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002162VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
2163 VkDevice device,
2164 const VkShaderCreateInfo *pCreateInfo,
2165 VkShader *pShader)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002166{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002167 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002168 if (result == VK_SUCCESS) {
2169 loader_platform_thread_lock_mutex(&globalLock);
2170 add_object_create_info(pShader->handle, VK_OBJECT_TYPE_SHADER, pCreateInfo);
2171 loader_platform_thread_unlock_mutex(&globalLock);
2172 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002173 return result;
2174}
2175
Jon Ashburnc669cc62015-07-09 15:02:25 -06002176//TODO do we need to intercept pipelineCache functions to track objects?
2177VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002178 VkDevice device,
Jon Ashburnc669cc62015-07-09 15:02:25 -06002179 VkPipelineCache pipelineCache,
2180 uint32_t count,
2181 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2182 VkPipeline *pPipelines)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002183{
Jon Ashburnc669cc62015-07-09 15:02:25 -06002184 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002185 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002186 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002187 /* TODO: pPipelines is now an array of pipelines */
2188 add_object_create_info(pPipelines->handle, VK_OBJECT_TYPE_PIPELINE, &pCreateInfos[0]);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002189 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002190 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002191 return result;
2192}
2193
Jon Ashburnc669cc62015-07-09 15:02:25 -06002194VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipelines(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002195 VkDevice device,
Jon Ashburnc669cc62015-07-09 15:02:25 -06002196 VkPipelineCache pipelineCache,
2197 uint32_t count,
2198 const VkComputePipelineCreateInfo *pCreateInfos,
2199 VkPipeline *pPipelines)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002200{
Jon Ashburnc669cc62015-07-09 15:02:25 -06002201 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002202 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002203 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002204 /* TODO: pPipelines is now an array of pipelines */
2205 add_object_create_info(pPipelines->handle, VK_OBJECT_TYPE_PIPELINE, &pCreateInfos[0]);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002206 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002207 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002208 return result;
2209}
2210
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002211VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(
2212 VkDevice device,
2213 const VkSamplerCreateInfo *pCreateInfo,
2214 VkSampler *pSampler)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002215{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002216 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002217 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002218 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002219 add_object_create_info(pSampler->handle, VK_OBJECT_TYPE_SAMPLER, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002220 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002221 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002222 return result;
2223}
2224
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002225VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(
2226 VkDevice device,
Tobin Ehlis257d9742015-07-08 17:08:02 -06002227 const VkDynamicViewportStateCreateInfo *pCreateInfo,
2228 VkDynamicViewportState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002229{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002230 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002231 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002232 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002233 add_object_create_info(pState->handle, VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002234 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002235 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002236 return result;
2237}
2238
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002239VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(
2240 VkDevice device,
Tobin Ehlis257d9742015-07-08 17:08:02 -06002241 const VkDynamicRasterStateCreateInfo *pCreateInfo,
2242 VkDynamicRasterState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002243{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002244 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002245 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002246 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002247 add_object_create_info(pState->handle, VK_OBJECT_TYPE_DYNAMIC_RASTER_STATE, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002248 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002249 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002250 return result;
2251}
2252
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002253VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(
2254 VkDevice device,
Tobin Ehlis257d9742015-07-08 17:08:02 -06002255 const VkDynamicColorBlendStateCreateInfo *pCreateInfo,
2256 VkDynamicColorBlendState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002257{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002258 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002259 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002260 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002261 add_object_create_info(pState->handle, VK_OBJECT_TYPE_DYNAMIC_COLOR_BLEND_STATE, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002262 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002263 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002264 return result;
2265}
2266
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002267VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(
2268 VkDevice device,
Tobin Ehlis257d9742015-07-08 17:08:02 -06002269 const VkDynamicDepthStencilStateCreateInfo *pCreateInfo,
2270 VkDynamicDepthStencilState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002271{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002272 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002273 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002274 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002275 add_object_create_info(pState->handle, VK_OBJECT_TYPE_DYNAMIC_DEPTH_STENCIL_STATE, pCreateInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002276 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07002277 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07002278 return result;
2279}
2280
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002281VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(
2282 VkDevice device,
2283 const VkCmdBufferCreateInfo *pCreateInfo,
2284 VkCmdBuffer *pCmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002285{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002286 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05002287 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002288 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002289 if (*pCmdBuffer)
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002290 add_cmd_buf_info(*pCmdBuffer);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002291 //printCBList(device);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002292 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002293 return result;
2294}
2295
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002296VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(
2297 VkCmdBuffer cmdBuffer,
2298 const VkCmdBufferBeginInfo *pBeginInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002299{
Mike Stroyan950496e2015-05-19 15:16:08 -06002300 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002301 // This implicitly resets the Cmd Buffer so make sure any fence is done and then clear memory references
Mike Stroyan950496e2015-05-19 15:16:08 -06002302 if (!checkCBCompleted(cmdBuffer)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002303 // TODO : want cmdBuffer to be srcObj here
2304 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002305 "Calling vkBeginCommandBuffer() on active CB %p before it has completed. "
Mike Stroyan950496e2015-05-19 15:16:08 -06002306 "You must check CB flag before this call.", cmdBuffer);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002307 }
Mike Stroyan950496e2015-05-19 15:16:08 -06002308 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002309 VkResult result = get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002310 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002311 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002312 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002313 return result;
2314}
2315
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002316VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(
2317 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002318{
2319 // TODO : Anything to do here?
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002320 VkResult result = get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002321 return result;
2322}
2323
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002324VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(
Cody Northrope62183e2015-07-09 18:08:05 -06002325 VkCmdBuffer cmdBuffer,
2326 VkCmdBufferResetFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002327{
Mike Stroyan950496e2015-05-19 15:16:08 -06002328 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002329 // Verify that CB is complete (not in-flight)
Mike Stroyan950496e2015-05-19 15:16:08 -06002330 if (!checkCBCompleted(cmdBuffer)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002331 // TODO : Want cmdBuffer to be srcObj here
2332 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002333 "Resetting CB %p before it has completed. You must check CB flag before "
Mike Stroyan950496e2015-05-19 15:16:08 -06002334 "calling vkResetCommandBuffer().", cmdBuffer);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07002335 }
2336 // Clear memory references as this point.
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002337 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002338 loader_platform_thread_unlock_mutex(&globalLock);
Cody Northrope62183e2015-07-09 18:08:05 -06002339 VkResult result = get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer, flags);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002340 return result;
2341}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002342// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis6663f492014-11-10 12:29:12 -07002343// need to account for that mem now having binding to given cmdBuffer
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002344VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(
2345 VkCmdBuffer cmdBuffer,
2346 VkPipelineBindPoint pipelineBindPoint,
2347 VkPipeline pipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002348{
Tobin Ehlisc145be82015-01-08 15:22:32 -07002349#if 0
2350 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
2351 if (getPipeline(pipeline)) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002352 MT_CB_INFO *pCBInfo = get_cmd_buf_info(cmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05002353 if (pCBInfo) {
2354 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlisc145be82015-01-08 15:22:32 -07002355 } else {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002356 "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002357 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_INVALID_CB, (char *) "DS", (char *) str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07002358 }
2359 }
2360 else {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002361 "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002362 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, MEMTRACK_INVALID_OBJECT, (char *) "DS", (char *) str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07002363 }
2364#endif
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002365 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002366}
2367
Tobin Ehlis257d9742015-07-08 17:08:02 -06002368void VKAPI vkCmdBindDynamicViewportState(
2369 VkCmdBuffer cmdBuffer,
2370 VkDynamicViewportState dynamicViewportState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002371{
Tobin Ehlis257d9742015-07-08 17:08:02 -06002372 VkDynamicViewportStateCreateInfo* pCI;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002373 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002374 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07002375 if (!pCmdBuf) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002376 // TODO : Want cmdBuffer to be srcObj here
2377 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_CB, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002378 "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07002379 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06002380 pCI = (VkDynamicViewportStateCreateInfo*)get_object_create_info(dynamicViewportState.handle, VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE);
2381 if (!pCI) {
2382 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_VIEWPORT_STATE, dynamicViewportState.handle, 0, MEMTRACK_INVALID_OBJECT, "MEM",
2383 "Unable to find dynamic viewport state object %#" PRIxLEAST64 ", was it ever created?", dynamicViewportState.handle);
Tobin Ehlisc145be82015-01-08 15:22:32 -07002384 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06002385 pCmdBuf->pLastBoundDynamicState[VK_STATE_BIND_POINT_VIEWPORT] = dynamicViewportState.handle;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002386 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002387 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindDynamicViewportState(cmdBuffer, dynamicViewportState);
2388}
2389
2390void VKAPI vkCmdBindDynamicRasterState(
2391 VkCmdBuffer cmdBuffer,
2392 VkDynamicRasterState dynamicRasterState)
2393{
2394 VkDynamicRasterStateCreateInfo* pCI;
2395 loader_platform_thread_lock_mutex(&globalLock);
2396 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
2397 if (!pCmdBuf) {
2398 // TODO : Want cmdBuffer to be srcObj here
2399 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_CB, "MEM",
2400 "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
2401 }
2402 pCI = (VkDynamicRasterStateCreateInfo*)get_object_create_info(dynamicRasterState.handle, VK_OBJECT_TYPE_DYNAMIC_RASTER_STATE);
2403 if (!pCI) {
2404 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_RASTER_STATE, dynamicRasterState.handle, 0, MEMTRACK_INVALID_OBJECT, "MEM",
2405 "Unable to find dynamic raster state object %#" PRIxLEAST64 ", was it ever created?", dynamicRasterState.handle);
2406 }
2407 pCmdBuf->pLastBoundDynamicState[VK_STATE_BIND_POINT_RASTER] = dynamicRasterState.handle;
2408 loader_platform_thread_unlock_mutex(&globalLock);
2409 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindDynamicRasterState(cmdBuffer, dynamicRasterState);
2410}
2411
2412void VKAPI vkCmdBindDynamicColorBlendState(
2413 VkCmdBuffer cmdBuffer,
2414 VkDynamicColorBlendState dynamicColorBlendState)
2415{
2416 VkDynamicColorBlendStateCreateInfo* pCI;
2417 loader_platform_thread_lock_mutex(&globalLock);
2418 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
2419 if (!pCmdBuf) {
2420 // TODO : Want cmdBuffer to be srcObj here
2421 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_CB, "MEM",
2422 "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
2423 }
2424 pCI = (VkDynamicColorBlendStateCreateInfo*)get_object_create_info(dynamicColorBlendState.handle, VK_OBJECT_TYPE_DYNAMIC_COLOR_BLEND_STATE);
2425 if (!pCI) {
2426 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_COLOR_BLEND_STATE, dynamicColorBlendState.handle, 0, MEMTRACK_INVALID_OBJECT, "MEM",
2427 "Unable to find dynamic raster state object %#" PRIxLEAST64 ", was it ever created?", dynamicColorBlendState.handle);
2428 }
2429 pCmdBuf->pLastBoundDynamicState[VK_STATE_BIND_POINT_COLOR_BLEND] = dynamicColorBlendState.handle;
2430 loader_platform_thread_unlock_mutex(&globalLock);
2431 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindDynamicColorBlendState(cmdBuffer, dynamicColorBlendState);
2432}
2433
2434void VKAPI vkCmdBindDynamicDepthStencilState(
2435 VkCmdBuffer cmdBuffer,
2436 VkDynamicDepthStencilState dynamicDepthStencilState)
2437{
2438 VkDynamicDepthStencilStateCreateInfo* pCI;
2439 loader_platform_thread_lock_mutex(&globalLock);
2440 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
2441 if (!pCmdBuf) {
2442 // TODO : Want cmdBuffer to be srcObj here
2443 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_INVALID_CB, "MEM",
2444 "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
2445 }
2446 pCI = (VkDynamicDepthStencilStateCreateInfo*)get_object_create_info(dynamicDepthStencilState.handle, VK_OBJECT_TYPE_DYNAMIC_DEPTH_STENCIL_STATE);
2447 if (!pCI) {
2448 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DYNAMIC_DEPTH_STENCIL_STATE, dynamicDepthStencilState.handle, 0, MEMTRACK_INVALID_OBJECT, "MEM",
2449 "Unable to find dynamic raster state object %#" PRIxLEAST64 ", was it ever created?", dynamicDepthStencilState.handle);
2450 }
2451 pCmdBuf->pLastBoundDynamicState[VK_STATE_BIND_POINT_DEPTH_STENCIL] = dynamicDepthStencilState.handle;
2452 loader_platform_thread_unlock_mutex(&globalLock);
2453 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindDynamicDepthStencilState(cmdBuffer, dynamicDepthStencilState);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002454}
2455
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002456VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002457 VkCmdBuffer cmdBuffer,
2458 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06002459 VkPipelineLayout layout,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002460 uint32_t firstSet,
2461 uint32_t setCount,
2462 const VkDescriptorSet *pDescriptorSets,
2463 uint32_t dynamicOffsetCount,
2464 const uint32_t *pDynamicOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002465{
Tobin Ehlisc145be82015-01-08 15:22:32 -07002466 // TODO : Somewhere need to verify that all textures referenced by shaders in DS are in some type of *SHADER_READ* state
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002467 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindDescriptorSets(
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06002468 cmdBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002469}
2470
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002471VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002472 VkCmdBuffer cmdBuffer,
2473 uint32_t startBinding,
2474 uint32_t bindingCount,
2475 const VkBuffer *pBuffers,
2476 const VkDeviceSize *pOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002477{
Tobin Ehlis257d9742015-07-08 17:08:02 -06002478 // TODO : Somewhere need to verify that VBs have correct usage state flagged
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002479 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wu19156822015-01-05 13:42:56 +08002480}
2481
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002482VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(
2483 VkCmdBuffer cmdBuffer,
2484 VkBuffer buffer,
2485 VkDeviceSize offset,
2486 VkIndexType indexType)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002487{
Tobin Ehlis257d9742015-07-08 17:08:02 -06002488 // TODO : Somewhere need to verify that IBs have correct usage state flagged
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002489 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002490}
2491
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002492VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(
2493 VkCmdBuffer cmdBuffer,
2494 VkBuffer buffer,
2495 VkDeviceSize offset,
2496 uint32_t count,
2497 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002498{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002499 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002500 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, buffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002501 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002502 // TODO : Want cmdBuffer to be srcObj here
2503 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2504 "In vkCmdDrawIndirect() call unable to update binding of buffer %#" PRIxLEAST64 " to cmdBuffer %p", buffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002505 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002506 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002507 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002508}
2509
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002510VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
2511 VkCmdBuffer cmdBuffer,
2512 VkBuffer buffer,
2513 VkDeviceSize offset,
2514 uint32_t count,
2515 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002516{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002517 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002518 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, buffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002519 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002520 // TODO : Want cmdBuffer to be srcObj here
2521 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2522 "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %#" PRIxLEAST64 " to cmdBuffer %p", buffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002523 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002524 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002525 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002526}
2527
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002528VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(
2529 VkCmdBuffer cmdBuffer,
2530 VkBuffer buffer,
2531 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002532{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002533 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002534 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, buffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002535 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002536 // TODO : Want cmdBuffer to be srcObj here
2537 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2538 "In vkCmdDispatchIndirect() call unable to update binding of buffer %#" PRIxLEAST64 " to cmdBuffer %p", buffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002539 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002540 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002541 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002542}
2543
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002544VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(
2545 VkCmdBuffer cmdBuffer,
2546 VkBuffer srcBuffer,
2547 VkBuffer destBuffer,
2548 uint32_t regionCount,
2549 const VkBufferCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002550{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002551 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002552 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcBuffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002553 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002554 // TODO : Want cmdBuffer to be srcObj here
2555 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2556 "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %#" PRIxLEAST64 " to cmdBuffer %p", srcBuffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002557 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06002558 mem = get_mem_binding_from_object(cmdBuffer, destBuffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002559 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002560 // TODO : Want cmdBuffer to be srcObj here
2561 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2562 "In vkCmdCopyBuffer() call unable to update binding of destBuffer %#" PRIxLEAST64 " to cmdBuffer %p", destBuffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002563 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06002564 // Validate that SRC & DST buffers have correct usage flags set
2565 validate_buffer_usage_flags(cmdBuffer, srcBuffer, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT");
2566 validate_buffer_usage_flags(cmdBuffer, destBuffer, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002567 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002568 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002569}
2570
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002571VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(
2572 VkCmdBuffer cmdBuffer,
2573 VkImage srcImage,
2574 VkImageLayout srcImageLayout,
2575 VkImage destImage,
2576 VkImageLayout destImageLayout,
2577 uint32_t regionCount,
2578 const VkImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002579{
Tobin Ehlis41376e12015-07-03 08:45:14 -06002580 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis41376e12015-07-03 08:45:14 -06002581 // Validate that src & dst images have correct usage flags set
Tobin Ehlis257d9742015-07-08 17:08:02 -06002582 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcImage.handle, VK_OBJECT_TYPE_IMAGE);
2583 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
2584 // TODO : Want cmdBuffer to be srcObj here
2585 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2586 "In vkCmdCopyImage() call unable to update binding of srcImage %#" PRIxLEAST64 " to cmdBuffer %p", srcImage.handle, cmdBuffer);
2587 }
2588 mem = get_mem_binding_from_object(cmdBuffer, destImage.handle, VK_OBJECT_TYPE_IMAGE);
2589 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
2590 // TODO : Want cmdBuffer to be srcObj here
2591 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2592 "In vkCmdCopyImage() call unable to update binding of destImage %#" PRIxLEAST64 " to cmdBuffer %p", destImage.handle, cmdBuffer);
2593 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06002594 validate_image_usage_flags(cmdBuffer, srcImage, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT");
2595 validate_image_usage_flags(cmdBuffer, destImage, VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT");
2596 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002597 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002598 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002599}
2600
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002601VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(
2602 VkCmdBuffer cmdBuffer,
2603 VkImage srcImage,
2604 VkImageLayout srcImageLayout,
2605 VkImage destImage,
2606 VkImageLayout destImageLayout,
2607 uint32_t regionCount,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05002608 const VkImageBlit *pRegions,
2609 VkTexFilter filter)
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06002610{
Tobin Ehlis41376e12015-07-03 08:45:14 -06002611 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis41376e12015-07-03 08:45:14 -06002612 // Validate that src & dst images have correct usage flags set
Tobin Ehlis257d9742015-07-08 17:08:02 -06002613 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcImage.handle, VK_OBJECT_TYPE_IMAGE);
2614 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
2615 // TODO : Want cmdBuffer to be srcObj here
2616 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2617 "In vkCmdBlitImage() call unable to update binding of srcImage %#" PRIxLEAST64 " to cmdBuffer %p", srcImage.handle, cmdBuffer);
2618 }
2619 mem = get_mem_binding_from_object(cmdBuffer, destImage.handle, VK_OBJECT_TYPE_IMAGE);
2620 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
2621 // TODO : Want cmdBuffer to be srcObj here
2622 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2623 "In vkCmdBlitImage() call unable to update binding of destImage %#" PRIxLEAST64 " to cmdBuffer %p", destImage.handle, cmdBuffer);
2624 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06002625 validate_image_usage_flags(cmdBuffer, srcImage, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT");
2626 validate_image_usage_flags(cmdBuffer, destImage, VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT");
2627 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002628 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBlitImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002629 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06002630}
2631
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002632VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(
2633 VkCmdBuffer cmdBuffer,
2634 VkBuffer srcBuffer,
2635 VkImage destImage,
2636 VkImageLayout destImageLayout,
2637 uint32_t regionCount,
2638 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002639{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002640 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002641 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, destImage.handle, VK_OBJECT_TYPE_IMAGE);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002642 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002643 // TODO : Want cmdBuffer to be srcObj here
2644 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2645 "In vkCmdCopyMemoryToImage() call unable to update binding of destImage %#" PRIxLEAST64 " to cmdBuffer %p", destImage.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002646 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06002647 mem = get_mem_binding_from_object(cmdBuffer, srcBuffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002648 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002649 // TODO : Want cmdBuffer to be srcObj here
2650 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2651 "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %#" PRIxLEAST64 " to cmdBuffer %p", srcBuffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002652 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06002653 // Validate that src buff & dst image have correct usage flags set
2654 validate_buffer_usage_flags(cmdBuffer, srcBuffer, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT");
2655 validate_image_usage_flags(cmdBuffer, destImage, VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdCopyBufferToImage()", "VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002656 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002657 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyBufferToImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002658 cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002659}
2660
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002661VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(
2662 VkCmdBuffer cmdBuffer,
2663 VkImage srcImage,
2664 VkImageLayout srcImageLayout,
2665 VkBuffer destBuffer,
2666 uint32_t regionCount,
2667 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002668{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002669 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002670 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcImage.handle, VK_OBJECT_TYPE_IMAGE);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002671 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002672 // TODO : Want cmdBuffer to be srcObj here
2673 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2674 "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %#" PRIxLEAST64 " to cmdBuffer %p", srcImage.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002675 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06002676 mem = get_mem_binding_from_object(cmdBuffer, destBuffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002677 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002678 // TODO : Want cmdBuffer to be srcObj here
2679 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2680 "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %#" PRIxLEAST64 " to cmdBuffer %p", destBuffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002681 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06002682 // Validate that dst buff & src image have correct usage flags set
2683 validate_image_usage_flags(cmdBuffer, srcImage, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT");
2684 validate_buffer_usage_flags(cmdBuffer, destBuffer, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdCopyImageToBuffer()", "VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002685 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002686 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002687 cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002688}
2689
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002690VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
2691 VkCmdBuffer cmdBuffer,
2692 VkBuffer destBuffer,
2693 VkDeviceSize destOffset,
2694 VkDeviceSize dataSize,
2695 const uint32_t *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002696{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002697 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002698 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, destBuffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002699 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002700 // TODO : Want cmdBuffer to be srcObj here
2701 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2702 "In vkCmdUpdateMemory() call unable to update binding of destBuffer %#" PRIxLEAST64 " to cmdBuffer %p", destBuffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002703 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06002704 // Validate that dst buff has correct usage flags set
2705 validate_buffer_usage_flags(cmdBuffer, destBuffer, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdUpdateBuffer()", "VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002706 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002707 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002708}
2709
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002710VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
2711 VkCmdBuffer cmdBuffer,
2712 VkBuffer destBuffer,
2713 VkDeviceSize destOffset,
2714 VkDeviceSize fillSize,
2715 uint32_t data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002716{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002717 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002718 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, destBuffer.handle, VK_OBJECT_TYPE_BUFFER);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002719 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002720 // TODO : Want cmdBuffer to be srcObj here
2721 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2722 "In vkCmdFillMemory() call unable to update binding of destBuffer %#" PRIxLEAST64 " to cmdBuffer %p", destBuffer.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002723 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06002724 // Validate that dst buff has correct usage flags set
2725 validate_buffer_usage_flags(cmdBuffer, destBuffer, VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DESTINATION_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002726 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002727 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002728}
2729
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002730VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
2731 VkCmdBuffer cmdBuffer,
2732 VkImage image,
2733 VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12002734 const VkClearColorValue *pColor,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002735 uint32_t rangeCount,
2736 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002737{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002738 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002739 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002740 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, image.handle, VK_OBJECT_TYPE_IMAGE);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002741 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002742 // TODO : Want cmdBuffer to be srcObj here
2743 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2744 "In vkCmdClearColorImage() call unable to update binding of image buffer %#" PRIxLEAST64 " to cmdBuffer %p", image.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002745 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002746 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002747 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002748}
2749
Chris Forbesd9be82b2015-06-22 17:21:59 +12002750VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002751 VkCmdBuffer cmdBuffer,
2752 VkImage image,
2753 VkImageLayout imageLayout,
2754 float depth,
2755 uint32_t stencil,
2756 uint32_t rangeCount,
2757 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002758{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002759 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002760 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002761 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, image.handle, VK_OBJECT_TYPE_IMAGE);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002762 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002763 // TODO : Want cmdBuffer to be srcObj here
2764 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2765 "In vkCmdClearDepthStencil() call unable to update binding of image buffer %#" PRIxLEAST64 " to cmdBuffer %p", image.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002766 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002767 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbesd9be82b2015-06-22 17:21:59 +12002768 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002769 cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002770}
2771
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002772VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(
2773 VkCmdBuffer cmdBuffer,
2774 VkImage srcImage,
2775 VkImageLayout srcImageLayout,
2776 VkImage destImage,
2777 VkImageLayout destImageLayout,
2778 uint32_t regionCount,
2779 const VkImageResolve *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002780{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002781 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002782 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcImage.handle, VK_OBJECT_TYPE_IMAGE);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002783 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002784 // TODO : Want cmdBuffer to be srcObj here
2785 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2786 "In vkCmdResolveImage() call unable to update binding of srcImage buffer %#" PRIxLEAST64 " to cmdBuffer %p", srcImage.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002787 }
Tobin Ehlis257d9742015-07-08 17:08:02 -06002788 mem = get_mem_binding_from_object(cmdBuffer, destImage.handle, VK_OBJECT_TYPE_IMAGE);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002789 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002790 // TODO : Want cmdBuffer to be srcObj here
2791 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2792 "In vkCmdResolveImage() call unable to update binding of destImage buffer %#" PRIxLEAST64 " to cmdBuffer %p", destImage.handle, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002793 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002794 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002795 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdResolveImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002796 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002797}
2798
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002799VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(
2800 VkCmdBuffer cmdBuffer,
2801 VkQueryPool queryPool,
2802 uint32_t slot,
2803 VkFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002804{
Tobin Ehlis257d9742015-07-08 17:08:02 -06002805// loader_platform_thread_lock_mutex(&globalLock);
2806// VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, queryPool);
2807// if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
2808// log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2809// "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %#" PRIxLEAST64 " to cmdBuffer %p", queryPool.handle, cmdBuffer);
2810// }
2811// loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002812 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002813}
2814
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002815VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(
2816 VkCmdBuffer cmdBuffer,
2817 VkQueryPool queryPool,
2818 uint32_t slot)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002819{
Tobin Ehlis257d9742015-07-08 17:08:02 -06002820// loader_platform_thread_lock_mutex(&globalLock);
2821// VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, queryPool);
2822// if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
2823// // TODO : Want cmdBuffer to be srcObj here
2824// log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2825// "In vkCmdEndQuery() call unable to update binding of queryPool buffer %#" PRIxLEAST64 " to cmdBuffer %p", queryPool.handle, cmdBuffer);
2826// }
2827// loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002828 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002829}
2830
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002831VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(
2832 VkCmdBuffer cmdBuffer,
2833 VkQueryPool queryPool,
2834 uint32_t startQuery,
2835 uint32_t queryCount)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002836{
Tobin Ehlis257d9742015-07-08 17:08:02 -06002837// loader_platform_thread_lock_mutex(&globalLock);
2838// VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, queryPool);
2839// if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
2840// // TODO : Want cmdBuffer to be srcObj here
2841// log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, 0, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2842// "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %#" PRIxLEAST64 " to cmdBuffer %p", queryPool.handle, cmdBuffer);
2843// }
2844// loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002845 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002846}
2847
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002848VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2849 VkInstance instance,
2850 VkFlags msgFlags,
2851 const PFN_vkDbgMsgCallback pfnMsgCallback,
2852 void* pUserData,
2853 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002854{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002855 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, instance);
2856 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2857 if (res == VK_SUCCESS) {
2858 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2859
2860 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2861 }
2862 return res;
Tobin Ehlis6663f492014-11-10 12:29:12 -07002863}
2864
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002865VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2866 VkInstance instance,
2867 VkDbgMsgCallback msgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002868{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002869 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, instance);
2870 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2871
2872 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2873 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2874
2875 return res;
Tobin Ehlis6663f492014-11-10 12:29:12 -07002876}
2877
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002878VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(
2879 VkDevice device,
2880 const VkSwapChainCreateInfoWSI *pCreateInfo,
2881 VkSwapChainWSI *pSwapChain)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002882{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002883 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002884
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002885 if (VK_SUCCESS == result) {
Chia-I Wuf8693382015-04-16 22:02:10 +08002886 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchtercf48cad2015-07-13 18:41:17 -06002887 MT_SWAP_CHAIN_INFO *new_rec = new MT_SWAP_CHAIN_INFO;
2888 new_rec->createInfo = *pCreateInfo;
2889 swapChainMap[pSwapChain->handle]= new_rec;
Chia-I Wuf8693382015-04-16 22:02:10 +08002890 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002891 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002892
Tobin Ehlis6663f492014-11-10 12:29:12 -07002893 return result;
2894}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002895
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002896VK_LAYER_EXPORT VkResult VKAPI vkDestroySwapChainWSI(
Ian Elliott1064fe32015-07-06 14:31:32 -06002897 VkDevice device,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002898 VkSwapChainWSI swapChain)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002899{
2900 loader_platform_thread_lock_mutex(&globalLock);
Ian Elliott1064fe32015-07-06 14:31:32 -06002901 if (swapChainMap.find(swapChain.handle) != swapChainMap.end()) {
2902 MT_SWAP_CHAIN_INFO* pInfo = swapChainMap[swapChain.handle];
Chia-I Wuf8693382015-04-16 22:02:10 +08002903
David Pinedod8f83d82015-04-27 16:36:17 -06002904 if (pInfo->images.size() > 0) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002905 for (auto it = pInfo->images.begin(); it != pInfo->images.end(); it++) {
Courtney Goeltzenleuchtercf48cad2015-07-13 18:41:17 -06002906 clear_object_binding(device, it->image.handle, VK_OBJECT_TYPE_SWAP_CHAIN_WSI);
Tobin Ehlis257d9742015-07-08 17:08:02 -06002907 auto image_item = imageMap.find(it->image.handle);
2908 if (image_item != imageMap.end())
2909 imageMap.erase(image_item);
David Pinedod8f83d82015-04-27 16:36:17 -06002910 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002911 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002912 delete pInfo;
Ian Elliott1064fe32015-07-06 14:31:32 -06002913 swapChainMap.erase(swapChain.handle);
Chia-I Wuf8693382015-04-16 22:02:10 +08002914 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002915 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtercf48cad2015-07-13 18:41:17 -06002916 return get_dispatch_table(mem_tracker_device_table_map, device)->DestroySwapChainWSI(device, swapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002917}
2918
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002919VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(
Ian Elliott1064fe32015-07-06 14:31:32 -06002920 VkDevice device,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002921 VkSwapChainWSI swapChain,
2922 VkSwapChainInfoTypeWSI infoType,
2923 size_t *pDataSize,
2924 void *pData)
Chia-I Wuf8693382015-04-16 22:02:10 +08002925{
Courtney Goeltzenleuchtercf48cad2015-07-13 18:41:17 -06002926 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetSwapChainInfoWSI(device, swapChain, infoType, pDataSize, pData);
Chia-I Wuf8693382015-04-16 22:02:10 +08002927
Courtney Goeltzenleuchterc04704b2015-07-13 18:40:35 -06002928 if (infoType == VK_SWAP_CHAIN_INFO_TYPE_IMAGES_WSI && result == VK_SUCCESS && pData != NULL) {
Ian Elliott1064fe32015-07-06 14:31:32 -06002929 const size_t count = *pDataSize / sizeof(VkSwapChainImagePropertiesWSI);
2930 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain.handle];
Chia-I Wuf8693382015-04-16 22:02:10 +08002931
2932 if (pInfo->images.empty()) {
2933 pInfo->images.resize(count);
2934 memcpy(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count);
2935
David Pinedod8f83d82015-04-27 16:36:17 -06002936 if (pInfo->images.size() > 0) {
Ian Elliott1064fe32015-07-06 14:31:32 -06002937 for (std::vector<VkSwapChainImagePropertiesWSI>::const_iterator it = pInfo->images.begin();
David Pinedod8f83d82015-04-27 16:36:17 -06002938 it != pInfo->images.end(); it++) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002939 // Add image object binding, then insert the new Mem Object and then bind it to created image
2940 add_object_create_info(it->image.handle, VK_OBJECT_TYPE_SWAP_CHAIN_WSI, &pInfo->createInfo);
Chia-I Wuf8693382015-04-16 22:02:10 +08002941 }
2942 }
2943 } else {
Ian Elliott1064fe32015-07-06 14:31:32 -06002944 const size_t count = *pDataSize / sizeof(VkSwapChainImagePropertiesWSI);
2945 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain.handle];
Chia-I Wuf8693382015-04-16 22:02:10 +08002946 const bool mismatch = (pInfo->images.size() != count ||
2947 memcmp(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count));
2948
2949 if (mismatch) {
Tobin Ehlis257d9742015-07-08 17:08:02 -06002950 // TODO : Want swapChain to be srcObj here
Courtney Goeltzenleuchtercf48cad2015-07-13 18:41:17 -06002951 log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_SWAP_CHAIN_WSI, 0, 0, MEMTRACK_NONE, "SWAP_CHAIN",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002952 "vkGetSwapChainInfoWSI(%p, VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI) returned mismatching data", swapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002953 }
2954 }
2955 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002956 return result;
2957}
Tobin Ehlis6663f492014-11-10 12:29:12 -07002958
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002959VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002960 VkDevice dev,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002961 const char *funcName)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002962{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002963 if (dev == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002964 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002965 }
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002966
Jon Ashburn8fd08252015-05-28 16:25:02 -06002967 /* loader uses this to force layer initialization; device object is wrapped */
2968 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002969 initDeviceTable(mem_tracker_device_table_map, (const VkBaseLayerObject *) dev);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002970 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002971 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06002972 if (!strcmp(funcName, "vkCreateDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002973 return (PFN_vkVoidFunction) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002974 if (!strcmp(funcName, "vkDestroyDevice"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002975 return (PFN_vkVoidFunction) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002976 if (!strcmp(funcName, "vkQueueSubmit"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002977 return (PFN_vkVoidFunction) vkQueueSubmit;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002978 if (!strcmp(funcName, "vkAllocMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002979 return (PFN_vkVoidFunction) vkAllocMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002980 if (!strcmp(funcName, "vkFreeMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002981 return (PFN_vkVoidFunction) vkFreeMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002982 if (!strcmp(funcName, "vkMapMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002983 return (PFN_vkVoidFunction) vkMapMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002984 if (!strcmp(funcName, "vkUnmapMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002985 return (PFN_vkVoidFunction) vkUnmapMemory;
Tobin Ehlis257d9742015-07-08 17:08:02 -06002986 if (!strcmp(funcName, "vkDestroyFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002987 return (PFN_vkVoidFunction) vkDestroyFence;
Tobin Ehlis257d9742015-07-08 17:08:02 -06002988 if (!strcmp(funcName, "vkDestroyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002989 return (PFN_vkVoidFunction) vkDestroyBuffer;
Tobin Ehlis257d9742015-07-08 17:08:02 -06002990 if (!strcmp(funcName, "vkDestroyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002991 return (PFN_vkVoidFunction) vkDestroyImage;
Tobin Ehlis257d9742015-07-08 17:08:02 -06002992 if (!strcmp(funcName, "vkDestroyAttachmentView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002993 return (PFN_vkVoidFunction) vkDestroyAttachmentView;
Tobin Ehlis257d9742015-07-08 17:08:02 -06002994 if (!strcmp(funcName, "vkDestroyImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002995 return (PFN_vkVoidFunction) vkDestroyImageView;
Tobin Ehlis257d9742015-07-08 17:08:02 -06002996 if (!strcmp(funcName, "vkDestroyPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002997 return (PFN_vkVoidFunction) vkDestroyPipeline;
Tobin Ehlis257d9742015-07-08 17:08:02 -06002998 if (!strcmp(funcName, "vkDestroySampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06002999 return (PFN_vkVoidFunction) vkDestroySampler;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003000 if (!strcmp(funcName, "vkDestroySemaphore"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003001 return (PFN_vkVoidFunction) vkDestroySemaphore;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003002 if (!strcmp(funcName, "vkDestroyEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003003 return (PFN_vkVoidFunction) vkDestroyEvent;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003004 if (!strcmp(funcName, "vkDestroyQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003005 return (PFN_vkVoidFunction) vkDestroyQueryPool;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003006 if (!strcmp(funcName, "vkDestroyBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003007 return (PFN_vkVoidFunction) vkDestroyBufferView;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003008 if (!strcmp(funcName, "vkDestroyShaderModule"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003009 return (PFN_vkVoidFunction) vkDestroyShaderModule;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003010 if (!strcmp(funcName, "vkDestroyShader"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003011 return (PFN_vkVoidFunction) vkDestroyShader;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003012 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003013 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003014 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003015 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003016 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003017 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003018 if (!strcmp(funcName, "vkDestroyRenderPass"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003019 return (PFN_vkVoidFunction) vkDestroyRenderPass;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003020 if (!strcmp(funcName, "vkDestroyFramebuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003021 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003022 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003023 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003024 if (!strcmp(funcName, "vkDestroyDynamicRasterState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003025 return (PFN_vkVoidFunction) vkDestroyDynamicRasterState;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003026 if (!strcmp(funcName, "vkDestroyDynamicColorBlendState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003027 return (PFN_vkVoidFunction) vkDestroyDynamicColorBlendState;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003028 if (!strcmp(funcName, "vkDestroyDynamicDepthStencilState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003029 return (PFN_vkVoidFunction) vkDestroyDynamicDepthStencilState;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003030 if (!strcmp(funcName, "vkBindBufferMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003031 return (PFN_vkVoidFunction) vkBindBufferMemory;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003032 if (!strcmp(funcName, "vkBindImageMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003033 return (PFN_vkVoidFunction) vkBindImageMemory;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003034 if (!strcmp(funcName, "vkGetBufferMemoryRequirements"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003035 return (PFN_vkVoidFunction) vkGetBufferMemoryRequirements;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003036 if (!strcmp(funcName, "vkGetImageMemoryRequirements"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003037 return (PFN_vkVoidFunction) vkGetImageMemoryRequirements;
Mark Lobodzinski942b1722015-05-11 17:21:15 -05003038 if (!strcmp(funcName, "vkQueueBindSparseBufferMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003039 return (PFN_vkVoidFunction) vkQueueBindSparseBufferMemory;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003040 if (!strcmp(funcName, "vkQueueBindSparseImageOpaqueMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003041 return (PFN_vkVoidFunction) vkQueueBindSparseImageOpaqueMemory;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003042 if (!strcmp(funcName, "vkQueueBindSparseImageMemory"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003043 return (PFN_vkVoidFunction) vkQueueBindSparseImageMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003044 if (!strcmp(funcName, "vkCreateFence"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003045 return (PFN_vkVoidFunction) vkCreateFence;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003046 if (!strcmp(funcName, "vkGetFenceStatus"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003047 return (PFN_vkVoidFunction) vkGetFenceStatus;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003048 if (!strcmp(funcName, "vkResetFences"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003049 return (PFN_vkVoidFunction) vkResetFences;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003050 if (!strcmp(funcName, "vkWaitForFences"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003051 return (PFN_vkVoidFunction) vkWaitForFences;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003052 if (!strcmp(funcName, "vkQueueWaitIdle"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003053 return (PFN_vkVoidFunction) vkQueueWaitIdle;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003054 if (!strcmp(funcName, "vkDeviceWaitIdle"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003055 return (PFN_vkVoidFunction) vkDeviceWaitIdle;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003056 if (!strcmp(funcName, "vkCreateEvent"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003057 return (PFN_vkVoidFunction) vkCreateEvent;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003058 if (!strcmp(funcName, "vkCreateQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003059 return (PFN_vkVoidFunction) vkCreateQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003060 if (!strcmp(funcName, "vkCreateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003061 return (PFN_vkVoidFunction) vkCreateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003062 if (!strcmp(funcName, "vkCreateBufferView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003063 return (PFN_vkVoidFunction) vkCreateBufferView;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003064 if (!strcmp(funcName, "vkCreateImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003065 return (PFN_vkVoidFunction) vkCreateImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003066 if (!strcmp(funcName, "vkCreateImageView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003067 return (PFN_vkVoidFunction) vkCreateImageView;
Chia-I Wu08accc62015-07-07 11:50:03 +08003068 if (!strcmp(funcName, "vkCreateAttachmentView"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003069 return (PFN_vkVoidFunction) vkCreateAttachmentView;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003070 if (!strcmp(funcName, "vkCreateShader"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003071 return (PFN_vkVoidFunction) vkCreateShader;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003072 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003073 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
Jon Ashburnc669cc62015-07-09 15:02:25 -06003074 if (!strcmp(funcName, "vkCreateComputePipelines"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003075 return (PFN_vkVoidFunction) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003076 if (!strcmp(funcName, "vkCreateSampler"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003077 return (PFN_vkVoidFunction) vkCreateSampler;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003078 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003079 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003080 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003081 return (PFN_vkVoidFunction) vkCreateDynamicRasterState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003082 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003083 return (PFN_vkVoidFunction) vkCreateDynamicColorBlendState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003084 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003085 return (PFN_vkVoidFunction) vkCreateDynamicDepthStencilState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003086 if (!strcmp(funcName, "vkCreateCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003087 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003088 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003089 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003090 if (!strcmp(funcName, "vkEndCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003091 return (PFN_vkVoidFunction) vkEndCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003092 if (!strcmp(funcName, "vkResetCommandBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003093 return (PFN_vkVoidFunction) vkResetCommandBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003094 if (!strcmp(funcName, "vkCmdBindPipeline"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003095 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003096 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003097 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003098 if (!strcmp(funcName, "vkCmdBindDynamicRasterState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003099 return (PFN_vkVoidFunction) vkCmdBindDynamicRasterState;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003100 if (!strcmp(funcName, "vkCmdBindDynamicColorBlendState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003101 return (PFN_vkVoidFunction) vkCmdBindDynamicColorBlendState;
Tobin Ehlis257d9742015-07-08 17:08:02 -06003102 if (!strcmp(funcName, "vkCmdBindDynamicDepthStencilState"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003103 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthStencilState;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003104 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003105 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06003106 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003107 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003108 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003109 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003110 if (!strcmp(funcName, "vkCmdDrawIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003111 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003112 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003113 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003114 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003115 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003116 if (!strcmp(funcName, "vkCmdCopyBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003117 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003118 if (!strcmp(funcName, "vkCmdCopyImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003119 return (PFN_vkVoidFunction) vkCmdCopyImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003120 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003121 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003122 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003123 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003124 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003125 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003126 if (!strcmp(funcName, "vkCmdFillBuffer"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003127 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003128 if (!strcmp(funcName, "vkCmdClearColorImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003129 return (PFN_vkVoidFunction) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12003130 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003131 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003132 if (!strcmp(funcName, "vkCmdResolveImage"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003133 return (PFN_vkVoidFunction) vkCmdResolveImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003134 if (!strcmp(funcName, "vkCmdBeginQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003135 return (PFN_vkVoidFunction) vkCmdBeginQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003136 if (!strcmp(funcName, "vkCmdEndQuery"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003137 return (PFN_vkVoidFunction) vkCmdEndQuery;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003138 if (!strcmp(funcName, "vkCmdResetQueryPool"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003139 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003140 if (!strcmp(funcName, "vkGetDeviceQueue"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003141 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003142
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -06003143 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Ian Elliott1064fe32015-07-06 14:31:32 -06003144 if (my_device_data->wsi_enabled)
Jon Ashburn747f2b62015-06-18 15:02:58 -06003145 {
Tobin Ehlis6bc1b8e2015-07-13 14:21:59 -06003146// if (!strcmp(funcName, "vkGetSurfaceInfoWSI"))
3147// return (PFN_vkVoidFunction) vkGetSurfaceInfoWSI;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003148 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003149 return (PFN_vkVoidFunction) vkCreateSwapChainWSI;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003150 if (!strcmp(funcName, "vkDestroySwapChainWSI"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003151 return (PFN_vkVoidFunction) vkDestroySwapChainWSI;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003152 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003153 return (PFN_vkVoidFunction) vkGetSwapChainInfoWSI;
Tobin Ehlis6bc1b8e2015-07-13 14:21:59 -06003154// if (!strcmp(funcName, "vkAcquireNextImageWSI"))
3155// return (PFN_vkVoidFunction) vkAcquireNextImageWSI;
3156// if (!strcmp(funcName, "vkQueuePresentWSI"))
3157// return (PFN_vkVoidFunction) vkQueuePresentWSI;
Jon Ashburn747f2b62015-06-18 15:02:58 -06003158 }
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06003159
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -06003160 VkLayerDispatchTable *pDisp = get_dispatch_table(mem_tracker_device_table_map, dev);
3161 if (pDisp->GetDeviceProcAddr == NULL)
3162 return NULL;
3163 return pDisp->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003164}
3165
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003166VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003167 VkInstance instance,
3168 const char *funcName)
3169{
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003170 PFN_vkVoidFunction fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003171 if (instance == NULL) {
3172 return NULL;
3173 }
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06003174
Jon Ashburn8fd08252015-05-28 16:25:02 -06003175 /* loader uses this to force layer initialization; instance object is wrapped */
3176 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06003177 initInstanceTable(mem_tracker_instance_table_map, (const VkBaseLayerObject *) instance);
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003178 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06003179 }
3180
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05003181 if (!strcmp(funcName, "vkDestroyInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003182 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06003183 if (!strcmp(funcName, "vkCreateInstance"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003184 return (PFN_vkVoidFunction) vkCreateInstance;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -06003185 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003186 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06003187 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003188 return (PFN_vkVoidFunction) vkGetGlobalLayerProperties;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06003189 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003190 return (PFN_vkVoidFunction) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06003191 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003192 return (PFN_vkVoidFunction) vkGetPhysicalDeviceLayerProperties;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06003193 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -06003194 return (PFN_vkVoidFunction) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06003195
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06003196 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
3197 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06003198 if (fptr)
3199 return fptr;
3200
Jon Ashburn8fd08252015-05-28 16:25:02 -06003201 {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06003202 if (get_dispatch_table(mem_tracker_instance_table_map, instance)->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06003203 return NULL;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06003204 return get_dispatch_table(mem_tracker_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis6663f492014-11-10 12:29:12 -07003205 }
3206}