blob: b77b74236c9015bb4e4c667d6387fe8ce4a8a482 [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
799 layer_initialize_dispatch_table(pTable, (PFN_vkGetDeviceProcAddr) devw->pGPA, (VkDevice) devw->nextObject);
800
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
821 layer_init_instance_dispatch_table(pTable, (PFN_vkGetInstanceProcAddr) instw->pGPA, (VkInstance) instw->nextObject);
822
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
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600866VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
867 VkPhysicalDevice gpu,
868 const VkDeviceCreateInfo *pCreateInfo,
869 VkDevice *pDevice)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700870{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500871 VkResult result = instance_dispatch_table(gpu)->CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600872 if (result == VK_SUCCESS) {
873 // Save off device in case we need it to create Fences
874 globalDevice = *pDevice;
875
876 enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
877 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700878 return result;
879}
880
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600881VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(
882 VkDevice device)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700883{
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700884 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600885 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600886 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600887 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500888 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500889 printCBList();
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500890 print_object_list();
891 if (VK_FALSE == delete_cmd_buf_info_list()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600892 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600893 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700894 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700895 // Report any memory leaks
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500896 MT_MEM_OBJ_INFO* pInfo = NULL;
David Pinedod8f83d82015-04-27 16:36:17 -0600897 if (memObjMap.size() > 0) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600898 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
899 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500900
David Pinedod8f83d82015-04-27 16:36:17 -0600901 if (pInfo->allocInfo.allocationSize != 0) {
902 sprintf(str, "Mem Object %p has not been freed. You should clean up this memory by calling "
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600903 "vkFreeMemory(%p) prior to vkDestroyDevice().", pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600904 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 -0600905 }
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600906 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700907 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500908
909 // Queues persist until device is destroyed
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500910 delete_queue_info_list();
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500911
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600912 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500913
914 VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;
915 VkLayerDispatchTable *pTable = tableMap[pDisp];
916 VkResult result = pTable->DestroyDevice(device);
917 tableMap.erase(pDisp);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700918 return result;
919}
920
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600921struct extProps {
922 uint32_t version;
923 const char * const name;
924};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600925#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 1
926static const VkExtensionProperties mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
927 {
928 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
929 "MemTracker",
930 0x10,
931 "Sample layer: MemTracker",
932 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600933};
934
935VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600936 VkExtensionInfoType infoType,
937 uint32_t extensionIndex,
938 size_t *pDataSize,
939 void *pData)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600940{
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500941 // This entrypoint is NOT going to init its own dispatch table since loader calls here early
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600942 uint32_t *count;
943
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600944 if (pDataSize == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600945 return VK_ERROR_INVALID_POINTER;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600946 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600947
948 switch (infoType) {
949 case VK_EXTENSION_INFO_TYPE_COUNT:
950 *pDataSize = sizeof(uint32_t);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600951 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600952 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600953 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600954 count = (uint32_t *) pData;
955 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
956 break;
957 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
958 *pDataSize = sizeof(VkExtensionProperties);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600959 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600960 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600961 }
962 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600963 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600964 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600965 memcpy((VkExtensionProperties *) pData, &mtExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600966 break;
967 default:
968 return VK_ERROR_INVALID_VALUE;
969 };
970
971 return VK_SUCCESS;
972}
973
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600974VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(
975 VkDevice device,
976 uint32_t queueNodeIndex,
977 uint32_t queueIndex,
978 VkQueue *pQueue)
Mark Lobodzinski748eddf2015-03-31 16:05:35 -0500979{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -0500980 VkResult result = device_dispatch_table(device)->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600981 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500982 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500983 add_queue_info(*pQueue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500984 loader_platform_thread_unlock_mutex(&globalLock);
985 }
Mark Lobodzinski748eddf2015-03-31 16:05:35 -0500986 return result;
987}
988
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600989VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
990 VkQueue queue,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600991 uint32_t cmdBufferCount,
992 const VkCmdBuffer *pCmdBuffers,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600993 VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700994{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600995 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700996 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500997 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500998 uint64_t fenceId = add_fence_info(fence, queue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500999
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001000 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001001 printCBList();
Tobin Ehlis6663f492014-11-10 12:29:12 -07001002 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001003 pCBInfo = get_cmd_buf_info(pCmdBuffers[i]);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001004 pCBInfo->fenceId = fenceId;
Mike Stroyan950496e2015-05-19 15:16:08 -06001005 pCBInfo->lastSubmittedFence = fence;
1006 pCBInfo->lastSubmittedQueue = queue;
Tobin Ehlis6663f492014-11-10 12:29:12 -07001007 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001008
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001009 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001010 VkResult result = device_dispatch_table(queue)->QueueSubmit(
1011 queue, cmdBufferCount, pCmdBuffers, fence);
Courtney Goeltzenleuchterd3fb9552015-04-02 13:39:07 -06001012 return result;
1013}
1014
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001015VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(
1016 VkDevice device,
1017 const VkMemoryAllocInfo *pAllocInfo,
1018 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001019{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001020 VkResult result = device_dispatch_table(device)->AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001021 // TODO : Track allocations and overall size here
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001022 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001023 add_mem_obj_info(*pMem, pAllocInfo);
1024 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001025 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001026 return result;
1027}
1028
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001029VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(
1030 VkDevice device,
1031 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001032{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001033 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisc0418f92014-11-25 14:47:20 -07001034 * freeing a memory object, an application must ensure the memory object is unbound from
1035 * all API objects referencing it and that it is not referenced by any queued command buffers
1036 */
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001037 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001038 bool32_t noerror = freeMemObjInfo(mem, false);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001039 print_mem_list();
1040 print_object_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001041 printCBList();
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001042 // Output an warning message for proper error/warning handling
1043 if (noerror == VK_FALSE) {
1044 char str[1024];
1045 sprintf(str, "Freeing memory object while it still has references: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001046 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 -05001047 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001048 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001049 VkResult result = device_dispatch_table(device)->FreeMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001050 return result;
1051}
1052
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001053VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(
1054 VkDevice device,
1055 VkDeviceMemory mem,
1056 VkMemoryPriority priority)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001057{
1058 // TODO : Update tracking for this alloc
1059 // Make sure memory is not pinned, which can't have priority set
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001060 VkResult result = device_dispatch_table(device)->SetMemoryPriority(device, mem, priority);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001061 return result;
1062}
1063
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001064VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(
1065 VkDevice device,
1066 VkDeviceMemory mem,
1067 VkDeviceSize offset,
1068 VkDeviceSize size,
1069 VkFlags flags,
1070 void **ppData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001071{
1072 // TODO : Track when memory is mapped
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001073 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001074 MT_MEM_OBJ_INFO *pMemObj = get_mem_obj_info(mem);
Tony Barbourd1c35722015-04-16 15:59:00 -06001075 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001076 char str[1024];
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001077 sprintf(str, "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001078 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 -06001079 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001080 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001081 VkResult result = device_dispatch_table(device)->MapMemory(device, mem, offset, size, flags, ppData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001082 return result;
1083}
1084
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001085VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(
1086 VkDevice device,
1087 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001088{
1089 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1090 // Make sure that memory was ever mapped to begin with
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001091 VkResult result = device_dispatch_table(device)->UnmapMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001092 return result;
1093}
1094
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001095VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(
1096 VkDevice device,
1097 const void *pSysMem,
1098 size_t memSize,
1099 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001100{
1101 // TODO : Track this
1102 // Verify that memory is actually pinnable
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001103 VkResult result = device_dispatch_table(device)->PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001104 return result;
1105}
1106
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001107VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(
1108 VkDevice device,
1109 const VkMemoryOpenInfo *pOpenInfo,
1110 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001111{
1112 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001113 VkResult result = device_dispatch_table(device)->OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001114 return result;
1115}
1116
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001117VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(
1118 VkDevice device,
1119 const VkPeerMemoryOpenInfo *pOpenInfo,
1120 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001121{
1122 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001123 VkResult result = device_dispatch_table(device)->OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001124 return result;
1125}
1126
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001127VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(
1128 VkDevice device,
1129 const VkPeerImageOpenInfo *pOpenInfo,
1130 VkImage *pImage,
1131 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001132{
1133 // TODO : Track this
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001134 VkResult result = device_dispatch_table(device)->OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001135 return result;
1136}
1137
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001138VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(
1139 VkDevice device,
1140 VkObjectType objType,
1141 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001142{
Mike Stroyandd7aed72015-05-19 17:03:40 -06001143 unordered_map<VkObject, MT_OBJ_INFO>::iterator item;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001144 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001145
Mike Stroyan950496e2015-05-19 15:16:08 -06001146 // First check if this is a CmdBuffer or fence
1147 switch (objType) {
1148 case VK_OBJECT_TYPE_COMMAND_BUFFER:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001149 delete_cmd_buf_info((VkCmdBuffer)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001150 break;
1151 case VK_OBJECT_TYPE_FENCE:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001152 delete_fence_info((VkFence)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001153 break;
1154 default:
1155 break;
Tobin Ehlisa98df732014-11-27 07:52:04 -07001156 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001157
Mike Stroyan950496e2015-05-19 15:16:08 -06001158 if ((item = objectMap.find(object)) != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -06001159 MT_OBJ_INFO* pDelInfo = &(*item).second;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001160 if (pDelInfo->pMemObjInfo) {
Tobin Ehlisa98df732014-11-27 07:52:04 -07001161 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001162 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Tony Barbourd1c35722015-04-16 15:59:00 -06001163 VkDeviceMemory memToFree = pDelInfo->pMemObjInfo->mem;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001164 clear_object_binding(object);
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -06001165 freeMemObjInfo(memToFree, true);
1166 }
1167 else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001168 // Remove this object from memory object's reference list and decrement its ref counter
1169 clear_object_binding(object);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001170 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001171 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001172 objectMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001173 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001174
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001175 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001176 VkResult result = device_dispatch_table(device)->DestroyObject(device, objType, object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001177 return result;
1178}
1179
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001180VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(
1181 VkDevice device,
1182 VkObjectType objType,
1183 VkObject object,
1184 VkObjectInfoType infoType,
1185 size_t *pDataSize,
1186 void *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001187{
1188 // TODO : What to track here?
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001189 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001190 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues,
1191 // command buffers, shaders and memory objects.
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001192 VkResult result = device_dispatch_table(device)->GetObjectInfo(device, objType, object, infoType, pDataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001193 return result;
1194}
1195
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001196VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(
1197 VkDevice device,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001198 VkObjectType objType,
1199 VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001200 VkDeviceMemory mem,
1201 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001202{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001203 VkResult result = device_dispatch_table(device)->BindObjectMemory(device, objType, object, mem, offset);
Mike Stroyanb050c682015-04-17 12:36:38 -06001204 loader_platform_thread_lock_mutex(&globalLock);
1205 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001206 set_object_binding(object, mem);
1207 print_object_list();
1208 print_mem_list();
Mike Stroyanb050c682015-04-17 12:36:38 -06001209 loader_platform_thread_unlock_mutex(&globalLock);
1210 return result;
1211}
1212
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001213VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001214 VkQueue queue,
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001215 VkBuffer buffer,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001216 VkDeviceSize rangeOffset,
1217 VkDeviceSize rangeSize,
1218 VkDeviceMemory mem,
1219 VkDeviceSize memOffset)
Mike Stroyanb050c682015-04-17 12:36:38 -06001220{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001221 VkResult result = device_dispatch_table(queue)->QueueBindSparseBufferMemory(
1222 queue, buffer, rangeOffset, rangeSize, mem, memOffset);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001223 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001224 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001225 if (VK_FALSE == set_sparse_buffer_binding(buffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001226 char str[1024];
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001227 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)buffer, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001228 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 -07001229 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001230 print_object_list();
1231 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001232 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001233 return result;
1234}
1235
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001236VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(
1237 VkDevice device,
1238 const VkFenceCreateInfo *pCreateInfo,
1239 VkFence *pFence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001240{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001241 VkResult result = device_dispatch_table(device)->CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001242 if (VK_SUCCESS == result) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001243 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001244 add_object_info(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001245 loader_platform_thread_unlock_mutex(&globalLock);
1246 }
1247 return result;
1248}
1249
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001250VK_LAYER_EXPORT VkResult VKAPI vkResetFences(
1251 VkDevice device,
1252 uint32_t fenceCount,
1253 VkFence *pFences)
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001254{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001255 VkResult result = device_dispatch_table(device)->ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001256 if (VK_SUCCESS == result) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001257 loader_platform_thread_lock_mutex(&globalLock);
1258 // Reset fence state in fenceCreateInfo structure
1259 for (uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001260 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001261 if (pObjectInfo != NULL) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001262 // Validate fences in SIGNALED state
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001263 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001264 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001265 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001266 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 -06001267 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001268 }
1269 else {
1270 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001271 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001272 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001273 }
1274 }
1275 loader_platform_thread_unlock_mutex(&globalLock);
1276 }
1277 return result;
1278}
1279
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001280VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(
1281 VkDevice device,
1282 VkFence fence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001283{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001284 VkResult result = device_dispatch_table(device)->GetFenceStatus(device, fence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001285 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001286 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001287 update_fence_tracking(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001288 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001289 }
1290 return result;
1291}
1292
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001293VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(
1294 VkDevice device,
1295 uint32_t fenceCount,
1296 const VkFence *pFences,
1297 bool32_t waitAll,
1298 uint64_t timeout)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001299{
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001300 // Verify fence status of submitted fences
1301 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001302 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001303 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001304 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001305 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001306 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001307 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 -05001308 }
1309 }
1310 }
1311
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001312 VkResult result = device_dispatch_table(device)->WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001313 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05001314
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001315 if (VK_SUCCESS == result) {
Mark Lobodzinski50932972015-04-02 20:49:09 -05001316 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001317 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001318 update_fence_tracking(pFences[i]);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001319 }
1320 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001321 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001322 loader_platform_thread_unlock_mutex(&globalLock);
1323 return result;
1324}
1325
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001326VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(
1327 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001328{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001329 VkResult result = device_dispatch_table(queue)->QueueWaitIdle(queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001330 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001331 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001332 retire_queue_fences(queue);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001333 loader_platform_thread_unlock_mutex(&globalLock);
1334 }
1335 return result;
1336}
1337
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001338VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(
1339 VkDevice device)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001340{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001341 VkResult result = device_dispatch_table(device)->DeviceWaitIdle(device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001342 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001343 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001344 retire_device_fences(device);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001345 loader_platform_thread_unlock_mutex(&globalLock);
1346 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001347 return result;
1348}
1349
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001350VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(
1351 VkDevice device,
1352 const VkEventCreateInfo *pCreateInfo,
1353 VkEvent *pEvent)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001354{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001355 VkResult result = device_dispatch_table(device)->CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001356 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001357 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001358 add_object_info(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001359 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001360 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001361 return result;
1362}
1363
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001364VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(
1365 VkDevice device,
1366 const VkQueryPoolCreateInfo *pCreateInfo,
1367 VkQueryPool *pQueryPool)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001368{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001369 VkResult result = device_dispatch_table(device)->CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001370 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001371 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001372 add_object_info(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001373 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001374 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001375 return result;
1376}
1377
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001378VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(
1379 VkDevice device,
1380 const VkBufferCreateInfo *pCreateInfo,
1381 VkBuffer *pBuffer)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001382{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001383 VkResult result = device_dispatch_table(device)->CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001384 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001385 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001386 add_object_info(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001387 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001388 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001389 return result;
1390}
1391
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001392VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(
1393 VkDevice device,
1394 const VkBufferViewCreateInfo *pCreateInfo,
1395 VkBufferView *pView)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001396{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001397 VkResult result = device_dispatch_table(device)->CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001398 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001399 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001400 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001401 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001402 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001403 return result;
1404}
1405
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001406VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
1407 VkDevice device,
1408 const VkImageCreateInfo *pCreateInfo,
1409 VkImage *pImage)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001410{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001411 VkResult result = device_dispatch_table(device)->CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001412 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001413 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001414 add_object_info(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001415 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001416 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001417 return result;
1418}
1419
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001420VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(
1421 VkDevice device,
1422 const VkImageViewCreateInfo *pCreateInfo,
1423 VkImageView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001424{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001425 VkResult result = device_dispatch_table(device)->CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001426 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001427 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001428 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001429 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001430 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001431 return result;
1432}
1433
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001434VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(
1435 VkDevice device,
1436 const VkColorAttachmentViewCreateInfo *pCreateInfo,
1437 VkColorAttachmentView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001438{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001439 VkResult result = device_dispatch_table(device)->CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001440 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001441 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001442 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001443 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001444 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001445 return result;
1446}
1447
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001448VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(
1449 VkDevice device,
1450 const VkDepthStencilViewCreateInfo *pCreateInfo,
1451 VkDepthStencilView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001452{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001453 VkResult result = device_dispatch_table(device)->CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001454 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001455 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001456 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001457 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001458 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001459 return result;
1460}
1461
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001462VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
1463 VkDevice device,
1464 const VkShaderCreateInfo *pCreateInfo,
1465 VkShader *pShader)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001466{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001467 VkResult result = device_dispatch_table(device)->CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001468 return result;
1469}
1470
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001471VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(
1472 VkDevice device,
1473 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1474 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001475{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001476 VkResult result = device_dispatch_table(device)->CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001477 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001478 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001479 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001480 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001481 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001482 return result;
1483}
1484
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001485VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001486 VkDevice device,
1487 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1488 VkPipeline basePipeline,
1489 VkPipeline *pPipeline)
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001490{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001491 VkResult result = device_dispatch_table(device)->CreateGraphicsPipelineDerivative(
1492 device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001493 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001494 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001495 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001496 loader_platform_thread_unlock_mutex(&globalLock);
1497 }
1498 return result;
1499}
1500
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001501VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(
1502 VkDevice device,
1503 const VkComputePipelineCreateInfo *pCreateInfo,
1504 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001505{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001506 VkResult result = device_dispatch_table(device)->CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001507 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001508 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001509 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001510 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001511 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001512 return result;
1513}
1514
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001515VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(
1516 VkDevice device,
1517 const VkSamplerCreateInfo *pCreateInfo,
1518 VkSampler *pSampler)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001519{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001520 VkResult result = device_dispatch_table(device)->CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001521 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001522 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001523 add_object_info(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001524 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001525 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001526 return result;
1527}
1528
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001529VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(
1530 VkDevice device,
1531 const VkDynamicVpStateCreateInfo *pCreateInfo,
1532 VkDynamicVpState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001533{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001534 VkResult result = device_dispatch_table(device)->CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001535 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001536 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001537 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001538 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001539 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001540 return result;
1541}
1542
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001543VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(
1544 VkDevice device,
1545 const VkDynamicRsStateCreateInfo *pCreateInfo,
1546 VkDynamicRsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001547{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001548 VkResult result = device_dispatch_table(device)->CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001549 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001550 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001551 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001552 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001553 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001554 return result;
1555}
1556
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001557VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(
1558 VkDevice device,
1559 const VkDynamicCbStateCreateInfo *pCreateInfo,
1560 VkDynamicCbState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001561{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001562 VkResult result = device_dispatch_table(device)->CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001563 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001564 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001565 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001566 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001567 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001568 return result;
1569}
1570
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001571VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(
1572 VkDevice device,
1573 const VkDynamicDsStateCreateInfo *pCreateInfo,
1574 VkDynamicDsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001575{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001576 VkResult result = device_dispatch_table(device)->CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001577 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001578 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001579 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001580 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001581 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001582 return result;
1583}
1584
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001585VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(
1586 VkDevice device,
1587 const VkCmdBufferCreateInfo *pCreateInfo,
1588 VkCmdBuffer *pCmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001589{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001590 VkResult result = device_dispatch_table(device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001591 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001592 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001593 if (*pCmdBuffer)
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001594 add_cmd_buf_info(*pCmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001595 printCBList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001596 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001597 return result;
1598}
1599
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001600VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(
1601 VkCmdBuffer cmdBuffer,
1602 const VkCmdBufferBeginInfo *pBeginInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001603{
Mike Stroyan950496e2015-05-19 15:16:08 -06001604 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001605 // 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 -06001606 if (!checkCBCompleted(cmdBuffer)) {
1607 char str[1024];
1608 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. "
1609 "You must check CB flag before this call.", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001610 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 -07001611 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001612 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001613 VkResult result = device_dispatch_table(cmdBuffer)->BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001614 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001615 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001616 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001617 return result;
1618}
1619
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001620VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(
1621 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001622{
1623 // TODO : Anything to do here?
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001624 VkResult result = device_dispatch_table(cmdBuffer)->EndCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001625 return result;
1626}
1627
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001628VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(
1629 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001630{
Mike Stroyan950496e2015-05-19 15:16:08 -06001631 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001632 // Verify that CB is complete (not in-flight)
Mike Stroyan950496e2015-05-19 15:16:08 -06001633 if (!checkCBCompleted(cmdBuffer)) {
1634 char str[1024];
1635 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before "
1636 "calling vkResetCommandBuffer().", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001637 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 -07001638 }
1639 // Clear memory references as this point.
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001640 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001641 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001642 VkResult result = device_dispatch_table(cmdBuffer)->ResetCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001643 return result;
1644}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001645// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis6663f492014-11-10 12:29:12 -07001646// need to account for that mem now having binding to given cmdBuffer
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001647VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(
1648 VkCmdBuffer cmdBuffer,
1649 VkPipelineBindPoint pipelineBindPoint,
1650 VkPipeline pipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001651{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001652#if 0
1653 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1654 if (getPipeline(pipeline)) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001655 MT_CB_INFO *pCBInfo = get_cmd_buf_info(cmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001656 if (pCBInfo) {
1657 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlisc145be82015-01-08 15:22:32 -07001658 } else {
1659 char str[1024];
1660 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001661 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 -07001662 }
1663 }
1664 else {
1665 char str[1024];
1666 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001667 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 -07001668 }
1669#endif
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001670 device_dispatch_table(cmdBuffer)->CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001671}
1672
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001673VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(
1674 VkCmdBuffer cmdBuffer,
1675 VkStateBindPoint stateBindPoint,
1676 VkDynamicStateObject state)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001677{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001678 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001679 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001680 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001681 if (!pCmdBuf) {
1682 char str[1024];
1683 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001684 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 -07001685 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001686 pObjInfo = get_object_info(state);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001687 if (!pObjInfo) {
Tobin Ehlisc145be82015-01-08 15:22:32 -07001688 char str[1024];
1689 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001690 /* TODO: put in real object type */
1691 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001692 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001693 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001694 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001695 device_dispatch_table(cmdBuffer)->CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001696}
1697
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001698VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001699 VkCmdBuffer cmdBuffer,
1700 VkPipelineBindPoint pipelineBindPoint,
1701 uint32_t firstSet,
1702 uint32_t setCount,
1703 const VkDescriptorSet *pDescriptorSets,
1704 uint32_t dynamicOffsetCount,
1705 const uint32_t *pDynamicOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001706{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001707 // 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 -05001708 device_dispatch_table(cmdBuffer)->CmdBindDescriptorSets(
1709 cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001710}
1711
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001712VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001713 VkCmdBuffer cmdBuffer,
1714 uint32_t startBinding,
1715 uint32_t bindingCount,
1716 const VkBuffer *pBuffers,
1717 const VkDeviceSize *pOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001718{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001719 device_dispatch_table(cmdBuffer)->CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wu19156822015-01-05 13:42:56 +08001720}
1721
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001722VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(
1723 VkCmdBuffer cmdBuffer,
1724 VkBuffer buffer,
1725 VkDeviceSize offset,
1726 VkIndexType indexType)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001727{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001728 device_dispatch_table(cmdBuffer)->CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001729}
1730
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001731VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(
1732 VkCmdBuffer cmdBuffer,
1733 VkBuffer buffer,
1734 VkDeviceSize offset,
1735 uint32_t count,
1736 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001737{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001738 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001739 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1740 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001741 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001742 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001743 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 -07001744 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001745 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001746 device_dispatch_table(cmdBuffer)->CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001747}
1748
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001749VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
1750 VkCmdBuffer cmdBuffer,
1751 VkBuffer buffer,
1752 VkDeviceSize offset,
1753 uint32_t count,
1754 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001755{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001756 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001757 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1758 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001759 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001760 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001761 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 -07001762 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001763 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001764 device_dispatch_table(cmdBuffer)->CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001765}
1766
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001767VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(
1768 VkCmdBuffer cmdBuffer,
1769 VkBuffer buffer,
1770 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001771{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001772 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001773 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1774 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001775 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001776 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001777 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 -07001778 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001779 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001780 device_dispatch_table(cmdBuffer)->CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001781}
1782
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001783VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(
1784 VkCmdBuffer cmdBuffer,
1785 VkBuffer srcBuffer,
1786 VkBuffer destBuffer,
1787 uint32_t regionCount,
1788 const VkBufferCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001789{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001790 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001791 VkDeviceMemory mem = get_mem_binding_from_object(srcBuffer);
1792 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001793 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001794 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001795 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 -07001796 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001797 mem = get_mem_binding_from_object(destBuffer);
1798 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001799 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001800 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001801 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 -07001802 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001803 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001804 device_dispatch_table(cmdBuffer)->CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001805}
1806
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001807VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(
1808 VkCmdBuffer cmdBuffer,
1809 VkImage srcImage,
1810 VkImageLayout srcImageLayout,
1811 VkImage destImage,
1812 VkImageLayout destImageLayout,
1813 uint32_t regionCount,
1814 const VkImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001815{
1816 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001817 device_dispatch_table(cmdBuffer)->CmdCopyImage(
1818 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001819}
1820
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001821VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(
1822 VkCmdBuffer cmdBuffer,
1823 VkImage srcImage,
1824 VkImageLayout srcImageLayout,
1825 VkImage destImage,
1826 VkImageLayout destImageLayout,
1827 uint32_t regionCount,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05001828 const VkImageBlit *pRegions,
1829 VkTexFilter filter)
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001830{
1831 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001832 device_dispatch_table(cmdBuffer)->CmdBlitImage(
1833 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001834}
1835
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001836VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(
1837 VkCmdBuffer cmdBuffer,
1838 VkBuffer srcBuffer,
1839 VkImage destImage,
1840 VkImageLayout destImageLayout,
1841 uint32_t regionCount,
1842 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001843{
1844 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001845 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001846 VkDeviceMemory mem = get_mem_binding_from_object(destImage);
1847 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001848 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001849 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 -06001850 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 -07001851 }
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001852
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001853 mem = get_mem_binding_from_object(srcBuffer);
1854 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001855 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001856 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001857 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 -07001858 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001859 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001860 device_dispatch_table(cmdBuffer)->CmdCopyBufferToImage(
1861 cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001862}
1863
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001864VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(
1865 VkCmdBuffer cmdBuffer,
1866 VkImage srcImage,
1867 VkImageLayout srcImageLayout,
1868 VkBuffer destBuffer,
1869 uint32_t regionCount,
1870 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001871{
1872 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001873 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001874 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
1875 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001876 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001877 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 -06001878 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 -07001879 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001880 mem = get_mem_binding_from_object(destBuffer);
1881 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001882 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001883 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001884 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 -07001885 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001886 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001887 device_dispatch_table(cmdBuffer)->CmdCopyImageToBuffer(
1888 cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001889}
1890
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001891VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
1892 VkCmdBuffer cmdBuffer,
1893 VkBuffer destBuffer,
1894 VkDeviceSize destOffset,
1895 VkDeviceSize dataSize,
1896 const uint32_t *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001897{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001898 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001899 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1900 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001901 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001902 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001903 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 -07001904 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001905 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001906 device_dispatch_table(cmdBuffer)->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001907}
1908
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001909VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
1910 VkCmdBuffer cmdBuffer,
1911 VkBuffer destBuffer,
1912 VkDeviceSize destOffset,
1913 VkDeviceSize fillSize,
1914 uint32_t data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001915{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001916 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001917 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1918 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001919 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001920 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001921 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 -07001922 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001923 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001924 device_dispatch_table(cmdBuffer)->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001925}
1926
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001927VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
1928 VkCmdBuffer cmdBuffer,
1929 VkImage image,
1930 VkImageLayout imageLayout,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001931 const VkClearColor *pColor,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001932 uint32_t rangeCount,
1933 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001934{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001935 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001936 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001937 VkDeviceMemory mem = get_mem_binding_from_object(image);
1938 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001939 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001940 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 -06001941 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 -07001942 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001943 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001944 device_dispatch_table(cmdBuffer)->CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001945}
1946
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001947VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(
1948 VkCmdBuffer cmdBuffer,
1949 VkImage image,
1950 VkImageLayout imageLayout,
1951 float depth,
1952 uint32_t stencil,
1953 uint32_t rangeCount,
1954 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001955{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001956 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001957 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001958 VkDeviceMemory mem = get_mem_binding_from_object(image);
1959 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001960 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001961 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 -06001962 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 -07001963 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001964 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05001965 device_dispatch_table(cmdBuffer)->CmdClearDepthStencil(
1966 cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001967}
1968
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001969VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(
1970 VkCmdBuffer cmdBuffer,
1971 VkImage srcImage,
1972 VkImageLayout srcImageLayout,
1973 VkImage destImage,
1974 VkImageLayout destImageLayout,
1975 uint32_t regionCount,
1976 const VkImageResolve *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001977{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001978 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001979 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
1980 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001981 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001982 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 -06001983 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 -07001984 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001985 mem = get_mem_binding_from_object(destImage);
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 vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, 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)->CmdResolveImage(
1993 cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001994}
1995
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001996VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(
1997 VkCmdBuffer cmdBuffer,
1998 VkQueryPool queryPool,
1999 uint32_t slot,
2000 VkFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002001{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002002 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002003 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2004 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002005 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002006 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 -06002007 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 -07002008 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002009 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002010 device_dispatch_table(cmdBuffer)->CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002011}
2012
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002013VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(
2014 VkCmdBuffer cmdBuffer,
2015 VkQueryPool queryPool,
2016 uint32_t slot)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002017{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002018 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002019 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2020 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002021 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002022 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 -06002023 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 -07002024 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002025 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002026 device_dispatch_table(cmdBuffer)->CmdEndQuery(cmdBuffer, queryPool, slot);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002027}
2028
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002029VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(
2030 VkCmdBuffer cmdBuffer,
2031 VkQueryPool queryPool,
2032 uint32_t startQuery,
2033 uint32_t queryCount)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002034{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002035 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002036 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
2037 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002038 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002039 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 -06002040 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 -07002041 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06002042 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002043 device_dispatch_table(cmdBuffer)->CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002044}
2045
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002046VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
2047 VkInstance instance,
2048 VkFlags msgFlags,
2049 const PFN_vkDbgMsgCallback pfnMsgCallback,
2050 void* pUserData,
2051 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002052{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002053 return layer_create_msg_callback(instance, instance_dispatch_table(instance), msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002054}
2055
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002056VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2057 VkInstance instance,
2058 VkDbgMsgCallback msgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002059{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002060 return layer_destroy_msg_callback(instance, instance_dispatch_table(instance), msgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002061}
2062
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002063VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(
2064 VkDevice device,
2065 const VkSwapChainCreateInfoWSI *pCreateInfo,
2066 VkSwapChainWSI *pSwapChain)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002067{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002068 VkResult result = device_dispatch_table(device)->CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002069
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002070 if (VK_SUCCESS == result) {
Chia-I Wuf8693382015-04-16 22:02:10 +08002071 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002072 add_swap_chain_info(*pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002073 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002074 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002075
Tobin Ehlis6663f492014-11-10 12:29:12 -07002076 return result;
2077}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002078
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002079VK_LAYER_EXPORT VkResult VKAPI vkDestroySwapChainWSI(
2080 VkSwapChainWSI swapChain)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002081{
2082 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002083
2084 if (swapChainMap.find(swapChain) != swapChainMap.end()) {
2085 MT_SWAP_CHAIN_INFO* pInfo = swapChainMap[swapChain];
2086
David Pinedod8f83d82015-04-27 16:36:17 -06002087 if (pInfo->images.size() > 0) {
2088 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2089 it != pInfo->images.end(); it++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002090 clear_object_binding(it->image);
David Pinedod8f83d82015-04-27 16:36:17 -06002091 freeMemObjInfo(it->memory, true);
Chia-I Wuf8693382015-04-16 22:02:10 +08002092
David Pinedod8f83d82015-04-27 16:36:17 -06002093 objectMap.erase(it->image);
2094 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002095 }
2096
2097 delete pInfo;
2098 swapChainMap.erase(swapChain);
2099 }
2100
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002101 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002102
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002103 return device_dispatch_table(swapChain)->DestroySwapChainWSI(swapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002104}
2105
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002106VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(
2107 VkSwapChainWSI swapChain,
2108 VkSwapChainInfoTypeWSI infoType,
2109 size_t *pDataSize,
2110 void *pData)
Chia-I Wuf8693382015-04-16 22:02:10 +08002111{
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002112 VkResult result = device_dispatch_table(swapChain)->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
Chia-I Wuf8693382015-04-16 22:02:10 +08002113
2114 if (infoType == VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI && result == VK_SUCCESS) {
2115 const size_t count = *pDataSize / sizeof(VkSwapChainImageInfoWSI);
2116 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain];
2117
2118 if (pInfo->images.empty()) {
2119 pInfo->images.resize(count);
2120 memcpy(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count);
2121
David Pinedod8f83d82015-04-27 16:36:17 -06002122 if (pInfo->images.size() > 0) {
2123 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2124 it != pInfo->images.end(); it++) {
2125 // Add image object, then insert the new Mem Object and then bind it to created image
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002126 add_object_info(it->image, VK_STRUCTURE_TYPE_MAX_ENUM, &pInfo->createInfo, sizeof(pInfo->createInfo), "persistent_image");
2127 add_mem_obj_info(it->memory, NULL);
2128 if (VK_FALSE == set_object_binding(it->image, it->memory)) {
David Pinedod8f83d82015-04-27 16:36:17 -06002129 char str[1024];
2130 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 -06002131 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 -06002132 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002133 }
2134 }
2135 } else {
2136 const bool mismatch = (pInfo->images.size() != count ||
2137 memcmp(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count));
2138
2139 if (mismatch) {
2140 char str[1024];
2141 sprintf(str, "vkGetSwapChainInfoWSI(%p, VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI) returned mismatching data", swapChain);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002142 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 +08002143 }
2144 }
2145 }
2146
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002147 return result;
2148}
Tobin Ehlis6663f492014-11-10 12:29:12 -07002149
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002150VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(
2151 VkDevice dev,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002152 const char *funcName)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002153{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002154 VkBaseLayerObject* devw = (VkBaseLayerObject *) dev;
Chia-I Wu4d11dcc2015-01-05 13:18:57 +08002155
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002156 if (dev == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002157 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002158 }
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002159
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07002160 loader_platform_thread_once(&g_initOnce, initMemTracker);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002161 initDeviceTable((const VkBaseLayerObject *) dev);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002162
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002163 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
2164 return (void *) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002165 if (!strcmp(funcName, "vkDestroyDevice"))
2166 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002167 if (!strcmp(funcName, "vkQueueSubmit"))
2168 return (void*) vkQueueSubmit;
2169 if (!strcmp(funcName, "vkAllocMemory"))
2170 return (void*) vkAllocMemory;
2171 if (!strcmp(funcName, "vkFreeMemory"))
2172 return (void*) vkFreeMemory;
2173 if (!strcmp(funcName, "vkSetMemoryPriority"))
2174 return (void*) vkSetMemoryPriority;
2175 if (!strcmp(funcName, "vkMapMemory"))
2176 return (void*) vkMapMemory;
2177 if (!strcmp(funcName, "vkUnmapMemory"))
2178 return (void*) vkUnmapMemory;
2179 if (!strcmp(funcName, "vkPinSystemMemory"))
2180 return (void*) vkPinSystemMemory;
2181 if (!strcmp(funcName, "vkOpenSharedMemory"))
2182 return (void*) vkOpenSharedMemory;
2183 if (!strcmp(funcName, "vkOpenPeerMemory"))
2184 return (void*) vkOpenPeerMemory;
2185 if (!strcmp(funcName, "vkOpenPeerImage"))
2186 return (void*) vkOpenPeerImage;
2187 if (!strcmp(funcName, "vkDestroyObject"))
2188 return (void*) vkDestroyObject;
2189 if (!strcmp(funcName, "vkGetObjectInfo"))
2190 return (void*) vkGetObjectInfo;
Mark Lobodzinski942b1722015-05-11 17:21:15 -05002191 if (!strcmp(funcName, "vkBindObjectMemory"))
2192 return (void*) vkBindObjectMemory;
2193 if (!strcmp(funcName, "vkQueueBindSparseBufferMemory"))
2194 return (void*) vkQueueBindSparseBufferMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002195 if (!strcmp(funcName, "vkCreateFence"))
2196 return (void*) vkCreateFence;
2197 if (!strcmp(funcName, "vkGetFenceStatus"))
2198 return (void*) vkGetFenceStatus;
2199 if (!strcmp(funcName, "vkResetFences"))
2200 return (void*) vkResetFences;
2201 if (!strcmp(funcName, "vkWaitForFences"))
2202 return (void*) vkWaitForFences;
2203 if (!strcmp(funcName, "vkQueueWaitIdle"))
2204 return (void*) vkQueueWaitIdle;
2205 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2206 return (void*) vkDeviceWaitIdle;
2207 if (!strcmp(funcName, "vkCreateEvent"))
2208 return (void*) vkCreateEvent;
2209 if (!strcmp(funcName, "vkCreateQueryPool"))
2210 return (void*) vkCreateQueryPool;
2211 if (!strcmp(funcName, "vkCreateBuffer"))
2212 return (void*) vkCreateBuffer;
2213 if (!strcmp(funcName, "vkCreateBufferView"))
2214 return (void*) vkCreateBufferView;
2215 if (!strcmp(funcName, "vkCreateImage"))
2216 return (void*) vkCreateImage;
2217 if (!strcmp(funcName, "vkCreateImageView"))
2218 return (void*) vkCreateImageView;
2219 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2220 return (void*) vkCreateColorAttachmentView;
2221 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2222 return (void*) vkCreateDepthStencilView;
2223 if (!strcmp(funcName, "vkCreateShader"))
2224 return (void*) vkCreateShader;
2225 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2226 return (void*) vkCreateGraphicsPipeline;
2227 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2228 return (void*) vkCreateGraphicsPipelineDerivative;
2229 if (!strcmp(funcName, "vkCreateComputePipeline"))
2230 return (void*) vkCreateComputePipeline;
2231 if (!strcmp(funcName, "vkCreateSampler"))
2232 return (void*) vkCreateSampler;
2233 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2234 return (void*) vkCreateDynamicViewportState;
2235 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2236 return (void*) vkCreateDynamicRasterState;
2237 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2238 return (void*) vkCreateDynamicColorBlendState;
2239 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2240 return (void*) vkCreateDynamicDepthStencilState;
2241 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2242 return (void*) vkCreateCommandBuffer;
2243 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2244 return (void*) vkBeginCommandBuffer;
2245 if (!strcmp(funcName, "vkEndCommandBuffer"))
2246 return (void*) vkEndCommandBuffer;
2247 if (!strcmp(funcName, "vkResetCommandBuffer"))
2248 return (void*) vkResetCommandBuffer;
2249 if (!strcmp(funcName, "vkCmdBindPipeline"))
2250 return (void*) vkCmdBindPipeline;
2251 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2252 return (void*) vkCmdBindDynamicStateObject;
2253 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2254 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002255 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2256 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002257 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2258 return (void*) vkCmdBindIndexBuffer;
2259 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2260 return (void*) vkCmdDrawIndirect;
2261 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2262 return (void*) vkCmdDrawIndexedIndirect;
2263 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2264 return (void*) vkCmdDispatchIndirect;
2265 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2266 return (void*) vkCmdCopyBuffer;
2267 if (!strcmp(funcName, "vkCmdCopyImage"))
2268 return (void*) vkCmdCopyImage;
2269 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2270 return (void*) vkCmdCopyBufferToImage;
2271 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2272 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002273 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2274 return (void*) vkCmdUpdateBuffer;
2275 if (!strcmp(funcName, "vkCmdFillBuffer"))
2276 return (void*) vkCmdFillBuffer;
2277 if (!strcmp(funcName, "vkCmdClearColorImage"))
2278 return (void*) vkCmdClearColorImage;
2279 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2280 return (void*) vkCmdClearDepthStencil;
2281 if (!strcmp(funcName, "vkCmdResolveImage"))
2282 return (void*) vkCmdResolveImage;
2283 if (!strcmp(funcName, "vkCmdBeginQuery"))
2284 return (void*) vkCmdBeginQuery;
2285 if (!strcmp(funcName, "vkCmdEndQuery"))
2286 return (void*) vkCmdEndQuery;
2287 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2288 return (void*) vkCmdResetQueryPool;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002289 if (g_DEBUG_REPORT && !strcmp(funcName, "vkDbgCreateMsgCallback"))
2290 return (void*) vkDbgCreateMsgCallback;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002291 if (!strcmp(funcName, "vkGetDeviceQueue"))
2292 return (void*) vkGetDeviceQueue;
Chia-I Wuf8693382015-04-16 22:02:10 +08002293 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
2294 return (void*) vkCreateSwapChainWSI;
2295 if (!strcmp(funcName, "vkDestroySwapChainWSI"))
2296 return (void*) vkDestroySwapChainWSI;
2297 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
2298 return (void*) vkGetSwapChainInfoWSI;
Tobin Ehlis6663f492014-11-10 12:29:12 -07002299 else {
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002300 if (devw->pGPA == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002301 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002302 }
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002303 return devw->pGPA((VkObject)devw->nextObject, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002304 }
2305}
2306
2307VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(
2308 VkInstance instance,
2309 const char *funcName)
2310{
2311 VkBaseLayerObject* instw = (VkBaseLayerObject *) instance;
2312
2313 if (instance == NULL) {
2314 return NULL;
2315 }
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002316
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002317 loader_platform_thread_once(&g_initOnce, initMemTracker);
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002318 initInstanceTable((const VkBaseLayerObject *) instance);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002319
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002320 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
2321 return (void *) vkGetInstanceProcAddr;
Mark Lobodzinski76c991d2015-05-20 16:16:37 -05002322 if (!strcmp(funcName, "vkDestroyInstance"))
2323 return (void *) vkDestroyInstance;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002324 if (!strcmp(funcName, "vkCreateDevice"))
2325 return (void*) vkCreateDevice;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002326 else {
2327 if (instw->pGPA == NULL) {
2328 return NULL;
2329 }
2330 return instw->pGPA((VkObject)instw->nextObject, funcName);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002331 }
2332}