blob: 9e51e8893af3917250067cba3d71bc9406c64d04 [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>
Mike Stroyan950496e2015-05-19 15:16:08 -060032#include <unordered_map>
Chia-I Wuf8693382015-04-16 22:02:10 +080033#include <vector>
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050034using namespace std;
35
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070036#include "loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060037#include "vk_dispatch_table_helper.h"
38#include "vk_struct_string_helper_cpp.h"
Tobin Ehliscd9223b2014-11-19 16:19:28 -070039#include "mem_tracker.h"
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070040#include "layers_config.h"
Ian Elliott655cad72015-02-12 17:08:34 -070041// The following is #included again to catch certain OS-specific functions
42// being used:
43#include "loader_platform.h"
Jon Ashburn2e672892015-02-16 08:46:53 -070044#include "layers_msg.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070045
Mark Lobodzinski76c991d2015-05-20 16:16:37 -050046static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;
47static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;
48
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070049static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -050050
51static inline VkLayerDispatchTable *device_dispatch_table(VkObject object) {
52 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object;
53 VkLayerDispatchTable *pTable = tableMap[pDisp];
54 return pTable;
55}
56
57static inline VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object) {
58 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) object;
59 VkLayerInstanceDispatchTable *pInstanceTable = tableInstanceMap[*ppDisp];
60 return pInstanceTable;
61}
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060062
Mark Lobodzinski93f494b2015-03-02 20:23:52 -060063// TODO : This can be much smarter, using separate locks for separate global data
64static int globalLockInitialized = 0;
65static loader_platform_thread_mutex globalLock;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070066
Tobin Ehlisc145be82015-01-08 15:22:32 -070067#define MAX_BINDING 0xFFFFFFFF
Tobin Ehlisc145be82015-01-08 15:22:32 -070068
Mike Stroyandd7aed72015-05-19 17:03:40 -060069unordered_map<VkCmdBuffer, MT_CB_INFO> cbMap;
70unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO> memObjMap;
71unordered_map<VkObject, MT_OBJ_INFO> objectMap;
72unordered_map<VkFence, MT_FENCE_INFO> fenceMap; // Map fence to fence info
73unordered_map<VkQueue, MT_QUEUE_INFO> queueMap;
Mike Stroyan950496e2015-05-19 15:16:08 -060074unordered_map<VkSwapChainWSI, MT_SWAP_CHAIN_INFO*> swapChainMap;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050075
Mark Lobodzinski50932972015-04-02 20:49:09 -050076// TODO : Add per-device fence completion
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060077static uint64_t g_currentFenceId = 1;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060078static VkDevice globalDevice = NULL;
Mark Lobodzinskic52b7752015-02-18 16:38:17 -060079
Mark Lobodzinski223ca202015-04-02 08:52:53 -050080// Add new queue for this device to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -050081static void add_queue_info(const VkQueue queue)
Mark Lobodzinski223ca202015-04-02 08:52:53 -050082{
Mike Stroyandd7aed72015-05-19 17:03:40 -060083 MT_QUEUE_INFO* pInfo = &queueMap[queue];
Mark Lobodzinski50932972015-04-02 20:49:09 -050084 pInfo->lastRetiredId = 0;
85 pInfo->lastSubmittedId = 0;
Mark Lobodzinski223ca202015-04-02 08:52:53 -050086}
87
Mark Lobodzinski944aab12015-06-05 13:59:04 -050088static void delete_queue_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060089 void)
Mark Lobodzinski223ca202015-04-02 08:52:53 -050090{
91 // Process queue list, cleaning up each entry before deleting
Mark Lobodzinski223ca202015-04-02 08:52:53 -050092 queueMap.clear();
93}
94
Mark Lobodzinski944aab12015-06-05 13:59:04 -050095static void add_swap_chain_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060096 const VkSwapChainWSI swapChain)
Chia-I Wuf8693382015-04-16 22:02:10 +080097{
98 MT_SWAP_CHAIN_INFO* pInfo = new MT_SWAP_CHAIN_INFO;
99 swapChainMap[swapChain] = pInfo;
100}
101
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500102// Add new CBInfo for this cb to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500103static void add_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600104 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700105{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600106 cbMap[cb].cmdBuffer = cb;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700107}
108
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500109// Return ptr to Info in CB map, or NULL if not found
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500110static MT_CB_INFO* get_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600111 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700112{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600113 unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator item = cbMap.find(cb);
Mike Stroyan950496e2015-05-19 15:16:08 -0600114 if (item != cbMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600115 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600116 } else {
117 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600118 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700119}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600120
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500121// Return object info for 'object' or return NULL if no info exists
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500122static MT_OBJ_INFO* get_object_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600123 const VkObject object)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500124{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600125 unordered_map<VkObject, MT_OBJ_INFO>::iterator item = objectMap.find(object);
Mike Stroyan950496e2015-05-19 15:16:08 -0600126 if (item != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600127 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600128 } else {
129 return NULL;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500130 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500131}
132
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500133static MT_OBJ_INFO* add_object_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600134 VkObject object,
135 VkStructureType sType,
136 const void *pCreateInfo,
137 const int struct_size,
138 const char *name_prefix)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500139{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600140 MT_OBJ_INFO* pInfo = &objectMap[object];
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500141 memset(pInfo, 0, sizeof(MT_OBJ_INFO));
142 memcpy(&pInfo->create_info, pCreateInfo, struct_size);
143 sprintf(pInfo->object_name, "%s_%p", name_prefix, object);
144
145 pInfo->object = object;
146 pInfo->ref_count = 1;
147 pInfo->sType = sType;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500148
149 return pInfo;
150}
151
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500152// Add a fence, creating one if necessary to our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500153static uint64_t add_fence_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600154 VkFence fence,
155 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500156{
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500157 // Create fence object
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500158 uint64_t fenceId = g_currentFenceId++;
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500159 // If no fence, create an internal fence to track the submissions
Mike Stroyan950496e2015-05-19 15:16:08 -0600160 if (fence != NULL) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600161 fenceMap[fence].fenceId = fenceId;
162 fenceMap[fence].queue = queue;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500163 // Validate that fence is in UNSIGNALED state
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500164 MT_OBJ_INFO* pObjectInfo = get_object_info(fence);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500165 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600166 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500167 char str[1024];
168 sprintf(str, "Fence %p submitted in SIGNALED state. Fences must be reset before being submitted", fence);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600169 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, fence, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500170 }
171 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700172 }
Mike Stroyan950496e2015-05-19 15:16:08 -0600173 // Update most recently submitted fence and fenceId for Queue
Mike Stroyandd7aed72015-05-19 17:03:40 -0600174 queueMap[queue].lastSubmittedId = fenceId;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500175 return fenceId;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500176}
177
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500178// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500179static void delete_fence_info(
Mike Stroyan950496e2015-05-19 15:16:08 -0600180 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500181{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600182 fenceMap.erase(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500183}
184
Mike Stroyan950496e2015-05-19 15:16:08 -0600185// Record information when a fence is known to be signalled
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500186static void update_fence_tracking(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600187 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500188{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600189 unordered_map<VkFence, MT_FENCE_INFO>::iterator fence_item = fenceMap.find(fence);
Mike Stroyan950496e2015-05-19 15:16:08 -0600190 if (fence_item != fenceMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600191 MT_FENCE_INFO *pCurFenceInfo = &(*fence_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600192 VkQueue queue = pCurFenceInfo->queue;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600193 unordered_map<VkQueue, MT_QUEUE_INFO>::iterator queue_item = queueMap.find(queue);
Mike Stroyan950496e2015-05-19 15:16:08 -0600194 if (queue_item != queueMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600195 MT_QUEUE_INFO *pQueueInfo = &(*queue_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600196 if (pQueueInfo->lastRetiredId < pCurFenceInfo->fenceId) {
197 pQueueInfo->lastRetiredId = pCurFenceInfo->fenceId;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500198 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500199 }
200 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500201
Mike Stroyan950496e2015-05-19 15:16:08 -0600202 // Update fence state in fenceCreateInfo structure
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500203 MT_OBJ_INFO* pObjectInfo = get_object_info(fence);
Mike Stroyan950496e2015-05-19 15:16:08 -0600204 if (pObjectInfo != NULL) {
205 pObjectInfo->create_info.fence_create_info.flags =
206 static_cast<VkFenceCreateFlags>(
207 pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500208 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500209}
210
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500211// Helper routine that updates the fence list for a specific queue to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500212static void retire_queue_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600213 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500214{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600215 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
216 // Set queue's lastRetired to lastSubmitted indicating all fences completed
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600217 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700218}
219
Mike Stroyandd7aed72015-05-19 17:03:40 -0600220// Helper routine that updates all queues to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500221static void retire_device_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600222 VkDevice device)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500223{
224 // Process each queue for device
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600225 // TODO: Add multiple device support
Mike Stroyandd7aed72015-05-19 17:03:40 -0600226 for (unordered_map<VkQueue, MT_QUEUE_INFO>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
227 // Set queue's lastRetired to lastSubmitted indicating all fences completed
228 MT_QUEUE_INFO *pQueueInfo = &(*ii).second;
229 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500230 }
231}
232
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500233// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700234// Calls to this function should be wrapped in mutex
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500235static MT_MEM_OBJ_INFO* get_mem_obj_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600236 const VkDeviceMemory mem)
Tobin Ehlisc145be82015-01-08 15:22:32 -0700237{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600238 unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator item = memObjMap.find(mem);
Mike Stroyan950496e2015-05-19 15:16:08 -0600239 if (item != memObjMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600240 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600241 } else {
242 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600243 }
Tobin Ehlisc145be82015-01-08 15:22:32 -0700244}
245
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500246static void add_mem_obj_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600247 const VkDeviceMemory mem,
248 const VkMemoryAllocInfo *pAllocInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700249{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600250 memObjMap[mem].refCount = 0;
Chia-I Wuf8693382015-04-16 22:02:10 +0800251 if (pAllocInfo) { // MEM alloc created by vkCreateSwapChainWSI() doesn't have alloc info struct
Mike Stroyandd7aed72015-05-19 17:03:40 -0600252 memcpy(&memObjMap[mem].allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500253 // TODO: Update for real hardware, actually process allocation info structures
Mike Stroyandd7aed72015-05-19 17:03:40 -0600254 memObjMap[mem].allocInfo.pNext = NULL;
255 } else {
256 memset(&memObjMap[mem].allocInfo, 0, sizeof(VkMemoryAllocInfo));
Tobin Ehlis6663f492014-11-10 12:29:12 -0700257 }
Mike Stroyandd7aed72015-05-19 17:03:40 -0600258 memObjMap[mem].mem = mem;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700259}
260
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500261// Find CB Info and add mem reference to list container
262// Find Mem Obj Info and add CB reference to list container
263static bool32_t update_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600264 const VkCmdBuffer cb,
265 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700266{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600267 bool32_t result = VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700268 // First update CB binding in MemObj mini CB list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500269 MT_MEM_OBJ_INFO* pMemInfo = get_mem_obj_info(mem);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500270 if (!pMemInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700271 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600272 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that mem obj.\n "
273 "Was it correctly allocated? Did it already get freed?", mem, cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600274 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600275 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600276 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500277 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600278 bool32_t found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600279 if (pMemInfo->pCmdBufferBindings.size() > 0) {
280 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
281 if ((*it) == cb) {
282 found = VK_TRUE;
283 break;
284 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500285 }
286 }
287 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600288 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500289 pMemInfo->pCmdBufferBindings.push_front(cb);
290 pMemInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500291 }
292
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500293 // Now update CBInfo's Mem reference list
294 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
295 // 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 -0500296 if (!pCBInfo) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500297 char str[1024];
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500298 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that CB. Was CB incorrectly destroyed?", mem, cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600299 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600300 result = VK_FALSE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500301 } else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500302 // Search for memory object in cmd buffer's reference list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600303 bool32_t found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600304 if (pCBInfo->pMemObjList.size() > 0) {
305 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
306 if ((*it) == mem) {
307 found = VK_TRUE;
308 break;
309 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500310 }
311 }
312 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600313 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500314 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600315 }
316 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700317 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600318 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700319}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600320
Tobin Ehlis6663f492014-11-10 12:29:12 -0700321// Clear the CB Binding for mem
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500322// Calls to this function should be wrapped in mutex
323static void remove_cmd_buf_and_mem_reference(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600324 const VkCmdBuffer cb,
325 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700326{
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500327 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500328 // TODO : Having this check is not ideal, really if memInfo was deleted,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500329 // its CB bindings should be cleared and then clear_cmd_buf_and_mem_references wouldn't call
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700330 // us here with stale mem objs
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500331 if (pInfo) {
332 pInfo->pCmdBufferBindings.remove(cb);
333 pInfo->refCount--;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700334 }
335}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600336
Tobin Ehlis6663f492014-11-10 12:29:12 -0700337// Free bindings related to CB
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500338static bool32_t clear_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600339 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700340{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600341 bool32_t result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500342 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500343 if (!pCBInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700344 char str[1024];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500345 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600346 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600347 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600348 } else {
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600349 if (pCBInfo->pMemObjList.size() > 0) {
350 list<VkDeviceMemory> mem_obj_list = pCBInfo->pMemObjList;
351 for (list<VkDeviceMemory>::iterator it=mem_obj_list.begin(); it!=mem_obj_list.end(); ++it) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500352 remove_cmd_buf_and_mem_reference(cb, (*it));
David Pinedod8f83d82015-04-27 16:36:17 -0600353 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600354 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500355 pCBInfo->pMemObjList.clear();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700356 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600357 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700358}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600359
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500360// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500361// and also clear mem references to CB
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500362static bool32_t delete_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600363 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700364{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 bool32_t result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500366 result = clear_cmd_buf_and_mem_references(cb);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500367 // Delete the CBInfo info
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600368 if (result == VK_TRUE) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600369 cbMap.erase(cb);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700370 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600371 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700372}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600373
Tobin Ehlis6663f492014-11-10 12:29:12 -0700374// Delete the entire CB list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500375static bool32_t delete_cmd_buf_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600376 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700377{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600378 for (unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500379 clear_cmd_buf_and_mem_references((*ii).first);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700380 }
Mike Stroyandd7aed72015-05-19 17:03:40 -0600381 cbMap.clear();
382 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700383}
384
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500385// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600386static void reportMemReferencesAndCleanUp(
387 MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700388{
Tony Barbour18f71552015-04-22 11:36:22 -0600389 size_t cmdBufRefCount = pMemObjInfo->pCmdBufferBindings.size();
390 size_t objRefCount = pMemObjInfo->pObjBindings.size();
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500391
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500392 if ((pMemObjInfo->pCmdBufferBindings.size() + pMemObjInfo->pObjBindings.size()) != 0) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700393 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600394 sprintf(str, "Attempting to free memory object %p which still contains %lu references",
395 pMemObjInfo->mem, (cmdBufRefCount + objRefCount));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600396 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700397 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500398
David Pinedod8f83d82015-04-27 16:36:17 -0600399 if (cmdBufRefCount > 0 && pMemObjInfo->pCmdBufferBindings.size() > 0) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500400 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
401 char str[1024];
402 sprintf(str, "Command Buffer %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600403 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (*it), 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500404 }
405 // Clear the list of hanging references
406 pMemObjInfo->pCmdBufferBindings.clear();
407 }
408
David Pinedod8f83d82015-04-27 16:36:17 -0600409 if (objRefCount > 0 && pMemObjInfo->pObjBindings.size() > 0) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500410 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
411 char str[1024];
412 sprintf(str, "VK Object %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600413 /* TODO: Would be nice to return the actual object type */
414 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500415 }
416 // Clear the list of hanging references
417 pMemObjInfo->pObjBindings.clear();
418 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500419
Tobin Ehlis6663f492014-11-10 12:29:12 -0700420}
421
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600422static void deleteMemObjInfo(
423 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700424{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600425 unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator item = memObjMap.find(mem);
Mike Stroyan950496e2015-05-19 15:16:08 -0600426 if (item != memObjMap.end()) {
Mike Stroyan950496e2015-05-19 15:16:08 -0600427 memObjMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700428 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500429 else {
430 char str[1024];
431 sprintf(str, "Request to delete memory object %p not present in memory Object Map", mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600432 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500433 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700434}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500435
Tobin Ehlis6663f492014-11-10 12:29:12 -0700436// Check if fence for given CB is completed
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600437static bool32_t checkCBCompleted(
438 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700439{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600440 bool32_t result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500441 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500442 if (!pCBInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700443 char str[1024];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500444 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600445 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600446 result = VK_FALSE;
Mike Stroyan950496e2015-05-19 15:16:08 -0600447 } else if (pCBInfo->lastSubmittedQueue != NULL) {
448 VkQueue queue = pCBInfo->lastSubmittedQueue;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600449 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
Mike Stroyan950496e2015-05-19 15:16:08 -0600450 if (pCBInfo->fenceId > pQueueInfo->lastRetiredId) {
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600451 char str[1024];
Mike Stroyan950496e2015-05-19 15:16:08 -0600452 sprintf(str, "fence %p for CB %p has not been checked for completion",
453 (void*)pCBInfo->lastSubmittedFence, cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600454 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600455 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600456 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700457 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600458 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700459}
460
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600461static bool32_t freeMemObjInfo(
462 VkDeviceMemory mem,
463 bool internal)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700464{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600465 bool32_t result = VK_TRUE;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500466 // Parse global list to find info w/ mem
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500467 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500468 if (!pInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700469 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600470 sprintf(str, "Couldn't find mem info object for %p\n Was %p never allocated or previously freed?",
471 (void*)mem, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600472 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600473 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600474 } else {
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -0600475 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600476 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600477 sprintf(str, "Attempting to free memory associated with a Persistent Image, %p, "
478 "this should not be explicitly freed\n", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600479 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600480 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600481 } else {
482 // Clear any CB bindings for completed CBs
483 // TODO : Is there a better place to do this?
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500484
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600485 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
486 list<VkCmdBuffer>::iterator temp;
David Pinedod8f83d82015-04-27 16:36:17 -0600487 while (pInfo->pCmdBufferBindings.size() > 0 && it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600488 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500489 temp = it;
490 ++temp;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500491 clear_cmd_buf_and_mem_references(*it);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500492 it = temp;
493 } else {
494 ++it;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600495 }
496 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500497
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600498 // Now verify that no references to this mem obj remain
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500499 if (0 != pInfo->refCount) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500500 reportMemReferencesAndCleanUp(pInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600501 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600502 }
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600503 // Delete mem obj info
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500504 deleteMemObjInfo(mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700505 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700506 }
507 return result;
508}
509
Tobin Ehlis6663f492014-11-10 12:29:12 -0700510// Remove object binding performs 3 tasks:
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500511// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
512// 2. Decrement refCount for MemObjInfo
513// 3. Clear MemObjInfo ptr from ObjectInfo
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500514static bool32_t clear_object_binding(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600515 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700516{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600517 bool32_t result = VK_FALSE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500518 MT_OBJ_INFO* pObjInfo = get_object_info(object);
519 if (pObjInfo) {
David Pinedod8f83d82015-04-27 16:36:17 -0600520 if (!pObjInfo->pMemObjInfo || pObjInfo->pMemObjInfo->pObjBindings.size() <= 0) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600521 char str[1024];
522 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600523 layerCbMsg(VK_DBG_REPORT_WARN_BIT, (VkObjectType) 0, object, 0, MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600524 } else {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500525 // 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
526 // and set the objects memory binding pointer to NULL.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600527 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500528 if ((*it) == object) {
529 pObjInfo->pMemObjInfo->refCount--;
530 pObjInfo->pMemObjInfo->pObjBindings.erase(it);
531 pObjInfo->pMemObjInfo = NULL;
532 result = VK_TRUE;
533 break;
534 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600535 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600536 if (result == VK_FALSE) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600537 char str[1024];
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500538 sprintf(str, "While trying to clear mem binding for object %p, unable to find that object referenced by mem obj %p",
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500539 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600540 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600541 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700542 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700543 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600544 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700545}
546
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500547// For NULL mem case, output warning
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500548// Make sure given object is in global object map
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500549// IF a previous binding existed, output validation error
550// Otherwise, add reference from objectInfo to memoryInfo
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500551// Add reference off of objInfo
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600552// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500553static bool32_t set_object_binding(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600554 VkObject object,
555 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700556{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600557 bool32_t result = VK_FALSE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700558 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600559 if (mem == VK_NULL_HANDLE) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500560 char str[1024];
561 sprintf(str, "Attempting to Bind Obj(%p) to NULL", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600562 layerCbMsg(VK_DBG_REPORT_WARN_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500563 return VK_TRUE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600564 } else {
565 char str[1024];
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500566 MT_OBJ_INFO* pObjInfo = get_object_info(object);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500567 if (!pObjInfo) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600568 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600569 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600570 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600571 }
572 // non-null case so should have real mem obj
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500573 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
574 if (!pInfo) {
575 sprintf(str, "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600576 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500577 return VK_FALSE;
578 } else {
579 if (pObjInfo->pMemObjInfo != NULL) {
580 sprintf(str, "Attempting to bind memory (%p) to object (%p) which has already been bound to mem object %p",
581 (void*)mem, (void*)object, (void*)pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600582 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_REBIND_OBJECT, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500583 return VK_FALSE;
584 }
585 else {
586 pInfo->pObjBindings.push_front(object);
587 pInfo->refCount++;
588
589 // For image objects, make sure default memory state is correctly set
590 // TODO : What's the best/correct way to handle this?
591 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
592 if (pObjInfo->create_info.image_create_info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
593 VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)) {
594 // TODO:: More memory state transition stuff.
595 }
596 }
597 pObjInfo->pMemObjInfo = pInfo;
598 }
599 }
600 }
601 return VK_TRUE;
602}
603
604// For NULL mem case, clear any previous binding Else...
605// Make sure given object is in global object map
606// IF a previous binding existed, update binding
607// Add reference from objectInfo to memoryInfo
608// Add reference off of objInfo
609// Return VK_TRUE if addition is successful, VK_FALSE otherwise
610static bool32_t set_sparse_buffer_binding(
611 VkObject object,
612 VkDeviceMemory mem)
613{
614 bool32_t result = VK_FALSE;
615 // Handle NULL case separately, just clear previous binding & decrement reference
616 if (mem == VK_NULL_HANDLE) {
617 clear_object_binding(object);
618 return VK_TRUE;
619 } else {
620 char str[1024];
621 MT_OBJ_INFO* pObjInfo = get_object_info(object);
622 if (!pObjInfo) {
623 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600624 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500625 return VK_FALSE;
626 }
627 // non-null case so should have real mem obj
628 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600629 if (!pInfo) {
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500630 sprintf(str, "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600631 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500632 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600633 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500634 // Search for object in memory object's binding list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600635 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600636 if (pInfo->pObjBindings.size() > 0) {
637 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
638 if ((*it) == object) {
639 found = VK_TRUE;
640 break;
641 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600642 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600643 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500644 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600645 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500646 pInfo->pObjBindings.push_front(object);
647 pInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500648 }
649
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500650 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500651 clear_object_binding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500652 sprintf(str, "Updating memory binding for object %p from mem obj %p to %p", object, pObjInfo->pMemObjInfo->mem, mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600653 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500654 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500655 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis8be20fd2015-01-07 17:49:29 -0700656 }
657 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600658 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700659}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600660
Tobin Ehlis6663f492014-11-10 12:29:12 -0700661// Print details of global Obj tracking list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500662static void print_object_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600663 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700664{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500665 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500666 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500667 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600668 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600669 if (objectMap.size() <= 0)
670 return;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600671 for (unordered_map<VkObject, MT_OBJ_INFO>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
672 pInfo = &(*ii).second;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500673 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600674 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700675 }
676}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600677
Tobin Ehlis6663f492014-11-10 12:29:12 -0700678// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500679static VkDeviceMemory get_mem_binding_from_object(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600680 const VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700681{
Tony Barbourd1c35722015-04-16 15:59:00 -0600682 VkDeviceMemory mem = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500683 MT_OBJ_INFO* pObjInfo = get_object_info(object);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500684 if (pObjInfo) {
685 if (pObjInfo->pMemObjInfo) {
686 mem = pObjInfo->pMemObjInfo->mem;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600687 } else {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700688 char str[1024];
689 sprintf(str, "Trying to get mem binding for object %p but object has no mem binding", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600690 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500691 print_object_list();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700692 }
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600693 } else {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700694 char str[1024];
695 sprintf(str, "Trying to get mem binding for object %p but no such object in global list", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600696 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500697 print_object_list();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700698 }
699 return mem;
700}
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500701
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500702// Print details of MemObjInfo list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500703static void print_mem_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600704 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700705{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500706 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700707 // Just printing each msg individually for now, may want to package these into single large print
708 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500709 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600710 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500711
David Pinedod8f83d82015-04-27 16:36:17 -0600712 if (memObjMap.size() <= 0)
713 return;
714
Mike Stroyandd7aed72015-05-19 17:03:40 -0600715 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
716 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500717
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500718 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600719 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500720 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600721 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500722 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600723 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500724 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600725 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500726 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600727 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500728 } else {
Chia-I Wuf8693382015-04-16 22:02:10 +0800729 sprintf(str, " Mem Alloc info is NULL (alloc done by vkCreateSwapChainWSI())");
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600730 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500731 }
732
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600733 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600734 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600735 if (pInfo->pObjBindings.size() > 0) {
736 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
737 sprintf(str, " VK OBJECT %p", (*it));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600738 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600739 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500740 }
741
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600742 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600743 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600744 if (pInfo->pCmdBufferBindings.size() > 0)
745 {
746 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
747 sprintf(str, " VK CB %p", (*it));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600748 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600749 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700750 }
751 }
752}
753
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600754static void printCBList(
755 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700756{
Mike Stroyan950496e2015-05-19 15:16:08 -0600757 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500758 MT_CB_INFO* pCBInfo = NULL;
759 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600760 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500761
David Pinedod8f83d82015-04-27 16:36:17 -0600762 if (cbMap.size() <= 0)
763 return;
764
Mike Stroyandd7aed72015-05-19 17:03:40 -0600765 for (unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
766 pCBInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500767
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500768 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
769 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
Mike Stroyan950496e2015-05-19 15:16:08 -0600770 (void*)pCBInfo->lastSubmittedFence);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600771 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500772
David Pinedod8f83d82015-04-27 16:36:17 -0600773 if (pCBInfo->pMemObjList.size() <= 0)
774 continue;
Tony Barbourd1c35722015-04-16 15:59:00 -0600775 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500776 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600777 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700778 }
779 }
780}
781
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500782static VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw)
783 {
784 VkLayerDispatchTable *pTable;
785
786 assert(devw);
787 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject);
788
789 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) *ppDisp);
790 if (it == tableMap.end())
791 {
792 pTable = new VkLayerDispatchTable;
793 tableMap[(void *) *ppDisp] = pTable;
794 } else
795 {
796 return it->second;
797 }
798
Jon Ashburn8fd08252015-05-28 16:25:02 -0600799 layer_initialize_dispatch_table(pTable, devw);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500800
801 return pTable;
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -0600802}
803
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500804
805static VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instw)
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -0600806{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500807 VkLayerInstanceDispatchTable *pTable;
808 assert(instw);
809 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;
810
811 std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap.find((void *) *ppDisp);
812 if (it == tableInstanceMap.end())
813 {
814 pTable = new VkLayerInstanceDispatchTable;
815 tableInstanceMap[(void *) *ppDisp] = pTable;
816 } else
817 {
818 return it->second;
819 }
820
Jon Ashburn8fd08252015-05-28 16:25:02 -0600821 layer_init_instance_dispatch_table(pTable, instw);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500822
823 return pTable;
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -0600824}
825
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600826static void initMemTracker(
827 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700828{
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700829 const char *strOpt;
830 // initialize MemTracker options
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600831 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportFlags);
Ian Elliotte7826712015-03-06 13:50:05 -0700832 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlisee702232015-01-08 14:26:53 -0700833
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600834 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700835 {
836 strOpt = getLayerOption("MemTrackerLogFilename");
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600837 if (strOpt) {
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700838 g_logFile = fopen(strOpt, "w");
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700839 }
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600840 if (g_logFile == NULL) {
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700841 g_logFile = stdout;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600842 }
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700843 }
844
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600845 if (!globalLockInitialized)
846 {
847 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600848 // suggestion is to call this during vkCreateInstance(), and then we
849 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600850 // that the layer have per-instance locks. We need to come back and
851 // address this soon.
852 loader_platform_thread_create_mutex(&globalLock);
853 globalLockInitialized = 1;
854 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700855}
856
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500857// hook DestroyInstance to remove tableInstanceMap entry
858VK_LAYER_EXPORT VkResult VKAPI vkDestroyInstance(VkInstance instance)
859{
860 VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;
861 VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);
862 tableInstanceMap.erase(pDisp);
863 return res;
864}
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600865
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600866VkResult VKAPI vkCreateInstance(
867 const VkInstanceCreateInfo* pCreateInfo,
868 VkInstance* pInstance)
869{
870 loader_platform_thread_once(&g_initOnce, initMemTracker);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600871
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -0600872 VkLayerInstanceDispatchTable *pTable = instance_dispatch_table(*pInstance);
873 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600874
875 if (result == VK_SUCCESS) {
876 enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
Courtney Goeltzenleuchterd02a9642015-06-08 14:58:39 -0600877
878 debug_report_init_instance_extension_dispatch_table(
879 pTable,
880 pTable->GetInstanceProcAddr,
881 *pInstance);
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600882 }
883 return result;
884}
885
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600886VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
887 VkPhysicalDevice gpu,
888 const VkDeviceCreateInfo *pCreateInfo,
889 VkDevice *pDevice)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700890{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500891 VkResult result = instance_dispatch_table(gpu)->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600892 if (result == VK_SUCCESS) {
893 // Save off device in case we need it to create Fences
894 globalDevice = *pDevice;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600895 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700896 return result;
897}
898
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600899VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(
900 VkDevice device)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700901{
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700902 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600903 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600904 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600905 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500906 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500907 printCBList();
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500908 print_object_list();
909 if (VK_FALSE == delete_cmd_buf_info_list()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600910 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600911 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700912 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700913 // Report any memory leaks
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500914 MT_MEM_OBJ_INFO* pInfo = NULL;
David Pinedod8f83d82015-04-27 16:36:17 -0600915 if (memObjMap.size() > 0) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600916 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
917 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500918
David Pinedod8f83d82015-04-27 16:36:17 -0600919 if (pInfo->allocInfo.allocationSize != 0) {
920 sprintf(str, "Mem Object %p has not been freed. You should clean up this memory by calling "
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600921 "vkFreeMemory(%p) prior to vkDestroyDevice().", pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600922 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600923 }
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600924 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700925 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500926
927 // Queues persist until device is destroyed
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500928 delete_queue_info_list();
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500929
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600930 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500931
932 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
933 VkLayerDispatchTable *pTable = tableMap[pDisp];
934 VkResult result = pTable->DestroyDevice(device);
935 tableMap.erase(pDisp);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700936 return result;
937}
938
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600939struct extProps {
940 uint32_t version;
941 const char * const name;
942};
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600943#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600944static const VkExtensionProperties mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
945 {
946 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
947 "MemTracker",
948 0x10,
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600949 "Validation layer: MemTracker",
950 },
951 {
952 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
953 "Validation",
954 0x10,
955 "Validation layer: MemTracker",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600956 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600957};
958
959VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600960 VkExtensionInfoType infoType,
961 uint32_t extensionIndex,
962 size_t *pDataSize,
963 void *pData)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600964{
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500965 // This entrypoint is NOT going to init its own dispatch table since loader calls here early
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600966 uint32_t *count;
967
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600968 if (pDataSize == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600969 return VK_ERROR_INVALID_POINTER;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600970 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600971
972 switch (infoType) {
973 case VK_EXTENSION_INFO_TYPE_COUNT:
974 *pDataSize = sizeof(uint32_t);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600975 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600976 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600977 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600978 count = (uint32_t *) pData;
979 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
980 break;
981 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
982 *pDataSize = sizeof(VkExtensionProperties);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600983 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600984 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600985 }
986 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600987 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600988 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600989 memcpy((VkExtensionProperties *) pData, &mtExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600990 break;
991 default:
992 return VK_ERROR_INVALID_VALUE;
993 };
994
995 return VK_SUCCESS;
996}
997
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600998VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionInfo(
999 VkPhysicalDevice physical_device,
1000 VkExtensionInfoType infoType,
1001 uint32_t extensionIndex,
1002 size_t *pDataSize,
1003 void *pData)
1004{
1005 uint32_t *count;
1006
1007 if (pDataSize == NULL) {
1008 return VK_ERROR_INVALID_POINTER;
1009 }
1010
1011 switch (infoType) {
1012 case VK_EXTENSION_INFO_TYPE_COUNT:
1013 *pDataSize = sizeof(uint32_t);
1014 if (pData == NULL) {
1015 return VK_SUCCESS;
1016 }
1017 count = (uint32_t *) pData;
1018 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
1019 break;
1020 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1021 *pDataSize = sizeof(VkExtensionProperties);
1022 if (pData == NULL) {
1023 return VK_SUCCESS;
1024 }
1025 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE) {
1026 return VK_ERROR_INVALID_VALUE;
1027 }
1028 memcpy((VkExtensionProperties *) pData, &mtExts[extensionIndex], sizeof(VkExtensionProperties));
1029 break;
1030 default:
1031 return VK_ERROR_INVALID_VALUE;
1032 }
1033
1034 return VK_SUCCESS;
1035}
1036
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001037VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(
1038 VkDevice device,
1039 uint32_t queueNodeIndex,
1040 uint32_t queueIndex,
1041 VkQueue *pQueue)
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001042{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001043 VkResult result = device_dispatch_table(device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001044 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001045 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001046 add_queue_info(*pQueue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001047 loader_platform_thread_unlock_mutex(&globalLock);
1048 }
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001049 return result;
1050}
1051
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001052VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1053 VkQueue queue,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001054 uint32_t cmdBufferCount,
1055 const VkCmdBuffer *pCmdBuffers,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001056 VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001057{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001058 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001059 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001060 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001061 uint64_t fenceId = add_fence_info(fence, queue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001062
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001063 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001064 printCBList();
Tobin Ehlis6663f492014-11-10 12:29:12 -07001065 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001066 pCBInfo = get_cmd_buf_info(pCmdBuffers[i]);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001067 pCBInfo->fenceId = fenceId;
Mike Stroyan950496e2015-05-19 15:16:08 -06001068 pCBInfo->lastSubmittedFence = fence;
1069 pCBInfo->lastSubmittedQueue = queue;
Tobin Ehlis6663f492014-11-10 12:29:12 -07001070 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001071
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001072 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001073 VkResult result = device_dispatch_table(queue)->QueueSubmit(
1074 queue, cmdBufferCount, pCmdBuffers, fence);
Courtney Goeltzenleuchterd3fb9552015-04-02 13:39:07 -06001075 return result;
1076}
1077
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001078VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(
1079 VkDevice device,
1080 const VkMemoryAllocInfo *pAllocInfo,
1081 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001082{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001083 VkResult result = device_dispatch_table(device)->AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001084 // TODO : Track allocations and overall size here
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001085 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001086 add_mem_obj_info(*pMem, pAllocInfo);
1087 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001088 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001089 return result;
1090}
1091
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001092VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(
1093 VkDevice device,
1094 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001095{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001096 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisc0418f92014-11-25 14:47:20 -07001097 * freeing a memory object, an application must ensure the memory object is unbound from
1098 * all API objects referencing it and that it is not referenced by any queued command buffers
1099 */
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001100 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001101 bool32_t noerror = freeMemObjInfo(mem, false);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001102 print_mem_list();
1103 print_object_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001104 printCBList();
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001105 // Output an warning message for proper error/warning handling
1106 if (noerror == VK_FALSE) {
1107 char str[1024];
1108 sprintf(str, "Freeing memory object while it still has references: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001109 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001110 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001111 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001112 VkResult result = device_dispatch_table(device)->FreeMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001113 return result;
1114}
1115
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001116VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(
1117 VkDevice device,
1118 VkDeviceMemory mem,
1119 VkMemoryPriority priority)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001120{
1121 // TODO : Update tracking for this alloc
1122 // Make sure memory is not pinned, which can't have priority set
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001123 VkResult result = device_dispatch_table(device)->SetMemoryPriority(device, mem, priority);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001124 return result;
1125}
1126
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001127VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(
1128 VkDevice device,
1129 VkDeviceMemory mem,
1130 VkDeviceSize offset,
1131 VkDeviceSize size,
1132 VkFlags flags,
1133 void **ppData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001134{
1135 // TODO : Track when memory is mapped
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001136 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001137 MT_MEM_OBJ_INFO *pMemObj = get_mem_obj_info(mem);
Tony Barbourd1c35722015-04-16 15:59:00 -06001138 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001139 char str[1024];
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001140 sprintf(str, "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001141 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001142 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001143 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001144 VkResult result = device_dispatch_table(device)->MapMemory(device, mem, offset, size, flags, ppData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001145 return result;
1146}
1147
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001148VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(
1149 VkDevice device,
1150 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001151{
1152 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1153 // Make sure that memory was ever mapped to begin with
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001154 VkResult result = device_dispatch_table(device)->UnmapMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001155 return result;
1156}
1157
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001158VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(
1159 VkDevice device,
1160 const void *pSysMem,
1161 size_t memSize,
1162 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001163{
1164 // TODO : Track this
1165 // Verify that memory is actually pinnable
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001166 VkResult result = device_dispatch_table(device)->PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001167 return result;
1168}
1169
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001170VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(
1171 VkDevice device,
1172 const VkMemoryOpenInfo *pOpenInfo,
1173 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001174{
1175 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001176 VkResult result = device_dispatch_table(device)->OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001177 return result;
1178}
1179
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001180VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(
1181 VkDevice device,
1182 const VkPeerMemoryOpenInfo *pOpenInfo,
1183 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001184{
1185 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001186 VkResult result = device_dispatch_table(device)->OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001187 return result;
1188}
1189
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001190VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(
1191 VkDevice device,
1192 const VkPeerImageOpenInfo *pOpenInfo,
1193 VkImage *pImage,
1194 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001195{
1196 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001197 VkResult result = device_dispatch_table(device)->OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001198 return result;
1199}
1200
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001201VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(
1202 VkDevice device,
1203 VkObjectType objType,
1204 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001205{
Mike Stroyandd7aed72015-05-19 17:03:40 -06001206 unordered_map<VkObject, MT_OBJ_INFO>::iterator item;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001207 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001208
Mike Stroyan950496e2015-05-19 15:16:08 -06001209 // First check if this is a CmdBuffer or fence
1210 switch (objType) {
1211 case VK_OBJECT_TYPE_COMMAND_BUFFER:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001212 delete_cmd_buf_info((VkCmdBuffer)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001213 break;
1214 case VK_OBJECT_TYPE_FENCE:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001215 delete_fence_info((VkFence)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001216 break;
1217 default:
1218 break;
Tobin Ehlisa98df732014-11-27 07:52:04 -07001219 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001220
Mike Stroyan950496e2015-05-19 15:16:08 -06001221 if ((item = objectMap.find(object)) != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -06001222 MT_OBJ_INFO* pDelInfo = &(*item).second;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001223 if (pDelInfo->pMemObjInfo) {
Tobin Ehlisa98df732014-11-27 07:52:04 -07001224 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001225 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Tony Barbourd1c35722015-04-16 15:59:00 -06001226 VkDeviceMemory memToFree = pDelInfo->pMemObjInfo->mem;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001227 clear_object_binding(object);
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -06001228 freeMemObjInfo(memToFree, true);
1229 }
1230 else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001231 // Remove this object from memory object's reference list and decrement its ref counter
1232 clear_object_binding(object);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001233 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001234 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001235 objectMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001236 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001237
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001238 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001239 VkResult result = device_dispatch_table(device)->DestroyObject(device, objType, object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001240 return result;
1241}
1242
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001243VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(
1244 VkDevice device,
1245 VkObjectType objType,
1246 VkObject object,
1247 VkObjectInfoType infoType,
1248 size_t *pDataSize,
1249 void *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001250{
1251 // TODO : What to track here?
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001252 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001253 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues,
1254 // command buffers, shaders and memory objects.
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001255 VkResult result = device_dispatch_table(device)->GetObjectInfo(device, objType, object, infoType, pDataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001256 return result;
1257}
1258
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001259VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(
1260 VkDevice device,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001261 VkObjectType objType,
1262 VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001263 VkDeviceMemory mem,
1264 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001265{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001266 VkResult result = device_dispatch_table(device)->BindObjectMemory(device, objType, object, mem, offset);
Mike Stroyanb050c682015-04-17 12:36:38 -06001267 loader_platform_thread_lock_mutex(&globalLock);
1268 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001269 set_object_binding(object, mem);
1270 print_object_list();
1271 print_mem_list();
Mike Stroyanb050c682015-04-17 12:36:38 -06001272 loader_platform_thread_unlock_mutex(&globalLock);
1273 return result;
1274}
1275
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001276VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001277 VkQueue queue,
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001278 VkBuffer buffer,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001279 VkDeviceSize rangeOffset,
1280 VkDeviceSize rangeSize,
1281 VkDeviceMemory mem,
1282 VkDeviceSize memOffset)
Mike Stroyanb050c682015-04-17 12:36:38 -06001283{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001284 VkResult result = device_dispatch_table(queue)->QueueBindSparseBufferMemory(
1285 queue, buffer, rangeOffset, rangeSize, mem, memOffset);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001286 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001287 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001288 if (VK_FALSE == set_sparse_buffer_binding(buffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001289 char str[1024];
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001290 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)buffer, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001291 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_BUFFER, buffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001292 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001293 print_object_list();
1294 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001295 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001296 return result;
1297}
1298
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001299VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(
1300 VkDevice device,
1301 const VkFenceCreateInfo *pCreateInfo,
1302 VkFence *pFence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001303{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001304 VkResult result = device_dispatch_table(device)->CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001305 if (VK_SUCCESS == result) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001306 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001307 add_object_info(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001308 loader_platform_thread_unlock_mutex(&globalLock);
1309 }
1310 return result;
1311}
1312
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001313VK_LAYER_EXPORT VkResult VKAPI vkResetFences(
1314 VkDevice device,
1315 uint32_t fenceCount,
1316 VkFence *pFences)
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001317{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001318 /*
1319 * TODO: Shouldn't we check for error conditions before passing down the chain?
1320 * What if reason result is not VK_SUCCESS is something we could report as a validation error?
1321 */
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001322 VkResult result = device_dispatch_table(device)->ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001323 if (VK_SUCCESS == result) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001324 loader_platform_thread_lock_mutex(&globalLock);
1325 // Reset fence state in fenceCreateInfo structure
1326 for (uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001327 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001328 if (pObjectInfo != NULL) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001329 // Validate fences in SIGNALED state
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001330 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001331 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001332 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001333 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001334 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001335 }
1336 else {
1337 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001338 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001339 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001340 }
1341 }
1342 loader_platform_thread_unlock_mutex(&globalLock);
1343 }
1344 return result;
1345}
1346
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001347VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(
1348 VkDevice device,
1349 VkFence fence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001350{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001351 VkResult result = device_dispatch_table(device)->GetFenceStatus(device, fence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001352 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001353 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001354 update_fence_tracking(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001355 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001356 }
1357 return result;
1358}
1359
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001360VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(
1361 VkDevice device,
1362 uint32_t fenceCount,
1363 const VkFence *pFences,
1364 bool32_t waitAll,
1365 uint64_t timeout)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001366{
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001367 // Verify fence status of submitted fences
1368 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001369 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001370 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001371 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001372 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001373 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001374 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_FENCE, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001375 }
1376 }
1377 }
1378
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001379 VkResult result = device_dispatch_table(device)->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001380 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05001381
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001382 if (VK_SUCCESS == result) {
Mark Lobodzinski50932972015-04-02 20:49:09 -05001383 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001384 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001385 update_fence_tracking(pFences[i]);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001386 }
1387 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001388 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001389 loader_platform_thread_unlock_mutex(&globalLock);
1390 return result;
1391}
1392
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001393VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(
1394 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001395{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001396 VkResult result = device_dispatch_table(queue)->QueueWaitIdle(queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001397 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001398 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001399 retire_queue_fences(queue);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001400 loader_platform_thread_unlock_mutex(&globalLock);
1401 }
1402 return result;
1403}
1404
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001405VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(
1406 VkDevice device)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001407{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001408 VkResult result = device_dispatch_table(device)->DeviceWaitIdle(device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001409 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001410 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001411 retire_device_fences(device);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001412 loader_platform_thread_unlock_mutex(&globalLock);
1413 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001414 return result;
1415}
1416
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001417VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(
1418 VkDevice device,
1419 const VkEventCreateInfo *pCreateInfo,
1420 VkEvent *pEvent)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001421{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001422 VkResult result = device_dispatch_table(device)->CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001423 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001424 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001425 add_object_info(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001426 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001427 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001428 return result;
1429}
1430
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001431VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(
1432 VkDevice device,
1433 const VkQueryPoolCreateInfo *pCreateInfo,
1434 VkQueryPool *pQueryPool)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001435{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001436 VkResult result = device_dispatch_table(device)->CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001437 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001438 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001439 add_object_info(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001440 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001441 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001442 return result;
1443}
1444
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001445VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(
1446 VkDevice device,
1447 const VkBufferCreateInfo *pCreateInfo,
1448 VkBuffer *pBuffer)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001449{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001450 VkResult result = device_dispatch_table(device)->CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001451 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001452 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001453 add_object_info(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001454 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001455 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001456 return result;
1457}
1458
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001459VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(
1460 VkDevice device,
1461 const VkBufferViewCreateInfo *pCreateInfo,
1462 VkBufferView *pView)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001463{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001464 VkResult result = device_dispatch_table(device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001465 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001466 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001467 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001468 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001469 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001470 return result;
1471}
1472
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001473VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
1474 VkDevice device,
1475 const VkImageCreateInfo *pCreateInfo,
1476 VkImage *pImage)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001477{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001478 VkResult result = device_dispatch_table(device)->CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001479 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001480 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001481 add_object_info(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001482 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001483 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001484 return result;
1485}
1486
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001487VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(
1488 VkDevice device,
1489 const VkImageViewCreateInfo *pCreateInfo,
1490 VkImageView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001491{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001492 VkResult result = device_dispatch_table(device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001493 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001494 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001495 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
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 vkCreateColorAttachmentView(
1502 VkDevice device,
1503 const VkColorAttachmentViewCreateInfo *pCreateInfo,
1504 VkColorAttachmentView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001505{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001506 VkResult result = device_dispatch_table(device)->CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001507 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001508 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001509 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001510 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001511 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001512 return result;
1513}
1514
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001515VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(
1516 VkDevice device,
1517 const VkDepthStencilViewCreateInfo *pCreateInfo,
1518 VkDepthStencilView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001519{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001520 VkResult result = device_dispatch_table(device)->CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001521 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001522 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001523 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001524 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001525 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001526 return result;
1527}
1528
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001529VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
1530 VkDevice device,
1531 const VkShaderCreateInfo *pCreateInfo,
1532 VkShader *pShader)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001533{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001534 VkResult result = device_dispatch_table(device)->CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001535 return result;
1536}
1537
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001538VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(
1539 VkDevice device,
1540 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1541 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001542{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001543 VkResult result = device_dispatch_table(device)->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001544 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001545 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001546 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001547 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001548 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001549 return result;
1550}
1551
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001552VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001553 VkDevice device,
1554 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1555 VkPipeline basePipeline,
1556 VkPipeline *pPipeline)
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001557{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001558 VkResult result = device_dispatch_table(device)->CreateGraphicsPipelineDerivative(
1559 device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001560 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001561 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001562 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001563 loader_platform_thread_unlock_mutex(&globalLock);
1564 }
1565 return result;
1566}
1567
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001568VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(
1569 VkDevice device,
1570 const VkComputePipelineCreateInfo *pCreateInfo,
1571 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001572{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001573 VkResult result = device_dispatch_table(device)->CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001574 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001575 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001576 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001577 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001578 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001579 return result;
1580}
1581
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001582VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(
1583 VkDevice device,
1584 const VkSamplerCreateInfo *pCreateInfo,
1585 VkSampler *pSampler)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001586{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001587 VkResult result = device_dispatch_table(device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001588 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001589 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001590 add_object_info(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001591 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001592 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001593 return result;
1594}
1595
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001596VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(
1597 VkDevice device,
1598 const VkDynamicVpStateCreateInfo *pCreateInfo,
1599 VkDynamicVpState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001600{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001601 VkResult result = device_dispatch_table(device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001602 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001603 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001604 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001605 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001606 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001607 return result;
1608}
1609
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001610VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(
1611 VkDevice device,
1612 const VkDynamicRsStateCreateInfo *pCreateInfo,
1613 VkDynamicRsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001614{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001615 VkResult result = device_dispatch_table(device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001616 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001617 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001618 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001619 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001620 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001621 return result;
1622}
1623
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001624VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(
1625 VkDevice device,
1626 const VkDynamicCbStateCreateInfo *pCreateInfo,
1627 VkDynamicCbState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001628{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001629 VkResult result = device_dispatch_table(device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001630 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001631 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001632 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001633 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001634 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001635 return result;
1636}
1637
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001638VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(
1639 VkDevice device,
1640 const VkDynamicDsStateCreateInfo *pCreateInfo,
1641 VkDynamicDsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001642{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001643 VkResult result = device_dispatch_table(device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001644 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001645 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001646 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001647 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001648 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001649 return result;
1650}
1651
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001652VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(
1653 VkDevice device,
1654 const VkCmdBufferCreateInfo *pCreateInfo,
1655 VkCmdBuffer *pCmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001656{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001657 VkResult result = device_dispatch_table(device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001658 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001659 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001660 if (*pCmdBuffer)
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001661 add_cmd_buf_info(*pCmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001662 printCBList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001663 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001664 return result;
1665}
1666
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001667VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(
1668 VkCmdBuffer cmdBuffer,
1669 const VkCmdBufferBeginInfo *pBeginInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001670{
Mike Stroyan950496e2015-05-19 15:16:08 -06001671 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001672 // 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 -06001673 if (!checkCBCompleted(cmdBuffer)) {
1674 char str[1024];
1675 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. "
1676 "You must check CB flag before this call.", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001677 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001678 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001679 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001680 VkResult result = device_dispatch_table(cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001681 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001682 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001683 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001684 return result;
1685}
1686
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001687VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(
1688 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001689{
1690 // TODO : Anything to do here?
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001691 VkResult result = device_dispatch_table(cmdBuffer)->EndCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001692 return result;
1693}
1694
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001695VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(
1696 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001697{
Mike Stroyan950496e2015-05-19 15:16:08 -06001698 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001699 // Verify that CB is complete (not in-flight)
Mike Stroyan950496e2015-05-19 15:16:08 -06001700 if (!checkCBCompleted(cmdBuffer)) {
1701 char str[1024];
1702 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before "
1703 "calling vkResetCommandBuffer().", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001704 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001705 }
1706 // Clear memory references as this point.
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001707 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001708 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001709 VkResult result = device_dispatch_table(cmdBuffer)->ResetCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001710 return result;
1711}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001712// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis6663f492014-11-10 12:29:12 -07001713// need to account for that mem now having binding to given cmdBuffer
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001714VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(
1715 VkCmdBuffer cmdBuffer,
1716 VkPipelineBindPoint pipelineBindPoint,
1717 VkPipeline pipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001718{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001719#if 0
1720 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1721 if (getPipeline(pipeline)) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001722 MT_CB_INFO *pCBInfo = get_cmd_buf_info(cmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001723 if (pCBInfo) {
1724 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlisc145be82015-01-08 15:22:32 -07001725 } else {
1726 char str[1024];
1727 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001728 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 -07001729 }
1730 }
1731 else {
1732 char str[1024];
1733 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001734 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 -07001735 }
1736#endif
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001737 device_dispatch_table(cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001738}
1739
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001740VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(
1741 VkCmdBuffer cmdBuffer,
1742 VkStateBindPoint stateBindPoint,
1743 VkDynamicStateObject state)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001744{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001745 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001746 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001747 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001748 if (!pCmdBuf) {
1749 char str[1024];
1750 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001751 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001752 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001753 pObjInfo = get_object_info(state);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001754 if (!pObjInfo) {
Tobin Ehlisc145be82015-01-08 15:22:32 -07001755 char str[1024];
1756 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001757 /* TODO: put in real object type */
1758 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001759 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001760 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001761 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001762 device_dispatch_table(cmdBuffer)->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001763}
1764
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001765VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001766 VkCmdBuffer cmdBuffer,
1767 VkPipelineBindPoint pipelineBindPoint,
1768 uint32_t firstSet,
1769 uint32_t setCount,
1770 const VkDescriptorSet *pDescriptorSets,
1771 uint32_t dynamicOffsetCount,
1772 const uint32_t *pDynamicOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001773{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001774 // TODO : Somewhere need to verify that all textures referenced by shaders in DS are in some type of *SHADER_READ* state
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001775 device_dispatch_table(cmdBuffer)->CmdBindDescriptorSets(
1776 cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001777}
1778
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001779VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001780 VkCmdBuffer cmdBuffer,
1781 uint32_t startBinding,
1782 uint32_t bindingCount,
1783 const VkBuffer *pBuffers,
1784 const VkDeviceSize *pOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001785{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001786 device_dispatch_table(cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wu19156822015-01-05 13:42:56 +08001787}
1788
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001789VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(
1790 VkCmdBuffer cmdBuffer,
1791 VkBuffer buffer,
1792 VkDeviceSize offset,
1793 VkIndexType indexType)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001794{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001795 device_dispatch_table(cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001796}
1797
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001798VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(
1799 VkCmdBuffer cmdBuffer,
1800 VkBuffer buffer,
1801 VkDeviceSize offset,
1802 uint32_t count,
1803 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001804{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001805 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001806 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1807 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001808 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001809 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001810 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001811 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001812 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001813 device_dispatch_table(cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001814}
1815
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001816VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
1817 VkCmdBuffer cmdBuffer,
1818 VkBuffer buffer,
1819 VkDeviceSize offset,
1820 uint32_t count,
1821 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001822{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001823 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001824 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1825 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001826 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001827 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001828 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001829 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001830 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001831 device_dispatch_table(cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001832}
1833
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001834VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(
1835 VkCmdBuffer cmdBuffer,
1836 VkBuffer buffer,
1837 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001838{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001839 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001840 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1841 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001842 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001843 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001844 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001845 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001846 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001847 device_dispatch_table(cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001848}
1849
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001850VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(
1851 VkCmdBuffer cmdBuffer,
1852 VkBuffer srcBuffer,
1853 VkBuffer destBuffer,
1854 uint32_t regionCount,
1855 const VkBufferCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001856{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001857 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858 VkDeviceMemory mem = get_mem_binding_from_object(srcBuffer);
1859 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001860 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001861 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001862 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001863 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001864 mem = get_mem_binding_from_object(destBuffer);
1865 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001866 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001867 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001868 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001869 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001870 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001871 device_dispatch_table(cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001872}
1873
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001874VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(
1875 VkCmdBuffer cmdBuffer,
1876 VkImage srcImage,
1877 VkImageLayout srcImageLayout,
1878 VkImage destImage,
1879 VkImageLayout destImageLayout,
1880 uint32_t regionCount,
1881 const VkImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001882{
1883 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001884 device_dispatch_table(cmdBuffer)->CmdCopyImage(
1885 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001886}
1887
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001888VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(
1889 VkCmdBuffer cmdBuffer,
1890 VkImage srcImage,
1891 VkImageLayout srcImageLayout,
1892 VkImage destImage,
1893 VkImageLayout destImageLayout,
1894 uint32_t regionCount,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05001895 const VkImageBlit *pRegions,
1896 VkTexFilter filter)
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001897{
1898 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001899 device_dispatch_table(cmdBuffer)->CmdBlitImage(
1900 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001901}
1902
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001903VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(
1904 VkCmdBuffer cmdBuffer,
1905 VkBuffer srcBuffer,
1906 VkImage destImage,
1907 VkImageLayout destImageLayout,
1908 uint32_t regionCount,
1909 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001910{
1911 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001912 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001913 VkDeviceMemory mem = get_mem_binding_from_object(destImage);
1914 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001915 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001916 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001917 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001918 }
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001919
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001920 mem = get_mem_binding_from_object(srcBuffer);
1921 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001922 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001923 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001924 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001925 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001926 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001927 device_dispatch_table(cmdBuffer)->CmdCopyBufferToImage(
1928 cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001929}
1930
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001931VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(
1932 VkCmdBuffer cmdBuffer,
1933 VkImage srcImage,
1934 VkImageLayout srcImageLayout,
1935 VkBuffer destBuffer,
1936 uint32_t regionCount,
1937 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001938{
1939 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001940 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001941 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
1942 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001943 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001944 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001945 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001946 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001947 mem = get_mem_binding_from_object(destBuffer);
1948 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001949 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001950 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001951 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001952 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001953 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001954 device_dispatch_table(cmdBuffer)->CmdCopyImageToBuffer(
1955 cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001956}
1957
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001958VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
1959 VkCmdBuffer cmdBuffer,
1960 VkBuffer destBuffer,
1961 VkDeviceSize destOffset,
1962 VkDeviceSize dataSize,
1963 const uint32_t *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001964{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001965 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001966 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1967 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001968 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001969 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001970 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001971 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001972 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001973 device_dispatch_table(cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001974}
1975
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001976VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
1977 VkCmdBuffer cmdBuffer,
1978 VkBuffer destBuffer,
1979 VkDeviceSize destOffset,
1980 VkDeviceSize fillSize,
1981 uint32_t data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001982{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001983 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001984 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1985 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001986 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001987 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001988 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001989 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001990 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001991 device_dispatch_table(cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001992}
1993
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001994VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
1995 VkCmdBuffer cmdBuffer,
1996 VkImage image,
1997 VkImageLayout imageLayout,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001998 const VkClearColor *pColor,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001999 uint32_t rangeCount,
2000 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002001{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002002 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002003 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002004 VkDeviceMemory mem = get_mem_binding_from_object(image);
2005 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002006 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002007 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002008 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002009 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002010 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002011 device_dispatch_table(cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002012}
2013
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002014VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(
2015 VkCmdBuffer cmdBuffer,
2016 VkImage image,
2017 VkImageLayout imageLayout,
2018 float depth,
2019 uint32_t stencil,
2020 uint32_t rangeCount,
2021 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002022{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002023 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002024 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002025 VkDeviceMemory mem = get_mem_binding_from_object(image);
2026 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002027 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002028 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002029 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002030 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002031 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002032 device_dispatch_table(cmdBuffer)->CmdClearDepthStencil(
2033 cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002034}
2035
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002036VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(
2037 VkCmdBuffer cmdBuffer,
2038 VkImage srcImage,
2039 VkImageLayout srcImageLayout,
2040 VkImage destImage,
2041 VkImageLayout destImageLayout,
2042 uint32_t regionCount,
2043 const VkImageResolve *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002044{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002045 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002046 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
2047 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002048 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002049 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002050 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002051 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 mem = get_mem_binding_from_object(destImage);
2053 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002054 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002055 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002056 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002057 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002058 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002059 device_dispatch_table(cmdBuffer)->CmdResolveImage(
2060 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002061}
2062
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002063VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(
2064 VkCmdBuffer cmdBuffer,
2065 VkQueryPool queryPool,
2066 uint32_t slot,
2067 VkFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002068{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002069 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002070 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2071 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002072 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002073 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002074 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002075 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002076 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002077 device_dispatch_table(cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002078}
2079
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002080VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(
2081 VkCmdBuffer cmdBuffer,
2082 VkQueryPool queryPool,
2083 uint32_t slot)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002084{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002085 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002086 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2087 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002088 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002089 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002090 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002091 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002092 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002093 device_dispatch_table(cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002094}
2095
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002096VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(
2097 VkCmdBuffer cmdBuffer,
2098 VkQueryPool queryPool,
2099 uint32_t startQuery,
2100 uint32_t queryCount)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002101{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002102 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002103 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2104 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002105 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002106 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002107 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002108 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002109 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002110 device_dispatch_table(cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002111}
2112
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002113VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2114 VkInstance instance,
2115 VkFlags msgFlags,
2116 const PFN_vkDbgMsgCallback pfnMsgCallback,
2117 void* pUserData,
2118 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002119{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002120 return layer_create_msg_callback(instance, instance_dispatch_table(instance), msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002121}
2122
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002123VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2124 VkInstance instance,
2125 VkDbgMsgCallback msgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002126{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002127 return layer_destroy_msg_callback(instance, instance_dispatch_table(instance), msgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002128}
2129
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002130VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(
2131 VkDevice device,
2132 const VkSwapChainCreateInfoWSI *pCreateInfo,
2133 VkSwapChainWSI *pSwapChain)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002134{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002135 VkResult result = device_dispatch_table(device)->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002136
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002137 if (VK_SUCCESS == result) {
Chia-I Wuf8693382015-04-16 22:02:10 +08002138 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002139 add_swap_chain_info(*pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002140 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002141 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002142
Tobin Ehlis6663f492014-11-10 12:29:12 -07002143 return result;
2144}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002145
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002146VK_LAYER_EXPORT VkResult VKAPI vkDestroySwapChainWSI(
2147 VkSwapChainWSI swapChain)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002148{
2149 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002150
2151 if (swapChainMap.find(swapChain) != swapChainMap.end()) {
2152 MT_SWAP_CHAIN_INFO* pInfo = swapChainMap[swapChain];
2153
David Pinedod8f83d82015-04-27 16:36:17 -06002154 if (pInfo->images.size() > 0) {
2155 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2156 it != pInfo->images.end(); it++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002157 clear_object_binding(it->image);
David Pinedod8f83d82015-04-27 16:36:17 -06002158 freeMemObjInfo(it->memory, true);
Chia-I Wuf8693382015-04-16 22:02:10 +08002159
David Pinedod8f83d82015-04-27 16:36:17 -06002160 objectMap.erase(it->image);
2161 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002162 }
2163
2164 delete pInfo;
2165 swapChainMap.erase(swapChain);
2166 }
2167
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002168 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002169
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002170 return device_dispatch_table(swapChain)->DestroySwapChainWSI(swapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002171}
2172
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002173VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(
2174 VkSwapChainWSI swapChain,
2175 VkSwapChainInfoTypeWSI infoType,
2176 size_t *pDataSize,
2177 void *pData)
Chia-I Wuf8693382015-04-16 22:02:10 +08002178{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002179 VkResult result = device_dispatch_table(swapChain)->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
Chia-I Wuf8693382015-04-16 22:02:10 +08002180
2181 if (infoType == VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI && result == VK_SUCCESS) {
2182 const size_t count = *pDataSize / sizeof(VkSwapChainImageInfoWSI);
2183 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain];
2184
2185 if (pInfo->images.empty()) {
2186 pInfo->images.resize(count);
2187 memcpy(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count);
2188
David Pinedod8f83d82015-04-27 16:36:17 -06002189 if (pInfo->images.size() > 0) {
2190 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2191 it != pInfo->images.end(); it++) {
2192 // Add image object, then insert the new Mem Object and then bind it to created image
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002193 add_object_info(it->image, VK_STRUCTURE_TYPE_MAX_ENUM, &pInfo->createInfo, sizeof(pInfo->createInfo), "persistent_image");
2194 add_mem_obj_info(it->memory, NULL);
2195 if (VK_FALSE == set_object_binding(it->image, it->memory)) {
David Pinedod8f83d82015-04-27 16:36:17 -06002196 char str[1024];
2197 sprintf(str, "In vkGetSwapChainInfoWSI(), unable to set image %p binding to mem obj %p", (void*)it->image, (void*)it->memory);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002198 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, it->image, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -06002199 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002200 }
2201 }
2202 } else {
2203 const bool mismatch = (pInfo->images.size() != count ||
2204 memcmp(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count));
2205
2206 if (mismatch) {
2207 char str[1024];
2208 sprintf(str, "vkGetSwapChainInfoWSI(%p, VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI) returned mismatching data", swapChain);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002209 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_SWAP_CHAIN_WSI, (VkObject) swapChain, 0, MEMTRACK_NONE, "SWAP_CHAIN", str);
Chia-I Wuf8693382015-04-16 22:02:10 +08002210 }
2211 }
2212 }
2213
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002214 return result;
2215}
Tobin Ehlis6663f492014-11-10 12:29:12 -07002216
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002217VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(
2218 VkDevice dev,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002219 const char *funcName)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002220{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002221 void *fptr;
2222
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002223 if (dev == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002224 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002225 }
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002226
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07002227 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002228
Jon Ashburn8fd08252015-05-28 16:25:02 -06002229 /* loader uses this to force layer initialization; device object is wrapped */
2230 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
2231 initDeviceTable((const VkBaseLayerObject *) dev);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002232 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002233 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002234 if (!strcmp(funcName, "vkDestroyDevice"))
2235 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002236 if (!strcmp(funcName, "vkQueueSubmit"))
2237 return (void*) vkQueueSubmit;
2238 if (!strcmp(funcName, "vkAllocMemory"))
2239 return (void*) vkAllocMemory;
2240 if (!strcmp(funcName, "vkFreeMemory"))
2241 return (void*) vkFreeMemory;
2242 if (!strcmp(funcName, "vkSetMemoryPriority"))
2243 return (void*) vkSetMemoryPriority;
2244 if (!strcmp(funcName, "vkMapMemory"))
2245 return (void*) vkMapMemory;
2246 if (!strcmp(funcName, "vkUnmapMemory"))
2247 return (void*) vkUnmapMemory;
2248 if (!strcmp(funcName, "vkPinSystemMemory"))
2249 return (void*) vkPinSystemMemory;
2250 if (!strcmp(funcName, "vkOpenSharedMemory"))
2251 return (void*) vkOpenSharedMemory;
2252 if (!strcmp(funcName, "vkOpenPeerMemory"))
2253 return (void*) vkOpenPeerMemory;
2254 if (!strcmp(funcName, "vkOpenPeerImage"))
2255 return (void*) vkOpenPeerImage;
2256 if (!strcmp(funcName, "vkDestroyObject"))
2257 return (void*) vkDestroyObject;
2258 if (!strcmp(funcName, "vkGetObjectInfo"))
2259 return (void*) vkGetObjectInfo;
Mark Lobodzinski942b1722015-05-11 17:21:15 -05002260 if (!strcmp(funcName, "vkBindObjectMemory"))
2261 return (void*) vkBindObjectMemory;
2262 if (!strcmp(funcName, "vkQueueBindSparseBufferMemory"))
2263 return (void*) vkQueueBindSparseBufferMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002264 if (!strcmp(funcName, "vkCreateFence"))
2265 return (void*) vkCreateFence;
2266 if (!strcmp(funcName, "vkGetFenceStatus"))
2267 return (void*) vkGetFenceStatus;
2268 if (!strcmp(funcName, "vkResetFences"))
2269 return (void*) vkResetFences;
2270 if (!strcmp(funcName, "vkWaitForFences"))
2271 return (void*) vkWaitForFences;
2272 if (!strcmp(funcName, "vkQueueWaitIdle"))
2273 return (void*) vkQueueWaitIdle;
2274 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2275 return (void*) vkDeviceWaitIdle;
2276 if (!strcmp(funcName, "vkCreateEvent"))
2277 return (void*) vkCreateEvent;
2278 if (!strcmp(funcName, "vkCreateQueryPool"))
2279 return (void*) vkCreateQueryPool;
2280 if (!strcmp(funcName, "vkCreateBuffer"))
2281 return (void*) vkCreateBuffer;
2282 if (!strcmp(funcName, "vkCreateBufferView"))
2283 return (void*) vkCreateBufferView;
2284 if (!strcmp(funcName, "vkCreateImage"))
2285 return (void*) vkCreateImage;
2286 if (!strcmp(funcName, "vkCreateImageView"))
2287 return (void*) vkCreateImageView;
2288 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2289 return (void*) vkCreateColorAttachmentView;
2290 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2291 return (void*) vkCreateDepthStencilView;
2292 if (!strcmp(funcName, "vkCreateShader"))
2293 return (void*) vkCreateShader;
2294 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2295 return (void*) vkCreateGraphicsPipeline;
2296 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2297 return (void*) vkCreateGraphicsPipelineDerivative;
2298 if (!strcmp(funcName, "vkCreateComputePipeline"))
2299 return (void*) vkCreateComputePipeline;
2300 if (!strcmp(funcName, "vkCreateSampler"))
2301 return (void*) vkCreateSampler;
2302 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2303 return (void*) vkCreateDynamicViewportState;
2304 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2305 return (void*) vkCreateDynamicRasterState;
2306 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2307 return (void*) vkCreateDynamicColorBlendState;
2308 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2309 return (void*) vkCreateDynamicDepthStencilState;
2310 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2311 return (void*) vkCreateCommandBuffer;
2312 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2313 return (void*) vkBeginCommandBuffer;
2314 if (!strcmp(funcName, "vkEndCommandBuffer"))
2315 return (void*) vkEndCommandBuffer;
2316 if (!strcmp(funcName, "vkResetCommandBuffer"))
2317 return (void*) vkResetCommandBuffer;
2318 if (!strcmp(funcName, "vkCmdBindPipeline"))
2319 return (void*) vkCmdBindPipeline;
2320 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2321 return (void*) vkCmdBindDynamicStateObject;
2322 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2323 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002324 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2325 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002326 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2327 return (void*) vkCmdBindIndexBuffer;
2328 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2329 return (void*) vkCmdDrawIndirect;
2330 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2331 return (void*) vkCmdDrawIndexedIndirect;
2332 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2333 return (void*) vkCmdDispatchIndirect;
2334 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2335 return (void*) vkCmdCopyBuffer;
2336 if (!strcmp(funcName, "vkCmdCopyImage"))
2337 return (void*) vkCmdCopyImage;
2338 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2339 return (void*) vkCmdCopyBufferToImage;
2340 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2341 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002342 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2343 return (void*) vkCmdUpdateBuffer;
2344 if (!strcmp(funcName, "vkCmdFillBuffer"))
2345 return (void*) vkCmdFillBuffer;
2346 if (!strcmp(funcName, "vkCmdClearColorImage"))
2347 return (void*) vkCmdClearColorImage;
2348 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2349 return (void*) vkCmdClearDepthStencil;
2350 if (!strcmp(funcName, "vkCmdResolveImage"))
2351 return (void*) vkCmdResolveImage;
2352 if (!strcmp(funcName, "vkCmdBeginQuery"))
2353 return (void*) vkCmdBeginQuery;
2354 if (!strcmp(funcName, "vkCmdEndQuery"))
2355 return (void*) vkCmdEndQuery;
2356 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2357 return (void*) vkCmdResetQueryPool;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002358 if (!strcmp(funcName, "vkGetDeviceQueue"))
2359 return (void*) vkGetDeviceQueue;
Chia-I Wuf8693382015-04-16 22:02:10 +08002360 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
2361 return (void*) vkCreateSwapChainWSI;
2362 if (!strcmp(funcName, "vkDestroySwapChainWSI"))
2363 return (void*) vkDestroySwapChainWSI;
2364 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
2365 return (void*) vkGetSwapChainInfoWSI;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002366
2367 fptr = msg_callback_get_proc_addr(funcName);
2368 if (fptr)
2369 return fptr;
2370
Jon Ashburn8fd08252015-05-28 16:25:02 -06002371 {
2372 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) dev;
2373 VkLayerDispatchTable* pTable = tableMap[*ppDisp];
2374 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002375 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002376 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002377 }
2378}
2379
2380VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(
2381 VkInstance instance,
2382 const char *funcName)
2383{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002384 void *fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002385 if (instance == NULL) {
2386 return NULL;
2387 }
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002388
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002389 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002390
Jon Ashburn8fd08252015-05-28 16:25:02 -06002391 /* loader uses this to force layer initialization; instance object is wrapped */
2392 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
2393 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002394 return (void *) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002395 }
2396
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002397 if (!strcmp(funcName, "vkDestroyInstance"))
2398 return (void *) vkDestroyInstance;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002399 if (!strcmp(funcName, "vkCreateInstance"))
2400 return (void*) vkCreateInstance;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002401 if (!strcmp(funcName, "vkCreateDevice"))
2402 return (void*) vkCreateDevice;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002403
2404 fptr = msg_callback_get_proc_addr(funcName);
2405 if (fptr)
2406 return fptr;
2407
Jon Ashburn8fd08252015-05-28 16:25:02 -06002408 {
2409 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
2410 VkLayerInstanceDispatchTable* pTable = tableInstanceMap[*ppDisp];
2411 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002412 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002413 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002414 }
2415}