blob: 0da8996c9e7ea6a733b6ce91d3b3c7f3675e1b91 [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>
31#include <map>
Chia-I Wuf8693382015-04-16 22:02:10 +080032#include <vector>
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050033using namespace std;
34
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070035#include "loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036#include "vk_dispatch_table_helper.h"
37#include "vk_struct_string_helper_cpp.h"
Tobin Ehliscd9223b2014-11-19 16:19:28 -070038#include "mem_tracker.h"
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070039#include "layers_config.h"
Ian Elliott655cad72015-02-12 17:08:34 -070040// The following is #included again to catch certain OS-specific functions
41// being used:
42#include "loader_platform.h"
Jon Ashburn2e672892015-02-16 08:46:53 -070043#include "layers_msg.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070044
Jon Ashburnbacb0f52015-04-06 10:58:22 -060045static VkLayerDispatchTable nextTable;
46static VkBaseLayerObject *pCurObj;
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070047static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -060048// TODO : This can be much smarter, using separate locks for separate global data
49static int globalLockInitialized = 0;
50static loader_platform_thread_mutex globalLock;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070051
Tobin Ehlisc145be82015-01-08 15:22:32 -070052#define MAX_BINDING 0xFFFFFFFF
Tobin Ehlisc145be82015-01-08 15:22:32 -070053
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060054map<VkCmdBuffer, MT_CB_INFO*> cbMap;
Tony Barbourd1c35722015-04-16 15:59:00 -060055map<VkDeviceMemory, MT_MEM_OBJ_INFO*> memObjMap;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060056map<VkObject, MT_OBJ_INFO*> objectMap;
Mark Lobodzinski223ca202015-04-02 08:52:53 -050057map<uint64_t, MT_FENCE_INFO*> fenceMap; // Map fenceId to fence info
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060058map<VkQueue, MT_QUEUE_INFO*> queueMap;
Chia-I Wuf8693382015-04-16 22:02:10 +080059map<VkSwapChainWSI, MT_SWAP_CHAIN_INFO*> swapChainMap;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050060
Mark Lobodzinski50932972015-04-02 20:49:09 -050061// TODO : Add per-device fence completion
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050062static uint64_t g_currentFenceId = 1;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060063static VkDevice globalDevice = NULL;
Mark Lobodzinskic52b7752015-02-18 16:38:17 -060064
Mark Lobodzinski223ca202015-04-02 08:52:53 -050065// Add new queue for this device to map container
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060066static void addQueueInfo(const VkQueue queue)
Mark Lobodzinski223ca202015-04-02 08:52:53 -050067{
Mark Lobodzinski50932972015-04-02 20:49:09 -050068 MT_QUEUE_INFO* pInfo = new MT_QUEUE_INFO;
69 pInfo->lastRetiredId = 0;
70 pInfo->lastSubmittedId = 0;
71 queueMap[queue] = pInfo;
Mark Lobodzinski223ca202015-04-02 08:52:53 -050072}
73
74static void deleteQueueInfoList(void)
75{
76 // Process queue list, cleaning up each entry before deleting
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060077 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski223ca202015-04-02 08:52:53 -050078 (*ii).second->pQueueCmdBuffers.clear();
79 }
80 queueMap.clear();
81}
82
Chia-I Wuf8693382015-04-16 22:02:10 +080083static void addSwapChainInfo(const VkSwapChainWSI swapChain)
84{
85 MT_SWAP_CHAIN_INFO* pInfo = new MT_SWAP_CHAIN_INFO;
86 swapChainMap[swapChain] = pInfo;
87}
88
Mark Lobodzinski223ca202015-04-02 08:52:53 -050089// Add new CBInfo for this cb to map container
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060090static void addCBInfo(const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -070091{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -050092 MT_CB_INFO* pInfo = new MT_CB_INFO;
Tony Barbourd1c35722015-04-16 15:59:00 -060093 memset(pInfo, 0, (sizeof(MT_CB_INFO) - sizeof(list<VkDeviceMemory>)));
Mark Lobodzinski6434eff2015-03-31 16:05:35 -050094 pInfo->cmdBuffer = cb;
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -060095 cbMap[cb] = pInfo;
Tobin Ehlis6663f492014-11-10 12:29:12 -070096}
97
Mark Lobodzinski223ca202015-04-02 08:52:53 -050098// Return ptr to Info in CB map, or NULL if not found
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060099static MT_CB_INFO* getCBInfo(const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700100{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500101 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500102 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500103 pCBInfo = cbMap[cb];
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600104 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500105 return pCBInfo;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700106}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600107
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500108// Return object info for 'object' or return NULL if no info exists
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600109static MT_OBJ_INFO* getObjectInfo(const VkObject object)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500110{
111 MT_OBJ_INFO* pObjInfo = NULL;
112
113 if (objectMap.find(object) != objectMap.end()) {
114 pObjInfo = objectMap[object];
115 }
116 return pObjInfo;
117}
118
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600119static MT_OBJ_INFO* addObjectInfo(VkObject object, VkStructureType sType, const void *pCreateInfo, const int struct_size, const char *name_prefix)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500120{
121 MT_OBJ_INFO* pInfo = new MT_OBJ_INFO;
122 memset(pInfo, 0, sizeof(MT_OBJ_INFO));
123 memcpy(&pInfo->create_info, pCreateInfo, struct_size);
124 sprintf(pInfo->object_name, "%s_%p", name_prefix, object);
125
126 pInfo->object = object;
127 pInfo->ref_count = 1;
128 pInfo->sType = sType;
129 objectMap[object] = pInfo;
130
131 return pInfo;
132}
133
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500134// Add a fence, creating one if necessary to our list of fences/fenceIds
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600135static uint64_t addFenceInfo(VkFence fence, VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500136{
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500137 // Create fence object
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500138 MT_FENCE_INFO* pFenceInfo = new MT_FENCE_INFO;
Mark Lobodzinski50932972015-04-02 20:49:09 -0500139 MT_QUEUE_INFO* pQueueInfo = queueMap[queue];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500140 uint64_t fenceId = g_currentFenceId++;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500141 memset(pFenceInfo, 0, sizeof(MT_FENCE_INFO));
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500142 // If no fence, create an internal fence to track the submissions
143 if (fence == NULL) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600144 VkFenceCreateInfo fci;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600145 fci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500146 fci.pNext = NULL;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600147 fci.flags = static_cast<VkFenceCreateFlags>(0);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500148 nextTable.CreateFence(globalDevice, &fci, &pFenceInfo->fence);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600149 addObjectInfo(pFenceInfo->fence, fci.sType, &fci, sizeof(VkFenceCreateInfo), "internalFence");
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600150 pFenceInfo->localFence = VK_TRUE;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500151 } else {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500152 // Validate that fence is in UNSIGNALED state
153 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
154 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600155 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500156 char str[1024];
157 sprintf(str, "Fence %p submitted in SIGNALED state. Fences must be reset before being submitted", fence);
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600158 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, fence, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500159 }
160 }
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600161 pFenceInfo->localFence = VK_FALSE;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500162 pFenceInfo->fence = fence;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700163 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500164 pFenceInfo->queue = queue;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500165 fenceMap[fenceId] = pFenceInfo;
Mark Lobodzinski50932972015-04-02 20:49:09 -0500166 // Update most recently submitted fenceId for Queue
167 pQueueInfo->lastSubmittedId = fenceId;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500168 return fenceId;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500169}
170
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500171// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500172static void deleteFenceInfo(uint64_t fenceId)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500173{
174 if (fenceId != 0) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500175 if (fenceMap.find(fenceId) != fenceMap.end()) {
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600176 map<uint64_t, MT_FENCE_INFO*>::iterator item;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500177 MT_FENCE_INFO* pDelInfo = fenceMap[fenceId];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500178 if (pDelInfo != NULL) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600179 if (pDelInfo->localFence == VK_TRUE) {
Mike Stroyanb050c682015-04-17 12:36:38 -0600180 nextTable.DestroyObject(globalDevice, VK_OBJECT_TYPE_FENCE, pDelInfo->fence);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500181 }
182 delete pDelInfo;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500183 }
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600184 item = fenceMap.find(fenceId);
185 fenceMap.erase(item);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500186 }
187 }
188}
189
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500190// Search through list for this fence, deleting all items before it (with lower IDs) and updating lastRetiredId
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600191static void updateFenceTracking(VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500192{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500193 MT_FENCE_INFO *pCurFenceInfo = NULL;
194 uint64_t fenceId = 0;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600195 VkQueue queue = NULL;
Mike Stroyan8fbeea92015-04-15 15:37:47 -0600196 bool found = false;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500197
Mike Stroyan8fbeea92015-04-15 15:37:47 -0600198 for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); !found && ii!=fenceMap.end(); ++ii) {
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500199 if ((*ii).second != NULL) {
200 if (fence == ((*ii).second)->fence) {
201 queue = ((*ii).second)->queue;
202 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
203 pQueueInfo->lastRetiredId = (*ii).first;
Mike Stroyan8fbeea92015-04-15 15:37:47 -0600204 found = true;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500205 } else {
206 deleteFenceInfo((*ii).first);
207 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500208 // Update fence state in fenceCreateInfo structure
209 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
210 if (pObjectInfo != NULL) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500211 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600212 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500213 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500214 }
215 }
216}
217
218// Utility function that determines if a fenceId has been retired yet
219static bool32_t fenceRetired(uint64_t fenceId)
220{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600221 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter0c55f3a2015-04-15 14:10:51 -0600222 if (fenceMap.find(fenceId) != fenceMap.end()) {
223 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500224 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
Mark Lobodzinski3bc3f6e2015-04-02 08:52:53 -0500225 if (fenceId <= pQueueInfo->lastRetiredId)
226 {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600227 result = VK_TRUE;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500228 }
Mark Lobodzinski50932972015-04-02 20:49:09 -0500229 } else { // If not in list, fence has been retired and deleted
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600230 result = VK_TRUE;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500231 }
232 return result;
233}
234
235// Return the fence associated with a fenceId
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600236static VkFence getFenceFromId(uint64_t fenceId)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500237{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600238 VkFence fence = NULL;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500239 if (fenceId != 0) {
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500240 // Search for an item with this fenceId
241 if (fenceMap.find(fenceId) != fenceMap.end()) {
242 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
243 if (pFenceInfo != NULL) {
244 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
245 if (fenceId > pQueueInfo->lastRetiredId) {
246 fence = pFenceInfo->fence;
247 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500248 }
249 }
250 }
251 return fence;
252}
253
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500254// Helper routine that updates the fence list for a specific queue to all-retired
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600255static void retireQueueFences(VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500256{
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600257 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
258 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
259 // Set Queue's lastRetired to lastSubmitted, free items in queue's fence list
260 map<uint64_t, MT_FENCE_INFO*>::iterator it = fenceMap.begin();
261 map<uint64_t, MT_FENCE_INFO*>::iterator temp;
262 while (it != fenceMap.end()) {
Tobin Ehlis5d37f702015-04-15 14:25:02 -0600263 if ((((*it).second) != NULL) && ((*it).second)->queue == queue) {
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600264 temp = it;
265 ++temp;
266 deleteFenceInfo((*it).first);
267 it = temp;
268 } else {
269 ++it;
270 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500271 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700272}
273
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500274// Helper routine that updates fence list for all queues to all-retired
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600275static void retireDeviceFences(VkDevice device)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500276{
277 // Process each queue for device
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600278 // TODO: Add multiple device support
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600279 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500280 retireQueueFences((*ii).first);
281 }
282}
283
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500284// Returns True if a memory reference is present in a Queue's memory reference list
285// Queue is validated by caller
286static bool32_t checkMemRef(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600287 VkQueue queue,
Tony Barbourd1c35722015-04-16 15:59:00 -0600288 VkDeviceMemory mem)
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500289{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600290 bool32_t result = VK_FALSE;
Tony Barbourd1c35722015-04-16 15:59:00 -0600291 list<VkDeviceMemory>::iterator it;
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500292 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
293 for (it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
294 if ((*it) == mem) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600295 result = VK_TRUE;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500296 break;
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500297 }
298 }
299 return result;
300}
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500301
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500302static bool32_t validateQueueMemRefs(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600303 VkQueue queue,
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500304 uint32_t cmdBufferCount,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600305 const VkCmdBuffer *pCmdBuffers)
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500306{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600307 bool32_t result = VK_TRUE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500308
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500309 // Verify Queue
310 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
311 if (pQueueInfo == NULL) {
312 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600313 sprintf(str, "Unknown Queue %p specified in vkQueueSubmit", queue);
314 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500315 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500316 else {
317 // Iterate through all CBs in pCmdBuffers
318 for (uint32_t i = 0; i < cmdBufferCount; i++) {
319 MT_CB_INFO* pCBInfo = getCBInfo(pCmdBuffers[i]);
320 if (!pCBInfo) {
321 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600322 sprintf(str, "Unable to find info for CB %p in order to check memory references in vkQueueSubmit for queue %p", (void*)pCmdBuffers[i], queue);
323 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_CB, "MEM", str);
324 result = VK_FALSE;
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500325 } else {
326 // Validate that all actual references are accounted for in pMemRefs
Tony Barbourd1c35722015-04-16 15:59:00 -0600327 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500328 // Search for each memref in queues memreflist.
329 if (checkMemRef(queue, *it)) {
330 char str[1024];
331 sprintf(str, "Found Mem Obj %p binding to CB %p for queue %p", (*it), pCmdBuffers[i], queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600332 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500333 }
334 else {
335 char str[1024];
336 sprintf(str, "Queue %p Memory reference list for Command Buffer %p is missing ref to mem obj %p", queue, pCmdBuffers[i], (*it));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600337 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
338 result = VK_FALSE;
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500339 }
340 }
341 }
342 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600343 if (result == VK_TRUE) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500344 char str[1024];
345 sprintf(str, "Verified all memory dependencies for Queue %p are included in pMemRefs list", queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600346 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500347 // TODO : Could report mem refs in pMemRefs that AREN'T in mem list, that would be primarily informational
348 // Currently just noting that there is a difference
349 }
350 }
351
352 return result;
353}
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -0600354
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500355// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700356// Calls to this function should be wrapped in mutex
Tony Barbourd1c35722015-04-16 15:59:00 -0600357static MT_MEM_OBJ_INFO* getMemObjInfo(const VkDeviceMemory mem)
Tobin Ehlisc145be82015-01-08 15:22:32 -0700358{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500359 MT_MEM_OBJ_INFO* pMemObjInfo = NULL;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500360
361 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500362 pMemObjInfo = memObjMap[mem];
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600363 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500364 return pMemObjInfo;
Tobin Ehlisc145be82015-01-08 15:22:32 -0700365}
366
Tony Barbourd1c35722015-04-16 15:59:00 -0600367static void addMemObjInfo(const VkDeviceMemory mem, const VkMemoryAllocInfo* pAllocInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700368{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500369 MT_MEM_OBJ_INFO* pInfo = new MT_MEM_OBJ_INFO;
370 pInfo->refCount = 0;
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600371 memset(&pInfo->allocInfo, 0, sizeof(VkMemoryAllocInfo));
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500372
Chia-I Wuf8693382015-04-16 22:02:10 +0800373 if (pAllocInfo) { // MEM alloc created by vkCreateSwapChainWSI() doesn't have alloc info struct
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600374 memcpy(&pInfo->allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500375 // TODO: Update for real hardware, actually process allocation info structures
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500376 pInfo->allocInfo.pNext = NULL;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700377 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500378 pInfo->mem = mem;
379 memObjMap[mem] = pInfo;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700380}
381
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500382// Find CB Info and add mem binding to list container
383// Find Mem Obj Info and add CB binding to list container
Tony Barbourd1c35722015-04-16 15:59:00 -0600384static bool32_t updateCBBinding(const VkCmdBuffer cb, const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700385{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600386 bool32_t result = VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700387 // First update CB binding in MemObj mini CB list
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500388 MT_MEM_OBJ_INFO* pMemInfo = getMemObjInfo(mem);
389 if (!pMemInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700390 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500391 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that mem obj.\n Was it correctly allocated? Did it already get freed?", mem, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600392 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
393 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600394 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500395 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600396 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600397 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500398 if ((*it) == cb) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600399 found = VK_TRUE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500400 break;
401 }
402 }
403 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600404 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500405 pMemInfo->pCmdBufferBindings.push_front(cb);
406 pMemInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500407 }
408
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500409 // Now update CBInfo's Mem binding list
410 MT_CB_INFO* pCBInfo = getCBInfo(cb);
411 if (!pCBInfo) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500412 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500413 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that CB. Was it CB incorrectly destroyed?", mem, cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600414 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
415 result = VK_FALSE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500416 } else {
417 // Search for memory object in cmd buffer's binding list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600418 bool32_t found = VK_FALSE;
Tony Barbourd1c35722015-04-16 15:59:00 -0600419 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500420 if ((*it) == mem) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600421 found = VK_TRUE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500422 break;
423 }
424 }
425 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600426 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500427 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600428 }
429 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700430 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600431 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700432}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600433
Tobin Ehlis6663f492014-11-10 12:29:12 -0700434// Clear the CB Binding for mem
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700435// Calls to this function should be wrapped in mutex
Tony Barbourd1c35722015-04-16 15:59:00 -0600436static void clearCBBinding(const VkCmdBuffer cb, const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700437{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500438 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500439 // TODO : Having this check is not ideal, really if memInfo was deleted,
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700440 // its CB bindings should be cleared and then freeCBBindings wouldn't call
441 // us here with stale mem objs
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500442 if (pInfo) {
443 pInfo->pCmdBufferBindings.remove(cb);
444 pInfo->refCount--;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700445 }
446}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600447
Tobin Ehlis6663f492014-11-10 12:29:12 -0700448// Free bindings related to CB
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600449static bool32_t freeCBBindings(const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700450{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600451 bool32_t result = VK_TRUE;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500452 MT_CB_INFO* pCBInfo = getCBInfo(cb);
453 if (!pCBInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700454 char str[1024];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500455 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600456 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
457 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600458 } else {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500459 if (!fenceRetired(pCBInfo->fenceId)) {
460 deleteFenceInfo(pCBInfo->fenceId);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600461 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500462
Tony Barbourd1c35722015-04-16 15:59:00 -0600463 for (list<VkDeviceMemory>::iterator it=pCBInfo->pMemObjList.begin(); it!=pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500464 clearCBBinding(cb, (*it));
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600465 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500466 pCBInfo->pMemObjList.clear();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700467 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600468 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700469}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600470
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500471// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500472// and also clear mem references to CB
Tobin Ehlis6663f492014-11-10 12:29:12 -0700473// TODO : When should this be called? There's no Destroy of CBs that I see
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600474static bool32_t deleteCBInfo(const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700475{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600476 bool32_t result = VK_TRUE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600477 result = freeCBBindings(cb);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500478 // Delete the CBInfo info
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600479 if (result == VK_TRUE) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500480 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500481 MT_CB_INFO* pDelInfo = cbMap[cb];
482 delete pDelInfo;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500483 cbMap.erase(cb);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600484 }
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700485 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600486 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700487}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600488
Tobin Ehlis6663f492014-11-10 12:29:12 -0700489// Delete the entire CB list
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500490static bool32_t deleteCBInfoList()
Tobin Ehlis6663f492014-11-10 12:29:12 -0700491{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600492 bool32_t result = VK_TRUE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600493 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500494 freeCBBindings((*ii).first);
495 delete (*ii).second;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700496 }
497 return result;
498}
499
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500500// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500501static void reportMemReferencesAndCleanUp(MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700502{
Tony Barbour18f71552015-04-22 11:36:22 -0600503 size_t cmdBufRefCount = pMemObjInfo->pCmdBufferBindings.size();
504 size_t objRefCount = pMemObjInfo->pObjBindings.size();
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500505
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500506 if ((pMemObjInfo->pCmdBufferBindings.size() + pMemObjInfo->pObjBindings.size()) != 0) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700507 char str[1024];
Tony Barbour18f71552015-04-22 11:36:22 -0600508 sprintf(str, "Attempting to free memory object %p which still contains %lu references", pMemObjInfo->mem, (cmdBufRefCount + objRefCount));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600509 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700510 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500511
512 if (cmdBufRefCount > 0) {
513 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
514 char str[1024];
515 sprintf(str, "Command Buffer %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
516 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
517 }
518 // Clear the list of hanging references
519 pMemObjInfo->pCmdBufferBindings.clear();
520 }
521
522 if (objRefCount > 0) {
523 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
524 char str[1024];
525 sprintf(str, "VK Object %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
526 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
527 }
528 // Clear the list of hanging references
529 pMemObjInfo->pObjBindings.clear();
530 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700531}
532
Tony Barbourd1c35722015-04-16 15:59:00 -0600533static void deleteMemObjInfo(VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700534{
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500535 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500536 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
537 delete pDelInfo;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500538 memObjMap.erase(mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700539 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500540 else {
541 char str[1024];
542 sprintf(str, "Request to delete memory object %p not present in memory Object Map", mem);
543 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
544 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700545}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500546
Tobin Ehlis6663f492014-11-10 12:29:12 -0700547// Check if fence for given CB is completed
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600548static bool32_t checkCBCompleted(const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700549{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600550 bool32_t result = VK_TRUE;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500551 MT_CB_INFO* pCBInfo = getCBInfo(cb);
552 if (!pCBInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700553 char str[1024];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500554 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600555 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
556 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600557 } else {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500558 if (!fenceRetired(pCBInfo->fenceId)) {
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600559 char str[1024];
560 sprintf(str, "FenceId %" PRIx64", fence %p for CB %p has not been checked for completion", pCBInfo->fenceId, getFenceFromId(pCBInfo->fenceId), cb);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600561 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_NONE, "MEM", str);
562 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600563 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700564 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600565 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700566}
567
Tony Barbourd1c35722015-04-16 15:59:00 -0600568static bool32_t freeMemObjInfo(VkDeviceMemory mem, bool internal)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700569{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600570 bool32_t result = VK_TRUE;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500571 // Parse global list to find info w/ mem
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500572 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
573 if (!pInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700574 char str[1024];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500575 sprintf(str, "Couldn't find mem info object for %p\n Was %p never allocated or previously freed?", (void*)mem, (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600576 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
577 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600578 } else {
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -0600579 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600580 char str[1024];
Chia-I Wuf8693382015-04-16 22:02:10 +0800581 sprintf(str, "Attempting to free memory associated with a Persistent Image, %p, this should not be explicitly freed\n", (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600582 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
583 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600584 } else {
585 // Clear any CB bindings for completed CBs
586 // TODO : Is there a better place to do this?
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500587
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600588 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
589 list<VkCmdBuffer>::iterator temp;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500590 while (it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600591 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500592 temp = it;
593 ++temp;
594 freeCBBindings(*it);
595 it = temp;
596 } else {
597 ++it;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600598 }
599 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500600
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600601 // Now verify that no references to this mem obj remain
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500602 if (0 != pInfo->refCount) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500603 // If references remain, report the error and can search CB list to find references
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600604 char str[1024];
605 sprintf(str, "Freeing mem obj %p while it still has references", (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600606 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM", str);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500607 reportMemReferencesAndCleanUp(pInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600608 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600609 }
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600610 // Delete mem obj info
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500611 deleteMemObjInfo(mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700612 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700613 }
614 return result;
615}
616
Tobin Ehlis6663f492014-11-10 12:29:12 -0700617// Remove object binding performs 3 tasks:
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500618// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
619// 2. Decrement refCount for MemObjInfo
620// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600621static bool32_t clearObjectBinding(VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700622{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600623 bool32_t result = VK_FALSE;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500624 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
625 if (!pObjInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700626 char str[1024];
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600627 sprintf(str, "Attempting to clear mem binding for object %p: devices, queues, command buffers, shaders and memory objects do not have external memory requirements and it is unneccessary to call bind/unbindObjectMemory on them.", object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600628 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600629 } else {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500630 if (!pObjInfo->pMemObjInfo) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600631 char str[1024];
632 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600633 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600634 } else {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500635 // 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
636 // and set the objects memory binding pointer to NULL.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600637 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500638 if ((*it) == object) {
639 pObjInfo->pMemObjInfo->refCount--;
640 pObjInfo->pMemObjInfo->pObjBindings.erase(it);
641 pObjInfo->pMemObjInfo = NULL;
642 result = VK_TRUE;
643 break;
644 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600645 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600646 if (result == VK_FALSE) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600647 char str[1024];
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500648 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 -0500649 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600650 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600651 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700652 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700653 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600654 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700655}
656
657// For NULL mem case, clear any previous binding Else...
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500658// Make sure given object is in global object map
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700659// IF a previous binding existed, clear it
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500660// Add reference from objectInfo to memoryInfo
661// Add reference off of objInfo
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600662// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Tony Barbourd1c35722015-04-16 15:59:00 -0600663static bool32_t updateObjectBinding(VkObject object, VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700664{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600665 bool32_t result = VK_FALSE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700666 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600667 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis6663f492014-11-10 12:29:12 -0700668 clearObjectBinding(object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600669 result = VK_TRUE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600670 } else {
671 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500672 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
673 if (!pObjInfo) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600674 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600675 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
676 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600677 }
678 // non-null case so should have real mem obj
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500679 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
680 if (!pInfo) {
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500681 sprintf(str, "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600682 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600683 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500684 // Search for object in memory object's binding list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600685 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600686 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500687 if ((*it) == object) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600688 found = VK_TRUE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500689 break;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600690 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600691 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500692 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600693 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500694 pInfo->pObjBindings.push_front(object);
695 pInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500696 }
697
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500698 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500699 clearObjectBinding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500700 sprintf(str, "Updating memory binding for object %p from mem obj %p to %p", object, pObjInfo->pMemObjInfo->mem, mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600701 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500702 }
703 // For image objects, make sure default memory state is correctly set
704 // TODO : What's the best/correct way to handle this?
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600705 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
706 if (pObjInfo->create_info.image_create_info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500707 // TODO:: More memory state transition stuff.
708 }
709 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500710 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis8be20fd2015-01-07 17:49:29 -0700711 }
712 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600713 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700714}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600715
Tobin Ehlis6663f492014-11-10 12:29:12 -0700716// Print details of global Obj tracking list
717static void printObjList()
718{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500719 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500720 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500721 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600722 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600723 for (map<VkObject, MT_OBJ_INFO*>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500724 pInfo = (*ii).second;
725 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600726 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700727 }
728}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600729
Tobin Ehlis6663f492014-11-10 12:29:12 -0700730// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Tony Barbourd1c35722015-04-16 15:59:00 -0600731static VkDeviceMemory getMemBindingFromObject(const VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700732{
Tony Barbourd1c35722015-04-16 15:59:00 -0600733 VkDeviceMemory mem = NULL;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500734 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
735 if (pObjInfo) {
736 if (pObjInfo->pMemObjInfo) {
737 mem = pObjInfo->pMemObjInfo->mem;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700738 }
739 else {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700740 char str[1024];
741 sprintf(str, "Trying to get mem binding for object %p but object has no mem binding", (void*)object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600742 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700743 printObjList();
744 }
745 }
746 else {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700747 char str[1024];
748 sprintf(str, "Trying to get mem binding for object %p but no such object in global list", (void*)object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600749 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700750 printObjList();
751 }
752 return mem;
753}
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500754
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500755// Print details of MemObjInfo list
Tobin Ehlis6663f492014-11-10 12:29:12 -0700756static void printMemList()
757{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500758 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700759 // Just printing each msg individually for now, may want to package these into single large print
760 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500761 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600762 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500763
Tony Barbourd1c35722015-04-16 15:59:00 -0600764 for (map<VkDeviceMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500765 pInfo = (*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500766
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500767 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600768 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500769 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600770 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500771 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600772 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500773 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600774 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500775 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600776 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500777 } else {
Chia-I Wuf8693382015-04-16 22:02:10 +0800778 sprintf(str, " Mem Alloc info is NULL (alloc done by vkCreateSwapChainWSI())");
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600779 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500780 }
781
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600782 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
783 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600784 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600785 sprintf(str, " VK OBJECT %p", (*it));
786 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500787 }
788
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600789 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
790 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600791 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600792 sprintf(str, " VK CB %p", (*it));
793 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700794 }
795 }
796}
797
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500798static void printCBList()
Tobin Ehlis6663f492014-11-10 12:29:12 -0700799{
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700800 char str[1024] = {0};
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500801 MT_CB_INFO* pCBInfo = NULL;
802 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600803 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500804
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600805 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500806 pCBInfo = (*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500807
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500808 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
809 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
810 (void*)getFenceFromId(pCBInfo->fenceId));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600811 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500812
Tony Barbourd1c35722015-04-16 15:59:00 -0600813 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500814 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600815 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700816 }
817 }
818}
819
Mark Lobodzinskic52b7752015-02-18 16:38:17 -0600820static void initMemTracker(void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700821{
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700822 const char *strOpt;
823 // initialize MemTracker options
Ian Elliotte7826712015-03-06 13:50:05 -0700824 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportingLevel);
825 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlisee702232015-01-08 14:26:53 -0700826
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600827 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700828 {
829 strOpt = getLayerOption("MemTrackerLogFilename");
830 if (strOpt)
831 {
832 g_logFile = fopen(strOpt, "w");
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700833 }
834 if (g_logFile == NULL)
835 g_logFile = stdout;
836 }
837
838 // initialize Layer dispatch table
839 // TODO handle multiple GPUs
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600840 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700841 fpNextGPA = pCurObj->pGPA;
842 assert(fpNextGPA);
843
Tony Barbourd1c35722015-04-16 15:59:00 -0600844 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Chia-I Wuaa4121f2015-01-04 23:11:43 +0800845
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600846 if (!globalLockInitialized)
847 {
848 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600849 // suggestion is to call this during vkCreateInstance(), and then we
850 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600851 // that the layer have per-instance locks. We need to come back and
852 // address this soon.
853 loader_platform_thread_create_mutex(&globalLock);
854 globalLockInitialized = 1;
855 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700856}
857
Tony Barbourd1c35722015-04-16 15:59:00 -0600858VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700859{
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600860 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700861 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600862 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700863 // Save off device in case we need it to create Fences
864 globalDevice = *pDevice;
865 return result;
866}
867
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600868VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700869{
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700870 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600871 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600872 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600873 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700874 printMemList();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500875 printCBList();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700876 printObjList();
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600877 if (VK_FALSE == deleteCBInfoList()) {
878 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
879 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700880 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700881 // Report any memory leaks
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500882 MT_MEM_OBJ_INFO* pInfo = NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -0600883 for (map<VkDeviceMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500884 pInfo = (*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500885
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500886 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600887 sprintf(str, "Mem Object %p has not been freed. You should clean up this memory by calling vkFreeMemory(%p) prior to vkDestroyDevice().",
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500888 pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600889 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600890 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700891 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500892
893 // Queues persist until device is destroyed
894 deleteQueueInfoList();
895
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600896 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600897 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700898 return result;
899}
900
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600901struct extProps {
902 uint32_t version;
903 const char * const name;
904};
Jon Ashburn120cfbe2015-04-14 14:12:59 -0600905#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600906static const struct extProps mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
907 // TODO what is the version?
Jon Ashburn120cfbe2015-04-14 14:12:59 -0600908 0x10, "MemTracker",
909 0x10, "Validation"
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600910};
911
912VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
913 VkExtensionInfoType infoType,
914 uint32_t extensionIndex,
915 size_t* pDataSize,
916 void* pData)
917{
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600918 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
919 VkExtensionProperties *ext_props;
920 uint32_t *count;
921
922 if (pDataSize == NULL)
923 return VK_ERROR_INVALID_POINTER;
924
925 switch (infoType) {
926 case VK_EXTENSION_INFO_TYPE_COUNT:
927 *pDataSize = sizeof(uint32_t);
928 if (pData == NULL)
929 return VK_SUCCESS;
930 count = (uint32_t *) pData;
931 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
932 break;
933 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
934 *pDataSize = sizeof(VkExtensionProperties);
935 if (pData == NULL)
936 return VK_SUCCESS;
937 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE)
938 return VK_ERROR_INVALID_VALUE;
939 ext_props = (VkExtensionProperties *) pData;
940 ext_props->version = mtExts[extensionIndex].version;
941 strncpy(ext_props->extName, mtExts[extensionIndex].name,
942 VK_MAX_EXTENSION_NAME);
943 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
944 break;
945 default:
946 return VK_ERROR_INVALID_VALUE;
947 };
948
949 return VK_SUCCESS;
950}
951
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600952VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu,
953 size_t maxStringSize, size_t* pLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700954{
Jon Ashburnf7a08742014-11-25 11:08:42 -0700955 if (gpu != NULL)
956 {
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600957 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700958 loader_platform_thread_once(&g_initOnce, initMemTracker);
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600959 VkResult result = nextTable.EnumerateLayers(gpu,
960 maxStringSize, pLayerCount, pOutLayers, pReserved);
Jon Ashburnf7a08742014-11-25 11:08:42 -0700961 return result;
962 } else
963 {
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600964 if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600965 return VK_ERROR_INVALID_POINTER;
Jon Ashburnf7a08742014-11-25 11:08:42 -0700966 // This layer compatible with all GPUs
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600967 *pLayerCount = 1;
Chia-I Wu1da4b9f2014-12-16 10:47:33 +0800968 strncpy((char *) pOutLayers[0], "MemTracker", maxStringSize);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600969 return VK_SUCCESS;
Jon Ashburnf7a08742014-11-25 11:08:42 -0700970 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700971}
972
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600973VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue)
Mark Lobodzinski748eddf2015-03-31 16:05:35 -0500974{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600975 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600976 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500977 loader_platform_thread_lock_mutex(&globalLock);
978 addQueueInfo(*pQueue);
979 loader_platform_thread_unlock_mutex(&globalLock);
980 }
Mark Lobodzinski748eddf2015-03-31 16:05:35 -0500981 return result;
982}
983
Tony Barbourd1c35722015-04-16 15:59:00 -0600984VK_LAYER_EXPORT VkResult VKAPI vkQueueAddMemReferences(VkQueue queue, uint32_t count, const VkDeviceMemory* pMems)
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500985{
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -0600986 VkResult result = nextTable.QueueAddMemReferences(queue, count, pMems);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600987 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500988 loader_platform_thread_lock_mutex(&globalLock);
989
990 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
991 if (pQueueInfo == NULL) {
992 char str[1024];
993 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600994 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -0600995 } else {
Tony Barbour18f71552015-04-22 11:36:22 -0600996 for (uint32_t i = 0; i < count; i++) {
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -0600997 if (checkMemRef(queue, pMems[i]) == VK_TRUE) {
998 // Alread in list, just warn
999 char str[1024];
1000 sprintf(str, "Request to add a memory reference (%p) to Queue %p -- ref is already present in the queue's reference list", pMems[i], queue);
1001 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pMems[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
1002 } else {
1003 // Add to queue's memory reference list
1004 pQueueInfo->pMemRefList.push_front(pMems[i]);
1005 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001006 }
1007 }
1008 loader_platform_thread_unlock_mutex(&globalLock);
1009 }
1010 return result;
1011}
1012
Tony Barbourd1c35722015-04-16 15:59:00 -06001013VK_LAYER_EXPORT VkResult VKAPI vkQueueRemoveMemReferences(VkQueue queue, uint32_t count, const VkDeviceMemory* pMems)
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001014{
1015 // TODO : Decrement ref count for this memory reference on this queue. Remove if ref count is zero.
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001016 VkResult result = nextTable.QueueRemoveMemReferences(queue, count, pMems);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001017 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001018 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001019
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001020 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
1021 if (pQueueInfo == NULL) {
1022 char str[1024];
1023 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001024 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001025 } else {
Tony Barbour18f71552015-04-22 11:36:22 -06001026 for (uint32_t i = 0; i < count; i++) {
Tony Barbourd1c35722015-04-16 15:59:00 -06001027 for (list<VkDeviceMemory>::iterator it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001028 if ((*it) == pMems[i]) {
1029 it = pQueueInfo->pMemRefList.erase(it);
1030 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001031 }
1032 }
1033 }
1034 loader_platform_thread_unlock_mutex(&globalLock);
1035 }
1036 return result;
1037}
1038
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001039VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1040 VkQueue queue,
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001041 uint32_t cmdBufferCount,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001042 const VkCmdBuffer *pCmdBuffers,
1043 VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001044{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001045 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001046 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001047 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001048 uint64_t fenceId = addFenceInfo(fence, queue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001049
Tobin Ehlis6663f492014-11-10 12:29:12 -07001050 printMemList();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001051 printCBList();
Tobin Ehlis6663f492014-11-10 12:29:12 -07001052 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001053 pCBInfo = getCBInfo(pCmdBuffers[i]);
1054 pCBInfo->fenceId = fenceId;
Tobin Ehlis6663f492014-11-10 12:29:12 -07001055 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001056
Mark Lobodzinskie01252d2015-04-17 11:44:25 -05001057 validateQueueMemRefs(queue, cmdBufferCount, pCmdBuffers);
Mark Lobodzinskied450b02015-04-07 13:38:21 -05001058
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001059 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001060 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, getFenceFromId(fenceId));
Courtney Goeltzenleuchterd3fb9552015-04-02 13:39:07 -06001061 return result;
1062}
1063
Tony Barbourd1c35722015-04-16 15:59:00 -06001064VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(VkDevice device, const VkMemoryAllocInfo* pAllocInfo, VkDeviceMemory* pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001065{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001066 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001067 // TODO : Track allocations and overall size here
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001068 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001069 addMemObjInfo(*pMem, pAllocInfo);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001070 printMemList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001071 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001072 return result;
1073}
1074
Mike Stroyanb050c682015-04-17 12:36:38 -06001075VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(VkDevice device, VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001076{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001077 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisc0418f92014-11-25 14:47:20 -07001078 * freeing a memory object, an application must ensure the memory object is unbound from
1079 * all API objects referencing it and that it is not referenced by any queued command buffers
1080 */
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001081 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001082 if (VK_FALSE == freeMemObjInfo(mem, false)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001083 char str[1024];
1084 sprintf(str, "Issue while freeing mem obj %p", (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001085 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREE_MEM_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001086 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001087 printMemList();
1088 printObjList();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001089 printCBList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001090 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanb050c682015-04-17 12:36:38 -06001091 VkResult result = nextTable.FreeMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001092 return result;
1093}
1094
Mike Stroyanb050c682015-04-17 12:36:38 -06001095VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(VkDevice device, VkDeviceMemory mem, VkMemoryPriority priority)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001096{
1097 // TODO : Update tracking for this alloc
1098 // Make sure memory is not pinned, which can't have priority set
Mike Stroyanb050c682015-04-17 12:36:38 -06001099 VkResult result = nextTable.SetMemoryPriority(device, mem, priority);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001100 return result;
1101}
1102
Mike Stroyanb050c682015-04-17 12:36:38 -06001103VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkFlags flags, void** ppData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001104{
1105 // TODO : Track when memory is mapped
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001106 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001107 MT_MEM_OBJ_INFO *pMemObj = getMemObjInfo(mem);
Tony Barbourd1c35722015-04-16 15:59:00 -06001108 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001109 char str[1024];
Tony Barbourd1c35722015-04-16 15:59:00 -06001110 sprintf(str, "Mapping Memory (%p) without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set", (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001111 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001112 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001113 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanb050c682015-04-17 12:36:38 -06001114 VkResult result = nextTable.MapMemory(device, mem, offset, size, flags, ppData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001115 return result;
1116}
1117
Mike Stroyanb050c682015-04-17 12:36:38 -06001118VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(VkDevice device, VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001119{
1120 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1121 // Make sure that memory was ever mapped to begin with
Mike Stroyanb050c682015-04-17 12:36:38 -06001122 VkResult result = nextTable.UnmapMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001123 return result;
1124}
1125
Tony Barbourd1c35722015-04-16 15:59:00 -06001126VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSysMem, size_t memSize, VkDeviceMemory* pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001127{
1128 // TODO : Track this
1129 // Verify that memory is actually pinnable
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001130 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001131 return result;
1132}
1133
Tony Barbourd1c35722015-04-16 15:59:00 -06001134VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkDeviceMemory* pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001135{
1136 // TODO : Track this
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001137 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001138 return result;
1139}
1140
Tony Barbourd1c35722015-04-16 15:59:00 -06001141VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkDeviceMemory* pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001142{
1143 // TODO : Track this
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001144 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001145 return result;
1146}
1147
Tony Barbourd1c35722015-04-16 15:59:00 -06001148VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, VkDeviceMemory* pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001149{
1150 // TODO : Track this
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001151 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001152 return result;
1153}
1154
Mike Stroyanb050c682015-04-17 12:36:38 -06001155VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkDevice device, VkObjectType objType, VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001156{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001157 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001158
Tobin Ehlisa98df732014-11-27 07:52:04 -07001159 // First check if this is a CmdBuffer
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001160 if (NULL != getCBInfo((VkCmdBuffer)object)) {
1161 deleteCBInfo((VkCmdBuffer)object);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001162 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001163
1164 if (objectMap.find(object) != objectMap.end()) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001165 MT_OBJ_INFO* pDelInfo = objectMap[object];
1166 if (pDelInfo->pMemObjInfo) {
Tobin Ehlisa98df732014-11-27 07:52:04 -07001167 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001168 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Tony Barbourd1c35722015-04-16 15:59:00 -06001169 VkDeviceMemory memToFree = pDelInfo->pMemObjInfo->mem;
Tobin Ehlisa98df732014-11-27 07:52:04 -07001170 clearObjectBinding(object);
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -06001171 freeMemObjInfo(memToFree, true);
1172 }
1173 else {
Tobin Ehlisa98df732014-11-27 07:52:04 -07001174 char str[1024];
Mark Lobodzinski40f7f402015-04-16 11:44:05 -05001175 sprintf(str, "Destroying obj %p that is still bound to memory object %p\nYou should first clear binding by calling vkQueueBindObjectMemory(queue, %p, 0, VK_NULL_HANDLE, 0)", object, (void*)pDelInfo->pMemObjInfo->mem, object);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001176 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001177 // From the spec : If an object has previous memory binding, it is required to unbind memory from an API object before it is destroyed.
1178 clearObjectBinding(object);
1179 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001180 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001181 delete pDelInfo;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001182 objectMap.erase(object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001183 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001184
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001185 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanb050c682015-04-17 12:36:38 -06001186 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001187 return result;
1188}
1189
Mike Stroyanb050c682015-04-17 12:36:38 -06001190VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(VkDevice device, VkObjectType objType, VkObject object, VkObjectInfoType infoType, size_t* pDataSize, void* pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001191{
1192 // TODO : What to track here?
Mark Lobodzinski40f7f402015-04-16 11:44:05 -05001193 // Could potentially save returned mem requirements and validate values passed into QueueBindObjectMemory for this object
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001194 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues, command buffers, shaders and memory objects.
Mike Stroyanb050c682015-04-17 12:36:38 -06001195 VkResult result = nextTable.GetObjectInfo(device, objType, object, infoType, pDataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001196 return result;
1197}
1198
Mike Stroyanb050c682015-04-17 12:36:38 -06001199VK_LAYER_EXPORT VkResult VKAPI vkQueueBindObjectMemory(VkQueue queue, VkObjectType objType, VkObject object, uint32_t allocationIdx, VkDeviceMemory mem, VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001200{
Mike Stroyanb050c682015-04-17 12:36:38 -06001201 VkResult result = nextTable.QueueBindObjectMemory(queue, objType, object, allocationIdx, mem, offset);
1202 loader_platform_thread_lock_mutex(&globalLock);
1203 // Track objects tied to memory
1204 if (VK_FALSE == updateObjectBinding(object, mem)) {
1205 char str[1024];
1206 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
1207 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
1208 }
1209 printObjList();
1210 printMemList();
1211 loader_platform_thread_unlock_mutex(&globalLock);
1212 return result;
1213}
1214
1215VK_LAYER_EXPORT VkResult VKAPI vkQueueBindObjectMemoryRange(VkQueue queue, VkObjectType objType, VkObject object, uint32_t allocationIdx, VkDeviceSize rangeOffset, VkDeviceSize rangeSize, VkDeviceMemory mem, VkDeviceSize memOffset)
1216{
1217 VkResult result = nextTable.QueueBindObjectMemoryRange(queue, objType, object, allocationIdx, rangeOffset, rangeSize, mem, memOffset);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001218 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001219 // Track objects tied to memory
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001220 if (VK_FALSE == updateObjectBinding(object, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001221 char str[1024];
1222 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001223 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001224 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001225 printObjList();
1226 printMemList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001227 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001228 return result;
1229}
1230
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001231VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001232{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001233 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001234 if (VK_SUCCESS == result) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001235 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001236 addObjectInfo(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001237 loader_platform_thread_unlock_mutex(&globalLock);
1238 }
1239 return result;
1240}
1241
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001242VK_LAYER_EXPORT VkResult VKAPI vkResetFences(VkDevice device, uint32_t fenceCount, VkFence* pFences)
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001243{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001244 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001245 if (VK_SUCCESS == result) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001246 loader_platform_thread_lock_mutex(&globalLock);
1247 // Reset fence state in fenceCreateInfo structure
1248 for (uint32_t i = 0; i < fenceCount; i++) {
1249 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1250 if (pObjectInfo != NULL) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001251 // Validate fences in SIGNALED state
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001252 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001253 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001254 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001255 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
1256 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001257 }
1258 else {
1259 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001260 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001261 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001262 }
1263 }
1264 loader_platform_thread_unlock_mutex(&globalLock);
1265 }
1266 return result;
1267}
1268
Mike Stroyanb050c682015-04-17 12:36:38 -06001269VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(VkDevice device, VkFence fence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001270{
Mike Stroyanb050c682015-04-17 12:36:38 -06001271 VkResult result = nextTable.GetFenceStatus(device, fence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001272 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001273 loader_platform_thread_lock_mutex(&globalLock);
1274 updateFenceTracking(fence);
1275 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001276 }
1277 return result;
1278}
1279
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001280VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, bool32_t waitAll, uint64_t timeout)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001281{
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001282 // Verify fence status of submitted fences
1283 for(uint32_t i = 0; i < fenceCount; i++) {
1284 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1285 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001286 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001287 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001288 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001289 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001290 }
1291 }
1292 }
1293
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001294 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001295 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05001296
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001297 if (VK_SUCCESS == result) {
Mark Lobodzinski50932972015-04-02 20:49:09 -05001298 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001299 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001300 updateFenceTracking(pFences[i]);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001301 }
1302 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001303 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001304 loader_platform_thread_unlock_mutex(&globalLock);
1305 return result;
1306}
1307
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001308VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001309{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001310 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001311 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001312 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001313 retireQueueFences(queue);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001314 loader_platform_thread_unlock_mutex(&globalLock);
1315 }
1316 return result;
1317}
1318
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001319VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(VkDevice device)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001320{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001321 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001322 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001323 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05001324 retireDeviceFences(device);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001325 loader_platform_thread_unlock_mutex(&globalLock);
1326 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001327 return result;
1328}
1329
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001330VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001331{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001332 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001333 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001334 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001335 addObjectInfo(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001336 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001337 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001338 return result;
1339}
1340
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001341VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001342{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001343 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001344 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001345 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001346 addObjectInfo(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001347 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001348 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001349 return result;
1350}
1351
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001352VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001353{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001354 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001355 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001356 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001357 addObjectInfo(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001358 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001359 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001360 return result;
1361}
1362
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001363VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001364{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001365 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001366 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001367 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001368 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001369 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001370 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001371 return result;
1372}
1373
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001374VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001375{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001376 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001377 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001378 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001379 addObjectInfo(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001380 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001381 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001382 return result;
1383}
1384
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001385VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001386{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001387 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001388 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001389 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001390 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001391 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001392 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001393 return result;
1394}
1395
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001396VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(VkDevice device, const VkColorAttachmentViewCreateInfo* pCreateInfo,
1397 VkColorAttachmentView* pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001398{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001399 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001400 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001401 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001402 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001403 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001404 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001405 return result;
1406}
1407
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001408VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001409{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001410 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001411 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001412 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001413 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001414 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001415 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001416 return result;
1417}
1418
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001419VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001420{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001421 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001422 return result;
1423}
1424
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001425VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001426{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001427 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001428 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001429 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001430 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001431 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001432 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001433 return result;
1434}
1435
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001436VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1437 VkDevice device,
1438 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1439 VkPipeline basePipeline,
1440 VkPipeline* pPipeline)
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001441{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001442 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001443 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001444 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001445 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001446 loader_platform_thread_unlock_mutex(&globalLock);
1447 }
1448 return result;
1449}
1450
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001451VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001452{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001453 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
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);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001456 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
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
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001462VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001463{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001464 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001465 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001466 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001467 addObjectInfo(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001468 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001469 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001470 return result;
1471}
1472
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001473VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001474 VkDynamicVpState* pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001475{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001476 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
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);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001479 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
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 vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001486 VkDynamicRsState* pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001487{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001488 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001489 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001490 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001491 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001492 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001493 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001494 return result;
1495}
1496
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001497VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001498 VkDynamicCbState* pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001499{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001500 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001501 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001502 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001503 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001504 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001505 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001506 return result;
1507}
1508
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001509VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchter502744a2015-04-10 16:24:50 -06001510 VkDynamicDsState* pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001511{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001512 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001513 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001514 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001515 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001516 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001517 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001518 return result;
1519}
1520
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001521VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001522{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001523 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001524 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001525 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001526 if (*pCmdBuffer)
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001527 addCBInfo(*pCmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001528 printCBList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001529 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001530 return result;
1531}
1532
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001533VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001534{
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001535 // This implicitly resets the Cmd Buffer so make sure any fence is done and then clear memory references
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001536 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1537 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001538 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001539 if (VK_FALSE == cbDone) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001540 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001541 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. You must check CB flag before this call.", cmdBuffer);
1542 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001543 }
1544 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001545 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001546 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001547 freeCBBindings(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001548 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001549 return result;
1550}
1551
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001552VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001553{
1554 // TODO : Anything to do here?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001555 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001556 return result;
1557}
1558
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001559VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001560{
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001561 // Verify that CB is complete (not in-flight)
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001562 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1563 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001564 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001565 if (VK_FALSE == cbDone) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001566 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001567 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before calling vkResetCommandBuffer().", cmdBuffer);
1568 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001569 }
1570 }
1571 // Clear memory references as this point.
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001572 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001573 freeCBBindings(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001574 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001575 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001576 return result;
1577}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001578// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis6663f492014-11-10 12:29:12 -07001579// need to account for that mem now having binding to given cmdBuffer
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001580VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001581{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001582#if 0
1583 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1584 if (getPipeline(pipeline)) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001585 MT_CB_INFO *pCBInfo = getCBInfo(cmdBuffer);
1586 if (pCBInfo) {
1587 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlisc145be82015-01-08 15:22:32 -07001588 } else {
1589 char str[1024];
1590 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001591 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, (char *) "DS", (char *) str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001592 }
1593 }
1594 else {
1595 char str[1024];
1596 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001597 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, MEMTRACK_INVALID_OBJECT, (char *) "DS", (char *) str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001598 }
1599#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -07001600 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1601}
1602
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001603VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001604{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001605 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001606 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001607 MT_CB_INFO *pCmdBuf = getCBInfo(cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001608 if (!pCmdBuf) {
1609 char str[1024];
1610 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001611 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001612 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001613 pObjInfo = getObjectInfo(state);
1614 if (!pObjInfo) {
Tobin Ehlisc145be82015-01-08 15:22:32 -07001615 char str[1024];
1616 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001617 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001618 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001619 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001620 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001621 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001622}
1623
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001624VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001625 VkCmdBuffer cmdBuffer,
1626 VkPipelineBindPoint pipelineBindPoint,
Cody Northropd4c1a502015-04-16 13:41:56 -06001627 uint32_t firstSet,
1628 uint32_t setCount,
1629 const VkDescriptorSet* pDescriptorSets,
1630 uint32_t dynamicOffsetCount,
1631 const uint32_t* pDynamicOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001632{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001633 // TODO : Somewhere need to verify that all textures referenced by shaders in DS are in some type of *SHADER_READ* state
Cody Northropd4c1a502015-04-16 13:41:56 -06001634 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001635}
1636
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001637VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
1638 VkCmdBuffer cmdBuffer,
1639 uint32_t startBinding,
1640 uint32_t bindingCount,
1641 const VkBuffer* pBuffers,
Tony Barbourd1c35722015-04-16 15:59:00 -06001642 const VkDeviceSize* pOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001643{
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001644 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wu19156822015-01-05 13:42:56 +08001645}
1646
Tony Barbourd1c35722015-04-16 15:59:00 -06001647VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001648{
Tobin Ehlis7265e832015-01-19 08:42:29 -07001649 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001650}
1651
Tony Barbourd1c35722015-04-16 15:59:00 -06001652VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001653{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001654 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001655 VkDeviceMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001656 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001657 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001658 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1659 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001660 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001661 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001662 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001663}
1664
Tony Barbourd1c35722015-04-16 15:59:00 -06001665VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001666{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001667 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001668 VkDeviceMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001669 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001670 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001671 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1672 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001673 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001674 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001675 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001676}
1677
Tony Barbourd1c35722015-04-16 15:59:00 -06001678VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001679{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001680 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001681 VkDeviceMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001682 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001683 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001684 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1685 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001686 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001687 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001688 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001689}
1690
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001691VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer,
1692 uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001693{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001694 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001695 VkDeviceMemory mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001696 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001697 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001698 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1699 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001700 }
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001701 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001702 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001703 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001704 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1705 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001706 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001707 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001708 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001709}
1710
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001711VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
1712 VkImage srcImage, VkImageLayout srcImageLayout,
1713 VkImage destImage, VkImageLayout destImageLayout,
1714 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001715{
1716 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001717 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001718}
1719
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001720VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
1721 VkImage srcImage, VkImageLayout srcImageLayout,
1722 VkImage destImage, VkImageLayout destImageLayout,
1723 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001724{
1725 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001726 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001727}
1728
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001729VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
1730 VkBuffer srcBuffer,
1731 VkImage destImage, VkImageLayout destImageLayout,
1732 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001733{
1734 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001735 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001736 VkDeviceMemory mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001737 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001738 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001739 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1740 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001741 }
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001742
1743 mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001744 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001745 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001746 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1747 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001748 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001749 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001750 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001751}
1752
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001753VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
1754 VkImage srcImage, VkImageLayout srcImageLayout,
1755 VkBuffer destBuffer,
1756 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001757{
1758 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001759 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001760 VkDeviceMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001761 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001762 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001763 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1764 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001765 }
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001766 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001767 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001768 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001769 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1770 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001771 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001772 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001773 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001774}
1775
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001776VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1777 VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001778{
1779 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001780 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001781 VkDeviceMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001782 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001783 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001784 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1785 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001786 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001787 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001788 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001789 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001790 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1791 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001792 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001793 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanfb80d5f2014-12-04 11:08:39 +00001794 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001795}
1796
Tony Barbourd1c35722015-04-16 15:59:00 -06001797VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001798{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001799 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001800 VkDeviceMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001801 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001802 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001803 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1804 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001805 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001806 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001807 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001808}
1809
Tony Barbourd1c35722015-04-16 15:59:00 -06001810VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001811{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001812 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001813 VkDeviceMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001814 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001815 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001816 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1817 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001818 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001819 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001820 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001821}
1822
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001823VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
1824 VkImage image, VkImageLayout imageLayout,
1825 VkClearColor color,
1826 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001827{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001828 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001829 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001830 VkDeviceMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001831 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001832 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001833 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1834 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001835 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001836 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001837 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001838}
1839
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001840VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
1841 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001842 float depth, uint32_t stencil,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001843 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001844{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001845 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001846 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001847 VkDeviceMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001848 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001849 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001850 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1851 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001852 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001853 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001854 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001855}
1856
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001857VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
1858 VkImage srcImage, VkImageLayout srcImageLayout,
1859 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour6865d4a2015-04-13 15:02:52 -06001860 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001861{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001862 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001863 VkDeviceMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001864 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001865 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001866 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1867 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001868 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001869 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001870 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001871 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001872 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1873 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001874 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001875 loader_platform_thread_unlock_mutex(&globalLock);
Tony Barbour6865d4a2015-04-13 15:02:52 -06001876 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001877}
1878
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001879VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001880{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001881 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001882 VkDeviceMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001883 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001884 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001885 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1886 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001887 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001888 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001889 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1890}
1891
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001892VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001893{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001894 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001895 VkDeviceMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001896 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001897 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001898 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1899 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001900 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001901 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001902 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1903}
1904
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001905VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001906{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001907 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbourd1c35722015-04-16 15:59:00 -06001908 VkDeviceMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001909 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001910 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001911 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1912 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001913 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001914 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001915 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1916}
1917
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001918VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001919{
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001920 // This layer intercepts callbacks
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001921 VK_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (VK_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(VK_LAYER_DBG_FUNCTION_NODE));
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001922 if (!pNewDbgFuncNode)
Tony Barbourd1c35722015-04-16 15:59:00 -06001923 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001924 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
1925 pNewDbgFuncNode->pUserData = pUserData;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -07001926 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
1927 g_pDbgFunctionHead = pNewDbgFuncNode;
Jon Ashburna8aa8372015-03-03 15:07:15 -07001928 // force callbacks if DebugAction hasn't been set already other than initial value
Courtney Goeltzenleuchter90d93202015-03-04 15:47:34 -07001929 if (g_actionIsDefault) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001930 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Courtney Goeltzenleuchter90d93202015-03-04 15:47:34 -07001931 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001932 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001933 return result;
1934}
1935
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001936VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001937{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001938 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
1939 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001940 while (pInfo) {
1941 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
1942 pPrev->pNext = pInfo->pNext;
1943 if (g_pDbgFunctionHead == pInfo)
1944 g_pDbgFunctionHead = pInfo->pNext;
1945 free(pInfo);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001946 break;
1947 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001948 pPrev = pInfo;
1949 pInfo = pInfo->pNext;
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001950 }
Jon Ashburna8aa8372015-03-03 15:07:15 -07001951 if (g_pDbgFunctionHead == NULL)
1952 {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001953 if (g_actionIsDefault) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001954 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001955 } else {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001956 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001957 }
Jon Ashburna8aa8372015-03-03 15:07:15 -07001958 }
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001959 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001960 return result;
1961}
1962
Chia-I Wuf8693382015-04-16 22:02:10 +08001963VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(VkDevice device, const VkSwapChainCreateInfoWSI* pCreateInfo, VkSwapChainWSI* pSwapChain)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001964{
Chia-I Wuf8693382015-04-16 22:02:10 +08001965 VkResult result = nextTable.CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
1966
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001967 if (VK_SUCCESS == result) {
Chia-I Wuf8693382015-04-16 22:02:10 +08001968 loader_platform_thread_lock_mutex(&globalLock);
1969 addSwapChainInfo(*pSwapChain);
1970 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001971 }
Chia-I Wuf8693382015-04-16 22:02:10 +08001972
Tobin Ehlis6663f492014-11-10 12:29:12 -07001973 return result;
1974}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001975
Chia-I Wuf8693382015-04-16 22:02:10 +08001976VK_LAYER_EXPORT VkResult VKAPI vkDestroySwapChainWSI(VkSwapChainWSI swapChain)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001977{
1978 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08001979
1980 if (swapChainMap.find(swapChain) != swapChainMap.end()) {
1981 MT_SWAP_CHAIN_INFO* pInfo = swapChainMap[swapChain];
1982
1983 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
1984 it != pInfo->images.end(); it++) {
1985 clearObjectBinding(it->image);
1986 freeMemObjInfo(it->memory, true);
1987
1988 MT_OBJ_INFO* pDelInfo = objectMap[it->image];
1989 delete pDelInfo;
1990 objectMap.erase(it->image);
1991 }
1992
1993 delete pInfo;
1994 swapChainMap.erase(swapChain);
1995 }
1996
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001997 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08001998
1999 return nextTable.DestroySwapChainWSI(swapChain);
2000}
2001
2002VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(VkSwapChainWSI swapChain, VkSwapChainInfoTypeWSI infoType, size_t* pDataSize, void* pData)
2003{
2004 VkResult result = nextTable.GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
2005
2006 if (infoType == VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI && result == VK_SUCCESS) {
2007 const size_t count = *pDataSize / sizeof(VkSwapChainImageInfoWSI);
2008 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain];
2009
2010 if (pInfo->images.empty()) {
2011 pInfo->images.resize(count);
2012 memcpy(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count);
2013
2014 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2015 it != pInfo->images.end(); it++) {
2016 // Add image object, then insert the new Mem Object and then bind it to created image
2017 addObjectInfo(it->image, VK_STRUCTURE_TYPE_MAX_ENUM, &pInfo->createInfo, sizeof(pInfo->createInfo), "persistent_image");
2018 addMemObjInfo(it->memory, NULL);
2019 if (VK_FALSE == updateObjectBinding(it->image, it->memory)) {
2020 char str[1024];
2021 sprintf(str, "In vkGetSwapChainInfoWSI(), unable to set image %p binding to mem obj %p", (void*)it->image, (void*)it->memory);
2022 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, it->image, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
2023 }
2024 }
2025 } else {
2026 const bool mismatch = (pInfo->images.size() != count ||
2027 memcmp(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count));
2028
2029 if (mismatch) {
2030 char str[1024];
2031 sprintf(str, "vkGetSwapChainInfoWSI(%p, VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI) returned mismatching data", swapChain);
Mike Stroyanb050c682015-04-17 12:36:38 -06002032 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, (VkObject) swapChain, 0, MEMTRACK_NONE, "SWAP_CHAIN", str);
Chia-I Wuf8693382015-04-16 22:02:10 +08002033 }
2034 }
2035 }
2036
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002037 return result;
2038}
Tobin Ehlis6663f492014-11-10 12:29:12 -07002039
Tony Barbourd1c35722015-04-16 15:59:00 -06002040VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002041{
Jon Ashburnbacb0f52015-04-06 10:58:22 -06002042 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wu4d11dcc2015-01-05 13:18:57 +08002043
Tobin Ehlis6663f492014-11-10 12:29:12 -07002044 if (gpu == NULL)
2045 return NULL;
2046 pCurObj = gpuw;
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07002047 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002048
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002049 if (!strcmp(funcName, "vkGetProcAddr"))
2050 return (void *) vkGetProcAddr;
2051 if (!strcmp(funcName, "vkCreateDevice"))
2052 return (void*) vkCreateDevice;
2053 if (!strcmp(funcName, "vkDestroyDevice"))
2054 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002055 if (!strcmp(funcName, "vkEnumerateLayers"))
2056 return (void*) vkEnumerateLayers;
2057 if (!strcmp(funcName, "vkQueueSubmit"))
2058 return (void*) vkQueueSubmit;
2059 if (!strcmp(funcName, "vkAllocMemory"))
2060 return (void*) vkAllocMemory;
2061 if (!strcmp(funcName, "vkFreeMemory"))
2062 return (void*) vkFreeMemory;
2063 if (!strcmp(funcName, "vkSetMemoryPriority"))
2064 return (void*) vkSetMemoryPriority;
2065 if (!strcmp(funcName, "vkMapMemory"))
2066 return (void*) vkMapMemory;
2067 if (!strcmp(funcName, "vkUnmapMemory"))
2068 return (void*) vkUnmapMemory;
2069 if (!strcmp(funcName, "vkPinSystemMemory"))
2070 return (void*) vkPinSystemMemory;
2071 if (!strcmp(funcName, "vkOpenSharedMemory"))
2072 return (void*) vkOpenSharedMemory;
2073 if (!strcmp(funcName, "vkOpenPeerMemory"))
2074 return (void*) vkOpenPeerMemory;
2075 if (!strcmp(funcName, "vkOpenPeerImage"))
2076 return (void*) vkOpenPeerImage;
2077 if (!strcmp(funcName, "vkDestroyObject"))
2078 return (void*) vkDestroyObject;
2079 if (!strcmp(funcName, "vkGetObjectInfo"))
2080 return (void*) vkGetObjectInfo;
Mark Lobodzinski40f7f402015-04-16 11:44:05 -05002081 if (!strcmp(funcName, "vkQueueBindObjectMemory"))
2082 return (void*) vkQueueBindObjectMemory;
Mike Stroyanb050c682015-04-17 12:36:38 -06002083 if (!strcmp(funcName, "vkQueueBindObjectMemoryRange"))
2084 return (void*) vkQueueBindObjectMemoryRange;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002085 if (!strcmp(funcName, "vkCreateFence"))
2086 return (void*) vkCreateFence;
2087 if (!strcmp(funcName, "vkGetFenceStatus"))
2088 return (void*) vkGetFenceStatus;
2089 if (!strcmp(funcName, "vkResetFences"))
2090 return (void*) vkResetFences;
2091 if (!strcmp(funcName, "vkWaitForFences"))
2092 return (void*) vkWaitForFences;
2093 if (!strcmp(funcName, "vkQueueWaitIdle"))
2094 return (void*) vkQueueWaitIdle;
2095 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2096 return (void*) vkDeviceWaitIdle;
2097 if (!strcmp(funcName, "vkCreateEvent"))
2098 return (void*) vkCreateEvent;
2099 if (!strcmp(funcName, "vkCreateQueryPool"))
2100 return (void*) vkCreateQueryPool;
2101 if (!strcmp(funcName, "vkCreateBuffer"))
2102 return (void*) vkCreateBuffer;
2103 if (!strcmp(funcName, "vkCreateBufferView"))
2104 return (void*) vkCreateBufferView;
2105 if (!strcmp(funcName, "vkCreateImage"))
2106 return (void*) vkCreateImage;
2107 if (!strcmp(funcName, "vkCreateImageView"))
2108 return (void*) vkCreateImageView;
2109 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2110 return (void*) vkCreateColorAttachmentView;
2111 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2112 return (void*) vkCreateDepthStencilView;
2113 if (!strcmp(funcName, "vkCreateShader"))
2114 return (void*) vkCreateShader;
2115 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2116 return (void*) vkCreateGraphicsPipeline;
2117 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2118 return (void*) vkCreateGraphicsPipelineDerivative;
2119 if (!strcmp(funcName, "vkCreateComputePipeline"))
2120 return (void*) vkCreateComputePipeline;
2121 if (!strcmp(funcName, "vkCreateSampler"))
2122 return (void*) vkCreateSampler;
2123 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2124 return (void*) vkCreateDynamicViewportState;
2125 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2126 return (void*) vkCreateDynamicRasterState;
2127 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2128 return (void*) vkCreateDynamicColorBlendState;
2129 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2130 return (void*) vkCreateDynamicDepthStencilState;
2131 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2132 return (void*) vkCreateCommandBuffer;
2133 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2134 return (void*) vkBeginCommandBuffer;
2135 if (!strcmp(funcName, "vkEndCommandBuffer"))
2136 return (void*) vkEndCommandBuffer;
2137 if (!strcmp(funcName, "vkResetCommandBuffer"))
2138 return (void*) vkResetCommandBuffer;
2139 if (!strcmp(funcName, "vkCmdBindPipeline"))
2140 return (void*) vkCmdBindPipeline;
2141 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2142 return (void*) vkCmdBindDynamicStateObject;
2143 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2144 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002145 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2146 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002147 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2148 return (void*) vkCmdBindIndexBuffer;
2149 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2150 return (void*) vkCmdDrawIndirect;
2151 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2152 return (void*) vkCmdDrawIndexedIndirect;
2153 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2154 return (void*) vkCmdDispatchIndirect;
2155 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2156 return (void*) vkCmdCopyBuffer;
2157 if (!strcmp(funcName, "vkCmdCopyImage"))
2158 return (void*) vkCmdCopyImage;
2159 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2160 return (void*) vkCmdCopyBufferToImage;
2161 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2162 return (void*) vkCmdCopyImageToBuffer;
2163 if (!strcmp(funcName, "vkCmdCloneImageData"))
2164 return (void*) vkCmdCloneImageData;
2165 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2166 return (void*) vkCmdUpdateBuffer;
2167 if (!strcmp(funcName, "vkCmdFillBuffer"))
2168 return (void*) vkCmdFillBuffer;
2169 if (!strcmp(funcName, "vkCmdClearColorImage"))
2170 return (void*) vkCmdClearColorImage;
2171 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2172 return (void*) vkCmdClearDepthStencil;
2173 if (!strcmp(funcName, "vkCmdResolveImage"))
2174 return (void*) vkCmdResolveImage;
2175 if (!strcmp(funcName, "vkCmdBeginQuery"))
2176 return (void*) vkCmdBeginQuery;
2177 if (!strcmp(funcName, "vkCmdEndQuery"))
2178 return (void*) vkCmdEndQuery;
2179 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2180 return (void*) vkCmdResetQueryPool;
2181 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2182 return (void*) vkDbgRegisterMsgCallback;
2183 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2184 return (void*) vkDbgUnregisterMsgCallback;
2185 if (!strcmp(funcName, "vkGetDeviceQueue"))
2186 return (void*) vkGetDeviceQueue;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002187 if (!strcmp(funcName, "vkQueueAddMemReferences"))
2188 return (void*) vkQueueAddMemReferences;
2189 if (!strcmp(funcName, "vkQueueRemoveMemReferences"))
2190 return (void*) vkQueueRemoveMemReferences;
Chia-I Wuf8693382015-04-16 22:02:10 +08002191 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
2192 return (void*) vkCreateSwapChainWSI;
2193 if (!strcmp(funcName, "vkDestroySwapChainWSI"))
2194 return (void*) vkDestroySwapChainWSI;
2195 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
2196 return (void*) vkGetSwapChainInfoWSI;
Tobin Ehlis6663f492014-11-10 12:29:12 -07002197 else {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002198 if (gpuw->pGPA == NULL)
2199 return NULL;
Tony Barbourd1c35722015-04-16 15:59:00 -06002200 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002201 }
2202}