blob: 85af9c2b7849903e63167b91368abf5482ea4729 [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);
871 /*
872 * For layers, the pInstance has already been filled out
873 * by the loader so that dispatch table is available.
874 */
875 initInstanceTable((const VkBaseLayerObject *) (*pInstance));
876
877 VkResult result = instance_dispatch_table(*pInstance)->CreateInstance(pCreateInfo, pInstance);
878
879 if (result == VK_SUCCESS) {
880 enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
881 }
882 return result;
883}
884
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600885VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
886 VkPhysicalDevice gpu,
887 const VkDeviceCreateInfo *pCreateInfo,
888 VkDevice *pDevice)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700889{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500890 VkResult result = instance_dispatch_table(gpu)->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600891 if (result == VK_SUCCESS) {
892 // Save off device in case we need it to create Fences
893 globalDevice = *pDevice;
894
895 enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
896 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700897 return result;
898}
899
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600900VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(
901 VkDevice device)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700902{
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700903 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600904 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600905 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600906 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500907 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500908 printCBList();
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500909 print_object_list();
910 if (VK_FALSE == delete_cmd_buf_info_list()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600911 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600912 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700913 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700914 // Report any memory leaks
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500915 MT_MEM_OBJ_INFO* pInfo = NULL;
David Pinedod8f83d82015-04-27 16:36:17 -0600916 if (memObjMap.size() > 0) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600917 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
918 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500919
David Pinedod8f83d82015-04-27 16:36:17 -0600920 if (pInfo->allocInfo.allocationSize != 0) {
921 sprintf(str, "Mem Object %p has not been freed. You should clean up this memory by calling "
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600922 "vkFreeMemory(%p) prior to vkDestroyDevice().", pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600923 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 -0600924 }
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600925 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700926 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500927
928 // Queues persist until device is destroyed
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500929 delete_queue_info_list();
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500930
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600931 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500932
933 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
934 VkLayerDispatchTable *pTable = tableMap[pDisp];
935 VkResult result = pTable->DestroyDevice(device);
936 tableMap.erase(pDisp);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700937 return result;
938}
939
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600940struct extProps {
941 uint32_t version;
942 const char * const name;
943};
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600944#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600945static const VkExtensionProperties mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
946 {
947 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
948 "MemTracker",
949 0x10,
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600950 "Validation layer: MemTracker",
951 },
952 {
953 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
954 "Validation",
955 0x10,
956 "Validation layer: MemTracker",
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600957 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600958};
959
960VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600961 VkExtensionInfoType infoType,
962 uint32_t extensionIndex,
963 size_t *pDataSize,
964 void *pData)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600965{
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500966 // This entrypoint is NOT going to init its own dispatch table since loader calls here early
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600967 uint32_t *count;
968
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600969 if (pDataSize == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600970 return VK_ERROR_INVALID_POINTER;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600971 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600972
973 switch (infoType) {
974 case VK_EXTENSION_INFO_TYPE_COUNT:
975 *pDataSize = sizeof(uint32_t);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600976 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600977 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600978 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600979 count = (uint32_t *) pData;
980 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
981 break;
982 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
983 *pDataSize = sizeof(VkExtensionProperties);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600984 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600985 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600986 }
987 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600988 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600989 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600990 memcpy((VkExtensionProperties *) pData, &mtExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600991 break;
992 default:
993 return VK_ERROR_INVALID_VALUE;
994 };
995
996 return VK_SUCCESS;
997}
998
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600999VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceExtensionInfo(
1000 VkPhysicalDevice physical_device,
1001 VkExtensionInfoType infoType,
1002 uint32_t extensionIndex,
1003 size_t *pDataSize,
1004 void *pData)
1005{
1006 uint32_t *count;
1007
1008 if (pDataSize == NULL) {
1009 return VK_ERROR_INVALID_POINTER;
1010 }
1011
1012 switch (infoType) {
1013 case VK_EXTENSION_INFO_TYPE_COUNT:
1014 *pDataSize = sizeof(uint32_t);
1015 if (pData == NULL) {
1016 return VK_SUCCESS;
1017 }
1018 count = (uint32_t *) pData;
1019 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
1020 break;
1021 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
1022 *pDataSize = sizeof(VkExtensionProperties);
1023 if (pData == NULL) {
1024 return VK_SUCCESS;
1025 }
1026 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE) {
1027 return VK_ERROR_INVALID_VALUE;
1028 }
1029 memcpy((VkExtensionProperties *) pData, &mtExts[extensionIndex], sizeof(VkExtensionProperties));
1030 break;
1031 default:
1032 return VK_ERROR_INVALID_VALUE;
1033 }
1034
1035 return VK_SUCCESS;
1036}
1037
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001038VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(
1039 VkDevice device,
1040 uint32_t queueNodeIndex,
1041 uint32_t queueIndex,
1042 VkQueue *pQueue)
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001043{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001044 VkResult result = device_dispatch_table(device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001045 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001046 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001047 add_queue_info(*pQueue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001048 loader_platform_thread_unlock_mutex(&globalLock);
1049 }
Mark Lobodzinski748eddf2015-03-31 16:05:35 -05001050 return result;
1051}
1052
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001053VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1054 VkQueue queue,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001055 uint32_t cmdBufferCount,
1056 const VkCmdBuffer *pCmdBuffers,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001057 VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001058{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001059 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001060 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001061 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001062 uint64_t fenceId = add_fence_info(fence, queue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001063
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001064 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001065 printCBList();
Tobin Ehlis6663f492014-11-10 12:29:12 -07001066 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001067 pCBInfo = get_cmd_buf_info(pCmdBuffers[i]);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001068 pCBInfo->fenceId = fenceId;
Mike Stroyan950496e2015-05-19 15:16:08 -06001069 pCBInfo->lastSubmittedFence = fence;
1070 pCBInfo->lastSubmittedQueue = queue;
Tobin Ehlis6663f492014-11-10 12:29:12 -07001071 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001072
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001073 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001074 VkResult result = device_dispatch_table(queue)->QueueSubmit(
1075 queue, cmdBufferCount, pCmdBuffers, fence);
Courtney Goeltzenleuchterd3fb9552015-04-02 13:39:07 -06001076 return result;
1077}
1078
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001079VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(
1080 VkDevice device,
1081 const VkMemoryAllocInfo *pAllocInfo,
1082 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001083{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001084 VkResult result = device_dispatch_table(device)->AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001085 // TODO : Track allocations and overall size here
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001086 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001087 add_mem_obj_info(*pMem, pAllocInfo);
1088 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001089 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001090 return result;
1091}
1092
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001093VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(
1094 VkDevice device,
1095 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001096{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001097 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisc0418f92014-11-25 14:47:20 -07001098 * freeing a memory object, an application must ensure the memory object is unbound from
1099 * all API objects referencing it and that it is not referenced by any queued command buffers
1100 */
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001101 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001102 bool32_t noerror = freeMemObjInfo(mem, false);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001103 print_mem_list();
1104 print_object_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001105 printCBList();
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001106 // Output an warning message for proper error/warning handling
1107 if (noerror == VK_FALSE) {
1108 char str[1024];
1109 sprintf(str, "Freeing memory object while it still has references: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001110 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 -05001111 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001112 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001113 VkResult result = device_dispatch_table(device)->FreeMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001114 return result;
1115}
1116
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001117VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(
1118 VkDevice device,
1119 VkDeviceMemory mem,
1120 VkMemoryPriority priority)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001121{
1122 // TODO : Update tracking for this alloc
1123 // Make sure memory is not pinned, which can't have priority set
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001124 VkResult result = device_dispatch_table(device)->SetMemoryPriority(device, mem, priority);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001125 return result;
1126}
1127
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001128VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(
1129 VkDevice device,
1130 VkDeviceMemory mem,
1131 VkDeviceSize offset,
1132 VkDeviceSize size,
1133 VkFlags flags,
1134 void **ppData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001135{
1136 // TODO : Track when memory is mapped
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001137 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001138 MT_MEM_OBJ_INFO *pMemObj = get_mem_obj_info(mem);
Tony Barbourd1c35722015-04-16 15:59:00 -06001139 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001140 char str[1024];
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001141 sprintf(str, "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001142 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 -06001143 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001144 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001145 VkResult result = device_dispatch_table(device)->MapMemory(device, mem, offset, size, flags, ppData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001146 return result;
1147}
1148
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001149VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(
1150 VkDevice device,
1151 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001152{
1153 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1154 // Make sure that memory was ever mapped to begin with
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001155 VkResult result = device_dispatch_table(device)->UnmapMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001156 return result;
1157}
1158
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001159VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(
1160 VkDevice device,
1161 const void *pSysMem,
1162 size_t memSize,
1163 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001164{
1165 // TODO : Track this
1166 // Verify that memory is actually pinnable
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001167 VkResult result = device_dispatch_table(device)->PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001168 return result;
1169}
1170
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001171VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(
1172 VkDevice device,
1173 const VkMemoryOpenInfo *pOpenInfo,
1174 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001175{
1176 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001177 VkResult result = device_dispatch_table(device)->OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001178 return result;
1179}
1180
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001181VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(
1182 VkDevice device,
1183 const VkPeerMemoryOpenInfo *pOpenInfo,
1184 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001185{
1186 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001187 VkResult result = device_dispatch_table(device)->OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001188 return result;
1189}
1190
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001191VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(
1192 VkDevice device,
1193 const VkPeerImageOpenInfo *pOpenInfo,
1194 VkImage *pImage,
1195 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001196{
1197 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001198 VkResult result = device_dispatch_table(device)->OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001199 return result;
1200}
1201
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001202VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(
1203 VkDevice device,
1204 VkObjectType objType,
1205 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001206{
Mike Stroyandd7aed72015-05-19 17:03:40 -06001207 unordered_map<VkObject, MT_OBJ_INFO>::iterator item;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001208 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001209
Mike Stroyan950496e2015-05-19 15:16:08 -06001210 // First check if this is a CmdBuffer or fence
1211 switch (objType) {
1212 case VK_OBJECT_TYPE_COMMAND_BUFFER:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001213 delete_cmd_buf_info((VkCmdBuffer)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001214 break;
1215 case VK_OBJECT_TYPE_FENCE:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001216 delete_fence_info((VkFence)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001217 break;
1218 default:
1219 break;
Tobin Ehlisa98df732014-11-27 07:52:04 -07001220 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001221
Mike Stroyan950496e2015-05-19 15:16:08 -06001222 if ((item = objectMap.find(object)) != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -06001223 MT_OBJ_INFO* pDelInfo = &(*item).second;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001224 if (pDelInfo->pMemObjInfo) {
Tobin Ehlisa98df732014-11-27 07:52:04 -07001225 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001226 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Tony Barbourd1c35722015-04-16 15:59:00 -06001227 VkDeviceMemory memToFree = pDelInfo->pMemObjInfo->mem;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001228 clear_object_binding(object);
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -06001229 freeMemObjInfo(memToFree, true);
1230 }
1231 else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001232 // Remove this object from memory object's reference list and decrement its ref counter
1233 clear_object_binding(object);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001234 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001235 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001236 objectMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001237 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001238
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001239 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001240 VkResult result = device_dispatch_table(device)->DestroyObject(device, objType, object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001241 return result;
1242}
1243
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001244VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(
1245 VkDevice device,
1246 VkObjectType objType,
1247 VkObject object,
1248 VkObjectInfoType infoType,
1249 size_t *pDataSize,
1250 void *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001251{
1252 // TODO : What to track here?
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001253 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001254 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues,
1255 // command buffers, shaders and memory objects.
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001256 VkResult result = device_dispatch_table(device)->GetObjectInfo(device, objType, object, infoType, pDataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001257 return result;
1258}
1259
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001260VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(
1261 VkDevice device,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001262 VkObjectType objType,
1263 VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001264 VkDeviceMemory mem,
1265 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001266{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001267 VkResult result = device_dispatch_table(device)->BindObjectMemory(device, objType, object, mem, offset);
Mike Stroyanb050c682015-04-17 12:36:38 -06001268 loader_platform_thread_lock_mutex(&globalLock);
1269 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001270 set_object_binding(object, mem);
1271 print_object_list();
1272 print_mem_list();
Mike Stroyanb050c682015-04-17 12:36:38 -06001273 loader_platform_thread_unlock_mutex(&globalLock);
1274 return result;
1275}
1276
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001277VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001278 VkQueue queue,
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001279 VkBuffer buffer,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001280 VkDeviceSize rangeOffset,
1281 VkDeviceSize rangeSize,
1282 VkDeviceMemory mem,
1283 VkDeviceSize memOffset)
Mike Stroyanb050c682015-04-17 12:36:38 -06001284{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001285 VkResult result = device_dispatch_table(queue)->QueueBindSparseBufferMemory(
1286 queue, buffer, rangeOffset, rangeSize, mem, memOffset);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001287 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001288 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001289 if (VK_FALSE == set_sparse_buffer_binding(buffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001290 char str[1024];
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001291 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)buffer, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001292 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 -07001293 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001294 print_object_list();
1295 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001296 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001297 return result;
1298}
1299
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001300VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(
1301 VkDevice device,
1302 const VkFenceCreateInfo *pCreateInfo,
1303 VkFence *pFence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001304{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001305 VkResult result = device_dispatch_table(device)->CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001306 if (VK_SUCCESS == result) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001307 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001308 add_object_info(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001309 loader_platform_thread_unlock_mutex(&globalLock);
1310 }
1311 return result;
1312}
1313
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001314VK_LAYER_EXPORT VkResult VKAPI vkResetFences(
1315 VkDevice device,
1316 uint32_t fenceCount,
1317 VkFence *pFences)
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001318{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06001319 /*
1320 * TODO: Shouldn't we check for error conditions before passing down the chain?
1321 * What if reason result is not VK_SUCCESS is something we could report as a validation error?
1322 */
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001323 VkResult result = device_dispatch_table(device)->ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001324 if (VK_SUCCESS == result) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001325 loader_platform_thread_lock_mutex(&globalLock);
1326 // Reset fence state in fenceCreateInfo structure
1327 for (uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001328 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001329 if (pObjectInfo != NULL) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001330 // Validate fences in SIGNALED state
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001331 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001332 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001333 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001334 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 -06001335 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001336 }
1337 else {
1338 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001339 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001340 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001341 }
1342 }
1343 loader_platform_thread_unlock_mutex(&globalLock);
1344 }
1345 return result;
1346}
1347
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001348VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(
1349 VkDevice device,
1350 VkFence fence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001351{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001352 VkResult result = device_dispatch_table(device)->GetFenceStatus(device, fence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001353 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001354 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001355 update_fence_tracking(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001356 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001357 }
1358 return result;
1359}
1360
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001361VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(
1362 VkDevice device,
1363 uint32_t fenceCount,
1364 const VkFence *pFences,
1365 bool32_t waitAll,
1366 uint64_t timeout)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001367{
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001368 // Verify fence status of submitted fences
1369 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001370 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001371 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001372 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001373 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001374 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001375 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 -05001376 }
1377 }
1378 }
1379
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001380 VkResult result = device_dispatch_table(device)->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001381 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05001382
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001383 if (VK_SUCCESS == result) {
Mark Lobodzinski50932972015-04-02 20:49:09 -05001384 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001385 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001386 update_fence_tracking(pFences[i]);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001387 }
1388 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001389 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001390 loader_platform_thread_unlock_mutex(&globalLock);
1391 return result;
1392}
1393
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001394VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(
1395 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001396{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001397 VkResult result = device_dispatch_table(queue)->QueueWaitIdle(queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001398 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001399 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001400 retire_queue_fences(queue);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001401 loader_platform_thread_unlock_mutex(&globalLock);
1402 }
1403 return result;
1404}
1405
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001406VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(
1407 VkDevice device)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001408{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001409 VkResult result = device_dispatch_table(device)->DeviceWaitIdle(device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001410 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001411 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001412 retire_device_fences(device);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001413 loader_platform_thread_unlock_mutex(&globalLock);
1414 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001415 return result;
1416}
1417
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001418VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(
1419 VkDevice device,
1420 const VkEventCreateInfo *pCreateInfo,
1421 VkEvent *pEvent)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001422{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001423 VkResult result = device_dispatch_table(device)->CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001424 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001425 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001426 add_object_info(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001427 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001428 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001429 return result;
1430}
1431
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001432VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(
1433 VkDevice device,
1434 const VkQueryPoolCreateInfo *pCreateInfo,
1435 VkQueryPool *pQueryPool)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001436{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001437 VkResult result = device_dispatch_table(device)->CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001438 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001439 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001440 add_object_info(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001441 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001442 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001443 return result;
1444}
1445
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001446VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(
1447 VkDevice device,
1448 const VkBufferCreateInfo *pCreateInfo,
1449 VkBuffer *pBuffer)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001450{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001451 VkResult result = device_dispatch_table(device)->CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001452 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001453 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001454 add_object_info(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001455 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001456 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001457 return result;
1458}
1459
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001460VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(
1461 VkDevice device,
1462 const VkBufferViewCreateInfo *pCreateInfo,
1463 VkBufferView *pView)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001464{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001465 VkResult result = device_dispatch_table(device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001466 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001467 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001468 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001469 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001470 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001471 return result;
1472}
1473
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001474VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
1475 VkDevice device,
1476 const VkImageCreateInfo *pCreateInfo,
1477 VkImage *pImage)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001478{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001479 VkResult result = device_dispatch_table(device)->CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001480 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001481 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001482 add_object_info(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001483 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001484 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001485 return result;
1486}
1487
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001488VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(
1489 VkDevice device,
1490 const VkImageViewCreateInfo *pCreateInfo,
1491 VkImageView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001492{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001493 VkResult result = device_dispatch_table(device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001494 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001495 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001496 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001497 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001498 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001499 return result;
1500}
1501
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001502VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(
1503 VkDevice device,
1504 const VkColorAttachmentViewCreateInfo *pCreateInfo,
1505 VkColorAttachmentView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001506{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001507 VkResult result = device_dispatch_table(device)->CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001508 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001509 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001510 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001511 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001512 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001513 return result;
1514}
1515
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001516VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(
1517 VkDevice device,
1518 const VkDepthStencilViewCreateInfo *pCreateInfo,
1519 VkDepthStencilView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001520{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001521 VkResult result = device_dispatch_table(device)->CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001522 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001523 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001524 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001525 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001526 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001527 return result;
1528}
1529
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001530VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
1531 VkDevice device,
1532 const VkShaderCreateInfo *pCreateInfo,
1533 VkShader *pShader)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001534{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001535 VkResult result = device_dispatch_table(device)->CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001536 return result;
1537}
1538
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001539VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(
1540 VkDevice device,
1541 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1542 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001543{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001544 VkResult result = device_dispatch_table(device)->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001545 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001546 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001547 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001548 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001549 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001550 return result;
1551}
1552
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001553VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001554 VkDevice device,
1555 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1556 VkPipeline basePipeline,
1557 VkPipeline *pPipeline)
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001558{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001559 VkResult result = device_dispatch_table(device)->CreateGraphicsPipelineDerivative(
1560 device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001561 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001562 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001563 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001564 loader_platform_thread_unlock_mutex(&globalLock);
1565 }
1566 return result;
1567}
1568
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001569VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(
1570 VkDevice device,
1571 const VkComputePipelineCreateInfo *pCreateInfo,
1572 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001573{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001574 VkResult result = device_dispatch_table(device)->CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001575 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001576 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001577 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001578 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001579 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001580 return result;
1581}
1582
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001583VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(
1584 VkDevice device,
1585 const VkSamplerCreateInfo *pCreateInfo,
1586 VkSampler *pSampler)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001587{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001588 VkResult result = device_dispatch_table(device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001589 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001590 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001591 add_object_info(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001592 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001593 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001594 return result;
1595}
1596
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001597VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(
1598 VkDevice device,
1599 const VkDynamicVpStateCreateInfo *pCreateInfo,
1600 VkDynamicVpState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001601{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001602 VkResult result = device_dispatch_table(device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001603 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001604 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001605 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001606 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001607 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001608 return result;
1609}
1610
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001611VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(
1612 VkDevice device,
1613 const VkDynamicRsStateCreateInfo *pCreateInfo,
1614 VkDynamicRsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001615{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001616 VkResult result = device_dispatch_table(device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001617 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001618 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001619 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001620 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001621 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001622 return result;
1623}
1624
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001625VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(
1626 VkDevice device,
1627 const VkDynamicCbStateCreateInfo *pCreateInfo,
1628 VkDynamicCbState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001629{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001630 VkResult result = device_dispatch_table(device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001631 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001632 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001633 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001634 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001635 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001636 return result;
1637}
1638
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001639VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(
1640 VkDevice device,
1641 const VkDynamicDsStateCreateInfo *pCreateInfo,
1642 VkDynamicDsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001643{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001644 VkResult result = device_dispatch_table(device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001645 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001646 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001647 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001648 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001649 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001650 return result;
1651}
1652
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001653VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(
1654 VkDevice device,
1655 const VkCmdBufferCreateInfo *pCreateInfo,
1656 VkCmdBuffer *pCmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001657{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001658 VkResult result = device_dispatch_table(device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001659 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001660 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001661 if (*pCmdBuffer)
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001662 add_cmd_buf_info(*pCmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001663 printCBList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001664 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001665 return result;
1666}
1667
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001668VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(
1669 VkCmdBuffer cmdBuffer,
1670 const VkCmdBufferBeginInfo *pBeginInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001671{
Mike Stroyan950496e2015-05-19 15:16:08 -06001672 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001673 // 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 -06001674 if (!checkCBCompleted(cmdBuffer)) {
1675 char str[1024];
1676 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. "
1677 "You must check CB flag before this call.", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001678 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 -07001679 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001680 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001681 VkResult result = device_dispatch_table(cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001682 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001683 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001684 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001685 return result;
1686}
1687
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001688VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(
1689 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001690{
1691 // TODO : Anything to do here?
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001692 VkResult result = device_dispatch_table(cmdBuffer)->EndCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001693 return result;
1694}
1695
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001696VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(
1697 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001698{
Mike Stroyan950496e2015-05-19 15:16:08 -06001699 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001700 // Verify that CB is complete (not in-flight)
Mike Stroyan950496e2015-05-19 15:16:08 -06001701 if (!checkCBCompleted(cmdBuffer)) {
1702 char str[1024];
1703 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before "
1704 "calling vkResetCommandBuffer().", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001705 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 -07001706 }
1707 // Clear memory references as this point.
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001708 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001709 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001710 VkResult result = device_dispatch_table(cmdBuffer)->ResetCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001711 return result;
1712}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001713// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis6663f492014-11-10 12:29:12 -07001714// need to account for that mem now having binding to given cmdBuffer
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001715VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(
1716 VkCmdBuffer cmdBuffer,
1717 VkPipelineBindPoint pipelineBindPoint,
1718 VkPipeline pipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001719{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001720#if 0
1721 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1722 if (getPipeline(pipeline)) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001723 MT_CB_INFO *pCBInfo = get_cmd_buf_info(cmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001724 if (pCBInfo) {
1725 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlisc145be82015-01-08 15:22:32 -07001726 } else {
1727 char str[1024];
1728 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001729 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 -07001730 }
1731 }
1732 else {
1733 char str[1024];
1734 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001735 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 -07001736 }
1737#endif
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001738 device_dispatch_table(cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001739}
1740
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001741VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(
1742 VkCmdBuffer cmdBuffer,
1743 VkStateBindPoint stateBindPoint,
1744 VkDynamicStateObject state)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001745{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001746 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001747 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001748 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001749 if (!pCmdBuf) {
1750 char str[1024];
1751 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001752 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 -07001753 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001754 pObjInfo = get_object_info(state);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001755 if (!pObjInfo) {
Tobin Ehlisc145be82015-01-08 15:22:32 -07001756 char str[1024];
1757 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001758 /* TODO: put in real object type */
1759 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001760 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001761 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001762 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001763 device_dispatch_table(cmdBuffer)->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001764}
1765
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001766VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001767 VkCmdBuffer cmdBuffer,
1768 VkPipelineBindPoint pipelineBindPoint,
1769 uint32_t firstSet,
1770 uint32_t setCount,
1771 const VkDescriptorSet *pDescriptorSets,
1772 uint32_t dynamicOffsetCount,
1773 const uint32_t *pDynamicOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001774{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001775 // 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 -05001776 device_dispatch_table(cmdBuffer)->CmdBindDescriptorSets(
1777 cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001778}
1779
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001780VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001781 VkCmdBuffer cmdBuffer,
1782 uint32_t startBinding,
1783 uint32_t bindingCount,
1784 const VkBuffer *pBuffers,
1785 const VkDeviceSize *pOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001786{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001787 device_dispatch_table(cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wu19156822015-01-05 13:42:56 +08001788}
1789
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001790VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(
1791 VkCmdBuffer cmdBuffer,
1792 VkBuffer buffer,
1793 VkDeviceSize offset,
1794 VkIndexType indexType)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001795{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001796 device_dispatch_table(cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001797}
1798
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001799VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(
1800 VkCmdBuffer cmdBuffer,
1801 VkBuffer buffer,
1802 VkDeviceSize offset,
1803 uint32_t count,
1804 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001805{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001806 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001807 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1808 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001809 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001810 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001811 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 -07001812 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001813 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001814 device_dispatch_table(cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001815}
1816
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001817VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
1818 VkCmdBuffer cmdBuffer,
1819 VkBuffer buffer,
1820 VkDeviceSize offset,
1821 uint32_t count,
1822 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001823{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001824 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001825 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1826 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001827 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001828 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001829 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 -07001830 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001831 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001832 device_dispatch_table(cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001833}
1834
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001835VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(
1836 VkCmdBuffer cmdBuffer,
1837 VkBuffer buffer,
1838 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001839{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001840 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001841 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1842 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001843 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001844 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001845 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 -07001846 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001847 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001848 device_dispatch_table(cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001849}
1850
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001851VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(
1852 VkCmdBuffer cmdBuffer,
1853 VkBuffer srcBuffer,
1854 VkBuffer destBuffer,
1855 uint32_t regionCount,
1856 const VkBufferCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001857{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001858 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001859 VkDeviceMemory mem = get_mem_binding_from_object(srcBuffer);
1860 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001861 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001862 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001863 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 -07001864 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001865 mem = get_mem_binding_from_object(destBuffer);
1866 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001867 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001868 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001869 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 -07001870 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001871 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001872 device_dispatch_table(cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001873}
1874
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001875VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(
1876 VkCmdBuffer cmdBuffer,
1877 VkImage srcImage,
1878 VkImageLayout srcImageLayout,
1879 VkImage destImage,
1880 VkImageLayout destImageLayout,
1881 uint32_t regionCount,
1882 const VkImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001883{
1884 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001885 device_dispatch_table(cmdBuffer)->CmdCopyImage(
1886 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001887}
1888
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001889VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(
1890 VkCmdBuffer cmdBuffer,
1891 VkImage srcImage,
1892 VkImageLayout srcImageLayout,
1893 VkImage destImage,
1894 VkImageLayout destImageLayout,
1895 uint32_t regionCount,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05001896 const VkImageBlit *pRegions,
1897 VkTexFilter filter)
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001898{
1899 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001900 device_dispatch_table(cmdBuffer)->CmdBlitImage(
1901 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001902}
1903
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001904VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(
1905 VkCmdBuffer cmdBuffer,
1906 VkBuffer srcBuffer,
1907 VkImage destImage,
1908 VkImageLayout destImageLayout,
1909 uint32_t regionCount,
1910 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001911{
1912 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001913 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001914 VkDeviceMemory mem = get_mem_binding_from_object(destImage);
1915 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001916 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001917 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 -06001918 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 -07001919 }
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001920
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001921 mem = get_mem_binding_from_object(srcBuffer);
1922 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001923 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001924 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001925 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 -07001926 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001927 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001928 device_dispatch_table(cmdBuffer)->CmdCopyBufferToImage(
1929 cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001930}
1931
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001932VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(
1933 VkCmdBuffer cmdBuffer,
1934 VkImage srcImage,
1935 VkImageLayout srcImageLayout,
1936 VkBuffer destBuffer,
1937 uint32_t regionCount,
1938 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001939{
1940 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001941 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001942 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
1943 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001944 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001945 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 -06001946 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 -07001947 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001948 mem = get_mem_binding_from_object(destBuffer);
1949 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001950 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001951 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001952 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 -07001953 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001954 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001955 device_dispatch_table(cmdBuffer)->CmdCopyImageToBuffer(
1956 cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001957}
1958
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001959VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
1960 VkCmdBuffer cmdBuffer,
1961 VkBuffer destBuffer,
1962 VkDeviceSize destOffset,
1963 VkDeviceSize dataSize,
1964 const uint32_t *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001965{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001966 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001967 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1968 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001969 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001970 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001971 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 -07001972 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001973 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001974 device_dispatch_table(cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001975}
1976
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001977VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
1978 VkCmdBuffer cmdBuffer,
1979 VkBuffer destBuffer,
1980 VkDeviceSize destOffset,
1981 VkDeviceSize fillSize,
1982 uint32_t data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001983{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001984 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001985 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1986 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001987 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001988 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001989 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 -07001990 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001991 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001992 device_dispatch_table(cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001993}
1994
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001995VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
1996 VkCmdBuffer cmdBuffer,
1997 VkImage image,
1998 VkImageLayout imageLayout,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001999 const VkClearColor *pColor,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002000 uint32_t rangeCount,
2001 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002002{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002003 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002004 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002005 VkDeviceMemory mem = get_mem_binding_from_object(image);
2006 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002007 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002008 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 -06002009 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 -07002010 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002011 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002012 device_dispatch_table(cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002013}
2014
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002015VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(
2016 VkCmdBuffer cmdBuffer,
2017 VkImage image,
2018 VkImageLayout imageLayout,
2019 float depth,
2020 uint32_t stencil,
2021 uint32_t rangeCount,
2022 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002023{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002024 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002025 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002026 VkDeviceMemory mem = get_mem_binding_from_object(image);
2027 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002028 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002029 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 -06002030 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 -07002031 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002032 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002033 device_dispatch_table(cmdBuffer)->CmdClearDepthStencil(
2034 cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002035}
2036
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002037VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(
2038 VkCmdBuffer cmdBuffer,
2039 VkImage srcImage,
2040 VkImageLayout srcImageLayout,
2041 VkImage destImage,
2042 VkImageLayout destImageLayout,
2043 uint32_t regionCount,
2044 const VkImageResolve *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002045{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002046 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002047 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
2048 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002049 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002050 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 -06002051 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 -07002052 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053 mem = get_mem_binding_from_object(destImage);
2054 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002055 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002056 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 -06002057 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 -07002058 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002059 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002060 device_dispatch_table(cmdBuffer)->CmdResolveImage(
2061 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002062}
2063
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002064VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(
2065 VkCmdBuffer cmdBuffer,
2066 VkQueryPool queryPool,
2067 uint32_t slot,
2068 VkFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002069{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002070 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002071 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2072 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002073 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002074 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 -06002075 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 -07002076 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002077 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002078 device_dispatch_table(cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002079}
2080
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002081VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(
2082 VkCmdBuffer cmdBuffer,
2083 VkQueryPool queryPool,
2084 uint32_t slot)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002085{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002086 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002087 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2088 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002089 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002090 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 -06002091 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 -07002092 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002093 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002094 device_dispatch_table(cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002095}
2096
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002097VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(
2098 VkCmdBuffer cmdBuffer,
2099 VkQueryPool queryPool,
2100 uint32_t startQuery,
2101 uint32_t queryCount)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002102{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002103 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002104 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2105 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002106 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002107 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 -06002108 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 -07002109 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002110 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002111 device_dispatch_table(cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002112}
2113
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002114VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2115 VkInstance instance,
2116 VkFlags msgFlags,
2117 const PFN_vkDbgMsgCallback pfnMsgCallback,
2118 void* pUserData,
2119 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002120{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002121 return layer_create_msg_callback(instance, instance_dispatch_table(instance), msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002122}
2123
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002124VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2125 VkInstance instance,
2126 VkDbgMsgCallback msgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002127{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002128 return layer_destroy_msg_callback(instance, instance_dispatch_table(instance), msgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002129}
2130
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002131VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(
2132 VkDevice device,
2133 const VkSwapChainCreateInfoWSI *pCreateInfo,
2134 VkSwapChainWSI *pSwapChain)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002135{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002136 VkResult result = device_dispatch_table(device)->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002137
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002138 if (VK_SUCCESS == result) {
Chia-I Wuf8693382015-04-16 22:02:10 +08002139 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002140 add_swap_chain_info(*pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002141 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002142 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002143
Tobin Ehlis6663f492014-11-10 12:29:12 -07002144 return result;
2145}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002146
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002147VK_LAYER_EXPORT VkResult VKAPI vkDestroySwapChainWSI(
2148 VkSwapChainWSI swapChain)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002149{
2150 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002151
2152 if (swapChainMap.find(swapChain) != swapChainMap.end()) {
2153 MT_SWAP_CHAIN_INFO* pInfo = swapChainMap[swapChain];
2154
David Pinedod8f83d82015-04-27 16:36:17 -06002155 if (pInfo->images.size() > 0) {
2156 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2157 it != pInfo->images.end(); it++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002158 clear_object_binding(it->image);
David Pinedod8f83d82015-04-27 16:36:17 -06002159 freeMemObjInfo(it->memory, true);
Chia-I Wuf8693382015-04-16 22:02:10 +08002160
David Pinedod8f83d82015-04-27 16:36:17 -06002161 objectMap.erase(it->image);
2162 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002163 }
2164
2165 delete pInfo;
2166 swapChainMap.erase(swapChain);
2167 }
2168
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002169 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002170
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002171 return device_dispatch_table(swapChain)->DestroySwapChainWSI(swapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002172}
2173
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002174VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(
2175 VkSwapChainWSI swapChain,
2176 VkSwapChainInfoTypeWSI infoType,
2177 size_t *pDataSize,
2178 void *pData)
Chia-I Wuf8693382015-04-16 22:02:10 +08002179{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002180 VkResult result = device_dispatch_table(swapChain)->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
Chia-I Wuf8693382015-04-16 22:02:10 +08002181
2182 if (infoType == VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI && result == VK_SUCCESS) {
2183 const size_t count = *pDataSize / sizeof(VkSwapChainImageInfoWSI);
2184 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain];
2185
2186 if (pInfo->images.empty()) {
2187 pInfo->images.resize(count);
2188 memcpy(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count);
2189
David Pinedod8f83d82015-04-27 16:36:17 -06002190 if (pInfo->images.size() > 0) {
2191 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2192 it != pInfo->images.end(); it++) {
2193 // Add image object, then insert the new Mem Object and then bind it to created image
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002194 add_object_info(it->image, VK_STRUCTURE_TYPE_MAX_ENUM, &pInfo->createInfo, sizeof(pInfo->createInfo), "persistent_image");
2195 add_mem_obj_info(it->memory, NULL);
2196 if (VK_FALSE == set_object_binding(it->image, it->memory)) {
David Pinedod8f83d82015-04-27 16:36:17 -06002197 char str[1024];
2198 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 -06002199 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 -06002200 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002201 }
2202 }
2203 } else {
2204 const bool mismatch = (pInfo->images.size() != count ||
2205 memcmp(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count));
2206
2207 if (mismatch) {
2208 char str[1024];
2209 sprintf(str, "vkGetSwapChainInfoWSI(%p, VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI) returned mismatching data", swapChain);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002210 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 +08002211 }
2212 }
2213 }
2214
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002215 return result;
2216}
Tobin Ehlis6663f492014-11-10 12:29:12 -07002217
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002218VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(
2219 VkDevice dev,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002220 const char *funcName)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002221{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002222 void *fptr;
2223
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002224 if (dev == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002225 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002226 }
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002227
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07002228 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002229
Jon Ashburn8fd08252015-05-28 16:25:02 -06002230 /* loader uses this to force layer initialization; device object is wrapped */
2231 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
2232 initDeviceTable((const VkBaseLayerObject *) dev);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002233 return (void *) vkGetDeviceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002234 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002235 if (!strcmp(funcName, "vkDestroyDevice"))
2236 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002237 if (!strcmp(funcName, "vkQueueSubmit"))
2238 return (void*) vkQueueSubmit;
2239 if (!strcmp(funcName, "vkAllocMemory"))
2240 return (void*) vkAllocMemory;
2241 if (!strcmp(funcName, "vkFreeMemory"))
2242 return (void*) vkFreeMemory;
2243 if (!strcmp(funcName, "vkSetMemoryPriority"))
2244 return (void*) vkSetMemoryPriority;
2245 if (!strcmp(funcName, "vkMapMemory"))
2246 return (void*) vkMapMemory;
2247 if (!strcmp(funcName, "vkUnmapMemory"))
2248 return (void*) vkUnmapMemory;
2249 if (!strcmp(funcName, "vkPinSystemMemory"))
2250 return (void*) vkPinSystemMemory;
2251 if (!strcmp(funcName, "vkOpenSharedMemory"))
2252 return (void*) vkOpenSharedMemory;
2253 if (!strcmp(funcName, "vkOpenPeerMemory"))
2254 return (void*) vkOpenPeerMemory;
2255 if (!strcmp(funcName, "vkOpenPeerImage"))
2256 return (void*) vkOpenPeerImage;
2257 if (!strcmp(funcName, "vkDestroyObject"))
2258 return (void*) vkDestroyObject;
2259 if (!strcmp(funcName, "vkGetObjectInfo"))
2260 return (void*) vkGetObjectInfo;
Mark Lobodzinski942b1722015-05-11 17:21:15 -05002261 if (!strcmp(funcName, "vkBindObjectMemory"))
2262 return (void*) vkBindObjectMemory;
2263 if (!strcmp(funcName, "vkQueueBindSparseBufferMemory"))
2264 return (void*) vkQueueBindSparseBufferMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002265 if (!strcmp(funcName, "vkCreateFence"))
2266 return (void*) vkCreateFence;
2267 if (!strcmp(funcName, "vkGetFenceStatus"))
2268 return (void*) vkGetFenceStatus;
2269 if (!strcmp(funcName, "vkResetFences"))
2270 return (void*) vkResetFences;
2271 if (!strcmp(funcName, "vkWaitForFences"))
2272 return (void*) vkWaitForFences;
2273 if (!strcmp(funcName, "vkQueueWaitIdle"))
2274 return (void*) vkQueueWaitIdle;
2275 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2276 return (void*) vkDeviceWaitIdle;
2277 if (!strcmp(funcName, "vkCreateEvent"))
2278 return (void*) vkCreateEvent;
2279 if (!strcmp(funcName, "vkCreateQueryPool"))
2280 return (void*) vkCreateQueryPool;
2281 if (!strcmp(funcName, "vkCreateBuffer"))
2282 return (void*) vkCreateBuffer;
2283 if (!strcmp(funcName, "vkCreateBufferView"))
2284 return (void*) vkCreateBufferView;
2285 if (!strcmp(funcName, "vkCreateImage"))
2286 return (void*) vkCreateImage;
2287 if (!strcmp(funcName, "vkCreateImageView"))
2288 return (void*) vkCreateImageView;
2289 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2290 return (void*) vkCreateColorAttachmentView;
2291 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2292 return (void*) vkCreateDepthStencilView;
2293 if (!strcmp(funcName, "vkCreateShader"))
2294 return (void*) vkCreateShader;
2295 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2296 return (void*) vkCreateGraphicsPipeline;
2297 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2298 return (void*) vkCreateGraphicsPipelineDerivative;
2299 if (!strcmp(funcName, "vkCreateComputePipeline"))
2300 return (void*) vkCreateComputePipeline;
2301 if (!strcmp(funcName, "vkCreateSampler"))
2302 return (void*) vkCreateSampler;
2303 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2304 return (void*) vkCreateDynamicViewportState;
2305 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2306 return (void*) vkCreateDynamicRasterState;
2307 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2308 return (void*) vkCreateDynamicColorBlendState;
2309 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2310 return (void*) vkCreateDynamicDepthStencilState;
2311 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2312 return (void*) vkCreateCommandBuffer;
2313 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2314 return (void*) vkBeginCommandBuffer;
2315 if (!strcmp(funcName, "vkEndCommandBuffer"))
2316 return (void*) vkEndCommandBuffer;
2317 if (!strcmp(funcName, "vkResetCommandBuffer"))
2318 return (void*) vkResetCommandBuffer;
2319 if (!strcmp(funcName, "vkCmdBindPipeline"))
2320 return (void*) vkCmdBindPipeline;
2321 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2322 return (void*) vkCmdBindDynamicStateObject;
2323 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2324 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002325 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2326 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002327 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2328 return (void*) vkCmdBindIndexBuffer;
2329 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2330 return (void*) vkCmdDrawIndirect;
2331 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2332 return (void*) vkCmdDrawIndexedIndirect;
2333 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2334 return (void*) vkCmdDispatchIndirect;
2335 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2336 return (void*) vkCmdCopyBuffer;
2337 if (!strcmp(funcName, "vkCmdCopyImage"))
2338 return (void*) vkCmdCopyImage;
2339 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2340 return (void*) vkCmdCopyBufferToImage;
2341 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2342 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002343 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2344 return (void*) vkCmdUpdateBuffer;
2345 if (!strcmp(funcName, "vkCmdFillBuffer"))
2346 return (void*) vkCmdFillBuffer;
2347 if (!strcmp(funcName, "vkCmdClearColorImage"))
2348 return (void*) vkCmdClearColorImage;
2349 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2350 return (void*) vkCmdClearDepthStencil;
2351 if (!strcmp(funcName, "vkCmdResolveImage"))
2352 return (void*) vkCmdResolveImage;
2353 if (!strcmp(funcName, "vkCmdBeginQuery"))
2354 return (void*) vkCmdBeginQuery;
2355 if (!strcmp(funcName, "vkCmdEndQuery"))
2356 return (void*) vkCmdEndQuery;
2357 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2358 return (void*) vkCmdResetQueryPool;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002359 if (g_DEBUG_REPORT && !strcmp(funcName, "vkDbgCreateMsgCallback"))
2360 return (void*) vkDbgCreateMsgCallback;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002361 if (!strcmp(funcName, "vkGetDeviceQueue"))
2362 return (void*) vkGetDeviceQueue;
Chia-I Wuf8693382015-04-16 22:02:10 +08002363 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
2364 return (void*) vkCreateSwapChainWSI;
2365 if (!strcmp(funcName, "vkDestroySwapChainWSI"))
2366 return (void*) vkDestroySwapChainWSI;
2367 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
2368 return (void*) vkGetSwapChainInfoWSI;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002369
2370 fptr = msg_callback_get_proc_addr(funcName);
2371 if (fptr)
2372 return fptr;
2373
Jon Ashburn8fd08252015-05-28 16:25:02 -06002374 {
2375 VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) dev;
2376 VkLayerDispatchTable* pTable = tableMap[*ppDisp];
2377 if (pTable->GetDeviceProcAddr == NULL)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002378 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002379 return pTable->GetDeviceProcAddr(dev, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002380 }
2381}
2382
2383VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(
2384 VkInstance instance,
2385 const char *funcName)
2386{
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002387 void *fptr;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002388 if (instance == NULL) {
2389 return NULL;
2390 }
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002391
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002392 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002393
Jon Ashburn8fd08252015-05-28 16:25:02 -06002394 /* loader uses this to force layer initialization; instance object is wrapped */
2395 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
2396 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002397 return (void *) vkGetInstanceProcAddr;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002398 }
2399
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002400 if (!strcmp(funcName, "vkDestroyInstance"))
2401 return (void *) vkDestroyInstance;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002402 if (!strcmp(funcName, "vkCreateInstance"))
2403 return (void*) vkCreateInstance;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002404 if (!strcmp(funcName, "vkCreateDevice"))
2405 return (void*) vkCreateDevice;
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -06002406
2407 fptr = msg_callback_get_proc_addr(funcName);
2408 if (fptr)
2409 return fptr;
2410
Jon Ashburn8fd08252015-05-28 16:25:02 -06002411 {
2412 VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;
2413 VkLayerInstanceDispatchTable* pTable = tableInstanceMap[*ppDisp];
2414 if (pTable->GetInstanceProcAddr == NULL)
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002415 return NULL;
Jon Ashburn8fd08252015-05-28 16:25:02 -06002416 return pTable->GetInstanceProcAddr(instance, funcName);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002417 }
2418}