blob: 10215e6cea4d2ffe4d9838983d81b4530256713d [file] [log] [blame]
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001/*
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05002 * Vulkan
Tobin Ehlis791a49c2014-11-10 12:29:12 -07003 *
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05004 * Copyright (C) 2015 LunarG, Inc.
Tobin Ehlis791a49c2014-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 Lobodzinski283a4c22015-03-24 16:29:24 -050017* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Tobin Ehlis791a49c2014-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 Lobodzinski4aad3642015-03-17 10:53:12 -050025#include <inttypes.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070026#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050030#include <list>
31#include <map>
32using namespace std;
33
Ian Elliott81ac44c2015-01-13 17:52:38 -070034#include "loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060035#include "vk_dispatch_table_helper.h"
36#include "vk_struct_string_helper_cpp.h"
Tobin Ehlis62086412014-11-19 16:19:28 -070037#include "mem_tracker.h"
Jon Ashburnf57ea372014-12-22 13:24:15 -070038#include "layers_config.h"
Ian Elliott20f06872015-02-12 17:08:34 -070039// The following is #included again to catch certain OS-specific functions
40// being used:
41#include "loader_platform.h"
Jon Ashburn5a7be202015-02-16 08:46:53 -070042#include "layers_msg.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070043
Jon Ashburn301c5f02015-04-06 10:58:22 -060044static VkLayerDispatchTable nextTable;
45static VkBaseLayerObject *pCurObj;
Ian Elliott81ac44c2015-01-13 17:52:38 -070046static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -060047// TODO : This can be much smarter, using separate locks for separate global data
48static int globalLockInitialized = 0;
49static loader_platform_thread_mutex globalLock;
Jon Ashburnf57ea372014-12-22 13:24:15 -070050
Tobin Ehlis2836a7d2015-01-08 15:22:32 -070051#define MAX_BINDING 0xFFFFFFFF
Tobin Ehlis2836a7d2015-01-08 15:22:32 -070052
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060053map<VkCmdBuffer, MT_CB_INFO*> cbMap;
Tony Barbour8205d902015-04-16 15:59:00 -060054map<VkDeviceMemory, MT_MEM_OBJ_INFO*> memObjMap;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060055map<VkObject, MT_OBJ_INFO*> objectMap;
Mark Lobodzinski85a83982015-04-02 08:52:53 -050056map<uint64_t, MT_FENCE_INFO*> fenceMap; // Map fenceId to fence info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060057map<VkQueue, MT_QUEUE_INFO*> queueMap;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050058
Mark Lobodzinski8ee96342015-04-02 20:49:09 -050059// TODO : Add per-device fence completion
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050060static uint64_t g_currentFenceId = 1;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060061static VkDevice globalDevice = NULL;
Mark Lobodzinski15427102015-02-18 16:38:17 -060062
Mark Lobodzinski85a83982015-04-02 08:52:53 -050063// Add new queue for this device to map container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060064static void addQueueInfo(const VkQueue queue)
Mark Lobodzinski85a83982015-04-02 08:52:53 -050065{
Mark Lobodzinski8ee96342015-04-02 20:49:09 -050066 MT_QUEUE_INFO* pInfo = new MT_QUEUE_INFO;
67 pInfo->lastRetiredId = 0;
68 pInfo->lastSubmittedId = 0;
69 queueMap[queue] = pInfo;
Mark Lobodzinski85a83982015-04-02 08:52:53 -050070}
71
72static void deleteQueueInfoList(void)
73{
74 // Process queue list, cleaning up each entry before deleting
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060075 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -050076 (*ii).second->pQueueCmdBuffers.clear();
77 }
78 queueMap.clear();
79}
80
81// Add new CBInfo for this cb to map container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060082static void addCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070083{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050084 MT_CB_INFO* pInfo = new MT_CB_INFO;
Tony Barbour8205d902015-04-16 15:59:00 -060085 memset(pInfo, 0, (sizeof(MT_CB_INFO) - sizeof(list<VkDeviceMemory>)));
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050086 pInfo->cmdBuffer = cb;
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -060087 cbMap[cb] = pInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -070088}
89
Mark Lobodzinski85a83982015-04-02 08:52:53 -050090// Return ptr to Info in CB map, or NULL if not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060091static MT_CB_INFO* getCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070092{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050093 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050094 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050095 pCBInfo = cbMap[cb];
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -060096 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050097 return pCBInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -070098}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -060099
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500100// Return object info for 'object' or return NULL if no info exists
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600101static MT_OBJ_INFO* getObjectInfo(const VkObject object)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500102{
103 MT_OBJ_INFO* pObjInfo = NULL;
104
105 if (objectMap.find(object) != objectMap.end()) {
106 pObjInfo = objectMap[object];
107 }
108 return pObjInfo;
109}
110
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600111static MT_OBJ_INFO* addObjectInfo(VkObject object, VkStructureType sType, const void *pCreateInfo, const int struct_size, const char *name_prefix)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500112{
113 MT_OBJ_INFO* pInfo = new MT_OBJ_INFO;
114 memset(pInfo, 0, sizeof(MT_OBJ_INFO));
115 memcpy(&pInfo->create_info, pCreateInfo, struct_size);
116 sprintf(pInfo->object_name, "%s_%p", name_prefix, object);
117
118 pInfo->object = object;
119 pInfo->ref_count = 1;
120 pInfo->sType = sType;
121 objectMap[object] = pInfo;
122
123 return pInfo;
124}
125
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500126// Add a fence, creating one if necessary to our list of fences/fenceIds
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600127static uint64_t addFenceInfo(VkFence fence, VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500128{
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500129 // Create fence object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500130 MT_FENCE_INFO* pFenceInfo = new MT_FENCE_INFO;
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500131 MT_QUEUE_INFO* pQueueInfo = queueMap[queue];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500132 uint64_t fenceId = g_currentFenceId++;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500133 memset(pFenceInfo, 0, sizeof(MT_FENCE_INFO));
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500134 // If no fence, create an internal fence to track the submissions
135 if (fence == NULL) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600136 VkFenceCreateInfo fci;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600137 fci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500138 fci.pNext = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139 fci.flags = static_cast<VkFenceCreateFlags>(0);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500140 nextTable.CreateFence(globalDevice, &fci, &pFenceInfo->fence);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 addObjectInfo(pFenceInfo->fence, fci.sType, &fci, sizeof(VkFenceCreateInfo), "internalFence");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600142 pFenceInfo->localFence = VK_TRUE;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500143 } else {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500144 // Validate that fence is in UNSIGNALED state
145 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
146 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -0600147 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500148 char str[1024];
149 sprintf(str, "Fence %p submitted in SIGNALED state. Fences must be reset before being submitted", fence);
Tobin Ehlisf29da382015-04-15 07:46:12 -0600150 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, fence, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinski56945182015-04-09 13:46:09 -0500151 }
152 }
Tobin Ehlisf29da382015-04-15 07:46:12 -0600153 pFenceInfo->localFence = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500154 pFenceInfo->fence = fence;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700155 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500156 pFenceInfo->queue = queue;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500157 fenceMap[fenceId] = pFenceInfo;
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500158 // Update most recently submitted fenceId for Queue
159 pQueueInfo->lastSubmittedId = fenceId;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500160 return fenceId;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500161}
162
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500163// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500164static void deleteFenceInfo(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500165{
166 if (fenceId != 0) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500167 if (fenceMap.find(fenceId) != fenceMap.end()) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600168 map<uint64_t, MT_FENCE_INFO*>::iterator item;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500169 MT_FENCE_INFO* pDelInfo = fenceMap[fenceId];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500170 if (pDelInfo != NULL) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600171 if (pDelInfo->localFence == VK_TRUE) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500172 nextTable.DestroyObject(pDelInfo->fence);
173 }
174 delete pDelInfo;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500175 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600176 item = fenceMap.find(fenceId);
177 fenceMap.erase(item);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500178 }
179 }
180}
181
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500182// Search through list for this fence, deleting all items before it (with lower IDs) and updating lastRetiredId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600183static void updateFenceTracking(VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500184{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500185 MT_FENCE_INFO *pCurFenceInfo = NULL;
186 uint64_t fenceId = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187 VkQueue queue = NULL;
Mike Stroyan62d0bbf2015-04-15 15:37:47 -0600188 bool found = false;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500189
Mike Stroyan62d0bbf2015-04-15 15:37:47 -0600190 for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); !found && ii!=fenceMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500191 if ((*ii).second != NULL) {
192 if (fence == ((*ii).second)->fence) {
193 queue = ((*ii).second)->queue;
194 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
195 pQueueInfo->lastRetiredId = (*ii).first;
Mike Stroyan62d0bbf2015-04-15 15:37:47 -0600196 found = true;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500197 } else {
198 deleteFenceInfo((*ii).first);
199 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500200 // Update fence state in fenceCreateInfo structure
201 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
202 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500203 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -0600204 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500205 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500206 }
207 }
208}
209
210// Utility function that determines if a fenceId has been retired yet
211static bool32_t fenceRetired(uint64_t fenceId)
212{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600213 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter60edc352015-04-15 14:10:51 -0600214 if (fenceMap.find(fenceId) != fenceMap.end()) {
215 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500216 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
Mark Lobodzinski91a1ec52015-04-02 08:52:53 -0500217 if (fenceId <= pQueueInfo->lastRetiredId)
218 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219 result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500220 }
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500221 } else { // If not in list, fence has been retired and deleted
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 result = VK_TRUE;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500223 }
224 return result;
225}
226
227// Return the fence associated with a fenceId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600228static VkFence getFenceFromId(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500229{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600230 VkFence fence = NULL;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500231 if (fenceId != 0) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500232 // Search for an item with this fenceId
233 if (fenceMap.find(fenceId) != fenceMap.end()) {
234 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
235 if (pFenceInfo != NULL) {
236 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
237 if (fenceId > pQueueInfo->lastRetiredId) {
238 fence = pFenceInfo->fence;
239 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500240 }
241 }
242 }
243 return fence;
244}
245
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500246// Helper routine that updates the fence list for a specific queue to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600247static void retireQueueFences(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500248{
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600249 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
250 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
251 // Set Queue's lastRetired to lastSubmitted, free items in queue's fence list
252 map<uint64_t, MT_FENCE_INFO*>::iterator it = fenceMap.begin();
253 map<uint64_t, MT_FENCE_INFO*>::iterator temp;
254 while (it != fenceMap.end()) {
Tobin Ehlisbfc55032015-04-15 14:25:02 -0600255 if ((((*it).second) != NULL) && ((*it).second)->queue == queue) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600256 temp = it;
257 ++temp;
258 deleteFenceInfo((*it).first);
259 it = temp;
260 } else {
261 ++it;
262 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500263 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700264}
265
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500266// Helper routine that updates fence list for all queues to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600267static void retireDeviceFences(VkDevice device)
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500268{
269 // Process each queue for device
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600270 // TODO: Add multiple device support
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600271 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500272 retireQueueFences((*ii).first);
273 }
274}
275
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500276// Returns True if a memory reference is present in a Queue's memory reference list
277// Queue is validated by caller
278static bool32_t checkMemRef(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600279 VkQueue queue,
Tony Barbour8205d902015-04-16 15:59:00 -0600280 VkDeviceMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500281{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600282 bool32_t result = VK_FALSE;
Tony Barbour8205d902015-04-16 15:59:00 -0600283 list<VkDeviceMemory>::iterator it;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500284 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
285 for (it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
286 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600287 result = VK_TRUE;
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500288 break;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500289 }
290 }
291 return result;
292}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500293
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500294static bool32_t validateQueueMemRefs(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600295 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500296 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600297 const VkCmdBuffer *pCmdBuffers)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500298{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600299 bool32_t result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500300
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500301 // Verify Queue
302 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
303 if (pQueueInfo == NULL) {
304 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600305 sprintf(str, "Unknown Queue %p specified in vkQueueSubmit", queue);
306 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500307 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500308 else {
309 // Iterate through all CBs in pCmdBuffers
310 for (uint32_t i = 0; i < cmdBufferCount; i++) {
311 MT_CB_INFO* pCBInfo = getCBInfo(pCmdBuffers[i]);
312 if (!pCBInfo) {
313 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600314 sprintf(str, "Unable to find info for CB %p in order to check memory references in vkQueueSubmit for queue %p", (void*)pCmdBuffers[i], queue);
315 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_CB, "MEM", str);
316 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500317 } else {
318 // Validate that all actual references are accounted for in pMemRefs
Tony Barbour8205d902015-04-16 15:59:00 -0600319 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500320 // Search for each memref in queues memreflist.
321 if (checkMemRef(queue, *it)) {
322 char str[1024];
323 sprintf(str, "Found Mem Obj %p binding to CB %p for queue %p", (*it), pCmdBuffers[i], queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600324 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500325 }
326 else {
327 char str[1024];
328 sprintf(str, "Queue %p Memory reference list for Command Buffer %p is missing ref to mem obj %p", queue, pCmdBuffers[i], (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600329 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
330 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500331 }
332 }
333 }
334 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600335 if (result == VK_TRUE) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500336 char str[1024];
337 sprintf(str, "Verified all memory dependencies for Queue %p are included in pMemRefs list", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600338 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500339 // TODO : Could report mem refs in pMemRefs that AREN'T in mem list, that would be primarily informational
340 // Currently just noting that there is a difference
341 }
342 }
343
344 return result;
345}
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600346
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500347// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700348// Calls to this function should be wrapped in mutex
Tony Barbour8205d902015-04-16 15:59:00 -0600349static MT_MEM_OBJ_INFO* getMemObjInfo(const VkDeviceMemory mem)
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700350{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500351 MT_MEM_OBJ_INFO* pMemObjInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500352
353 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500354 pMemObjInfo = memObjMap[mem];
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600355 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500356 return pMemObjInfo;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700357}
358
Tony Barbour8205d902015-04-16 15:59:00 -0600359static void addMemObjInfo(const VkDeviceMemory mem, const VkMemoryAllocInfo* pAllocInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700360{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500361 MT_MEM_OBJ_INFO* pInfo = new MT_MEM_OBJ_INFO;
362 pInfo->refCount = 0;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600363 memset(&pInfo->allocInfo, 0, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500364
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365 if (pAllocInfo) { // MEM alloc created by vkWsiX11CreatePresentableImage() doesn't have alloc info struct
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600366 memcpy(&pInfo->allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500367 // TODO: Update for real hardware, actually process allocation info structures
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500368 pInfo->allocInfo.pNext = NULL;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700369 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500370 pInfo->mem = mem;
371 memObjMap[mem] = pInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700372}
373
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500374// Find CB Info and add mem binding to list container
375// Find Mem Obj Info and add CB binding to list container
Tony Barbour8205d902015-04-16 15:59:00 -0600376static bool32_t updateCBBinding(const VkCmdBuffer cb, const VkDeviceMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700377{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 bool32_t result = VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700379 // First update CB binding in MemObj mini CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500380 MT_MEM_OBJ_INFO* pMemInfo = getMemObjInfo(mem);
381 if (!pMemInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700382 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500383 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600384 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
385 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600386 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500387 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600389 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500390 if ((*it) == cb) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600391 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500392 break;
393 }
394 }
395 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600396 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500397 pMemInfo->pCmdBufferBindings.push_front(cb);
398 pMemInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500399 }
400
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500401 // Now update CBInfo's Mem binding list
402 MT_CB_INFO* pCBInfo = getCBInfo(cb);
403 if (!pCBInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500404 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500405 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
407 result = VK_FALSE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500408 } else {
409 // Search for memory object in cmd buffer's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600410 bool32_t found = VK_FALSE;
Tony Barbour8205d902015-04-16 15:59:00 -0600411 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500412 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600413 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500414 break;
415 }
416 }
417 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500419 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600420 }
421 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700422 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600423 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700424}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600425
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700426// Clear the CB Binding for mem
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700427// Calls to this function should be wrapped in mutex
Tony Barbour8205d902015-04-16 15:59:00 -0600428static void clearCBBinding(const VkCmdBuffer cb, const VkDeviceMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700429{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500430 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500431 // TODO : Having this check is not ideal, really if memInfo was deleted,
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700432 // its CB bindings should be cleared and then freeCBBindings wouldn't call
433 // us here with stale mem objs
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500434 if (pInfo) {
435 pInfo->pCmdBufferBindings.remove(cb);
436 pInfo->refCount--;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700437 }
438}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600439
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700440// Free bindings related to CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600441static bool32_t freeCBBindings(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700442{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600443 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500444 MT_CB_INFO* pCBInfo = getCBInfo(cb);
445 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700446 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500447 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600448 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
449 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600450 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500451 if (!fenceRetired(pCBInfo->fenceId)) {
452 deleteFenceInfo(pCBInfo->fenceId);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600453 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500454
Tony Barbour8205d902015-04-16 15:59:00 -0600455 for (list<VkDeviceMemory>::iterator it=pCBInfo->pMemObjList.begin(); it!=pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500456 clearCBBinding(cb, (*it));
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600457 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500458 pCBInfo->pMemObjList.clear();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700459 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600460 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700461}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600462
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500463// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500464// and also clear mem references to CB
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700465// TODO : When should this be called? There's no Destroy of CBs that I see
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466static bool32_t deleteCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700467{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600468 bool32_t result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600469 result = freeCBBindings(cb);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500470 // Delete the CBInfo info
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600471 if (result == VK_TRUE) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500472 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500473 MT_CB_INFO* pDelInfo = cbMap[cb];
474 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500475 cbMap.erase(cb);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600476 }
Ian Elliott81ac44c2015-01-13 17:52:38 -0700477 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600478 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700479}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600480
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700481// Delete the entire CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500482static bool32_t deleteCBInfoList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700483{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600484 bool32_t result = VK_TRUE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600485 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500486 freeCBBindings((*ii).first);
487 delete (*ii).second;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700488 }
489 return result;
490}
491
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500492// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500493static void reportMemReferencesAndCleanUp(MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700494{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500495 uint32_t cmdBufRefCount = pMemObjInfo->pCmdBufferBindings.size();
496 uint32_t objRefCount = pMemObjInfo->pObjBindings.size();
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500497
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500498 if ((pMemObjInfo->pCmdBufferBindings.size() + pMemObjInfo->pObjBindings.size()) != 0) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700499 char str[1024];
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500500 sprintf(str, "Attempting to free memory object %p which still contains %d references", pMemObjInfo->mem, (cmdBufRefCount + objRefCount));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600501 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700502 }
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500503
504 if (cmdBufRefCount > 0) {
505 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
506 char str[1024];
507 sprintf(str, "Command Buffer %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
508 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
509 }
510 // Clear the list of hanging references
511 pMemObjInfo->pCmdBufferBindings.clear();
512 }
513
514 if (objRefCount > 0) {
515 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
516 char str[1024];
517 sprintf(str, "VK Object %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
518 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
519 }
520 // Clear the list of hanging references
521 pMemObjInfo->pObjBindings.clear();
522 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700523}
524
Tony Barbour8205d902015-04-16 15:59:00 -0600525static void deleteMemObjInfo(VkDeviceMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700526{
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500527 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500528 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
529 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500530 memObjMap.erase(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700531 }
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500532 else {
533 char str[1024];
534 sprintf(str, "Request to delete memory object %p not present in memory Object Map", mem);
535 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
536 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700537}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500538
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700539// Check if fence for given CB is completed
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600540static bool32_t checkCBCompleted(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700541{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600542 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500543 MT_CB_INFO* pCBInfo = getCBInfo(cb);
544 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700545 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500546 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600547 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
548 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600549 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500550 if (!fenceRetired(pCBInfo->fenceId)) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600551 char str[1024];
552 sprintf(str, "FenceId %" PRIx64", fence %p for CB %p has not been checked for completion", pCBInfo->fenceId, getFenceFromId(pCBInfo->fenceId), cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600553 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_NONE, "MEM", str);
554 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600555 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700556 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600557 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700558}
559
Tony Barbour8205d902015-04-16 15:59:00 -0600560static bool32_t freeMemObjInfo(VkDeviceMemory mem, bool internal)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700561{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600562 bool32_t result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500563 // Parse global list to find info w/ mem
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500564 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
565 if (!pInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700566 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500567 sprintf(str, "Couldn't find mem info object for %p\n Was %p never allocated or previously freed?", (void*)mem, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600568 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
569 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600570 } else {
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -0600571 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600572 char str[1024];
573 sprintf(str, "Attempting to free memory associated with a Presentable Image, %p, this should not be explicitly freed\n", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600574 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
575 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600576 } else {
577 // Clear any CB bindings for completed CBs
578 // TODO : Is there a better place to do this?
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500579
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600580 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
581 list<VkCmdBuffer>::iterator temp;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500582 while (it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600583 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500584 temp = it;
585 ++temp;
586 freeCBBindings(*it);
587 it = temp;
588 } else {
589 ++it;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600590 }
591 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500592
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600593 // Now verify that no references to this mem obj remain
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500594 if (0 != pInfo->refCount) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500595 // If references remain, report the error and can search CB list to find references
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600596 char str[1024];
597 sprintf(str, "Freeing mem obj %p while it still has references", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600598 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM", str);
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500599 reportMemReferencesAndCleanUp(pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600600 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600601 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600602 // Delete mem obj info
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500603 deleteMemObjInfo(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700604 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700605 }
606 return result;
607}
608
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700609// Remove object binding performs 3 tasks:
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500610// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
611// 2. Decrement refCount for MemObjInfo
612// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600613static bool32_t clearObjectBinding(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700614{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600615 bool32_t result = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500616 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
617 if (!pObjInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700618 char str[1024];
Mark Lobodzinski15427102015-02-18 16:38:17 -0600619 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600620 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600621 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500622 if (!pObjInfo->pMemObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600623 char str[1024];
624 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600626 } else {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500627 // 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
628 // and set the objects memory binding pointer to NULL.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600629 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500630 if ((*it) == object) {
631 pObjInfo->pMemObjInfo->refCount--;
632 pObjInfo->pMemObjInfo->pObjBindings.erase(it);
633 pObjInfo->pMemObjInfo = NULL;
634 result = VK_TRUE;
635 break;
636 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600637 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600638 if (result == VK_FALSE) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600639 char str[1024];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500640 sprintf(str, "While trying to clear mem binding for object %p, unable to find that object referenced by mem obj %p",
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500641 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600642 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600643 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700644 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700645 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600646 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700647}
648
649// For NULL mem case, clear any previous binding Else...
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500650// Make sure given object is in global object map
Tobin Ehlis62086412014-11-19 16:19:28 -0700651// IF a previous binding existed, clear it
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500652// Add reference from objectInfo to memoryInfo
653// Add reference off of objInfo
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600654// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Tony Barbour8205d902015-04-16 15:59:00 -0600655static bool32_t updateObjectBinding(VkObject object, VkDeviceMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700656{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600657 bool32_t result = VK_FALSE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700658 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600659 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700660 clearObjectBinding(object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600661 result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600662 } else {
663 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500664 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
665 if (!pObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600666 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600667 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
668 return VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600669 }
670 // non-null case so should have real mem obj
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500671 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
672 if (!pInfo) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500673 sprintf(str, "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600674 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600675 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500676 // Search for object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600677 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600678 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500679 if ((*it) == object) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600680 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500681 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600682 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600683 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500684 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500686 pInfo->pObjBindings.push_front(object);
687 pInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500688 }
689
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500690 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500691 clearObjectBinding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500692 sprintf(str, "Updating memory binding for object %p from mem obj %p to %p", object, pObjInfo->pMemObjInfo->mem, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600693 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500694 }
695 // For image objects, make sure default memory state is correctly set
696 // TODO : What's the best/correct way to handle this?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600697 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
698 if (pObjInfo->create_info.image_create_info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500699 // TODO:: More memory state transition stuff.
700 }
701 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500702 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700703 }
704 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600705 return VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700706}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600707
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700708// Print details of global Obj tracking list
709static void printObjList()
710{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500711 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500712 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500713 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600714 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600715 for (map<VkObject, MT_OBJ_INFO*>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500716 pInfo = (*ii).second;
717 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600718 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700719 }
720}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600721
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700722// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Tony Barbour8205d902015-04-16 15:59:00 -0600723static VkDeviceMemory getMemBindingFromObject(const VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700724{
Tony Barbour8205d902015-04-16 15:59:00 -0600725 VkDeviceMemory mem = NULL;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500726 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
727 if (pObjInfo) {
728 if (pObjInfo->pMemObjInfo) {
729 mem = pObjInfo->pMemObjInfo->mem;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700730 }
731 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700732 char str[1024];
733 sprintf(str, "Trying to get mem binding for object %p but object has no mem binding", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600734 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700735 printObjList();
736 }
737 }
738 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700739 char str[1024];
740 sprintf(str, "Trying to get mem binding for object %p but no such object in global list", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600741 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700742 printObjList();
743 }
744 return mem;
745}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500746
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500747// Print details of MemObjInfo list
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700748static void printMemList()
749{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500750 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehlis62086412014-11-19 16:19:28 -0700751 // Just printing each msg individually for now, may want to package these into single large print
752 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500753 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600754 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500755
Tony Barbour8205d902015-04-16 15:59:00 -0600756 for (map<VkDeviceMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500757 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500758
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500759 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600760 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500761 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600762 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500763 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600764 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500765 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600766 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500767 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600768 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500769 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600770 sprintf(str, " Mem Alloc info is NULL (alloc done by vkWsiX11CreatePresentableImage())");
771 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500772 }
773
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600774 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
775 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600776 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600777 sprintf(str, " VK OBJECT %p", (*it));
778 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500779 }
780
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600781 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
782 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600783 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600784 sprintf(str, " VK CB %p", (*it));
785 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700786 }
787 }
788}
789
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500790static void printCBList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700791{
Tobin Ehlis62086412014-11-19 16:19:28 -0700792 char str[1024] = {0};
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500793 MT_CB_INFO* pCBInfo = NULL;
794 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600795 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500796
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600797 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500798 pCBInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500799
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500800 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
801 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
802 (void*)getFenceFromId(pCBInfo->fenceId));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600803 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500804
Tony Barbour8205d902015-04-16 15:59:00 -0600805 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500806 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600807 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700808 }
809 }
810}
811
Mark Lobodzinski15427102015-02-18 16:38:17 -0600812static void initMemTracker(void)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700813{
Jon Ashburnf57ea372014-12-22 13:24:15 -0700814 const char *strOpt;
815 // initialize MemTracker options
Ian Elliott7d0b5d22015-03-06 13:50:05 -0700816 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportingLevel);
817 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlis5b7acaa2015-01-08 14:26:53 -0700818
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600819 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburnf57ea372014-12-22 13:24:15 -0700820 {
821 strOpt = getLayerOption("MemTrackerLogFilename");
822 if (strOpt)
823 {
824 g_logFile = fopen(strOpt, "w");
Jon Ashburnf57ea372014-12-22 13:24:15 -0700825 }
826 if (g_logFile == NULL)
827 g_logFile = stdout;
828 }
829
830 // initialize Layer dispatch table
831 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600832 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700833 fpNextGPA = pCurObj->pGPA;
834 assert(fpNextGPA);
835
Tony Barbour8205d902015-04-16 15:59:00 -0600836 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800837
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600838 if (!globalLockInitialized)
839 {
840 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600841 // suggestion is to call this during vkCreateInstance(), and then we
842 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600843 // that the layer have per-instance locks. We need to come back and
844 // address this soon.
845 loader_platform_thread_create_mutex(&globalLock);
846 globalLockInitialized = 1;
847 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700848}
849
Tony Barbour8205d902015-04-16 15:59:00 -0600850VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700851{
Jon Ashburn630e44f2015-04-08 21:33:34 -0600852 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700853 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600854 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700855 // Save off device in case we need it to create Fences
856 globalDevice = *pDevice;
857 return result;
858}
859
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600860VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700861{
Tobin Ehlis62086412014-11-19 16:19:28 -0700862 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600863 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600864 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600865 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700866 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500867 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700868 printObjList();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 if (VK_FALSE == deleteCBInfoList()) {
870 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
871 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -0700872 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700873 // Report any memory leaks
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500874 MT_MEM_OBJ_INFO* pInfo = NULL;
Tony Barbour8205d902015-04-16 15:59:00 -0600875 for (map<VkDeviceMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500876 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500877
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500878 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600879 sprintf(str, "Mem Object %p has not been freed. You should clean up this memory by calling vkFreeMemory(%p) prior to vkDestroyDevice().",
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500880 pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600881 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600882 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700883 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500884
885 // Queues persist until device is destroyed
886 deleteQueueInfoList();
887
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600888 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600889 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700890 return result;
891}
892
Jon Ashburneb2728b2015-04-10 14:33:07 -0600893struct extProps {
894 uint32_t version;
895 const char * const name;
896};
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600897#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Jon Ashburneb2728b2015-04-10 14:33:07 -0600898static const struct extProps mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
899 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600900 0x10, "MemTracker",
901 0x10, "Validation"
Jon Ashburneb2728b2015-04-10 14:33:07 -0600902};
903
904VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
905 VkExtensionInfoType infoType,
906 uint32_t extensionIndex,
907 size_t* pDataSize,
908 void* pData)
909{
910 VkResult result;
911
912 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
913 VkExtensionProperties *ext_props;
914 uint32_t *count;
915
916 if (pDataSize == NULL)
917 return VK_ERROR_INVALID_POINTER;
918
919 switch (infoType) {
920 case VK_EXTENSION_INFO_TYPE_COUNT:
921 *pDataSize = sizeof(uint32_t);
922 if (pData == NULL)
923 return VK_SUCCESS;
924 count = (uint32_t *) pData;
925 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
926 break;
927 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
928 *pDataSize = sizeof(VkExtensionProperties);
929 if (pData == NULL)
930 return VK_SUCCESS;
931 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE)
932 return VK_ERROR_INVALID_VALUE;
933 ext_props = (VkExtensionProperties *) pData;
934 ext_props->version = mtExts[extensionIndex].version;
935 strncpy(ext_props->extName, mtExts[extensionIndex].name,
936 VK_MAX_EXTENSION_NAME);
937 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
938 break;
939 default:
940 return VK_ERROR_INVALID_VALUE;
941 };
942
943 return VK_SUCCESS;
944}
945
Tony Barbour8205d902015-04-16 15:59:00 -0600946VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalDevice gpu, size_t maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500947 size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700948{
Jon Ashburn451c16f2014-11-25 11:08:42 -0700949 if (gpu != NULL)
950 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600951 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700952 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600953 VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500954 maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn451c16f2014-11-25 11:08:42 -0700955 return result;
956 } else
957 {
958 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600959 return VK_ERROR_INVALID_POINTER;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700960 // This layer compatible with all GPUs
961 *pOutLayerCount = 1;
Chia-I Wua837c522014-12-16 10:47:33 +0800962 strncpy((char *) pOutLayers[0], "MemTracker", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600963 return VK_SUCCESS;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700964 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700965}
966
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600967VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue)
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500968{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600969 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600970 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500971 loader_platform_thread_lock_mutex(&globalLock);
972 addQueueInfo(*pQueue);
973 loader_platform_thread_unlock_mutex(&globalLock);
974 }
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500975 return result;
976}
977
Tony Barbour8205d902015-04-16 15:59:00 -0600978VK_LAYER_EXPORT VkResult VKAPI vkQueueAddMemReferences(VkQueue queue, uint32_t count, const VkDeviceMemory* pMems)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500979{
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -0600980 VkResult result = nextTable.QueueAddMemReferences(queue, count, pMems);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600981 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500982 loader_platform_thread_lock_mutex(&globalLock);
983
984 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
985 if (pQueueInfo == NULL) {
986 char str[1024];
987 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600988 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -0600989 } else {
990 for (int i = 0; i < count; i++) {
991 if (checkMemRef(queue, pMems[i]) == VK_TRUE) {
992 // Alread in list, just warn
993 char str[1024];
994 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);
995 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pMems[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
996 } else {
997 // Add to queue's memory reference list
998 pQueueInfo->pMemRefList.push_front(pMems[i]);
999 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001000 }
1001 }
1002 loader_platform_thread_unlock_mutex(&globalLock);
1003 }
1004 return result;
1005}
1006
Tony Barbour8205d902015-04-16 15:59:00 -06001007VK_LAYER_EXPORT VkResult VKAPI vkQueueRemoveMemReferences(VkQueue queue, uint32_t count, const VkDeviceMemory* pMems)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001008{
1009 // TODO : Decrement ref count for this memory reference on this queue. Remove if ref count is zero.
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06001010 VkResult result = nextTable.QueueRemoveMemReferences(queue, count, pMems);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001011 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001012 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001013
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001014 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
1015 if (pQueueInfo == NULL) {
1016 char str[1024];
1017 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001018 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06001019 } else {
1020 for (int i = 0; i < count; i++) {
Tony Barbour8205d902015-04-16 15:59:00 -06001021 for (list<VkDeviceMemory>::iterator it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06001022 if ((*it) == pMems[i]) {
1023 it = pQueueInfo->pMemRefList.erase(it);
1024 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001025 }
1026 }
1027 }
1028 loader_platform_thread_unlock_mutex(&globalLock);
1029 }
1030 return result;
1031}
1032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001033VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1034 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001035 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001036 const VkCmdBuffer *pCmdBuffers,
1037 VkFence fence)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001038{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001039 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001040 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001041 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001042 uint64_t fenceId = addFenceInfo(fence, queue);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001043
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001044 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001045 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001046 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001047 pCBInfo = getCBInfo(pCmdBuffers[i]);
1048 pCBInfo->fenceId = fenceId;
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001049 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001050
Mark Lobodzinski2c01d182015-04-17 11:44:25 -05001051 validateQueueMemRefs(queue, cmdBufferCount, pCmdBuffers);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001052
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001053 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001054 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, getFenceFromId(fenceId));
Courtney Goeltzenleuchtercfedf362015-04-02 13:39:07 -06001055 return result;
1056}
1057
Tony Barbour8205d902015-04-16 15:59:00 -06001058VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(VkDevice device, const VkMemoryAllocInfo* pAllocInfo, VkDeviceMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001059{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001060 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001061 // TODO : Track allocations and overall size here
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001062 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001063 addMemObjInfo(*pMem, pAllocInfo);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001064 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001065 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001066 return result;
1067}
1068
Tony Barbour8205d902015-04-16 15:59:00 -06001069VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(VkDeviceMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001070{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001071 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisa747e682014-11-25 14:47:20 -07001072 * freeing a memory object, an application must ensure the memory object is unbound from
1073 * all API objects referencing it and that it is not referenced by any queued command buffers
1074 */
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001075 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001076 if (VK_FALSE == freeMemObjInfo(mem, false)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001077 char str[1024];
1078 sprintf(str, "Issue while freeing mem obj %p", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001079 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREE_MEM_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001080 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001081 printMemList();
1082 printObjList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001083 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001084 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001085 VkResult result = nextTable.FreeMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001086 return result;
1087}
1088
Tony Barbour8205d902015-04-16 15:59:00 -06001089VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(VkDeviceMemory mem, VkMemoryPriority priority)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001090{
1091 // TODO : Update tracking for this alloc
1092 // Make sure memory is not pinned, which can't have priority set
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001093 VkResult result = nextTable.SetMemoryPriority(mem, priority);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001094 return result;
1095}
1096
Tony Barbour3e3420a2015-04-16 19:09:28 -06001097VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, VkFlags flags, void** ppData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001098{
1099 // TODO : Track when memory is mapped
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001100 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001101 MT_MEM_OBJ_INFO *pMemObj = getMemObjInfo(mem);
Tony Barbour8205d902015-04-16 15:59:00 -06001102 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001103 char str[1024];
Tony Barbour8205d902015-04-16 15:59:00 -06001104 sprintf(str, "Mapping Memory (%p) without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001105 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001106 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001107 loader_platform_thread_unlock_mutex(&globalLock);
Tony Barbour3e3420a2015-04-16 19:09:28 -06001108 VkResult result = nextTable.MapMemory(mem, offset, size, flags, ppData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001109 return result;
1110}
1111
Tony Barbour8205d902015-04-16 15:59:00 -06001112VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(VkDeviceMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001113{
1114 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1115 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001116 VkResult result = nextTable.UnmapMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001117 return result;
1118}
1119
Tony Barbour8205d902015-04-16 15:59:00 -06001120VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSysMem, size_t memSize, VkDeviceMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001121{
1122 // TODO : Track this
1123 // Verify that memory is actually pinnable
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001124 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001125 return result;
1126}
1127
Tony Barbour8205d902015-04-16 15:59:00 -06001128VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkDeviceMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001129{
1130 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001131 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001132 return result;
1133}
1134
Tony Barbour8205d902015-04-16 15:59:00 -06001135VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkDeviceMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001136{
1137 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001138 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001139 return result;
1140}
1141
Tony Barbour8205d902015-04-16 15:59:00 -06001142VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, VkDeviceMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001143{
1144 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001146 return result;
1147}
1148
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001149VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001150{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001151 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001152
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001153 // First check if this is a CmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001154 if (NULL != getCBInfo((VkCmdBuffer)object)) {
1155 deleteCBInfo((VkCmdBuffer)object);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001156 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001157
1158 if (objectMap.find(object) != objectMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001159 MT_OBJ_INFO* pDelInfo = objectMap[object];
1160 if (pDelInfo->pMemObjInfo) {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001161 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001162 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Tony Barbour8205d902015-04-16 15:59:00 -06001163 VkDeviceMemory memToFree = pDelInfo->pMemObjInfo->mem;
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001164 clearObjectBinding(object);
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -06001165 freeMemObjInfo(memToFree, true);
1166 }
1167 else {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001168 char str[1024];
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05001169 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001170 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001171 // From the spec : If an object has previous memory binding, it is required to unbind memory from an API object before it is destroyed.
1172 clearObjectBinding(object);
1173 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001174 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001175 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001176 objectMap.erase(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001177 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001178
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001179 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001180 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001181 return result;
1182}
1183
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001184VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(VkBaseObject object, VkObjectInfoType infoType, size_t* pDataSize, void* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001185{
1186 // TODO : What to track here?
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05001187 // Could potentially save returned mem requirements and validate values passed into QueueBindObjectMemory for this object
Tobin Ehlis62086412014-11-19 16:19:28 -07001188 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues, command buffers, shaders and memory objects.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001189 VkResult result = nextTable.GetObjectInfo(object, infoType, pDataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001190 return result;
1191}
1192
Tony Barbour8205d902015-04-16 15:59:00 -06001193VK_LAYER_EXPORT VkResult VKAPI vkQueueBindObjectMemory(VkQueue queue, VkObject object, uint32_t allocationIdx, VkDeviceMemory mem, VkDeviceSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001194{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05001195 VkResult result = nextTable.QueueBindObjectMemory(queue, object, allocationIdx, mem, offset);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001196 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001197 // Track objects tied to memory
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001198 if (VK_FALSE == updateObjectBinding(object, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001199 char str[1024];
1200 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001201 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001202 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001203 printObjList();
1204 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001205 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001206 return result;
1207}
1208
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001209VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001210{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001211 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001212 if (VK_SUCCESS == result) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001213 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001214 addObjectInfo(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001215 loader_platform_thread_unlock_mutex(&globalLock);
1216 }
1217 return result;
1218}
1219
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220VK_LAYER_EXPORT VkResult VKAPI vkResetFences(VkDevice device, uint32_t fenceCount, VkFence* pFences)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001221{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001222 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001223 if (VK_SUCCESS == result) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001224 loader_platform_thread_lock_mutex(&globalLock);
1225 // Reset fence state in fenceCreateInfo structure
1226 for (uint32_t i = 0; i < fenceCount; i++) {
1227 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1228 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001229 // Validate fences in SIGNALED state
Tobin Ehlisf29da382015-04-15 07:46:12 -06001230 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001231 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001232 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001233 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
1234 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinski56945182015-04-09 13:46:09 -05001235 }
1236 else {
1237 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -06001238 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinski56945182015-04-09 13:46:09 -05001239 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001240 }
1241 }
1242 loader_platform_thread_unlock_mutex(&globalLock);
1243 }
1244 return result;
1245}
1246
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001247VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(VkFence fence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001248{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001249 VkResult result = nextTable.GetFenceStatus(fence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001250 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001251 loader_platform_thread_lock_mutex(&globalLock);
1252 updateFenceTracking(fence);
1253 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001254 }
1255 return result;
1256}
1257
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001258VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, bool32_t waitAll, uint64_t timeout)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001259{
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001260 // Verify fence status of submitted fences
1261 for(uint32_t i = 0; i < fenceCount; i++) {
1262 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1263 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -06001264 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001265 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001266 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001267 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001268 }
1269 }
1270 }
1271
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001272 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001273 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001274
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001275 if (VK_SUCCESS == result) {
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001276 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001277 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001278 updateFenceTracking(pFences[i]);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001279 }
1280 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001281 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001282 loader_platform_thread_unlock_mutex(&globalLock);
1283 return result;
1284}
1285
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001286VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001287{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001288 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001289 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001290 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001291 retireQueueFences(queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001292 loader_platform_thread_unlock_mutex(&globalLock);
1293 }
1294 return result;
1295}
1296
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001297VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(VkDevice device)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001298{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001299 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001300 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001301 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001302 retireDeviceFences(device);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001303 loader_platform_thread_unlock_mutex(&globalLock);
1304 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001305 return result;
1306}
1307
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001308VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001309{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001310 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001311 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001312 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001313 addObjectInfo(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001314 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001315 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001316 return result;
1317}
1318
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001319VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001320{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001321 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001322 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001323 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001324 addObjectInfo(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001325 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001326 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001327 return result;
1328}
1329
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001330VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001331{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001332 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001333 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001334 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001335 addObjectInfo(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001336 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001337 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001338 return result;
1339}
1340
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001341VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001342{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001343 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001344 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001345 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001346 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001347 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001348 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001349 return result;
1350}
1351
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001352VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001353{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001354 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001355 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001356 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001357 addObjectInfo(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001358 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001359 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001360 return result;
1361}
1362
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001363VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001364{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001365 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001366 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001367 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001368 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001369 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001370 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001371 return result;
1372}
1373
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001374VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(VkDevice device, const VkColorAttachmentViewCreateInfo* pCreateInfo,
1375 VkColorAttachmentView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001376{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001377 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001378 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001379 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001380 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001381 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001382 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001383 return result;
1384}
1385
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001386VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001387{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001388 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001389 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001390 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001391 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001392 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001393 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001394 return result;
1395}
1396
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001397VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001398{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001399 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001400 return result;
1401}
1402
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001403VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001404{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001405 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001406 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001407 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001408 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001409 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001410 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001411 return result;
1412}
1413
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001414VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1415 VkDevice device,
1416 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1417 VkPipeline basePipeline,
1418 VkPipeline* pPipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001419{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001420 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001421 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001422 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001423 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001424 loader_platform_thread_unlock_mutex(&globalLock);
1425 }
1426 return result;
1427}
1428
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001429VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001430{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001431 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001432 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001433 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001434 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001435 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001436 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001437 return result;
1438}
1439
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001440VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001441{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001442 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001443 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001444 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001445 addObjectInfo(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001446 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001447 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001448 return result;
1449}
1450
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001451VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001452 VkDynamicVpState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001453{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001454 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001455 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001456 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001457 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001458 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001459 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001460 return result;
1461}
1462
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001463VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001464 VkDynamicRsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001465{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001466 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001467 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001468 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001469 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001470 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001471 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001472 return result;
1473}
1474
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001475VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001476 VkDynamicCbState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001477{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001478 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001479 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001480 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001481 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001482 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001483 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001484 return result;
1485}
1486
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001487VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001488 VkDynamicDsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001489{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001490 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001491 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001492 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001493 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001494 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001495 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001496 return result;
1497}
1498
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001499VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001500{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001501 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001502 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001503 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001504 if (*pCmdBuffer)
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001505 addCBInfo(*pCmdBuffer);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001506 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001507 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001508 return result;
1509}
1510
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001511VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001512{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001513 // This implicitly resets the Cmd Buffer so make sure any fence is done and then clear memory references
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001514 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1515 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001516 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001517 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001518 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001519 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. You must check CB flag before this call.", cmdBuffer);
1520 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001521 }
1522 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001523 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001524 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001525 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001526 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001527 return result;
1528}
1529
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001530VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001531{
1532 // TODO : Anything to do here?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001533 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001534 return result;
1535}
1536
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001537VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001538{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001539 // Verify that CB is complete (not in-flight)
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001540 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1541 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001542 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001543 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001544 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001545 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before calling vkResetCommandBuffer().", cmdBuffer);
1546 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001547 }
1548 }
1549 // Clear memory references as this point.
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001550 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001551 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001552 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001553 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001554 return result;
1555}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001556// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001557// need to account for that mem now having binding to given cmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001558VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001559{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001560#if 0
1561 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1562 if (getPipeline(pipeline)) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001563 MT_CB_INFO *pCBInfo = getCBInfo(cmdBuffer);
1564 if (pCBInfo) {
1565 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001566 } else {
1567 char str[1024];
1568 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001569 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, (char *) "DS", (char *) str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001570 }
1571 }
1572 else {
1573 char str[1024];
1574 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001575 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, MEMTRACK_INVALID_OBJECT, (char *) "DS", (char *) str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001576 }
1577#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001578 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1579}
1580
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001581VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001582{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001583 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001584 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001585 MT_CB_INFO *pCmdBuf = getCBInfo(cmdBuffer);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001586 if (!pCmdBuf) {
1587 char str[1024];
1588 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001589 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001590 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001591 pObjInfo = getObjectInfo(state);
1592 if (!pObjInfo) {
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001593 char str[1024];
1594 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001595 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001596 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001597 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001598 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001599 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001600}
1601
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001602VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001603 VkCmdBuffer cmdBuffer,
1604 VkPipelineBindPoint pipelineBindPoint,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06001605 uint32_t firstSet,
1606 uint32_t setCount,
1607 const VkDescriptorSet* pDescriptorSets,
1608 uint32_t dynamicOffsetCount,
1609 const uint32_t* pDynamicOffsets)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001610{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001611 // TODO : Somewhere need to verify that all textures referenced by shaders in DS are in some type of *SHADER_READ* state
Cody Northrop1a01b1d2015-04-16 13:41:56 -06001612 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001613}
1614
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06001615VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
1616 VkCmdBuffer cmdBuffer,
1617 uint32_t startBinding,
1618 uint32_t bindingCount,
1619 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06001620 const VkDeviceSize* pOffsets)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001621{
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06001622 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wufb5062e2015-01-05 13:42:56 +08001623}
1624
Tony Barbour8205d902015-04-16 15:59:00 -06001625VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001626{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001627 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001628}
1629
Tony Barbour8205d902015-04-16 15:59:00 -06001630VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001631{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001632 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001633 VkDeviceMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001634 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001635 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001636 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1637 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001638 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001639 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001640 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001641}
1642
Tony Barbour8205d902015-04-16 15:59:00 -06001643VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001644{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001645 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001646 VkDeviceMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001647 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001648 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001649 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1650 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001651 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001652 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001653 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001654}
1655
Tony Barbour8205d902015-04-16 15:59:00 -06001656VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkDeviceSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001657{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001658 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001659 VkDeviceMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001660 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001661 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001662 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1663 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001664 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001665 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001666 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001667}
1668
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001669VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer,
1670 uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001671{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001672 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001673 VkDeviceMemory mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001674 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001675 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001676 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1677 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001678 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001679 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001681 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001682 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1683 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001684 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001685 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001686 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001687}
1688
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001689VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
1690 VkImage srcImage, VkImageLayout srcImageLayout,
1691 VkImage destImage, VkImageLayout destImageLayout,
1692 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001693{
1694 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001695 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001696}
1697
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001698VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
1699 VkImage srcImage, VkImageLayout srcImageLayout,
1700 VkImage destImage, VkImageLayout destImageLayout,
1701 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001702{
1703 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001704 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001705}
1706
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001707VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
1708 VkBuffer srcBuffer,
1709 VkImage destImage, VkImageLayout destImageLayout,
1710 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001711{
1712 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001713 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001714 VkDeviceMemory mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001715 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001716 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001717 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1718 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001719 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001720
1721 mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001722 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001723 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001724 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1725 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001726 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001727 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001728 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001729}
1730
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001731VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
1732 VkImage srcImage, VkImageLayout srcImageLayout,
1733 VkBuffer destBuffer,
1734 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001735{
1736 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001737 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001738 VkDeviceMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001739 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001740 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001741 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1742 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001743 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001744 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001745 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001746 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001747 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1748 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001749 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001750 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001751 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001752}
1753
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001754VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1755 VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001756{
1757 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001758 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001759 VkDeviceMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001760 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001761 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001762 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1763 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001764 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001765 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001766 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001767 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001768 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1769 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001770 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001771 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyan55658c22014-12-04 11:08:39 +00001772 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001773}
1774
Tony Barbour8205d902015-04-16 15:59:00 -06001775VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize dataSize, const uint32_t* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001776{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001777 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001778 VkDeviceMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001779 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001780 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001781 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1782 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001783 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001784 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001785 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001786}
1787
Tony Barbour8205d902015-04-16 15:59:00 -06001788VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkDeviceSize destOffset, VkDeviceSize fillSize, uint32_t data)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001789{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001790 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001791 VkDeviceMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001792 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001793 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001794 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1795 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001796 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001797 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001798 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001799}
1800
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001801VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
1802 VkImage image, VkImageLayout imageLayout,
1803 VkClearColor color,
1804 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001805{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001806 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001807 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001808 VkDeviceMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001809 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001810 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001811 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1812 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001813 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001814 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001815 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001816}
1817
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001818VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
1819 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001820 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001821 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001822{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001823 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001824 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001825 VkDeviceMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001826 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001827 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001828 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1829 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001830 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001831 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001832 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001833}
1834
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001835VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
1836 VkImage srcImage, VkImageLayout srcImageLayout,
1837 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06001838 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001839{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001840 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001841 VkDeviceMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001842 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001843 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001844 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1845 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001846 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001847 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001849 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001850 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1851 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001852 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001853 loader_platform_thread_unlock_mutex(&globalLock);
Tony Barbour11f74372015-04-13 15:02:52 -06001854 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001855}
1856
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001857VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001858{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001859 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001860 VkDeviceMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001861 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001862 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001863 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1864 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001865 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001866 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001867 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1868}
1869
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001870VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001871{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001872 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001873 VkDeviceMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001874 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001875 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001876 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1877 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001878 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001879 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001880 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1881}
1882
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001883VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001884{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001885 loader_platform_thread_lock_mutex(&globalLock);
Tony Barbour8205d902015-04-16 15:59:00 -06001886 VkDeviceMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001887 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001888 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001889 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1890 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001891 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001892 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001893 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1894}
1895
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001896VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001897{
Tobin Ehlis62086412014-11-19 16:19:28 -07001898 // This layer intercepts callbacks
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001899 VK_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (VK_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(VK_LAYER_DBG_FUNCTION_NODE));
Tobin Ehlis62086412014-11-19 16:19:28 -07001900 if (!pNewDbgFuncNode)
Tony Barbour8205d902015-04-16 15:59:00 -06001901 return VK_ERROR_OUT_OF_HOST_MEMORY;
Tobin Ehlis62086412014-11-19 16:19:28 -07001902 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
1903 pNewDbgFuncNode->pUserData = pUserData;
Jon Ashburnf57ea372014-12-22 13:24:15 -07001904 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
1905 g_pDbgFunctionHead = pNewDbgFuncNode;
Jon Ashburne4722392015-03-03 15:07:15 -07001906 // force callbacks if DebugAction hasn't been set already other than initial value
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001907 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001908 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001909 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001910 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001911 return result;
1912}
1913
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001914VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001915{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001916 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
1917 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001918 while (pInfo) {
1919 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
1920 pPrev->pNext = pInfo->pNext;
1921 if (g_pDbgFunctionHead == pInfo)
1922 g_pDbgFunctionHead = pInfo->pNext;
1923 free(pInfo);
Tobin Ehlis62086412014-11-19 16:19:28 -07001924 break;
1925 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001926 pPrev = pInfo;
1927 pInfo = pInfo->pNext;
Tobin Ehlis62086412014-11-19 16:19:28 -07001928 }
Jon Ashburne4722392015-03-03 15:07:15 -07001929 if (g_pDbgFunctionHead == NULL)
1930 {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001931 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001932 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001933 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001934 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001935 }
Jon Ashburne4722392015-03-03 15:07:15 -07001936 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001937 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001938 return result;
1939}
1940
Jon Ashburndc899962015-03-02 16:51:38 -07001941#if !defined(WIN32)
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001942VK_LAYER_EXPORT VkResult VKAPI vkWsiX11CreatePresentableImage(VkDevice device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo,
Tony Barbour8205d902015-04-16 15:59:00 -06001943 VkImage* pImage, VkDeviceMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001944{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001945 VkResult result = nextTable.WsiX11CreatePresentableImage(device, pCreateInfo, pImage, pMem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001946 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001947 if (VK_SUCCESS == result) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001948 // Add image object, then insert the new Mem Object and then bind it to created image
Tony Barbour8205d902015-04-16 15:59:00 -06001949 addObjectInfo(*pImage, VK_STRUCTURE_TYPE_MAX_ENUM, pCreateInfo, sizeof(VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO), "wsi_x11_image");
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001950 addMemObjInfo(*pMem, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 if (VK_FALSE == updateObjectBinding(*pImage, *pMem)) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001952 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001953 sprintf(str, "In vkWsiX11CreatePresentableImage(), unable to set image %p binding to mem obj %p", (void*)*pImage, (void*)*pMem);
1954 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pImage, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001955 }
Tobin Ehlis62086412014-11-19 16:19:28 -07001956 }
1957 printObjList();
1958 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001959 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001960 return result;
1961}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001962
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001963VK_LAYER_EXPORT VkResult VKAPI vkWsiX11QueuePresent(VkQueue queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001964{
1965 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001966 addFenceInfo(fence, queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001967 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001968 sprintf(str, "In vkWsiX11QueuePresent(), checking queue %p for fence %p", queue, fence);
1969 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001970 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001971 VkResult result = nextTable.WsiX11QueuePresent(queue, pPresentInfo, fence);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001972 return result;
1973}
Ian Elliott81ac44c2015-01-13 17:52:38 -07001974#endif // WIN32
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001975
Tony Barbour8205d902015-04-16 15:59:00 -06001976VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001977{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001978 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wu706533e2015-01-05 13:18:57 +08001979
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001980 if (gpu == NULL)
1981 return NULL;
1982 pCurObj = gpuw;
Ian Elliott81ac44c2015-01-13 17:52:38 -07001983 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001984
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001985 if (!strcmp(funcName, "vkGetProcAddr"))
1986 return (void *) vkGetProcAddr;
1987 if (!strcmp(funcName, "vkCreateDevice"))
1988 return (void*) vkCreateDevice;
1989 if (!strcmp(funcName, "vkDestroyDevice"))
1990 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001991 if (!strcmp(funcName, "vkEnumerateLayers"))
1992 return (void*) vkEnumerateLayers;
1993 if (!strcmp(funcName, "vkQueueSubmit"))
1994 return (void*) vkQueueSubmit;
1995 if (!strcmp(funcName, "vkAllocMemory"))
1996 return (void*) vkAllocMemory;
1997 if (!strcmp(funcName, "vkFreeMemory"))
1998 return (void*) vkFreeMemory;
1999 if (!strcmp(funcName, "vkSetMemoryPriority"))
2000 return (void*) vkSetMemoryPriority;
2001 if (!strcmp(funcName, "vkMapMemory"))
2002 return (void*) vkMapMemory;
2003 if (!strcmp(funcName, "vkUnmapMemory"))
2004 return (void*) vkUnmapMemory;
2005 if (!strcmp(funcName, "vkPinSystemMemory"))
2006 return (void*) vkPinSystemMemory;
2007 if (!strcmp(funcName, "vkOpenSharedMemory"))
2008 return (void*) vkOpenSharedMemory;
2009 if (!strcmp(funcName, "vkOpenPeerMemory"))
2010 return (void*) vkOpenPeerMemory;
2011 if (!strcmp(funcName, "vkOpenPeerImage"))
2012 return (void*) vkOpenPeerImage;
2013 if (!strcmp(funcName, "vkDestroyObject"))
2014 return (void*) vkDestroyObject;
2015 if (!strcmp(funcName, "vkGetObjectInfo"))
2016 return (void*) vkGetObjectInfo;
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05002017 if (!strcmp(funcName, "vkQueueBindObjectMemory"))
2018 return (void*) vkQueueBindObjectMemory;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002019 if (!strcmp(funcName, "vkCreateFence"))
2020 return (void*) vkCreateFence;
2021 if (!strcmp(funcName, "vkGetFenceStatus"))
2022 return (void*) vkGetFenceStatus;
2023 if (!strcmp(funcName, "vkResetFences"))
2024 return (void*) vkResetFences;
2025 if (!strcmp(funcName, "vkWaitForFences"))
2026 return (void*) vkWaitForFences;
2027 if (!strcmp(funcName, "vkQueueWaitIdle"))
2028 return (void*) vkQueueWaitIdle;
2029 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2030 return (void*) vkDeviceWaitIdle;
2031 if (!strcmp(funcName, "vkCreateEvent"))
2032 return (void*) vkCreateEvent;
2033 if (!strcmp(funcName, "vkCreateQueryPool"))
2034 return (void*) vkCreateQueryPool;
2035 if (!strcmp(funcName, "vkCreateBuffer"))
2036 return (void*) vkCreateBuffer;
2037 if (!strcmp(funcName, "vkCreateBufferView"))
2038 return (void*) vkCreateBufferView;
2039 if (!strcmp(funcName, "vkCreateImage"))
2040 return (void*) vkCreateImage;
2041 if (!strcmp(funcName, "vkCreateImageView"))
2042 return (void*) vkCreateImageView;
2043 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2044 return (void*) vkCreateColorAttachmentView;
2045 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2046 return (void*) vkCreateDepthStencilView;
2047 if (!strcmp(funcName, "vkCreateShader"))
2048 return (void*) vkCreateShader;
2049 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2050 return (void*) vkCreateGraphicsPipeline;
2051 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2052 return (void*) vkCreateGraphicsPipelineDerivative;
2053 if (!strcmp(funcName, "vkCreateComputePipeline"))
2054 return (void*) vkCreateComputePipeline;
2055 if (!strcmp(funcName, "vkCreateSampler"))
2056 return (void*) vkCreateSampler;
2057 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2058 return (void*) vkCreateDynamicViewportState;
2059 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2060 return (void*) vkCreateDynamicRasterState;
2061 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2062 return (void*) vkCreateDynamicColorBlendState;
2063 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2064 return (void*) vkCreateDynamicDepthStencilState;
2065 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2066 return (void*) vkCreateCommandBuffer;
2067 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2068 return (void*) vkBeginCommandBuffer;
2069 if (!strcmp(funcName, "vkEndCommandBuffer"))
2070 return (void*) vkEndCommandBuffer;
2071 if (!strcmp(funcName, "vkResetCommandBuffer"))
2072 return (void*) vkResetCommandBuffer;
2073 if (!strcmp(funcName, "vkCmdBindPipeline"))
2074 return (void*) vkCmdBindPipeline;
2075 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2076 return (void*) vkCmdBindDynamicStateObject;
2077 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2078 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002079 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2080 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002081 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2082 return (void*) vkCmdBindIndexBuffer;
2083 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2084 return (void*) vkCmdDrawIndirect;
2085 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2086 return (void*) vkCmdDrawIndexedIndirect;
2087 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2088 return (void*) vkCmdDispatchIndirect;
2089 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2090 return (void*) vkCmdCopyBuffer;
2091 if (!strcmp(funcName, "vkCmdCopyImage"))
2092 return (void*) vkCmdCopyImage;
2093 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2094 return (void*) vkCmdCopyBufferToImage;
2095 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2096 return (void*) vkCmdCopyImageToBuffer;
2097 if (!strcmp(funcName, "vkCmdCloneImageData"))
2098 return (void*) vkCmdCloneImageData;
2099 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2100 return (void*) vkCmdUpdateBuffer;
2101 if (!strcmp(funcName, "vkCmdFillBuffer"))
2102 return (void*) vkCmdFillBuffer;
2103 if (!strcmp(funcName, "vkCmdClearColorImage"))
2104 return (void*) vkCmdClearColorImage;
2105 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2106 return (void*) vkCmdClearDepthStencil;
2107 if (!strcmp(funcName, "vkCmdResolveImage"))
2108 return (void*) vkCmdResolveImage;
2109 if (!strcmp(funcName, "vkCmdBeginQuery"))
2110 return (void*) vkCmdBeginQuery;
2111 if (!strcmp(funcName, "vkCmdEndQuery"))
2112 return (void*) vkCmdEndQuery;
2113 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2114 return (void*) vkCmdResetQueryPool;
2115 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2116 return (void*) vkDbgRegisterMsgCallback;
2117 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2118 return (void*) vkDbgUnregisterMsgCallback;
2119 if (!strcmp(funcName, "vkGetDeviceQueue"))
2120 return (void*) vkGetDeviceQueue;
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06002121 if (!strcmp(funcName, "vkQueueAddMemReferences"))
2122 return (void*) vkQueueAddMemReferences;
2123 if (!strcmp(funcName, "vkQueueRemoveMemReferences"))
2124 return (void*) vkQueueRemoveMemReferences;
Jon Ashburndc899962015-03-02 16:51:38 -07002125#if !defined(WIN32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002126 if (!strcmp(funcName, "vkWsiX11CreatePresentableImage"))
2127 return (void*) vkWsiX11CreatePresentableImage;
2128 if (!strcmp(funcName, "vkWsiX11QueuePresent"))
2129 return (void*) vkWsiX11QueuePresent;
Jon Ashburndc899962015-03-02 16:51:38 -07002130#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002131 else {
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002132 if (gpuw->pGPA == NULL)
2133 return NULL;
Tony Barbour8205d902015-04-16 15:59:00 -06002134 return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002135 }
2136}