blob: 22d6ef3f136a50ec597eeb5505cda846e50426fe [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;
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -060053 bool wsi_lunarg_enabled;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060054} layer_data;
Mark Lobodzinski76c991d2015-05-20 16:16:37 -050055
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060056static std::unordered_map<void *, layer_data *> layer_data_map;
57static device_table_map mem_tracker_device_table_map;
58static instance_table_map mem_tracker_instance_table_map;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -060059static VkPhysicalDeviceMemoryProperties memProps;
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060060
Mark Lobodzinski93f494b2015-03-02 20:23:52 -060061// TODO : This can be much smarter, using separate locks for separate global data
62static int globalLockInitialized = 0;
63static loader_platform_thread_mutex globalLock;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070064
Tobin Ehlisc145be82015-01-08 15:22:32 -070065#define MAX_BINDING 0xFFFFFFFF
Tobin Ehlisc145be82015-01-08 15:22:32 -070066
Mike Stroyandd7aed72015-05-19 17:03:40 -060067unordered_map<VkCmdBuffer, MT_CB_INFO> cbMap;
68unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO> memObjMap;
69unordered_map<VkObject, MT_OBJ_INFO> objectMap;
70unordered_map<VkFence, MT_FENCE_INFO> fenceMap; // Map fence to fence info
71unordered_map<VkQueue, MT_QUEUE_INFO> queueMap;
Mike Stroyan950496e2015-05-19 15:16:08 -060072unordered_map<VkSwapChainWSI, MT_SWAP_CHAIN_INFO*> swapChainMap;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050073
Mark Lobodzinski50932972015-04-02 20:49:09 -050074// TODO : Add per-device fence completion
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060075static uint64_t g_currentFenceId = 1;
Mark Lobodzinskic52b7752015-02-18 16:38:17 -060076
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060077template layer_data *get_my_data_ptr<layer_data>(
78 void *data_key,
79 std::unordered_map<void *, layer_data *> &data_map);
80
81debug_report_data *mdd(VkObject object)
82{
Courtney Goeltzenleuchter62110862015-06-13 21:39:35 -060083 dispatch_key key = get_dispatch_key(object);
84 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Courtney Goeltzenleuchter89d68442015-06-13 21:40:22 -060085#if DISPATCH_MAP_DEBUG
86 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
87#endif
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060088 return my_data->report_data;
89}
90
91debug_report_data *mid(VkInstance object)
92{
Courtney Goeltzenleuchter62110862015-06-13 21:39:35 -060093 dispatch_key key = get_dispatch_key(object);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060094 layer_data *my_data = get_my_data_ptr(get_dispatch_key(object), layer_data_map);
Courtney Goeltzenleuchter89d68442015-06-13 21:40:22 -060095#if DISPATCH_MAP_DEBUG
96 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
97#endif
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -060098 return my_data->report_data;
99}
100
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500101// Add new queue for this device to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500102static void add_queue_info(const VkQueue queue)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500103{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600104 MT_QUEUE_INFO* pInfo = &queueMap[queue];
Mark Lobodzinski50932972015-04-02 20:49:09 -0500105 pInfo->lastRetiredId = 0;
106 pInfo->lastSubmittedId = 0;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500107}
108
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500109static void delete_queue_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600110 void)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500111{
112 // Process queue list, cleaning up each entry before deleting
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500113 queueMap.clear();
114}
115
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500116static void add_swap_chain_info(
Tobin Ehlis41376e12015-07-03 08:45:14 -0600117 const VkSwapChainWSI swapChain, const VkSwapChainCreateInfoWSI* pCI)
Chia-I Wuf8693382015-04-16 22:02:10 +0800118{
119 MT_SWAP_CHAIN_INFO* pInfo = new MT_SWAP_CHAIN_INFO;
Tobin Ehlis41376e12015-07-03 08:45:14 -0600120 memcpy(&pInfo->createInfo, pCI, sizeof(VkSwapChainCreateInfoWSI));
Chia-I Wuf8693382015-04-16 22:02:10 +0800121 swapChainMap[swapChain] = pInfo;
122}
123
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500124// Add new CBInfo for this cb to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500125static void add_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600126 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700127{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600128 cbMap[cb].cmdBuffer = cb;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700129}
130
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500131// Return ptr to Info in CB map, or NULL if not found
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500132static MT_CB_INFO* get_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600133 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700134{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600135 unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator item = cbMap.find(cb);
Mike Stroyan950496e2015-05-19 15:16:08 -0600136 if (item != cbMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600137 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600138 } else {
139 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600140 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700141}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600142
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500143// Return object info for 'object' or return NULL if no info exists
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500144static MT_OBJ_INFO* get_object_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600145 const VkObject object)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500146{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600147 unordered_map<VkObject, MT_OBJ_INFO>::iterator item = objectMap.find(object);
Mike Stroyan950496e2015-05-19 15:16:08 -0600148 if (item != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600149 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600150 } else {
151 return NULL;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500152 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500153}
154
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500155static MT_OBJ_INFO* add_object_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600156 VkObject object,
157 VkStructureType sType,
158 const void *pCreateInfo,
159 const int struct_size,
160 const char *name_prefix)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500161{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600162 MT_OBJ_INFO* pInfo = &objectMap[object];
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500163 memset(pInfo, 0, sizeof(MT_OBJ_INFO));
164 memcpy(&pInfo->create_info, pCreateInfo, struct_size);
165 sprintf(pInfo->object_name, "%s_%p", name_prefix, object);
166
167 pInfo->object = object;
168 pInfo->ref_count = 1;
169 pInfo->sType = sType;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500170
171 return pInfo;
172}
173
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500174// Add a fence, creating one if necessary to our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500175static uint64_t add_fence_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600176 VkFence fence,
177 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500178{
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500179 // Create fence object
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500180 uint64_t fenceId = g_currentFenceId++;
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500181 // If no fence, create an internal fence to track the submissions
Mike Stroyan950496e2015-05-19 15:16:08 -0600182 if (fence != NULL) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600183 fenceMap[fence].fenceId = fenceId;
184 fenceMap[fence].queue = queue;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500185 // Validate that fence is in UNSIGNALED state
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500186 MT_OBJ_INFO* pObjectInfo = get_object_info(fence);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500187 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600188 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600189 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, fence, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM",
190 "Fence %p submitted in SIGNALED state. Fences must be reset before being submitted", fence);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500191 }
192 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700193 }
Mike Stroyan950496e2015-05-19 15:16:08 -0600194 // Update most recently submitted fence and fenceId for Queue
Mike Stroyandd7aed72015-05-19 17:03:40 -0600195 queueMap[queue].lastSubmittedId = fenceId;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500196 return fenceId;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500197}
198
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500199// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500200static void delete_fence_info(
Mike Stroyan950496e2015-05-19 15:16:08 -0600201 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500202{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600203 fenceMap.erase(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500204}
205
Mike Stroyan950496e2015-05-19 15:16:08 -0600206// Record information when a fence is known to be signalled
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500207static void update_fence_tracking(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600208 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500209{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600210 unordered_map<VkFence, MT_FENCE_INFO>::iterator fence_item = fenceMap.find(fence);
Mike Stroyan950496e2015-05-19 15:16:08 -0600211 if (fence_item != fenceMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600212 MT_FENCE_INFO *pCurFenceInfo = &(*fence_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600213 VkQueue queue = pCurFenceInfo->queue;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600214 unordered_map<VkQueue, MT_QUEUE_INFO>::iterator queue_item = queueMap.find(queue);
Mike Stroyan950496e2015-05-19 15:16:08 -0600215 if (queue_item != queueMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600216 MT_QUEUE_INFO *pQueueInfo = &(*queue_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600217 if (pQueueInfo->lastRetiredId < pCurFenceInfo->fenceId) {
218 pQueueInfo->lastRetiredId = pCurFenceInfo->fenceId;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500219 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500220 }
221 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500222
Mike Stroyan950496e2015-05-19 15:16:08 -0600223 // Update fence state in fenceCreateInfo structure
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500224 MT_OBJ_INFO* pObjectInfo = get_object_info(fence);
Mike Stroyan950496e2015-05-19 15:16:08 -0600225 if (pObjectInfo != NULL) {
226 pObjectInfo->create_info.fence_create_info.flags =
227 static_cast<VkFenceCreateFlags>(
228 pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500229 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500230}
231
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500232// Helper routine that updates the fence list for a specific queue to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500233static void retire_queue_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600234 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500235{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600236 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
237 // Set queue's lastRetired to lastSubmitted indicating all fences completed
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600238 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700239}
240
Mike Stroyandd7aed72015-05-19 17:03:40 -0600241// Helper routine that updates all queues to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500242static void retire_device_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600243 VkDevice device)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500244{
245 // Process each queue for device
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600246 // TODO: Add multiple device support
Mike Stroyandd7aed72015-05-19 17:03:40 -0600247 for (unordered_map<VkQueue, MT_QUEUE_INFO>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
248 // Set queue's lastRetired to lastSubmitted indicating all fences completed
249 MT_QUEUE_INFO *pQueueInfo = &(*ii).second;
250 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500251 }
252}
Tobin Ehlis41376e12015-07-03 08:45:14 -0600253// Helper function to validate correct usage bits set for buffers or images
254// Verify that (actual & desired) flags != 0 or,
255// if strict is true, verify that (actual & desired) flags == desired
256// In case of error, report it via dbg callbacks
David Pinedo38310942015-07-09 16:23:44 -0600257static void validate_usage_flags(void* disp_obj, VkFlags actual, VkFlags desired,
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600258 VkBool32 strict, VkObject obj, VkObjectType obj_type,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600259 char const* ty_str, char const* func_name, char const* usage_str)
260{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600261 VkBool32 correct_usage = VK_FALSE;
Tobin Ehlis41376e12015-07-03 08:45:14 -0600262 if (strict)
263 correct_usage = ((actual & desired) == desired);
264 else
265 correct_usage = ((actual & desired) != 0);
266 if (!correct_usage) {
267 log_msg(mdd((VkObject)disp_obj), VK_DBG_REPORT_ERROR_BIT, obj_type, obj, 0, MEMTRACK_INVALID_USAGE_FLAG, "MEM",
268 "Invalid usage flag for %s %p used by %s. In this case, %s should have %s set during creation.",
269 ty_str, obj, func_name, ty_str, usage_str);
270 }
271}
272// Helper function to validate usage flags for images
273// Pulls image info and then sends actual vs. desired usage off to helper above where
274// an error will be flagged if usage is not correct
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600275static void validate_image_usage_flags(void* disp_obj, VkImage image, VkFlags desired, VkBool32 strict,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600276 char const* func_name, char const* usage_string)
277{
278 MT_OBJ_INFO* pInfo = get_object_info(image);
279 if (pInfo) {
280 validate_usage_flags(disp_obj, pInfo->create_info.image_create_info.usage, desired, strict,
281 image, VK_OBJECT_TYPE_IMAGE, "image", func_name, usage_string);
282 }
283}
284// Helper function to validate usage flags for buffers
285// Pulls buffer info and then sends actual vs. desired usage off to helper above where
286// an error will be flagged if usage is not correct
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600287static void validate_buffer_usage_flags(void* disp_obj, VkBuffer buffer, VkFlags desired, VkBool32 strict,
Tobin Ehlis41376e12015-07-03 08:45:14 -0600288 char const* func_name, char const* usage_string)
289{
290 MT_OBJ_INFO* pInfo = get_object_info(buffer);
291 if (pInfo) {
292 validate_usage_flags(disp_obj, pInfo->create_info.buffer_create_info.usage, desired, strict,
293 buffer, VK_OBJECT_TYPE_BUFFER, "buffer", func_name, usage_string);
294 }
295}
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500296// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700297// Calls to this function should be wrapped in mutex
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500298static MT_MEM_OBJ_INFO* get_mem_obj_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600299 const VkDeviceMemory mem)
Tobin Ehlisc145be82015-01-08 15:22:32 -0700300{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600301 unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator item = memObjMap.find(mem);
Mike Stroyan950496e2015-05-19 15:16:08 -0600302 if (item != memObjMap.end()) {
Courtney Goeltzenleuchter10100442015-06-13 21:36:49 -0600303 assert((*item).second.object != VK_NULL_HANDLE);
Mike Stroyandd7aed72015-05-19 17:03:40 -0600304 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600305 } else {
306 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600307 }
Tobin Ehlisc145be82015-01-08 15:22:32 -0700308}
309
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500310static void add_mem_obj_info(
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600311 const VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600312 const VkDeviceMemory mem,
313 const VkMemoryAllocInfo *pAllocInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700314{
Courtney Goeltzenleuchter17fd5ce2015-06-13 21:29:26 -0600315 assert(object != NULL);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600316
Chia-I Wuf8693382015-04-16 22:02:10 +0800317 if (pAllocInfo) { // MEM alloc created by vkCreateSwapChainWSI() doesn't have alloc info struct
Mike Stroyandd7aed72015-05-19 17:03:40 -0600318 memcpy(&memObjMap[mem].allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500319 // TODO: Update for real hardware, actually process allocation info structures
Mike Stroyandd7aed72015-05-19 17:03:40 -0600320 memObjMap[mem].allocInfo.pNext = NULL;
321 } else {
322 memset(&memObjMap[mem].allocInfo, 0, sizeof(VkMemoryAllocInfo));
Tobin Ehlis6663f492014-11-10 12:29:12 -0700323 }
Courtney Goeltzenleuchter17fd5ce2015-06-13 21:29:26 -0600324 memObjMap[mem].object = object;
325 memObjMap[mem].refCount = 0;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600326 memObjMap[mem].mem = mem;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700327}
328
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500329// Find CB Info and add mem reference to list container
330// Find Mem Obj Info and add CB reference to list container
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600331static VkBool32 update_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600332 const VkCmdBuffer cb,
333 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700334{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600335 VkBool32 result = VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700336 // First update CB binding in MemObj mini CB list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500337 MT_MEM_OBJ_INFO* pMemInfo = get_mem_obj_info(mem);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500338 if (!pMemInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600339 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
340 "Trying to bind mem obj %p to CB %p but no info for that mem obj.\n "
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600341 "Was it correctly allocated? Did it already get freed?", mem, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600342 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600343 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500344 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600345 VkBool32 found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600346 if (pMemInfo->pCmdBufferBindings.size() > 0) {
347 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
348 if ((*it) == cb) {
349 found = VK_TRUE;
350 break;
351 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500352 }
353 }
354 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600355 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500356 pMemInfo->pCmdBufferBindings.push_front(cb);
357 pMemInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500358 }
359
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500360 // Now update CBInfo's Mem reference list
361 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
362 // 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 -0500363 if (!pCBInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600364 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
365 "Trying to bind mem obj %p to CB %p but no info for that CB. Was CB incorrectly destroyed?", mem, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600366 result = VK_FALSE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500367 } else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500368 // Search for memory object in cmd buffer's reference list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600369 VkBool32 found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600370 if (pCBInfo->pMemObjList.size() > 0) {
371 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
372 if ((*it) == mem) {
373 found = VK_TRUE;
374 break;
375 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500376 }
377 }
378 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600379 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500380 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600381 }
382 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700383 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600384 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700385}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600386
Tobin Ehlis6663f492014-11-10 12:29:12 -0700387// Clear the CB Binding for mem
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500388// Calls to this function should be wrapped in mutex
389static void remove_cmd_buf_and_mem_reference(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600390 const VkCmdBuffer cb,
391 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700392{
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500393 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500394 // TODO : Having this check is not ideal, really if memInfo was deleted,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500395 // its CB bindings should be cleared and then clear_cmd_buf_and_mem_references wouldn't call
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700396 // us here with stale mem objs
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500397 if (pInfo) {
398 pInfo->pCmdBufferBindings.remove(cb);
399 pInfo->refCount--;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700400 }
401}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600402
Tobin Ehlis6663f492014-11-10 12:29:12 -0700403// Free bindings related to CB
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600404static VkBool32 clear_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600405 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700406{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600407 VkBool32 result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500408 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500409 if (!pCBInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600410 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_CB, "MEM",
411 "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600412 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600413 } else {
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600414 if (pCBInfo->pMemObjList.size() > 0) {
415 list<VkDeviceMemory> mem_obj_list = pCBInfo->pMemObjList;
416 for (list<VkDeviceMemory>::iterator it=mem_obj_list.begin(); it!=mem_obj_list.end(); ++it) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500417 remove_cmd_buf_and_mem_reference(cb, (*it));
David Pinedod8f83d82015-04-27 16:36:17 -0600418 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600419 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500420 pCBInfo->pMemObjList.clear();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700421 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600422 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700423}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600424
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500425// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500426// and also clear mem references to CB
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600427static VkBool32 delete_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600428 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700429{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600430 VkBool32 result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500431 result = clear_cmd_buf_and_mem_references(cb);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500432 // Delete the CBInfo info
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600433 if (result == VK_TRUE) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600434 cbMap.erase(cb);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700435 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600436 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700437}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600438
Tobin Ehlis6663f492014-11-10 12:29:12 -0700439// Delete the entire CB list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600440static VkBool32 delete_cmd_buf_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600441 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700442{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600443 for (unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500444 clear_cmd_buf_and_mem_references((*ii).first);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700445 }
Mike Stroyandd7aed72015-05-19 17:03:40 -0600446 cbMap.clear();
447 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700448}
449
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500450// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600451static void reportMemReferencesAndCleanUp(
452 MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700453{
Tony Barbour18f71552015-04-22 11:36:22 -0600454 size_t cmdBufRefCount = pMemObjInfo->pCmdBufferBindings.size();
455 size_t objRefCount = pMemObjInfo->pObjBindings.size();
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500456
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500457 if ((pMemObjInfo->pCmdBufferBindings.size() + pMemObjInfo->pObjBindings.size()) != 0) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600458 log_msg(mdd(pMemObjInfo->object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
459 "Attempting to free memory object %p which still contains %lu references",
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600460 pMemObjInfo->mem, (cmdBufRefCount + objRefCount));
Tobin Ehlis6663f492014-11-10 12:29:12 -0700461 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500462
David Pinedod8f83d82015-04-27 16:36:17 -0600463 if (cmdBufRefCount > 0 && pMemObjInfo->pCmdBufferBindings.size() > 0) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500464 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600465 log_msg(mdd(pMemObjInfo->object), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (*it), 0, MEMTRACK_NONE, "MEM",
466 "Command Buffer %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500467 }
468 // Clear the list of hanging references
469 pMemObjInfo->pCmdBufferBindings.clear();
470 }
471
David Pinedod8f83d82015-04-27 16:36:17 -0600472 if (objRefCount > 0 && pMemObjInfo->pObjBindings.size() > 0) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500473 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600474 /* TODO: Would be nice to return the actual object type */
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600475 log_msg(mdd(pMemObjInfo->object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, (*it), 0, MEMTRACK_NONE, "MEM",
476 "VK Object %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
Mark Lobodzinski6568f912015-06-11 16:11:20 -0500477
478 // Found an object referencing this memory, remove its pointer to this memobj
479 MT_OBJ_INFO *pObjInfo = get_object_info(*it);
480 pObjInfo->pMemObjInfo = NULL;
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500481 }
482 // Clear the list of hanging references
483 pMemObjInfo->pObjBindings.clear();
484 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500485
Tobin Ehlis6663f492014-11-10 12:29:12 -0700486}
487
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600488static void deleteMemObjInfo(
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600489 VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600490 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700491{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600492 unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator item = memObjMap.find(mem);
Mike Stroyan950496e2015-05-19 15:16:08 -0600493 if (item != memObjMap.end()) {
Mike Stroyan950496e2015-05-19 15:16:08 -0600494 memObjMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700495 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500496 else {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600497 log_msg(mdd(object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
498 "Request to delete memory object %p not present in memory Object Map", mem);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500499 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700500}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500501
Tobin Ehlis6663f492014-11-10 12:29:12 -0700502// Check if fence for given CB is completed
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600503static VkBool32 checkCBCompleted(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600504 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700505{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600506 VkBool32 result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500507 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500508 if (!pCBInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600509 log_msg(mdd(cb), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_CB, "MEM",
510 "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600511 result = VK_FALSE;
Mike Stroyan950496e2015-05-19 15:16:08 -0600512 } else if (pCBInfo->lastSubmittedQueue != NULL) {
513 VkQueue queue = pCBInfo->lastSubmittedQueue;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600514 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
Mike Stroyan950496e2015-05-19 15:16:08 -0600515 if (pCBInfo->fenceId > pQueueInfo->lastRetiredId) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600516 log_msg(mdd(cb), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_NONE, "MEM",
517 "fence %p for CB %p has not been checked for completion",
518 (void*)pCBInfo->lastSubmittedFence, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600519 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600520 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700521 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600522 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700523}
524
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600525static VkBool32 freeMemObjInfo(
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600526 VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600527 VkDeviceMemory mem,
528 bool internal)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700529{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600530 VkBool32 result = VK_TRUE;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500531 // Parse global list to find info w/ mem
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500532 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500533 if (!pInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600534 log_msg(mdd(object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
535 "Couldn't find mem info object for %p\n Was %p never allocated or previously freed?",
536 (void*)mem, (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600537 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600538 } else {
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -0600539 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600540 log_msg(mdd(pInfo->object), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
541 "Attempting to free memory associated with a Persistent Image, %p, "
542 "this should not be explicitly freed\n", (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600543 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600544 } else {
545 // Clear any CB bindings for completed CBs
546 // TODO : Is there a better place to do this?
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500547
Courtney Goeltzenleuchter10100442015-06-13 21:36:49 -0600548 assert(pInfo->object != VK_NULL_HANDLE);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600549 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
550 list<VkCmdBuffer>::iterator temp;
David Pinedod8f83d82015-04-27 16:36:17 -0600551 while (pInfo->pCmdBufferBindings.size() > 0 && it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600552 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500553 temp = it;
554 ++temp;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500555 clear_cmd_buf_and_mem_references(*it);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500556 it = temp;
557 } else {
558 ++it;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600559 }
560 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500561
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600562 // Now verify that no references to this mem obj remain
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500563 if (0 != pInfo->refCount) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500564 reportMemReferencesAndCleanUp(pInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600565 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600566 }
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600567 // Delete mem obj info
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600568 deleteMemObjInfo(object, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700569 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700570 }
571 return result;
572}
573
Tobin Ehlis6663f492014-11-10 12:29:12 -0700574// Remove object binding performs 3 tasks:
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500575// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
576// 2. Decrement refCount for MemObjInfo
577// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600578static VkBool32 clear_object_binding(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600579 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700580{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600581 VkBool32 result = VK_FALSE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500582 MT_OBJ_INFO* pObjInfo = get_object_info(object);
583 if (pObjInfo) {
David Pinedod8f83d82015-04-27 16:36:17 -0600584 if (!pObjInfo->pMemObjInfo || pObjInfo->pMemObjInfo->pObjBindings.size() <= 0) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600585 log_msg(mdd(object), VK_DBG_REPORT_WARN_BIT, (VkObjectType) 0, object, 0, MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, "MEM",
586 "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600587 } else {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500588 // 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
589 // and set the objects memory binding pointer to NULL.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600590 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500591 if ((*it) == object) {
592 pObjInfo->pMemObjInfo->refCount--;
593 pObjInfo->pMemObjInfo->pObjBindings.erase(it);
594 pObjInfo->pMemObjInfo = NULL;
595 result = VK_TRUE;
596 break;
597 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600598 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600599 if (result == VK_FALSE) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600600 log_msg(mdd(object), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
601 "While trying to clear mem binding for object %p, unable to find that object referenced by mem obj %p",
602 object, pObjInfo->pMemObjInfo->mem);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600603 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700604 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700605 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600606 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700607}
608
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500609// For NULL mem case, output warning
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500610// Make sure given object is in global object map
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500611// IF a previous binding existed, output validation error
612// Otherwise, add reference from objectInfo to memoryInfo
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500613// Add reference off of objInfo
Courtney Goeltzenleuchter540d3492015-06-13 21:37:34 -0600614// device is required for error logging, need a dispatchable
615// object for that.
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600616// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600617static VkBool32 set_object_binding(
Courtney Goeltzenleuchter540d3492015-06-13 21:37:34 -0600618 VkObject dispatch_object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600619 VkObject object,
620 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700621{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600622 VkBool32 result = VK_FALSE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700623 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600624 if (mem == VK_NULL_HANDLE) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600625 log_msg(mdd(dispatch_object), VK_DBG_REPORT_WARN_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
626 "Attempting to Bind Obj(%p) to NULL", (void*)object);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500627 return VK_TRUE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600628 } else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500629 MT_OBJ_INFO* pObjInfo = get_object_info(object);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500630 if (!pObjInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600631 log_msg(mdd(dispatch_object), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
632 "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600633 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600634 }
635 // non-null case so should have real mem obj
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500636 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
637 if (!pInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600638 log_msg(mdd(dispatch_object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
639 "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500640 return VK_FALSE;
641 } else {
642 if (pObjInfo->pMemObjInfo != NULL) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600643 log_msg(mdd(dispatch_object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_REBIND_OBJECT, "MEM",
644 "Attempting to bind memory (%p) to object (%p) which has already been bound to mem object %p",
645 (void*)mem, (void*)object, (void*)pObjInfo->pMemObjInfo->mem);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500646 return VK_FALSE;
647 }
648 else {
649 pInfo->pObjBindings.push_front(object);
650 pInfo->refCount++;
651
652 // For image objects, make sure default memory state is correctly set
653 // TODO : What's the best/correct way to handle this?
654 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
655 if (pObjInfo->create_info.image_create_info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
656 VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)) {
657 // TODO:: More memory state transition stuff.
658 }
659 }
660 pObjInfo->pMemObjInfo = pInfo;
661 }
662 }
663 }
664 return VK_TRUE;
665}
666
667// For NULL mem case, clear any previous binding Else...
668// Make sure given object is in global object map
669// IF a previous binding existed, update binding
670// Add reference from objectInfo to memoryInfo
671// Add reference off of objInfo
672// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600673static VkBool32 set_sparse_buffer_binding(
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500674 VkObject object,
675 VkDeviceMemory mem)
676{
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600677 VkBool32 result = VK_FALSE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500678 // Handle NULL case separately, just clear previous binding & decrement reference
679 if (mem == VK_NULL_HANDLE) {
680 clear_object_binding(object);
681 return VK_TRUE;
682 } else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500683 MT_OBJ_INFO* pObjInfo = get_object_info(object);
684 if (!pObjInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600685 log_msg(mdd(object), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
686 "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500687 return VK_FALSE;
688 }
689 // non-null case so should have real mem obj
690 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600691 if (!pInfo) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600692 log_msg(mdd(object), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM",
693 "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500694 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600695 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500696 // Search for object in memory object's binding list
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600697 VkBool32 found = VK_FALSE;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600698 if (pInfo->pObjBindings.size() > 0) {
699 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
700 if ((*it) == object) {
701 found = VK_TRUE;
702 break;
703 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600704 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600705 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500706 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600707 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500708 pInfo->pObjBindings.push_front(object);
709 pInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500710 }
711
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500712 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500713 clear_object_binding(object); // Need to clear the previous object binding before setting new binding
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600714 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, object, 0, MEMTRACK_NONE, "MEM",
715 "Updating memory binding for object %p from mem obj %p to %p", object, pObjInfo->pMemObjInfo->mem, mem);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500716 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500717 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis8be20fd2015-01-07 17:49:29 -0700718 }
719 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600720 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700721}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600722
Tobin Ehlis6663f492014-11-10 12:29:12 -0700723// Print details of global Obj tracking list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500724static void print_object_list(
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600725 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700726{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500727 MT_OBJ_INFO* pInfo = NULL;
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600728 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
729 "Details of Object list of size %lu elements", objectMap.size());
David Pinedod8f83d82015-04-27 16:36:17 -0600730 if (objectMap.size() <= 0)
731 return;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600732 for (unordered_map<VkObject, MT_OBJ_INFO>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
733 pInfo = &(*ii).second;
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600734 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, pInfo->object, 0, MEMTRACK_NONE, "MEM",
735 " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700736 }
737}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600738
Tobin Ehlis6663f492014-11-10 12:29:12 -0700739// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500740static VkDeviceMemory get_mem_binding_from_object(
Jon Ashburna79828d2015-06-18 17:12:57 -0600741 const VkObject dispObj, const VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700742{
Tony Barbourd1c35722015-04-16 15:59:00 -0600743 VkDeviceMemory mem = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500744 MT_OBJ_INFO* pObjInfo = get_object_info(object);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500745 if (pObjInfo) {
746 if (pObjInfo->pMemObjInfo) {
747 mem = pObjInfo->pMemObjInfo->mem;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600748 } else {
Jon Ashburna79828d2015-06-18 17:12:57 -0600749 log_msg(mdd(dispObj), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600750 "Trying to get mem binding for object %p but object has no mem binding", (void*)object);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600751 print_object_list(object);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700752 }
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600753 } else {
Jon Ashburna79828d2015-06-18 17:12:57 -0600754 log_msg(mdd(dispObj), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM",
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600755 "Trying to get mem binding for object %p but no such object in global list", (void*)object);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600756 print_object_list(object);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700757 }
758 return mem;
759}
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500760
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500761// Print details of MemObjInfo list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500762static void print_mem_list(
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600763 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700764{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500765 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700766 // Just printing each msg individually for now, may want to package these into single large print
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600767 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
768 "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500769
David Pinedod8f83d82015-04-27 16:36:17 -0600770 if (memObjMap.size() <= 0)
771 return;
772
Mike Stroyandd7aed72015-05-19 17:03:40 -0600773 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
774 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500775
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600776 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
777 " ===MemObjInfo at %p===", (void*)pInfo);
778 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
779 " Mem object: %p", (void*)pInfo->mem);
780 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
781 " Ref Count: %u", pInfo->refCount);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500782 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600783 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600784 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
785 " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500786 } else {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600787 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
788 " Mem Alloc info is NULL (alloc done by vkCreateSwapChainWSI())");
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500789 }
790
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600791 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
792 " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
David Pinedod8f83d82015-04-27 16:36:17 -0600793 if (pInfo->pObjBindings.size() > 0) {
794 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600795 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
796 " VK OBJECT %p", (*it));
David Pinedod8f83d82015-04-27 16:36:17 -0600797 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500798 }
799
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600800 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
801 " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
David Pinedod8f83d82015-04-27 16:36:17 -0600802 if (pInfo->pCmdBufferBindings.size() > 0)
803 {
804 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600805 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
806 " VK CB %p", (*it));
David Pinedod8f83d82015-04-27 16:36:17 -0600807 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700808 }
809 }
810}
811
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600812static void printCBList(
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600813 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700814{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500815 MT_CB_INFO* pCBInfo = NULL;
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600816 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
817 "Details of CB list of size %lu elements", cbMap.size());
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500818
David Pinedod8f83d82015-04-27 16:36:17 -0600819 if (cbMap.size() <= 0)
820 return;
821
Mike Stroyandd7aed72015-05-19 17:03:40 -0600822 for (unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
823 pCBInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500824
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600825 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
826 " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
827 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
828 (void*)pCBInfo->lastSubmittedFence);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500829
David Pinedod8f83d82015-04-27 16:36:17 -0600830 if (pCBInfo->pMemObjList.size() <= 0)
831 continue;
Tony Barbourd1c35722015-04-16 15:59:00 -0600832 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600833 log_msg(mdd(object), VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM",
834 " Mem obj %p", (*it));
Tobin Ehlis6663f492014-11-10 12:29:12 -0700835 }
836 }
837}
838
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600839static void init_mem_tracker(
840 layer_data *my_data)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700841{
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600842 uint32_t report_flags = 0;
843 uint32_t debug_action = 0;
844 FILE *log_output = NULL;
845 const char *option_str;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700846 // initialize MemTracker options
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600847 report_flags = getLayerOptionFlags("MemTrackerReportFlags", 0);
848 getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &debug_action);
Tobin Ehlisee702232015-01-08 14:26:53 -0700849
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600850 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700851 {
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600852 option_str = getLayerOption("MemTrackerLogFilename");
853 if (option_str) {
854 log_output = fopen(option_str, "w");
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700855 }
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600856 if (log_output == NULL) {
857 log_output = stdout;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600858 }
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600859
860 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 -0700861 }
862
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600863 if (!globalLockInitialized)
864 {
865 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600866 // suggestion is to call this during vkCreateInstance(), and then we
867 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600868 // that the layer have per-instance locks. We need to come back and
869 // address this soon.
870 loader_platform_thread_create_mutex(&globalLock);
871 globalLockInitialized = 1;
872 }
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600873
874 // Zero out memory property data
875 memset(&memProps, 0, sizeof(VkPhysicalDeviceMemoryProperties));
Tobin Ehlis6663f492014-11-10 12:29:12 -0700876}
877
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500878// hook DestroyInstance to remove tableInstanceMap entry
879VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
880{
Jeremy Hayes35f8afc2015-06-18 10:25:55 -0600881 // Grab the key before the instance is destroyed.
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600882 dispatch_key key = get_dispatch_key(instance);
883 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, instance);
884 VkResult res = pTable->DestroyInstance(instance);
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600885
886 // Clean up logging callback, if any
Courtney Goeltzenleuchter095e6772015-06-16 16:58:52 -0600887 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600888 if (my_data->logging_callback) {
889 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
890 }
891
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600892 layer_debug_report_destroy_instance(mid(instance));
893 layer_data_map.erase(pTable);
894
895 mem_tracker_instance_table_map.erase(key);
896 assert(mem_tracker_instance_table_map.size() == 0 && "Should not have any instance mappings hanging around");
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500897 return res;
898}
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600899
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600900VkResult VKAPI vkCreateInstance(
901 const VkInstanceCreateInfo* pCreateInfo,
902 VkInstance* pInstance)
903{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600904 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, *pInstance);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -0600905 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600906
907 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600908 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
909 my_data->report_data = debug_report_create_instance(
910 pTable,
911 *pInstance,
912 pCreateInfo->extensionCount,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600913 pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter6f484322015-06-14 11:37:01 -0600914
915 init_mem_tracker(my_data);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600916 }
917 return result;
918}
919
Jon Ashburn747f2b62015-06-18 15:02:58 -0600920static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
921{
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -0600922 uint32_t i;
923 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
924 my_device_data->wsi_lunarg_enabled = false;
925 for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600926 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_WSI_LUNARG_EXTENSION_NAME) == 0)
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -0600927 my_device_data->wsi_lunarg_enabled = true;
Jon Ashburn747f2b62015-06-18 15:02:58 -0600928
929 }
930}
931
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600932VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
933 VkPhysicalDevice gpu,
934 const VkDeviceCreateInfo *pCreateInfo,
935 VkDevice *pDevice)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700936{
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600937 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(mem_tracker_device_table_map, *pDevice);
938 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600939 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600940 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600941 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
942 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Jon Ashburn747f2b62015-06-18 15:02:58 -0600943 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600944 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700945 return result;
946}
947
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600948VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(
949 VkDevice device)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700950{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600951 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600952 log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_NONE, "MEM",
953 "Printing List details prior to vkDestroyDevice()");
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600954 print_mem_list(device);
955 printCBList(device);
956 print_object_list(device);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500957 if (VK_FALSE == delete_cmd_buf_info_list()) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600958 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM",
959 "Issue deleting global CB list in vkDestroyDevice()");
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700960 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700961 // Report any memory leaks
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500962 MT_MEM_OBJ_INFO* pInfo = NULL;
David Pinedod8f83d82015-04-27 16:36:17 -0600963 if (memObjMap.size() > 0) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600964 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
965 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500966
David Pinedod8f83d82015-04-27 16:36:17 -0600967 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -0600968 log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM",
969 "Mem Object %p has not been freed. You should clean up this memory by calling "
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600970 "vkFreeMemory(%p) prior to vkDestroyDevice().", pInfo->mem, pInfo->mem);
David Pinedod8f83d82015-04-27 16:36:17 -0600971 }
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600972 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700973 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500974
975 // Queues persist until device is destroyed
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500976 delete_queue_info_list();
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500977
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -0600978 layer_debug_report_destroy_device(device);
979
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600980 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500981
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600982 dispatch_key key = get_dispatch_key(device);
Courtney Goeltzenleuchter89d68442015-06-13 21:40:22 -0600983#if DISPATCH_MAP_DEBUG
984 fprintf(stderr, "Device: %p, key: %p\n", device, key);
985#endif
Jon Ashburn747f2b62015-06-18 15:02:58 -0600986 VkLayerDispatchTable *pDisp = get_dispatch_table(mem_tracker_device_table_map, device);
987 VkResult result = pDisp->DestroyDevice(device);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -0600988 mem_tracker_device_table_map.erase(key);
Courtney Goeltzenleuchter10100442015-06-13 21:36:49 -0600989 assert(mem_tracker_device_table_map.size() == 0 && "Should not have any instance mappings hanging around");
Jon Ashburn747f2b62015-06-18 15:02:58 -0600990
Tobin Ehlis6663f492014-11-10 12:29:12 -0700991 return result;
992}
993
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -0600994VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(
995 VkPhysicalDevice physicalDevice,
996 VkPhysicalDeviceMemoryProperties *pMemoryProperties)
997{
998 VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(mem_tracker_instance_table_map, physicalDevice);
999 VkResult result = pInstanceTable->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
1000 if (result == VK_SUCCESS) {
1001 // copy mem props to local var...
1002 memcpy(&memProps, pMemoryProperties, sizeof(VkPhysicalDeviceMemoryProperties));
1003 }
1004 return result;
1005}
1006
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001007static const VkLayerProperties mtGlobalLayers[] = {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001008 {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001009 "MemTracker",
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001010 VK_API_VERSION,
1011 VK_MAKE_VERSION(0, 1, 0),
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001012 "Validation layer: MemTracker",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001013 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001014};
1015
Tony Barbour59a47322015-06-24 16:06:58 -06001016VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001017 const char *pLayerName,
1018 uint32_t *pCount,
1019 VkExtensionProperties* pProperties)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001020{
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001021 /* Mem tracker does not have any global extensions */
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001022 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Tony Barbour59a47322015-06-24 16:06:58 -06001023}
1024
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001025VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(
1026 uint32_t *pCount,
1027 VkLayerProperties* pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -06001028{
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001029 return util_GetLayerProperties(ARRAY_SIZE(mtGlobalLayers),
1030 mtGlobalLayers,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001031 pCount, pProperties);
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001032}
1033
Tony Barbour59a47322015-06-24 16:06:58 -06001034VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionProperties(
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001035 VkPhysicalDevice physicalDevice,
1036 const char* pLayerName,
1037 uint32_t* pCount,
1038 VkExtensionProperties* pProperties)
Tony Barbour59a47322015-06-24 16:06:58 -06001039{
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001040 /* Mem tracker does not have any physical device extensions */
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001041 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001042}
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001043
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001044VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(
1045 VkPhysicalDevice physicalDevice,
1046 uint32_t* pCount,
1047 VkLayerProperties* pProperties)
1048{
1049 /* Mem tracker's physical device layers are the same as global */
Courtney Goeltzenleuchtere7481332015-07-07 10:04:16 -06001050 return util_GetLayerProperties(ARRAY_SIZE(mtGlobalLayers), mtGlobalLayers,
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001051 pCount, pProperties);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001052}
1053
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001054VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(
1055 VkDevice device,
1056 uint32_t queueNodeIndex,
1057 uint32_t queueIndex,
1058 VkQueue *pQueue)
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001059{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001060 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001061 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001062 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001063 add_queue_info(*pQueue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001064 loader_platform_thread_unlock_mutex(&globalLock);
1065 }
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001066 return result;
1067}
1068
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001069VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1070 VkQueue queue,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001071 uint32_t cmdBufferCount,
1072 const VkCmdBuffer *pCmdBuffers,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001073 VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001074{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001075 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001076 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001077 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001078 uint64_t fenceId = add_fence_info(fence, queue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001079
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001080 print_mem_list(queue);
1081 printCBList(queue);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001082 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001083 pCBInfo = get_cmd_buf_info(pCmdBuffers[i]);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001084 pCBInfo->fenceId = fenceId;
Mike Stroyan950496e2015-05-19 15:16:08 -06001085 pCBInfo->lastSubmittedFence = fence;
1086 pCBInfo->lastSubmittedQueue = queue;
Tobin Ehlis6663f492014-11-10 12:29:12 -07001087 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001088
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001089 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001090 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueSubmit(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001091 queue, cmdBufferCount, pCmdBuffers, fence);
Courtney Goeltzenleuchterd3fb9552015-04-02 13:39:07 -06001092 return result;
1093}
1094
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001095VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(
1096 VkDevice device,
1097 const VkMemoryAllocInfo *pAllocInfo,
1098 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001099{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001100 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001101 // TODO : Track allocations and overall size here
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001102 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001103 add_mem_obj_info(device, *pMem, pAllocInfo);
1104 print_mem_list(device);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001105 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001106 return result;
1107}
1108
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001109VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(
1110 VkDevice device,
1111 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001112{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001113 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisc0418f92014-11-25 14:47:20 -07001114 * freeing a memory object, an application must ensure the memory object is unbound from
1115 * all API objects referencing it and that it is not referenced by any queued command buffers
1116 */
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001117 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001118 VkBool32 noerror = freeMemObjInfo(device, mem, false);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001119 print_mem_list(device);
1120 print_object_list(device);
1121 printCBList(device);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001122 // Output an warning message for proper error/warning handling
1123 if (noerror == VK_FALSE) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001124 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM",
1125 "Freeing memory object while it still has references: mem obj %p", (void*)mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001126 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001127 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001128 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->FreeMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001129 return result;
1130}
1131
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001132VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(
1133 VkDevice device,
1134 VkDeviceMemory mem,
1135 VkDeviceSize offset,
1136 VkDeviceSize size,
1137 VkFlags flags,
1138 void **ppData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001139{
1140 // TODO : Track when memory is mapped
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001141 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001142 MT_MEM_OBJ_INFO *pMemObj = get_mem_obj_info(mem);
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -06001143 if ((memProps.memoryTypes[pMemObj->allocInfo.memoryTypeIndex].propertyFlags &
1144 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001145 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_STATE, "MEM",
1146 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set: mem obj %p", (void*)mem);
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001147 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001148 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001149 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 -07001150 return result;
1151}
1152
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001153VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(
1154 VkDevice device,
1155 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001156{
1157 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1158 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001159 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->UnmapMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001160 return result;
1161}
1162
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001163VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(
1164 VkDevice device,
1165 VkObjectType objType,
1166 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001167{
Mike Stroyandd7aed72015-05-19 17:03:40 -06001168 unordered_map<VkObject, MT_OBJ_INFO>::iterator item;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001169 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001170
Mike Stroyan950496e2015-05-19 15:16:08 -06001171 // First check if this is a CmdBuffer or fence
1172 switch (objType) {
1173 case VK_OBJECT_TYPE_COMMAND_BUFFER:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001174 delete_cmd_buf_info((VkCmdBuffer)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001175 break;
1176 case VK_OBJECT_TYPE_FENCE:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001177 delete_fence_info((VkFence)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001178 break;
1179 default:
1180 break;
Tobin Ehlisa98df732014-11-27 07:52:04 -07001181 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001182
Mike Stroyan950496e2015-05-19 15:16:08 -06001183 if ((item = objectMap.find(object)) != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -06001184 MT_OBJ_INFO* pDelInfo = &(*item).second;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001185 if (pDelInfo->pMemObjInfo) {
Tobin Ehlisa98df732014-11-27 07:52:04 -07001186 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001187 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Tony Barbourd1c35722015-04-16 15:59:00 -06001188 VkDeviceMemory memToFree = pDelInfo->pMemObjInfo->mem;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001189 clear_object_binding(object);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001190 freeMemObjInfo(device, memToFree, true);
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -06001191 }
1192 else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001193 // Remove this object from memory object's reference list and decrement its ref counter
1194 clear_object_binding(object);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001195 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001196 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001197 objectMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001198 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001199
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001200 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001201 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DestroyObject(device, objType, object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001202 return result;
1203}
1204
Tony Barbour59a47322015-06-24 16:06:58 -06001205VK_LAYER_EXPORT VkResult VKAPI vkGetObjectMemoryRequirements(
1206 VkDevice device,
1207 VkObjectType objType,
1208 VkObject object,
1209 VkMemoryRequirements* pRequirements)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001210{
1211 // TODO : What to track here?
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001212 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001213 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues,
1214 // command buffers, shaders and memory objects.
Tony Barbour59a47322015-06-24 16:06:58 -06001215 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetObjectMemoryRequirements(device, objType, object, pRequirements);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001216 return result;
1217}
1218
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001219VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(
1220 VkDevice device,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001221 VkObjectType objType,
1222 VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001223 VkDeviceMemory mem,
1224 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001225{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001226 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->BindObjectMemory(device, objType, object, mem, offset);
Mike Stroyanb050c682015-04-17 12:36:38 -06001227 loader_platform_thread_lock_mutex(&globalLock);
1228 // Track objects tied to memory
Courtney Goeltzenleuchter540d3492015-06-13 21:37:34 -06001229 set_object_binding(device, object, mem);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001230 print_object_list(device);
1231 print_mem_list(device);
Mike Stroyanb050c682015-04-17 12:36:38 -06001232 loader_platform_thread_unlock_mutex(&globalLock);
1233 return result;
1234}
1235
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001236VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -06001237 VkQueue queue,
1238 VkBuffer buffer,
1239 uint32_t numBindings,
1240 const VkSparseMemoryBindInfo* pBindInfo)
Mike Stroyanb050c682015-04-17 12:36:38 -06001241{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001242 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueBindSparseBufferMemory(
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -06001243 queue, buffer, numBindings, pBindInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001244 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001245 // Track objects tied to memory
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -06001246 if (VK_FALSE == set_sparse_buffer_binding(buffer, pBindInfo->mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001247 log_msg(mdd(queue), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_BUFFER, buffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
Mark Lobodzinski16e8bef2015-07-03 15:58:09 -06001248 "Unable to set object %p binding to mem obj %p", (void*)buffer, (void*)pBindInfo->mem);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001249 }
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001250 print_object_list(queue);
1251 print_mem_list(queue);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001252 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001253 return result;
1254}
1255
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001256VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(
1257 VkDevice device,
1258 const VkFenceCreateInfo *pCreateInfo,
1259 VkFence *pFence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001260{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001261 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001262 if (VK_SUCCESS == result) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001263 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001264 add_object_info(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001265 loader_platform_thread_unlock_mutex(&globalLock);
1266 }
1267 return result;
1268}
1269
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001270VK_LAYER_EXPORT VkResult VKAPI vkResetFences(
1271 VkDevice device,
1272 uint32_t fenceCount,
Courtney Goeltzenleuchter2bf8f902015-06-18 17:28:20 -06001273 const VkFence *pFences)
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001274{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001275 /*
1276 * TODO: Shouldn't we check for error conditions before passing down the chain?
1277 * What if reason result is not VK_SUCCESS is something we could report as a validation error?
1278 */
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001279 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001280 if (VK_SUCCESS == result) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001281 loader_platform_thread_lock_mutex(&globalLock);
1282 // Reset fence state in fenceCreateInfo structure
1283 for (uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001284 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001285 if (pObjectInfo != NULL) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001286 // Validate fences in SIGNALED state
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001287 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001288 log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM",
1289 "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001290 }
1291 else {
1292 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001293 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001294 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001295 }
1296 }
1297 loader_platform_thread_unlock_mutex(&globalLock);
1298 }
1299 return result;
1300}
1301
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001302VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(
1303 VkDevice device,
1304 VkFence fence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001305{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001306 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->GetFenceStatus(device, fence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001307 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001308 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001309 update_fence_tracking(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001310 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001311 }
1312 return result;
1313}
1314
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001315VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(
1316 VkDevice device,
1317 uint32_t fenceCount,
1318 const VkFence *pFences,
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -06001319 VkBool32 waitAll,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001320 uint64_t timeout)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001321{
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001322 // Verify fence status of submitted fences
1323 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001324 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001325 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001326 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001327 log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_FENCE, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM",
1328 "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001329 }
1330 }
1331 }
1332
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001333 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001334 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05001335
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001336 if (VK_SUCCESS == result) {
Mark Lobodzinski50932972015-04-02 20:49:09 -05001337 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001338 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001339 update_fence_tracking(pFences[i]);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001340 }
1341 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001342 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001343 loader_platform_thread_unlock_mutex(&globalLock);
1344 return result;
1345}
1346
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001347VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(
1348 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001349{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001350 VkResult result = get_dispatch_table(mem_tracker_device_table_map, queue)->QueueWaitIdle(queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001351 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001352 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001353 retire_queue_fences(queue);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001354 loader_platform_thread_unlock_mutex(&globalLock);
1355 }
1356 return result;
1357}
1358
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001359VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(
1360 VkDevice device)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001361{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001362 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->DeviceWaitIdle(device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001363 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001364 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001365 retire_device_fences(device);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001366 loader_platform_thread_unlock_mutex(&globalLock);
1367 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001368 return result;
1369}
1370
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001371VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(
1372 VkDevice device,
1373 const VkEventCreateInfo *pCreateInfo,
1374 VkEvent *pEvent)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001375{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001376 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001377 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001378 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001379 add_object_info(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001380 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001381 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001382 return result;
1383}
1384
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001385VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(
1386 VkDevice device,
1387 const VkQueryPoolCreateInfo *pCreateInfo,
1388 VkQueryPool *pQueryPool)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001389{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001390 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001391 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001392 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001393 add_object_info(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001394 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001395 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001396 return result;
1397}
1398
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001399VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(
1400 VkDevice device,
1401 const VkBufferCreateInfo *pCreateInfo,
1402 VkBuffer *pBuffer)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001403{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001404 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001405 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001406 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001407 add_object_info(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001408 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001409 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001410 return result;
1411}
1412
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001413VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(
1414 VkDevice device,
1415 const VkBufferViewCreateInfo *pCreateInfo,
1416 VkBufferView *pView)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001417{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001418 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001419 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001420 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001421 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001422 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001423 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001424 return result;
1425}
1426
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001427VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
1428 VkDevice device,
1429 const VkImageCreateInfo *pCreateInfo,
1430 VkImage *pImage)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001431{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001432 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001433 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001434 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001435 add_object_info(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001436 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001437 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001438 return result;
1439}
1440
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001441VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(
1442 VkDevice device,
1443 const VkImageViewCreateInfo *pCreateInfo,
1444 VkImageView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001445{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001446 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001447 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001448 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001449 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001450 // Validate that img has correct usage flags set
1451 validate_image_usage_flags(device, pCreateInfo->image, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
1452 false, "vkCreateImageView()", "VK_IMAGE_USAGE_[SAMPLED|STORAGE]_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001453 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001454 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001455 return result;
1456}
1457
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001458VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(
1459 VkDevice device,
1460 const VkColorAttachmentViewCreateInfo *pCreateInfo,
1461 VkColorAttachmentView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001462{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001463 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001464 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001465 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001466 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001467 // Validate that img has correct usage flags set
1468 // We don't use the image helper function here as it's a special case that checks struct type
1469 MT_OBJ_INFO* pInfo = get_object_info(pCreateInfo->image);
1470 if (pInfo) {
1471 if (VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI == pInfo->sType) {
1472 validate_usage_flags(device, pInfo->create_info.swap_chain_create_info.imageUsageFlags, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, true,
1473 pCreateInfo->image, VK_OBJECT_TYPE_IMAGE, "image", "vkCreateColorAttachmentView()", "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT");
1474 } else if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pInfo->sType) {
1475 validate_usage_flags(device, pInfo->create_info.image_create_info.usage, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, true,
1476 pCreateInfo->image, VK_OBJECT_TYPE_IMAGE, "image", "vkCreateColorAttachmentView()", "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT");
1477 }
1478 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001479 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001480 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001481 return result;
1482}
1483
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001484VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(
1485 VkDevice device,
1486 const VkDepthStencilViewCreateInfo *pCreateInfo,
1487 VkDepthStencilView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001488{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001489 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001490 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001491 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001492 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001493 // Validate that img has correct usage flags set
1494 validate_image_usage_flags(device, pCreateInfo->image, VK_IMAGE_USAGE_DEPTH_STENCIL_BIT,
1495 true, "vkCreateDepthStencilView()", "VK_IMAGE_USAGE_DEPTH_STENCIL_BIT");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001496 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001497 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001498 return result;
1499}
1500
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001501VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
1502 VkDevice device,
1503 const VkShaderCreateInfo *pCreateInfo,
1504 VkShader *pShader)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001505{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001506 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001507 return result;
1508}
1509
Jon Ashburnc669cc62015-07-09 15:02:25 -06001510//TODO do we need to intercept pipelineCache functions to track objects?
1511VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001512 VkDevice device,
Jon Ashburnc669cc62015-07-09 15:02:25 -06001513 VkPipelineCache pipelineCache,
1514 uint32_t count,
1515 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1516 VkPipeline *pPipelines)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001517{
Jon Ashburnc669cc62015-07-09 15:02:25 -06001518 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001519 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001520 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001521 add_object_info(*pPipelines, pCreateInfos->sType, pCreateInfos, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001522 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001523 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001524 return result;
1525}
1526
Jon Ashburnc669cc62015-07-09 15:02:25 -06001527VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipelines(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001528 VkDevice device,
Jon Ashburnc669cc62015-07-09 15:02:25 -06001529 VkPipelineCache pipelineCache,
1530 uint32_t count,
1531 const VkComputePipelineCreateInfo *pCreateInfos,
1532 VkPipeline *pPipelines)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001533{
Jon Ashburnc669cc62015-07-09 15:02:25 -06001534 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateComputePipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001535 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001536 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburnc669cc62015-07-09 15:02:25 -06001537 add_object_info(*pPipelines, pCreateInfos->sType, pCreateInfos, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001538 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001539 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001540 return result;
1541}
1542
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001543VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(
1544 VkDevice device,
1545 const VkSamplerCreateInfo *pCreateInfo,
1546 VkSampler *pSampler)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001547{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001548 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001549 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001550 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001551 add_object_info(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001552 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001553 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001554 return result;
1555}
1556
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001557VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(
1558 VkDevice device,
1559 const VkDynamicVpStateCreateInfo *pCreateInfo,
1560 VkDynamicVpState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001561{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001562 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001563 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001564 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001565 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001566 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001567 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001568 return result;
1569}
1570
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001571VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(
1572 VkDevice device,
1573 const VkDynamicRsStateCreateInfo *pCreateInfo,
1574 VkDynamicRsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001575{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001576 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001577 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001578 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001579 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001580 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001581 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001582 return result;
1583}
1584
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001585VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(
1586 VkDevice device,
1587 const VkDynamicCbStateCreateInfo *pCreateInfo,
1588 VkDynamicCbState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001589{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001590 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001591 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001592 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001593 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001594 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001595 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001596 return result;
1597}
1598
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001599VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(
1600 VkDevice device,
1601 const VkDynamicDsStateCreateInfo *pCreateInfo,
1602 VkDynamicDsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001603{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001604 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001605 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001606 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001607 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001608 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001609 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001610 return result;
1611}
1612
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001613VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(
1614 VkDevice device,
1615 const VkCmdBufferCreateInfo *pCreateInfo,
1616 VkCmdBuffer *pCmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001617{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001618 VkResult result = get_dispatch_table(mem_tracker_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001619 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001620 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001621 if (*pCmdBuffer)
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001622 add_cmd_buf_info(*pCmdBuffer);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06001623 printCBList(device);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001624 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001625 return result;
1626}
1627
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001628VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(
1629 VkCmdBuffer cmdBuffer,
1630 const VkCmdBufferBeginInfo *pBeginInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001631{
Mike Stroyan950496e2015-05-19 15:16:08 -06001632 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001633 // 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 -06001634 if (!checkCBCompleted(cmdBuffer)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001635 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM",
1636 "Calling vkBeginCommandBuffer() on active CB %p before it has completed. "
Mike Stroyan950496e2015-05-19 15:16:08 -06001637 "You must check CB flag before this call.", cmdBuffer);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001638 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001639 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001640 VkResult result = get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001641 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001642 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001643 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001644 return result;
1645}
1646
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001647VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(
1648 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001649{
1650 // TODO : Anything to do here?
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001651 VkResult result = get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->EndCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001652 return result;
1653}
1654
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001655VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(
1656 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001657{
Mike Stroyan950496e2015-05-19 15:16:08 -06001658 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001659 // Verify that CB is complete (not in-flight)
Mike Stroyan950496e2015-05-19 15:16:08 -06001660 if (!checkCBCompleted(cmdBuffer)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001661 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM",
1662 "Resetting CB %p before it has completed. You must check CB flag before "
Mike Stroyan950496e2015-05-19 15:16:08 -06001663 "calling vkResetCommandBuffer().", cmdBuffer);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001664 }
1665 // Clear memory references as this point.
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001666 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001667 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001668 VkResult result = get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->ResetCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001669 return result;
1670}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001671// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis6663f492014-11-10 12:29:12 -07001672// need to account for that mem now having binding to given cmdBuffer
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001673VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(
1674 VkCmdBuffer cmdBuffer,
1675 VkPipelineBindPoint pipelineBindPoint,
1676 VkPipeline pipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001677{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001678#if 0
1679 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1680 if (getPipeline(pipeline)) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001681 MT_CB_INFO *pCBInfo = get_cmd_buf_info(cmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001682 if (pCBInfo) {
1683 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlisc145be82015-01-08 15:22:32 -07001684 } else {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001685 "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001686 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 -07001687 }
1688 }
1689 else {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001690 "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001691 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 -07001692 }
1693#endif
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001694 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001695}
1696
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001697VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(
1698 VkCmdBuffer cmdBuffer,
1699 VkStateBindPoint stateBindPoint,
1700 VkDynamicStateObject state)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001701{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001702 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001703 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001704 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001705 if (!pCmdBuf) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001706 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_INVALID_CB, "MEM",
1707 "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001708 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001709 pObjInfo = get_object_info(state);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001710 if (!pObjInfo) {
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001711 /* TODO: put in real object type */
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001712 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, MEMTRACK_INVALID_OBJECT, "MEM",
1713 "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001714 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001715 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001716 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001717 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001718}
1719
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001720VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001721 VkCmdBuffer cmdBuffer,
1722 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06001723 VkPipelineLayout layout,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001724 uint32_t firstSet,
1725 uint32_t setCount,
1726 const VkDescriptorSet *pDescriptorSets,
1727 uint32_t dynamicOffsetCount,
1728 const uint32_t *pDynamicOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001729{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001730 // 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 -06001731 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindDescriptorSets(
Mark Lobodzinskif2093b62015-06-15 13:21:21 -06001732 cmdBuffer, pipelineBindPoint, layout, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001733}
1734
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001735VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001736 VkCmdBuffer cmdBuffer,
1737 uint32_t startBinding,
1738 uint32_t bindingCount,
1739 const VkBuffer *pBuffers,
1740 const VkDeviceSize *pOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001741{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001742 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wu19156822015-01-05 13:42:56 +08001743}
1744
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001745VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(
1746 VkCmdBuffer cmdBuffer,
1747 VkBuffer buffer,
1748 VkDeviceSize offset,
1749 VkIndexType indexType)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001750{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001751 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001752}
1753
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001754VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(
1755 VkCmdBuffer cmdBuffer,
1756 VkBuffer buffer,
1757 VkDeviceSize offset,
1758 uint32_t count,
1759 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001760{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001761 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001762 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, buffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001763 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001764 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1765 "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001766 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001767 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001768 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001769}
1770
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001771VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
1772 VkCmdBuffer cmdBuffer,
1773 VkBuffer buffer,
1774 VkDeviceSize offset,
1775 uint32_t count,
1776 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001777{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001778 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001779 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, buffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001780 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001781 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1782 "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001783 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001784 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001785 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001786}
1787
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001788VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(
1789 VkCmdBuffer cmdBuffer,
1790 VkBuffer buffer,
1791 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001792{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001793 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001794 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, buffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001795 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001796 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1797 "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001798 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001799 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001800 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001801}
1802
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001803VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(
1804 VkCmdBuffer cmdBuffer,
1805 VkBuffer srcBuffer,
1806 VkBuffer destBuffer,
1807 uint32_t regionCount,
1808 const VkBufferCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001809{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001810 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001811 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcBuffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001812 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001813 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1814 "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001815 }
Jon Ashburna79828d2015-06-18 17:12:57 -06001816 mem = get_mem_binding_from_object(cmdBuffer, destBuffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001817 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001818 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1819 "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001820 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06001821 // Validate that SRC & DST buffers have correct usage flags set
1822 validate_buffer_usage_flags(cmdBuffer, srcBuffer, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyBuffer()", "VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT");
1823 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 -06001824 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001825 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001826}
1827
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001828VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(
1829 VkCmdBuffer cmdBuffer,
1830 VkImage srcImage,
1831 VkImageLayout srcImageLayout,
1832 VkImage destImage,
1833 VkImageLayout destImageLayout,
1834 uint32_t regionCount,
1835 const VkImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001836{
Tobin Ehlis41376e12015-07-03 08:45:14 -06001837 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001838 // TODO : Each image will have mem mapping so track them
Tobin Ehlis41376e12015-07-03 08:45:14 -06001839 // Validate that src & dst images have correct usage flags set
1840 validate_image_usage_flags(cmdBuffer, srcImage, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT");
1841 validate_image_usage_flags(cmdBuffer, destImage, VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdCopyImage()", "VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT");
1842 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001843 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001844 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001845}
1846
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001847VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(
1848 VkCmdBuffer cmdBuffer,
1849 VkImage srcImage,
1850 VkImageLayout srcImageLayout,
1851 VkImage destImage,
1852 VkImageLayout destImageLayout,
1853 uint32_t regionCount,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05001854 const VkImageBlit *pRegions,
1855 VkTexFilter filter)
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001856{
Tobin Ehlis41376e12015-07-03 08:45:14 -06001857 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001858 // TODO : Each image will have mem mapping so track them
Tobin Ehlis41376e12015-07-03 08:45:14 -06001859 // Validate that src & dst images have correct usage flags set
1860 validate_image_usage_flags(cmdBuffer, srcImage, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT");
1861 validate_image_usage_flags(cmdBuffer, destImage, VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT, true, "vkCmdBlitImage()", "VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT");
1862 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001863 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBlitImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001864 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001865}
1866
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001867VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(
1868 VkCmdBuffer cmdBuffer,
1869 VkBuffer srcBuffer,
1870 VkImage destImage,
1871 VkImageLayout destImageLayout,
1872 uint32_t regionCount,
1873 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001874{
1875 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001876 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001877 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, destImage);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001878 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001879 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1880 "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001881 }
Jon Ashburna79828d2015-06-18 17:12:57 -06001882 mem = get_mem_binding_from_object(cmdBuffer, srcBuffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001883 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001884 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1885 "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001886 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06001887 // Validate that src buff & dst image have correct usage flags set
1888 validate_buffer_usage_flags(cmdBuffer, srcBuffer, VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyBufferToImage()", "VK_BUFFER_USAGE_TRANSFER_SOURCE_BIT");
1889 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 -06001890 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001891 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyBufferToImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001892 cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001893}
1894
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001895VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(
1896 VkCmdBuffer cmdBuffer,
1897 VkImage srcImage,
1898 VkImageLayout srcImageLayout,
1899 VkBuffer destBuffer,
1900 uint32_t regionCount,
1901 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001902{
1903 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001904 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001905 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcImage);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001906 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001907 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1908 "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001909 }
Jon Ashburna79828d2015-06-18 17:12:57 -06001910 mem = get_mem_binding_from_object(cmdBuffer, destBuffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001911 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001912 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1913 "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001914 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06001915 // Validate that dst buff & src image have correct usage flags set
1916 validate_image_usage_flags(cmdBuffer, srcImage, VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, true, "vkCmdCopyImageToBuffer()", "VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT");
1917 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 -06001918 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001919 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdCopyImageToBuffer(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001920 cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001921}
1922
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001923VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
1924 VkCmdBuffer cmdBuffer,
1925 VkBuffer destBuffer,
1926 VkDeviceSize destOffset,
1927 VkDeviceSize dataSize,
1928 const uint32_t *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001929{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001930 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001931 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, destBuffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001932 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001933 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1934 "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001935 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06001936 // Validate that dst buff has correct usage flags set
1937 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 -06001938 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001939 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001940}
1941
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001942VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
1943 VkCmdBuffer cmdBuffer,
1944 VkBuffer destBuffer,
1945 VkDeviceSize destOffset,
1946 VkDeviceSize fillSize,
1947 uint32_t data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001948{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001949 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001950 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, destBuffer);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001951 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001952 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1953 "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001954 }
Tobin Ehlis41376e12015-07-03 08:45:14 -06001955 // Validate that dst buff has correct usage flags set
1956 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 -06001957 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001958 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001959}
1960
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001961VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
1962 VkCmdBuffer cmdBuffer,
1963 VkImage image,
1964 VkImageLayout imageLayout,
Chris Forbesf0796e12015-06-24 14:34:53 +12001965 const VkClearColorValue *pColor,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001966 uint32_t rangeCount,
1967 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001968{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001969 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001970 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001971 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001972 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001973 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
1974 "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001975 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001976 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06001977 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001978}
1979
Chris Forbesd9be82b2015-06-22 17:21:59 +12001980VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencilImage(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001981 VkCmdBuffer cmdBuffer,
1982 VkImage image,
1983 VkImageLayout imageLayout,
1984 float depth,
1985 uint32_t stencil,
1986 uint32_t rangeCount,
1987 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001988{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001989 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001990 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06001991 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001992 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06001993 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
Chris Forbesd9be82b2015-06-22 17:21:59 +12001994 "In vkCmdClearDepthStencilImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001995 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001996 loader_platform_thread_unlock_mutex(&globalLock);
Chris Forbesd9be82b2015-06-22 17:21:59 +12001997 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdClearDepthStencilImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001998 cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001999}
2000
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002001VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(
2002 VkCmdBuffer cmdBuffer,
2003 VkImage srcImage,
2004 VkImageLayout srcImageLayout,
2005 VkImage destImage,
2006 VkImageLayout destImageLayout,
2007 uint32_t regionCount,
2008 const VkImageResolve *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002009{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002010 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06002011 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, srcImage);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002012 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002013 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2014 "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002015 }
Jon Ashburna79828d2015-06-18 17:12:57 -06002016 mem = get_mem_binding_from_object(cmdBuffer, destImage);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002017 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002018 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2019 "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002020 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002021 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002022 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdResolveImage(
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002023 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002024}
2025
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002026VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(
2027 VkCmdBuffer cmdBuffer,
2028 VkQueryPool queryPool,
2029 uint32_t slot,
2030 VkFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002031{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002032 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06002033 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, queryPool);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002034 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002035 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2036 "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002037 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002038 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002039 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002040}
2041
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002042VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(
2043 VkCmdBuffer cmdBuffer,
2044 VkQueryPool queryPool,
2045 uint32_t slot)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002046{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002047 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06002048 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, queryPool);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002050 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2051 "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002052 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002053 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002054 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002055}
2056
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002057VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(
2058 VkCmdBuffer cmdBuffer,
2059 VkQueryPool queryPool,
2060 uint32_t startQuery,
2061 uint32_t queryCount)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002062{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002063 loader_platform_thread_lock_mutex(&globalLock);
Jon Ashburna79828d2015-06-18 17:12:57 -06002064 VkDeviceMemory mem = get_mem_binding_from_object(cmdBuffer, queryPool);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002065 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002066 log_msg(mdd(cmdBuffer), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2067 "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002068 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002069 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002070 get_dispatch_table(mem_tracker_device_table_map, cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002071}
2072
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002073VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2074 VkInstance instance,
2075 VkFlags msgFlags,
2076 const PFN_vkDbgMsgCallback pfnMsgCallback,
2077 void* pUserData,
2078 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002079{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002080 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, instance);
2081 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2082 if (res == VK_SUCCESS) {
2083 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2084
2085 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
2086 }
2087 return res;
Tobin Ehlis6663f492014-11-10 12:29:12 -07002088}
2089
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002090VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2091 VkInstance instance,
2092 VkDbgMsgCallback msgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002093{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002094 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(mem_tracker_instance_table_map, instance);
2095 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
2096
2097 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2098 layer_destroy_msg_callback(my_data->report_data, msgCallback);
2099
2100 return res;
Tobin Ehlis6663f492014-11-10 12:29:12 -07002101}
2102
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002103VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(
2104 VkDevice device,
2105 const VkSwapChainCreateInfoWSI *pCreateInfo,
2106 VkSwapChainWSI *pSwapChain)
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)->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002109
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002110 if (VK_SUCCESS == result) {
Chia-I Wuf8693382015-04-16 22:02:10 +08002111 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis41376e12015-07-03 08:45:14 -06002112 add_swap_chain_info(*pSwapChain, pCreateInfo);
Chia-I Wuf8693382015-04-16 22:02:10 +08002113 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002114 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002115
Tobin Ehlis6663f492014-11-10 12:29:12 -07002116 return result;
2117}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002118
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002119VK_LAYER_EXPORT VkResult VKAPI vkDestroySwapChainWSI(
2120 VkSwapChainWSI swapChain)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002121{
2122 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002123
2124 if (swapChainMap.find(swapChain) != swapChainMap.end()) {
2125 MT_SWAP_CHAIN_INFO* pInfo = swapChainMap[swapChain];
2126
David Pinedod8f83d82015-04-27 16:36:17 -06002127 if (pInfo->images.size() > 0) {
2128 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2129 it != pInfo->images.end(); it++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002130 clear_object_binding(it->image);
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06002131 freeMemObjInfo(swapChain, it->memory, true);
Chia-I Wuf8693382015-04-16 22:02:10 +08002132
David Pinedod8f83d82015-04-27 16:36:17 -06002133 objectMap.erase(it->image);
2134 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002135 }
2136
2137 delete pInfo;
2138 swapChainMap.erase(swapChain);
2139 }
2140
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002141 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002142
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002143 return get_dispatch_table(mem_tracker_device_table_map, swapChain)->DestroySwapChainWSI(swapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002144}
2145
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002146VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(
2147 VkSwapChainWSI swapChain,
2148 VkSwapChainInfoTypeWSI infoType,
2149 size_t *pDataSize,
2150 void *pData)
Chia-I Wuf8693382015-04-16 22:02:10 +08002151{
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002152 VkResult result = get_dispatch_table(mem_tracker_device_table_map, swapChain)->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
Chia-I Wuf8693382015-04-16 22:02:10 +08002153
2154 if (infoType == VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI && result == VK_SUCCESS) {
2155 const size_t count = *pDataSize / sizeof(VkSwapChainImageInfoWSI);
2156 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain];
2157
2158 if (pInfo->images.empty()) {
2159 pInfo->images.resize(count);
2160 memcpy(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count);
2161
David Pinedod8f83d82015-04-27 16:36:17 -06002162 if (pInfo->images.size() > 0) {
2163 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2164 it != pInfo->images.end(); it++) {
2165 // Add image object, then insert the new Mem Object and then bind it to created image
Tobin Ehlis41376e12015-07-03 08:45:14 -06002166 add_object_info(it->image, VK_STRUCTURE_TYPE_SWAP_CHAIN_CREATE_INFO_WSI, &pInfo->createInfo, sizeof(pInfo->createInfo), "persistent_image");
Courtney Goeltzenleuchter7dcc6a72015-06-11 16:01:11 -06002167 add_mem_obj_info(swapChain, it->memory, NULL);
Courtney Goeltzenleuchter540d3492015-06-13 21:37:34 -06002168 if (VK_FALSE == set_object_binding(swapChain, it->image, it->memory)) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002169 log_msg(mdd(swapChain), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, it->image, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM",
2170 "In vkGetSwapChainInfoWSI(), unable to set image %p binding to mem obj %p", (void*)it->image, (void*)it->memory);
David Pinedod8f83d82015-04-27 16:36:17 -06002171 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002172 }
2173 }
2174 } else {
2175 const bool mismatch = (pInfo->images.size() != count ||
2176 memcmp(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count));
2177
2178 if (mismatch) {
Courtney Goeltzenleuchterb9f0bf32015-06-14 09:50:18 -06002179 log_msg(mdd(swapChain), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_SWAP_CHAIN_WSI, (VkObject) swapChain, 0, MEMTRACK_NONE, "SWAP_CHAIN",
2180 "vkGetSwapChainInfoWSI(%p, VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI) returned mismatching data", swapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002181 }
2182 }
2183 }
2184
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002185 return result;
2186}
Tobin Ehlis6663f492014-11-10 12:29:12 -07002187
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002188VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(
2189 VkDevice dev,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002190 const char *funcName)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002191{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002192 if (dev == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002193 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002194 }
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002195
Jon Ashburn8fd08252015-05-28 16:25:02 -06002196 /* loader uses this to force layer initialization; device object is wrapped */
2197 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002198 initDeviceTable(mem_tracker_device_table_map, (const VkBaseLayerObject *) dev);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002199 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002200 }
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -06002201 if (!strcmp(funcName, "vkCreateDevice"))
2202 return (void*) vkCreateDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002203 if (!strcmp(funcName, "vkDestroyDevice"))
2204 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002205 if (!strcmp(funcName, "vkQueueSubmit"))
2206 return (void*) vkQueueSubmit;
2207 if (!strcmp(funcName, "vkAllocMemory"))
2208 return (void*) vkAllocMemory;
2209 if (!strcmp(funcName, "vkFreeMemory"))
2210 return (void*) vkFreeMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002211 if (!strcmp(funcName, "vkMapMemory"))
2212 return (void*) vkMapMemory;
2213 if (!strcmp(funcName, "vkUnmapMemory"))
2214 return (void*) vkUnmapMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002215 if (!strcmp(funcName, "vkDestroyObject"))
2216 return (void*) vkDestroyObject;
Tony Barbour59a47322015-06-24 16:06:58 -06002217 if (!strcmp(funcName, "vkGetObjectMemoryRequirements"))
2218 return (void*) vkGetObjectMemoryRequirements;
Mark Lobodzinski942b1722015-05-11 17:21:15 -05002219 if (!strcmp(funcName, "vkBindObjectMemory"))
2220 return (void*) vkBindObjectMemory;
2221 if (!strcmp(funcName, "vkQueueBindSparseBufferMemory"))
2222 return (void*) vkQueueBindSparseBufferMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002223 if (!strcmp(funcName, "vkCreateFence"))
2224 return (void*) vkCreateFence;
2225 if (!strcmp(funcName, "vkGetFenceStatus"))
2226 return (void*) vkGetFenceStatus;
2227 if (!strcmp(funcName, "vkResetFences"))
2228 return (void*) vkResetFences;
2229 if (!strcmp(funcName, "vkWaitForFences"))
2230 return (void*) vkWaitForFences;
2231 if (!strcmp(funcName, "vkQueueWaitIdle"))
2232 return (void*) vkQueueWaitIdle;
2233 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2234 return (void*) vkDeviceWaitIdle;
2235 if (!strcmp(funcName, "vkCreateEvent"))
2236 return (void*) vkCreateEvent;
2237 if (!strcmp(funcName, "vkCreateQueryPool"))
2238 return (void*) vkCreateQueryPool;
2239 if (!strcmp(funcName, "vkCreateBuffer"))
2240 return (void*) vkCreateBuffer;
2241 if (!strcmp(funcName, "vkCreateBufferView"))
2242 return (void*) vkCreateBufferView;
2243 if (!strcmp(funcName, "vkCreateImage"))
2244 return (void*) vkCreateImage;
2245 if (!strcmp(funcName, "vkCreateImageView"))
2246 return (void*) vkCreateImageView;
2247 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2248 return (void*) vkCreateColorAttachmentView;
2249 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2250 return (void*) vkCreateDepthStencilView;
2251 if (!strcmp(funcName, "vkCreateShader"))
2252 return (void*) vkCreateShader;
Jon Ashburnc669cc62015-07-09 15:02:25 -06002253 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
2254 return (void*) vkCreateGraphicsPipelines;
2255 if (!strcmp(funcName, "vkCreateComputePipelines"))
2256 return (void*) vkCreateComputePipelines;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002257 if (!strcmp(funcName, "vkCreateSampler"))
2258 return (void*) vkCreateSampler;
2259 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2260 return (void*) vkCreateDynamicViewportState;
2261 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2262 return (void*) vkCreateDynamicRasterState;
2263 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2264 return (void*) vkCreateDynamicColorBlendState;
2265 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2266 return (void*) vkCreateDynamicDepthStencilState;
2267 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2268 return (void*) vkCreateCommandBuffer;
2269 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2270 return (void*) vkBeginCommandBuffer;
2271 if (!strcmp(funcName, "vkEndCommandBuffer"))
2272 return (void*) vkEndCommandBuffer;
2273 if (!strcmp(funcName, "vkResetCommandBuffer"))
2274 return (void*) vkResetCommandBuffer;
2275 if (!strcmp(funcName, "vkCmdBindPipeline"))
2276 return (void*) vkCmdBindPipeline;
2277 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2278 return (void*) vkCmdBindDynamicStateObject;
2279 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2280 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002281 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2282 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002283 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2284 return (void*) vkCmdBindIndexBuffer;
2285 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2286 return (void*) vkCmdDrawIndirect;
2287 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2288 return (void*) vkCmdDrawIndexedIndirect;
2289 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2290 return (void*) vkCmdDispatchIndirect;
2291 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2292 return (void*) vkCmdCopyBuffer;
2293 if (!strcmp(funcName, "vkCmdCopyImage"))
2294 return (void*) vkCmdCopyImage;
2295 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2296 return (void*) vkCmdCopyBufferToImage;
2297 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2298 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002299 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2300 return (void*) vkCmdUpdateBuffer;
2301 if (!strcmp(funcName, "vkCmdFillBuffer"))
2302 return (void*) vkCmdFillBuffer;
2303 if (!strcmp(funcName, "vkCmdClearColorImage"))
2304 return (void*) vkCmdClearColorImage;
Chris Forbesd9be82b2015-06-22 17:21:59 +12002305 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
2306 return (void*) vkCmdClearDepthStencilImage;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002307 if (!strcmp(funcName, "vkCmdResolveImage"))
2308 return (void*) vkCmdResolveImage;
2309 if (!strcmp(funcName, "vkCmdBeginQuery"))
2310 return (void*) vkCmdBeginQuery;
2311 if (!strcmp(funcName, "vkCmdEndQuery"))
2312 return (void*) vkCmdEndQuery;
2313 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2314 return (void*) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002315 if (!strcmp(funcName, "vkGetDeviceQueue"))
2316 return (void*) vkGetDeviceQueue;
Jon Ashburn747f2b62015-06-18 15:02:58 -06002317
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -06002318 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
2319 if (my_device_data->wsi_lunarg_enabled)
Jon Ashburn747f2b62015-06-18 15:02:58 -06002320 {
2321 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
2322 return (void*) vkCreateSwapChainWSI;
2323 if (!strcmp(funcName, "vkDestroySwapChainWSI"))
2324 return (void*) vkDestroySwapChainWSI;
2325 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
2326 return (void*) vkGetSwapChainInfoWSI;
2327 }
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002328
Courtney Goeltzenleuchterd54749c2015-07-05 11:17:01 -06002329 VkLayerDispatchTable *pDisp = get_dispatch_table(mem_tracker_device_table_map, dev);
2330 if (pDisp->GetDeviceProcAddr == NULL)
2331 return NULL;
2332 return pDisp->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002333}
2334
2335VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(
2336 VkInstance instance,
2337 const char *funcName)
2338{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002339 void *fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002340 if (instance == NULL) {
2341 return NULL;
2342 }
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002343
Jon Ashburn8fd08252015-05-28 16:25:02 -06002344 /* loader uses this to force layer initialization; instance object is wrapped */
2345 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002346 initInstanceTable(mem_tracker_instance_table_map, (const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002347 return (void *) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002348 }
2349
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002350 if (!strcmp(funcName, "vkDestroyInstance"))
2351 return (void *) vkDestroyInstance;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002352 if (!strcmp(funcName, "vkCreateInstance"))
2353 return (void*) vkCreateInstance;
Mark Lobodzinskib3fbcd92015-07-02 16:49:40 -06002354 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
2355 return (void*) vkGetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06002356 if (!strcmp(funcName, "vkGetGlobalLayerProperties"))
2357 return (void*) vkGetGlobalLayerProperties;
2358 if (!strcmp(funcName, "vkGetGlobalExtensionProperties"))
Tony Barbour59a47322015-06-24 16:06:58 -06002359 return (void*) vkGetGlobalExtensionProperties;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06002360 if (!strcmp(funcName, "vkGetPhysicalDeviceLayerProperties"))
2361 return (void*) vkGetPhysicalDeviceLayerProperties;
2362 if (!strcmp(funcName, "vkGetPhysicalDeviceExtensionProperties"))
2363 return (void*) vkGetPhysicalDeviceExtensionProperties;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002364
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002365 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
2366 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002367 if (fptr)
2368 return fptr;
2369
Jon Ashburn8fd08252015-05-28 16:25:02 -06002370 {
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002371 if (get_dispatch_table(mem_tracker_instance_table_map, instance)->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002372 return NULL;
Courtney Goeltzenleuchtere45acec2015-06-14 12:03:26 -06002373 return get_dispatch_table(mem_tracker_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002374 }
2375}