blob: 1b32f88690b8942f4a6250c8116470739a23e750 [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;
54map<VkGpuMemory, MT_MEM_OBJ_INFO*> memObjMap;
55map<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;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 memset(pInfo, 0, (sizeof(MT_CB_INFO) - sizeof(list<VkGpuMemory>)));
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 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600144 pFenceInfo->localFence = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500145 pFenceInfo->fence = fence;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700146 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500147 pFenceInfo->queue = queue;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500148 fenceMap[fenceId] = pFenceInfo;
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500149 // Update most recently submitted fenceId for Queue
150 pQueueInfo->lastSubmittedId = fenceId;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500151 return fenceId;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500152}
153
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500154// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500155static void deleteFenceInfo(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500156{
157 if (fenceId != 0) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500158 if (fenceMap.find(fenceId) != fenceMap.end()) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600159 map<uint64_t, MT_FENCE_INFO*>::iterator item;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500160 MT_FENCE_INFO* pDelInfo = fenceMap[fenceId];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500161 if (pDelInfo != NULL) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600162 if (pDelInfo->localFence == VK_TRUE) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500163 nextTable.DestroyObject(pDelInfo->fence);
164 }
165 delete pDelInfo;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500166 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600167 item = fenceMap.find(fenceId);
168 fenceMap.erase(item);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500169 }
170 }
171}
172
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500173// Search through list for this fence, deleting all items before it (with lower IDs) and updating lastRetiredId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600174static void updateFenceTracking(VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500175{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500176 MT_FENCE_INFO *pCurFenceInfo = NULL;
177 uint64_t fenceId = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600178 VkQueue queue = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500179
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500180 for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); ii!=fenceMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500181 if ((*ii).second != NULL) {
182 if (fence == ((*ii).second)->fence) {
183 queue = ((*ii).second)->queue;
184 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
185 pQueueInfo->lastRetiredId = (*ii).first;
186 } else {
187 deleteFenceInfo((*ii).first);
188 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500189 // Update fence state in fenceCreateInfo structure
190 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
191 if (pObjectInfo != NULL) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600192 pObjectInfo->create_info.fence_create_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500193 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500194 }
195 }
196}
197
198// Utility function that determines if a fenceId has been retired yet
199static bool32_t fenceRetired(uint64_t fenceId)
200{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600201 bool32_t result = VK_FALSE;
Mark Lobodzinski91a1ec52015-04-02 08:52:53 -0500202 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
203 if (pFenceInfo != 0)
204 {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500205 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
Mark Lobodzinski91a1ec52015-04-02 08:52:53 -0500206 if (fenceId <= pQueueInfo->lastRetiredId)
207 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600208 result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500209 }
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500210 } else { // If not in list, fence has been retired and deleted
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211 result = VK_TRUE;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500212 }
213 return result;
214}
215
216// Return the fence associated with a fenceId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600217static VkFence getFenceFromId(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500218{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600219 VkFence fence = NULL;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500220 if (fenceId != 0) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500221 // Search for an item with this fenceId
222 if (fenceMap.find(fenceId) != fenceMap.end()) {
223 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
224 if (pFenceInfo != NULL) {
225 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
226 if (fenceId > pQueueInfo->lastRetiredId) {
227 fence = pFenceInfo->fence;
228 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500229 }
230 }
231 }
232 return fence;
233}
234
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500235// Helper routine that updates the fence list for a specific queue to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600236static void retireQueueFences(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500237{
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600238 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
239 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
240 // Set Queue's lastRetired to lastSubmitted, free items in queue's fence list
241 map<uint64_t, MT_FENCE_INFO*>::iterator it = fenceMap.begin();
242 map<uint64_t, MT_FENCE_INFO*>::iterator temp;
243 while (it != fenceMap.end()) {
244 if (((*it).second)->queue == queue) {
245 temp = it;
246 ++temp;
247 deleteFenceInfo((*it).first);
248 it = temp;
249 } else {
250 ++it;
251 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500252 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700253}
254
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500255// Helper routine that updates fence list for all queues to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600256static void retireDeviceFences(VkDevice device)
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500257{
258 // Process each queue for device
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600259 // TODO: Add multiple device support
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600260 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500261 retireQueueFences((*ii).first);
262 }
263}
264
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500265// Returns True if a memory reference is present in a Queue's memory reference list
266// Queue is validated by caller
267static bool32_t checkMemRef(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600268 VkQueue queue,
269 VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500270{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600271 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600272 list<VkGpuMemory>::iterator it;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500273 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
274 for (it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
275 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600276 result = VK_TRUE;
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500277 break;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500278 }
279 }
280 return result;
281}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500282
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500283static bool32_t validateQueueMemRefs(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600284 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500285 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600286 const VkCmdBuffer *pCmdBuffers)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500287{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600288 bool32_t result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500289
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500290 // Verify Queue
291 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
292 if (pQueueInfo == NULL) {
293 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600294 sprintf(str, "Unknown Queue %p specified in vkQueueSubmit", queue);
295 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500296 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500297 else {
298 // Iterate through all CBs in pCmdBuffers
299 for (uint32_t i = 0; i < cmdBufferCount; i++) {
300 MT_CB_INFO* pCBInfo = getCBInfo(pCmdBuffers[i]);
301 if (!pCBInfo) {
302 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600303 sprintf(str, "Unable to find info for CB %p in order to check memory references in vkQueueSubmit for queue %p", (void*)pCmdBuffers[i], queue);
304 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_CB, "MEM", str);
305 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500306 } else {
307 // Validate that all actual references are accounted for in pMemRefs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600308 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500309 // Search for each memref in queues memreflist.
310 if (checkMemRef(queue, *it)) {
311 char str[1024];
312 sprintf(str, "Found Mem Obj %p binding to CB %p for queue %p", (*it), pCmdBuffers[i], queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600313 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500314 }
315 else {
316 char str[1024];
317 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 -0600318 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
319 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500320 }
321 }
322 }
323 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600324 if (result == VK_TRUE) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500325 char str[1024];
326 sprintf(str, "Verified all memory dependencies for Queue %p are included in pMemRefs list", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600327 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500328 // TODO : Could report mem refs in pMemRefs that AREN'T in mem list, that would be primarily informational
329 // Currently just noting that there is a difference
330 }
331 }
332
333 return result;
334}
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600335
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500336// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700337// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600338static MT_MEM_OBJ_INFO* getMemObjInfo(const VkGpuMemory mem)
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700339{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500340 MT_MEM_OBJ_INFO* pMemObjInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500341
342 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500343 pMemObjInfo = memObjMap[mem];
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600344 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500345 return pMemObjInfo;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700346}
347
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600348static void addMemObjInfo(const VkGpuMemory mem, const VkMemoryAllocInfo* pAllocInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700349{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500350 MT_MEM_OBJ_INFO* pInfo = new MT_MEM_OBJ_INFO;
351 pInfo->refCount = 0;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600352 memset(&pInfo->allocInfo, 0, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500353
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600354 if (pAllocInfo) { // MEM alloc created by vkWsiX11CreatePresentableImage() doesn't have alloc info struct
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600355 memcpy(&pInfo->allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500356 // TODO: Update for real hardware, actually process allocation info structures
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500357 pInfo->allocInfo.pNext = NULL;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700358 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500359 pInfo->mem = mem;
360 memObjMap[mem] = pInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700361}
362
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500363// Find CB Info and add mem binding to list container
364// Find Mem Obj Info and add CB binding to list container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600365static bool32_t updateCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700366{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600367 bool32_t result = VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700368 // First update CB binding in MemObj mini CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500369 MT_MEM_OBJ_INFO* pMemInfo = getMemObjInfo(mem);
370 if (!pMemInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700371 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500372 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 -0600373 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
374 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600375 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500376 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600378 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500379 if ((*it) == cb) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600380 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500381 break;
382 }
383 }
384 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600385 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500386 pMemInfo->pCmdBufferBindings.push_front(cb);
387 pMemInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500388 }
389
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500390 // Now update CBInfo's Mem binding list
391 MT_CB_INFO* pCBInfo = getCBInfo(cb);
392 if (!pCBInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500393 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500394 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 -0600395 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
396 result = VK_FALSE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500397 } else {
398 // Search for memory object in cmd buffer's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600399 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600400 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500401 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600402 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500403 break;
404 }
405 }
406 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600407 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500408 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600409 }
410 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700411 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600412 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700413}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600414
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700415// Clear the CB Binding for mem
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700416// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600417static void clearCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700418{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500419 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500420 // TODO : Having this check is not ideal, really if memInfo was deleted,
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700421 // its CB bindings should be cleared and then freeCBBindings wouldn't call
422 // us here with stale mem objs
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500423 if (pInfo) {
424 pInfo->pCmdBufferBindings.remove(cb);
425 pInfo->refCount--;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700426 }
427}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600428
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700429// Free bindings related to CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600430static bool32_t freeCBBindings(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700431{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600432 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500433 MT_CB_INFO* pCBInfo = getCBInfo(cb);
434 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700435 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500436 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600437 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
438 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600439 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500440 if (!fenceRetired(pCBInfo->fenceId)) {
441 deleteFenceInfo(pCBInfo->fenceId);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600442 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500443
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600444 for (list<VkGpuMemory>::iterator it=pCBInfo->pMemObjList.begin(); it!=pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500445 clearCBBinding(cb, (*it));
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600446 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500447 pCBInfo->pMemObjList.clear();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700448 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600449 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700450}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600451
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500452// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500453// and also clear mem references to CB
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700454// TODO : When should this be called? There's no Destroy of CBs that I see
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600455static bool32_t deleteCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700456{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600457 bool32_t result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600458 result = freeCBBindings(cb);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500459 // Delete the CBInfo info
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600460 if (result == VK_TRUE) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500461 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500462 MT_CB_INFO* pDelInfo = cbMap[cb];
463 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500464 cbMap.erase(cb);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600465 }
Ian Elliott81ac44c2015-01-13 17:52:38 -0700466 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600467 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700468}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600469
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700470// Delete the entire CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500471static bool32_t deleteCBInfoList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700472{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600473 bool32_t result = VK_TRUE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600474 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500475 freeCBBindings((*ii).first);
476 delete (*ii).second;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700477 }
478 return result;
479}
480
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500481// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500482static void reportMemReferences(const MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700483{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600484 uint32_t refCount = 0; // Count found references
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500485
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600486 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700487 refCount++;
Tobin Ehlis62086412014-11-19 16:19:28 -0700488 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500489 sprintf(str, "Command Buffer %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600490 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700491 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600492 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700493 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600494 sprintf(str, "VK Object %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
495 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700496 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500497 if (refCount != pMemObjInfo->refCount) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700498 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500499 sprintf(str, "Refcount of %u for Mem Obj %p does't match reported refs of %u", pMemObjInfo->refCount, pMemObjInfo->mem, refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600500 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700501 }
502}
503
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600504static void deleteMemObjInfo(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700505{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500506 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500507 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500508 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
509 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500510 memObjMap.erase(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700511 }
512}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500513
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700514// Check if fence for given CB is completed
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600515static bool32_t checkCBCompleted(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700516{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600517 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500518 MT_CB_INFO* pCBInfo = getCBInfo(cb);
519 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700520 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500521 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600522 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
523 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600524 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500525 if (!fenceRetired(pCBInfo->fenceId)) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600526 char str[1024];
527 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 -0600528 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_NONE, "MEM", str);
529 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600530 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700531 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600532 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700533}
534
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600535static bool32_t freeMemObjInfo(VkGpuMemory mem, bool internal)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700536{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600537 bool32_t result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500538 // Parse global list to find info w/ mem
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500539 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
540 if (!pInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700541 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500542 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 -0600543 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
544 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600545 } else {
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -0600546 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600547 char str[1024];
548 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 -0600549 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
550 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600551 } else {
552 // Clear any CB bindings for completed CBs
553 // TODO : Is there a better place to do this?
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500554
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600555 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
556 list<VkCmdBuffer>::iterator temp;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500557 while (it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600558 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500559 temp = it;
560 ++temp;
561 freeCBBindings(*it);
562 it = temp;
563 } else {
564 ++it;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600565 }
566 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500567
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600568 // Now verify that no references to this mem obj remain
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500569 if (0 != pInfo->refCount) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500570 // If references remain, report the error and can search CB list to find references
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600571 char str[1024];
572 sprintf(str, "Freeing mem obj %p while it still has references", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600573 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500574 reportMemReferences(pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600575 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600576 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600577 // Delete mem obj info
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500578 deleteMemObjInfo(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700579 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700580 }
581 return result;
582}
583
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700584// Remove object binding performs 3 tasks:
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500585// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
586// 2. Decrement refCount for MemObjInfo
587// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600588static bool32_t clearObjectBinding(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700589{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600590 bool32_t result = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500591 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
592 if (!pObjInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700593 char str[1024];
Mark Lobodzinski15427102015-02-18 16:38:17 -0600594 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 -0600595 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600596 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500597 if (!pObjInfo->pMemObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600598 char str[1024];
599 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600600 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 -0600601 } else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600602 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500603 pObjInfo->pMemObjInfo->refCount--;
604 pObjInfo->pMemObjInfo = NULL;
605 it = pObjInfo->pMemObjInfo->pObjBindings.erase(it);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600606 result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500607 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600608 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600609 if (result == VK_FALSE) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600610 char str[1024];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500611 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 -0500612 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600613 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600614 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700615 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700616 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600617 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700618}
619
620// For NULL mem case, clear any previous binding Else...
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500621// Make sure given object is in global object map
Tobin Ehlis62086412014-11-19 16:19:28 -0700622// IF a previous binding existed, clear it
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500623// Add reference from objectInfo to memoryInfo
624// Add reference off of objInfo
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600626static bool32_t updateObjectBinding(VkObject object, VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700627{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600628 bool32_t result = VK_FALSE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700629 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600630 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700631 clearObjectBinding(object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600632 result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600633 } else {
634 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500635 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
636 if (!pObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600637 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600638 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
639 return VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600640 }
641 // non-null case so should have real mem obj
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500642 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
643 if (!pInfo) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500644 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 -0600645 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600646 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500647 // Search for object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600648 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600649 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500650 if ((*it) == object) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600651 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500652 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600653 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600654 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500655 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600656 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500657 pInfo->pObjBindings.push_front(object);
658 pInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500659 }
660
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500661 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500662 clearObjectBinding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500663 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 -0600664 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500665 }
666 // For image objects, make sure default memory state is correctly set
667 // TODO : What's the best/correct way to handle this?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600668 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
669 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 -0500670 // TODO:: More memory state transition stuff.
671 }
672 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500673 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700674 }
675 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600676 return VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700677}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600678
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700679// Print details of global Obj tracking list
680static void printObjList()
681{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500682 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500683 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500684 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600686 for (map<VkObject, MT_OBJ_INFO*>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500687 pInfo = (*ii).second;
688 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600689 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700690 }
691}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600692
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700693// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600694static VkGpuMemory getMemBindingFromObject(const VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700695{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600696 VkGpuMemory mem = NULL;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500697 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
698 if (pObjInfo) {
699 if (pObjInfo->pMemObjInfo) {
700 mem = pObjInfo->pMemObjInfo->mem;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700701 }
702 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700703 char str[1024];
704 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 -0600705 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700706 printObjList();
707 }
708 }
709 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700710 char str[1024];
711 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 -0600712 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700713 printObjList();
714 }
715 return mem;
716}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500717
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500718// Print details of MemObjInfo list
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700719static void printMemList()
720{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500721 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehlis62086412014-11-19 16:19:28 -0700722 // Just printing each msg individually for now, may want to package these into single large print
723 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500724 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600725 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500726
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600727 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500728 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500729
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500730 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600731 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500732 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600733 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500734 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600735 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500736 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600737 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500738 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600739 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500740 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600741 sprintf(str, " Mem Alloc info is NULL (alloc done by vkWsiX11CreatePresentableImage())");
742 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500743 }
744
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600745 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
746 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600747 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600748 sprintf(str, " VK OBJECT %p", (*it));
749 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500750 }
751
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600752 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
753 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600754 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600755 sprintf(str, " VK CB %p", (*it));
756 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700757 }
758 }
759}
760
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500761static void printCBList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700762{
Tobin Ehlis62086412014-11-19 16:19:28 -0700763 char str[1024] = {0};
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500764 MT_CB_INFO* pCBInfo = NULL;
765 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600766 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500767
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600768 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500769 pCBInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500770
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500771 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
772 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
773 (void*)getFenceFromId(pCBInfo->fenceId));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600774 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500775
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600776 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500777 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600778 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700779 }
780 }
781}
782
Mark Lobodzinski15427102015-02-18 16:38:17 -0600783static void initMemTracker(void)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700784{
Jon Ashburnf57ea372014-12-22 13:24:15 -0700785 const char *strOpt;
786 // initialize MemTracker options
Ian Elliott7d0b5d22015-03-06 13:50:05 -0700787 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportingLevel);
788 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlis5b7acaa2015-01-08 14:26:53 -0700789
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600790 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburnf57ea372014-12-22 13:24:15 -0700791 {
792 strOpt = getLayerOption("MemTrackerLogFilename");
793 if (strOpt)
794 {
795 g_logFile = fopen(strOpt, "w");
Jon Ashburnf57ea372014-12-22 13:24:15 -0700796 }
797 if (g_logFile == NULL)
798 g_logFile = stdout;
799 }
800
801 // initialize Layer dispatch table
802 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600803 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700804 fpNextGPA = pCurObj->pGPA;
805 assert(fpNextGPA);
806
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600807 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalGpu) pCurObj->nextObject);
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800808
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600809 PFN_vkGetProcAddr fpGetProcAddr = (PFN_vkGetProcAddr)fpNextGPA((VkPhysicalGpu) pCurObj->nextObject, (char *) "vkGetProcAddr");
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700810 nextTable.GetProcAddr = fpGetProcAddr;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600811
812 if (!globalLockInitialized)
813 {
814 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600815 // suggestion is to call this during vkCreateInstance(), and then we
816 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600817 // that the layer have per-instance locks. We need to come back and
818 // address this soon.
819 loader_platform_thread_create_mutex(&globalLock);
820 globalLockInitialized = 1;
821 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700822}
823
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600824VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700825{
Jon Ashburn630e44f2015-04-08 21:33:34 -0600826 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700827 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600828 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700829 // Save off device in case we need it to create Fences
830 globalDevice = *pDevice;
831 return result;
832}
833
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600834VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700835{
Tobin Ehlis62086412014-11-19 16:19:28 -0700836 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600837 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600838 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600839 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700840 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500841 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700842 printObjList();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600843 if (VK_FALSE == deleteCBInfoList()) {
844 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
845 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -0700846 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700847 // Report any memory leaks
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500848 MT_MEM_OBJ_INFO* pInfo = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600849 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500850 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500851
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500852 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600853 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 -0500854 pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600855 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600856 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700857 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500858
859 // Queues persist until device is destroyed
860 deleteQueueInfoList();
861
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600862 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600863 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700864 return result;
865}
866
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600867VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
Jon Ashburn25566352015-04-02 12:06:28 -0600868{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600869 VkResult result;
Jon Ashburn25566352015-04-02 12:06:28 -0600870 /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */
871 if (!strcmp(pExtName, "MemTracker"))
872 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600873 result = VK_SUCCESS;
Jon Ashburn25566352015-04-02 12:06:28 -0600874 } else if (nextTable.GetExtensionSupport != NULL)
875 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600876 result = nextTable.GetExtensionSupport(gpu, pExtName);
Jon Ashburn25566352015-04-02 12:06:28 -0600877 } else
878 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600879 result = VK_ERROR_INVALID_EXTENSION;
Jon Ashburn25566352015-04-02 12:06:28 -0600880 }
881 return result;
882}
883
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600884VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500885 size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700886{
Jon Ashburn451c16f2014-11-25 11:08:42 -0700887 if (gpu != NULL)
888 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600889 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700890 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600891 VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500892 maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn451c16f2014-11-25 11:08:42 -0700893 return result;
894 } else
895 {
896 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600897 return VK_ERROR_INVALID_POINTER;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700898 // This layer compatible with all GPUs
899 *pOutLayerCount = 1;
Chia-I Wua837c522014-12-16 10:47:33 +0800900 strncpy((char *) pOutLayers[0], "MemTracker", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600901 return VK_SUCCESS;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700902 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700903}
904
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600905VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue)
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500906{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600907 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600908 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500909 loader_platform_thread_lock_mutex(&globalLock);
910 addQueueInfo(*pQueue);
911 loader_platform_thread_unlock_mutex(&globalLock);
912 }
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500913 return result;
914}
915
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600916VK_LAYER_EXPORT VkResult VKAPI vkQueueAddMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500917{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600918 VkResult result = nextTable.QueueAddMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600919 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500920 loader_platform_thread_lock_mutex(&globalLock);
921
922 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
923 if (pQueueInfo == NULL) {
924 char str[1024];
925 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600926 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500927 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500928 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600929 if (checkMemRef(queue, mem) == VK_TRUE) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500930 // Alread in list, just warn
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500931 char str[1024];
932 sprintf(str, "Request to add a memory reference (%p) to Queue %p -- ref is already present in the queue's reference list", mem, queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600933 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500934 }
935 else {
936 // Add to queue's memory reference list
937 pQueueInfo->pMemRefList.push_front(mem);
938 }
939 }
940 loader_platform_thread_unlock_mutex(&globalLock);
941 }
942 return result;
943}
944
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600945VK_LAYER_EXPORT VkResult VKAPI vkQueueRemoveMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500946{
947 // TODO : Decrement ref count for this memory reference on this queue. Remove if ref count is zero.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600948 VkResult result = nextTable.QueueRemoveMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600949 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500950 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500951
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500952 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
953 if (pQueueInfo == NULL) {
954 char str[1024];
955 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600956 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500957 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500958 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600959 for (list<VkGpuMemory>::iterator it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500960 if ((*it) == mem) {
961 it = pQueueInfo->pMemRefList.erase(it);
962 }
963 }
964 }
965 loader_platform_thread_unlock_mutex(&globalLock);
966 }
967 return result;
968}
969
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600970VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
971 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500972 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600973 const VkCmdBuffer *pCmdBuffers,
974 VkFence fence)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700975{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600976 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700977 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500978 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500979 uint64_t fenceId = addFenceInfo(fence, queue);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500980
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700981 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500982 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700983 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500984 pCBInfo = getCBInfo(pCmdBuffers[i]);
985 pCBInfo->fenceId = fenceId;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700986 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500987
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600988 if (VK_FALSE == validateQueueMemRefs(queue, cmdBufferCount, pCmdBuffers)) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500989 char str[1024];
990 sprintf(str, "Unable to verify memory references for Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600991 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500992 }
993
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600994 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600995 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, getFenceFromId(fenceId));
Courtney Goeltzenleuchtercfedf362015-04-02 13:39:07 -0600996 return result;
997}
998
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600999VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(VkDevice device, const VkMemoryAllocInfo* pAllocInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001000{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001001 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001002 // TODO : Track allocations and overall size here
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001003 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001004 addMemObjInfo(*pMem, pAllocInfo);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001005 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001006 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001007 return result;
1008}
1009
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001010VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001011{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001012 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisa747e682014-11-25 14:47:20 -07001013 * freeing a memory object, an application must ensure the memory object is unbound from
1014 * all API objects referencing it and that it is not referenced by any queued command buffers
1015 */
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001016 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001017 if (VK_FALSE == freeMemObjInfo(mem, false)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001018 char str[1024];
1019 sprintf(str, "Issue while freeing mem obj %p", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001020 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREE_MEM_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001021 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001022 printMemList();
1023 printObjList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001024 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001025 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001026 VkResult result = nextTable.FreeMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001027 return result;
1028}
1029
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001030VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(VkGpuMemory mem, VkMemoryPriority priority)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001031{
1032 // TODO : Update tracking for this alloc
1033 // Make sure memory is not pinned, which can't have priority set
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001034 VkResult result = nextTable.SetMemoryPriority(mem, priority);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001035 return result;
1036}
1037
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001038VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(VkGpuMemory mem, VkFlags flags, void** ppData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001039{
1040 // TODO : Track when memory is mapped
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001041 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001042 MT_MEM_OBJ_INFO *pMemObj = getMemObjInfo(mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001043 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT) == 0) {
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001044 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001045 sprintf(str, "Mapping Memory (%p) without VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT set", (void*)mem);
1046 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001047 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001048 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001049 VkResult result = nextTable.MapMemory(mem, flags, ppData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001050 return result;
1051}
1052
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001053VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001054{
1055 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1056 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001057 VkResult result = nextTable.UnmapMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001058 return result;
1059}
1060
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001061VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSysMem, size_t memSize, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001062{
1063 // TODO : Track this
1064 // Verify that memory is actually pinnable
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001065 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001066 return result;
1067}
1068
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001069VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001070{
1071 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001072 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001073 return result;
1074}
1075
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001076VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001077{
1078 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001079 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001080 return result;
1081}
1082
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001083VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001084{
1085 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001086 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001087 return result;
1088}
1089
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001090VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001091{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001092 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001093
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001094 // First check if this is a CmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001095 if (NULL != getCBInfo((VkCmdBuffer)object)) {
1096 deleteCBInfo((VkCmdBuffer)object);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001097 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001098
1099 if (objectMap.find(object) != objectMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001100 MT_OBJ_INFO* pDelInfo = objectMap[object];
1101 if (pDelInfo->pMemObjInfo) {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001102 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001103 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001104 VkGpuMemory memToFree = pDelInfo->pMemObjInfo->mem;
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001105 clearObjectBinding(object);
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -06001106 freeMemObjInfo(memToFree, true);
1107 }
1108 else {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001109 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001110 sprintf(str, "Destroying obj %p that is still bound to memory object %p\nYou should first clear binding by calling vkBindObjectMemory(%p, 0, VK_NULL_HANDLE, 0)", object, (void*)pDelInfo->pMemObjInfo->mem, object);
1111 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001112 // From the spec : If an object has previous memory binding, it is required to unbind memory from an API object before it is destroyed.
1113 clearObjectBinding(object);
1114 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001115 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001116 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001117 objectMap.erase(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001118 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001119
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001120 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001121 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001122 return result;
1123}
1124
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001125VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(VkBaseObject object, VkObjectInfoType infoType, size_t* pDataSize, void* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001126{
1127 // TODO : What to track here?
1128 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Tobin Ehlis62086412014-11-19 16:19:28 -07001129 // 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 -06001130 VkResult result = nextTable.GetObjectInfo(object, infoType, pDataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001131 return result;
1132}
1133
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001134VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(VkObject object, uint32_t allocationIdx, VkGpuMemory mem, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001135{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001136 VkResult result = nextTable.BindObjectMemory(object, allocationIdx, mem, offset);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001137 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001138 // Track objects tied to memory
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001139 if (VK_FALSE == updateObjectBinding(object, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001140 char str[1024];
1141 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001142 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001143 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001144 printObjList();
1145 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001146 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001147 return result;
1148}
1149
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001150VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001151{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001152 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001153 if (VK_SUCCESS == result) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001154 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001155 addObjectInfo(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001156 loader_platform_thread_unlock_mutex(&globalLock);
1157 }
1158 return result;
1159}
1160
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001161VK_LAYER_EXPORT VkResult VKAPI vkResetFences(VkDevice device, uint32_t fenceCount, VkFence* pFences)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001162{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001163 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001164 if (VK_SUCCESS == result) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001165 loader_platform_thread_lock_mutex(&globalLock);
1166 // Reset fence state in fenceCreateInfo structure
1167 for (uint32_t i = 0; i < fenceCount; i++) {
1168 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1169 if (pObjectInfo != NULL) {
1170 pObjectInfo->create_info.fence_create_info.flags =
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001171 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001172 }
1173 }
1174 loader_platform_thread_unlock_mutex(&globalLock);
1175 }
1176 return result;
1177}
1178
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001179VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(VkFence fence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001180{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001181 VkResult result = nextTable.GetFenceStatus(fence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001182 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001183 loader_platform_thread_lock_mutex(&globalLock);
1184 updateFenceTracking(fence);
1185 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001186 }
1187 return result;
1188}
1189
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001190VK_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 -07001191{
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001192 // Verify fence status of submitted fences
1193 for(uint32_t i = 0; i < fenceCount; i++) {
1194 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1195 if (pObjectInfo != NULL) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001196 if (pObjectInfo->create_info.fence_create_info.flags == VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001197 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001198 sprintf(str, "vkWaitForFences specified signaled-state Fence %p. Fences must be reset before being submitted", pFences[i]);
1199 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001200 }
1201 }
1202 }
1203
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001204 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001205 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001206
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001207 if (VK_SUCCESS == result) {
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001208 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001209 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001210 updateFenceTracking(pFences[i]);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001211 }
1212 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001213 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001214 loader_platform_thread_unlock_mutex(&globalLock);
1215 return result;
1216}
1217
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001218VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001219{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001220 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001221 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001222 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001223 retireQueueFences(queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001224 loader_platform_thread_unlock_mutex(&globalLock);
1225 }
1226 return result;
1227}
1228
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001229VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(VkDevice device)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001230{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001231 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001232 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001233 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001234 retireDeviceFences(device);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001235 loader_platform_thread_unlock_mutex(&globalLock);
1236 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001237 return result;
1238}
1239
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001240VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001241{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001242 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001243 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001244 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001245 addObjectInfo(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001246 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001247 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001248 return result;
1249}
1250
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001251VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001252{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001253 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001254 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001255 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001256 addObjectInfo(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001257 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001258 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001259 return result;
1260}
1261
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001262VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001263{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001264 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001265 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001266 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001267 addObjectInfo(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001268 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001269 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001270 return result;
1271}
1272
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001273VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001274{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001275 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001276 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001277 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001278 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001279 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001280 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001281 return result;
1282}
1283
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001284VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001285{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001286 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001287 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001288 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001289 addObjectInfo(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001290 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001291 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001292 return result;
1293}
1294
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001295VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001296{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001297 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001298 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001299 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001300 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001301 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001302 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001303 return result;
1304}
1305
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001306VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(VkDevice device, const VkColorAttachmentViewCreateInfo* pCreateInfo,
1307 VkColorAttachmentView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001308{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001309 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001310 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001311 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001312 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001313 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001314 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001315 return result;
1316}
1317
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001318VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001319{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001320 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001321 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001322 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001323 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001324 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001325 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001326 return result;
1327}
1328
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001329VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001330{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001331 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001332 return result;
1333}
1334
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001335VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001336{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001337 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001338 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001339 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001340 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001341 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001342 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001343 return result;
1344}
1345
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001346VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1347 VkDevice device,
1348 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1349 VkPipeline basePipeline,
1350 VkPipeline* pPipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001351{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001352 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001353 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001354 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001355 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001356 loader_platform_thread_unlock_mutex(&globalLock);
1357 }
1358 return result;
1359}
1360
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001361VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001362{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001363 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001364 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001365 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001366 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001367 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001368 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001369 return result;
1370}
1371
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001372VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001373{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001374 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001375 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001376 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001377 addObjectInfo(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001378 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001379 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001380 return result;
1381}
1382
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001383VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo,
1384 VkDynamicVpStateObject* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001385{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001386 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001387 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001388 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001389 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001390 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001391 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001392 return result;
1393}
1394
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001395VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo,
1396 VkDynamicRsStateObject* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001397{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001398 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001399 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001400 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001401 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001402 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001403 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001404 return result;
1405}
1406
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001407VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo,
1408 VkDynamicCbStateObject* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001409{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001410 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001411 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001412 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001413 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001414 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001415 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001416 return result;
1417}
1418
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001419VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo,
1420 VkDynamicDsStateObject* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001421{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001422 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001423 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001424 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001425 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001426 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001427 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001428 return result;
1429}
1430
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001431VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001432{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001433 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001434 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001435 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001436 if (*pCmdBuffer)
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001437 addCBInfo(*pCmdBuffer);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001438 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001439 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001440 return result;
1441}
1442
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001443VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001444{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001445 // 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 -05001446 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1447 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001448 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001449 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001450 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001451 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. You must check CB flag before this call.", cmdBuffer);
1452 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 -07001453 }
1454 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001455 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001456 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001457 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001458 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001459 return result;
1460}
1461
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001462VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001463{
1464 // TODO : Anything to do here?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001465 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001466 return result;
1467}
1468
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001469VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001470{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001471 // Verify that CB is complete (not in-flight)
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001472 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1473 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001474 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001475 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001476 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001477 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before calling vkResetCommandBuffer().", cmdBuffer);
1478 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 -07001479 }
1480 }
1481 // Clear memory references as this point.
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001482 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001483 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001484 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001485 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001486 return result;
1487}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001488// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001489// need to account for that mem now having binding to given cmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001490VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001491{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001492#if 0
1493 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1494 if (getPipeline(pipeline)) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001495 MT_CB_INFO *pCBInfo = getCBInfo(cmdBuffer);
1496 if (pCBInfo) {
1497 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001498 } else {
1499 char str[1024];
1500 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001501 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 -07001502 }
1503 }
1504 else {
1505 char str[1024];
1506 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001507 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 -07001508 }
1509#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001510 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1511}
1512
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001513VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001514{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001515 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001516 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001517 MT_CB_INFO *pCmdBuf = getCBInfo(cmdBuffer);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001518 if (!pCmdBuf) {
1519 char str[1024];
1520 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001521 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001522 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001523 pObjInfo = getObjectInfo(state);
1524 if (!pObjInfo) {
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001525 char str[1024];
1526 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001527 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001528 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001529 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001530 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001531 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001532}
1533
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001534VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001535 VkCmdBuffer cmdBuffer,
1536 VkPipelineBindPoint pipelineBindPoint,
1537 VkDescriptorSetLayoutChain layoutChain,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001538 uint32_t layoutChainSlot,
1539 uint32_t count,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001540 const VkDescriptorSet* pDescriptorSets,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001541 const uint32_t* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001542{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001543 // TODO : Somewhere need to verify that all textures referenced by shaders in DS are in some type of *SHADER_READ* state
Courtney Goeltzenleuchter24591b62015-04-02 22:54:15 -06001544 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layoutChain, layoutChainSlot, count, pDescriptorSets, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001545}
1546
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001547VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t binding)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001548{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001549 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
Chia-I Wufb5062e2015-01-05 13:42:56 +08001550}
1551
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001552VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, VkIndexType indexType)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001553{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001554 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001555}
1556
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001557VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001558{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001559 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001560 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001561 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001562 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001563 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1564 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001565 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001566 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001567 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001568}
1569
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001570VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001571{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001572 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001573 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001574 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001575 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001576 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1577 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001578 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001579 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001580 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001581}
1582
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001583VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001584{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001585 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001586 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001587 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001588 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001589 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1590 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001591 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001592 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001593 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001594}
1595
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001596VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer,
1597 uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001598{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001599 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001600 VkGpuMemory mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001601 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001602 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001603 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1604 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001605 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001606 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001607 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001608 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001609 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1610 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001611 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001612 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001613 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001614}
1615
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001616VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
1617 VkImage srcImage, VkImageLayout srcImageLayout,
1618 VkImage destImage, VkImageLayout destImageLayout,
1619 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001620{
1621 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001622 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001623}
1624
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001625VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
1626 VkImage srcImage, VkImageLayout srcImageLayout,
1627 VkImage destImage, VkImageLayout destImageLayout,
1628 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001629{
1630 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001631 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001632}
1633
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001634VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
1635 VkBuffer srcBuffer,
1636 VkImage destImage, VkImageLayout destImageLayout,
1637 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001638{
1639 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001640 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001641 VkGpuMemory mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001642 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001643 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001644 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1645 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001646 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001647
1648 mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001649 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001650 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001651 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1652 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001653 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001654 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001655 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001656}
1657
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001658VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
1659 VkImage srcImage, VkImageLayout srcImageLayout,
1660 VkBuffer destBuffer,
1661 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001662{
1663 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001664 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001665 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001666 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001667 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001668 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1669 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001670 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001671 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001672 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001673 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001674 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1675 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001676 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001677 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001678 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001679}
1680
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001681VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1682 VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001683{
1684 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001685 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001686 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001687 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001688 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001689 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1690 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001691 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001692 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001693 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001694 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001695 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1696 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001697 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001698 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyan55658c22014-12-04 11:08:39 +00001699 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001700}
1701
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001702VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize dataSize, const uint32_t* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001703{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001704 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001705 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001706 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001707 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001708 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1709 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001710 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001711 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001712 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001713}
1714
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001715VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize fillSize, uint32_t data)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001716{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001717 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001718 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001719 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001720 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001721 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1722 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001723 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001724 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001725 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001726}
1727
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001728VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
1729 VkImage image, VkImageLayout imageLayout,
1730 VkClearColor color,
1731 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001732{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001733 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001734 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001735 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001736 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001737 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001738 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1739 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001740 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001741 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001742 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001743}
1744
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001745VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
1746 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001747 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001748 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001749{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001750 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001751 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001752 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001753 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001754 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001755 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1756 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001757 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001758 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001759 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001760}
1761
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001762VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
1763 VkImage srcImage, VkImageLayout srcImageLayout,
1764 VkImage destImage, VkImageLayout destImageLayout,
1765 uint32_t rectCount, const VkImageResolve* pRects)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001766{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001767 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001768 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001769 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001770 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001771 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1772 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001773 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001774 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001775 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001776 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1778 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001779 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001780 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001781 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, rectCount, pRects);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001782}
1783
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001784VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001785{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001786 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001787 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001788 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001789 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001790 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1791 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001792 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001793 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001794 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1795}
1796
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001797VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001798{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001799 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001800 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001801 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001802 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001803 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1804 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001805 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001806 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001807 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1808}
1809
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001810VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001811{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001812 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001813 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001814 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001815 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001816 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1817 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001818 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001819 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001820 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1821}
1822
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001823VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001824{
Tobin Ehlis62086412014-11-19 16:19:28 -07001825 // This layer intercepts callbacks
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001826 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 -07001827 if (!pNewDbgFuncNode)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001828 return VK_ERROR_OUT_OF_MEMORY;
Tobin Ehlis62086412014-11-19 16:19:28 -07001829 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
1830 pNewDbgFuncNode->pUserData = pUserData;
Jon Ashburnf57ea372014-12-22 13:24:15 -07001831 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
1832 g_pDbgFunctionHead = pNewDbgFuncNode;
Jon Ashburne4722392015-03-03 15:07:15 -07001833 // force callbacks if DebugAction hasn't been set already other than initial value
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001834 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001835 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001836 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001837 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001838 return result;
1839}
1840
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001841VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001842{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001843 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
1844 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001845 while (pInfo) {
1846 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
1847 pPrev->pNext = pInfo->pNext;
1848 if (g_pDbgFunctionHead == pInfo)
1849 g_pDbgFunctionHead = pInfo->pNext;
1850 free(pInfo);
Tobin Ehlis62086412014-11-19 16:19:28 -07001851 break;
1852 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001853 pPrev = pInfo;
1854 pInfo = pInfo->pNext;
Tobin Ehlis62086412014-11-19 16:19:28 -07001855 }
Jon Ashburne4722392015-03-03 15:07:15 -07001856 if (g_pDbgFunctionHead == NULL)
1857 {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001858 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001859 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001860 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001861 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001862 }
Jon Ashburne4722392015-03-03 15:07:15 -07001863 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001864 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001865 return result;
1866}
1867
Jon Ashburndc899962015-03-02 16:51:38 -07001868#if !defined(WIN32)
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001869VK_LAYER_EXPORT VkResult VKAPI vkWsiX11CreatePresentableImage(VkDevice device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo,
1870 VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001871{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001872 VkResult result = nextTable.WsiX11CreatePresentableImage(device, pCreateInfo, pImage, pMem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001873 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001874 if (VK_SUCCESS == result) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001875 // Add image object, then insert the new Mem Object and then bind it to created image
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001876 addObjectInfo(*pImage, VkStructureType__MAX_ENUM, pCreateInfo, sizeof(VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO), "wsi_x11_image");
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001877 addMemObjInfo(*pMem, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001878 if (VK_FALSE == updateObjectBinding(*pImage, *pMem)) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001879 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001880 sprintf(str, "In vkWsiX11CreatePresentableImage(), unable to set image %p binding to mem obj %p", (void*)*pImage, (void*)*pMem);
1881 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pImage, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001882 }
Tobin Ehlis62086412014-11-19 16:19:28 -07001883 }
1884 printObjList();
1885 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001886 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001887 return result;
1888}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001889
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001890VK_LAYER_EXPORT VkResult VKAPI vkWsiX11QueuePresent(VkQueue queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001891{
1892 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001893 addFenceInfo(fence, queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001894 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001895 sprintf(str, "In vkWsiX11QueuePresent(), checking queue %p for fence %p", queue, fence);
1896 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001897 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001898 VkResult result = nextTable.WsiX11QueuePresent(queue, pPresentInfo, fence);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001899 return result;
1900}
Ian Elliott81ac44c2015-01-13 17:52:38 -07001901#endif // WIN32
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001902
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001903VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* funcName)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001904{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001905 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wu706533e2015-01-05 13:18:57 +08001906
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001907 if (gpu == NULL)
1908 return NULL;
1909 pCurObj = gpuw;
Ian Elliott81ac44c2015-01-13 17:52:38 -07001910 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001911
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001912 if (!strcmp(funcName, "vkGetProcAddr"))
1913 return (void *) vkGetProcAddr;
1914 if (!strcmp(funcName, "vkCreateDevice"))
1915 return (void*) vkCreateDevice;
1916 if (!strcmp(funcName, "vkDestroyDevice"))
1917 return (void*) vkDestroyDevice;
1918 if (!strcmp(funcName, "vkGetExtensionSupport"))
1919 return (void*) vkGetExtensionSupport;
1920 if (!strcmp(funcName, "vkEnumerateLayers"))
1921 return (void*) vkEnumerateLayers;
1922 if (!strcmp(funcName, "vkQueueSubmit"))
1923 return (void*) vkQueueSubmit;
1924 if (!strcmp(funcName, "vkAllocMemory"))
1925 return (void*) vkAllocMemory;
1926 if (!strcmp(funcName, "vkFreeMemory"))
1927 return (void*) vkFreeMemory;
1928 if (!strcmp(funcName, "vkSetMemoryPriority"))
1929 return (void*) vkSetMemoryPriority;
1930 if (!strcmp(funcName, "vkMapMemory"))
1931 return (void*) vkMapMemory;
1932 if (!strcmp(funcName, "vkUnmapMemory"))
1933 return (void*) vkUnmapMemory;
1934 if (!strcmp(funcName, "vkPinSystemMemory"))
1935 return (void*) vkPinSystemMemory;
1936 if (!strcmp(funcName, "vkOpenSharedMemory"))
1937 return (void*) vkOpenSharedMemory;
1938 if (!strcmp(funcName, "vkOpenPeerMemory"))
1939 return (void*) vkOpenPeerMemory;
1940 if (!strcmp(funcName, "vkOpenPeerImage"))
1941 return (void*) vkOpenPeerImage;
1942 if (!strcmp(funcName, "vkDestroyObject"))
1943 return (void*) vkDestroyObject;
1944 if (!strcmp(funcName, "vkGetObjectInfo"))
1945 return (void*) vkGetObjectInfo;
1946 if (!strcmp(funcName, "vkBindObjectMemory"))
1947 return (void*) vkBindObjectMemory;
1948 if (!strcmp(funcName, "vkCreateFence"))
1949 return (void*) vkCreateFence;
1950 if (!strcmp(funcName, "vkGetFenceStatus"))
1951 return (void*) vkGetFenceStatus;
1952 if (!strcmp(funcName, "vkResetFences"))
1953 return (void*) vkResetFences;
1954 if (!strcmp(funcName, "vkWaitForFences"))
1955 return (void*) vkWaitForFences;
1956 if (!strcmp(funcName, "vkQueueWaitIdle"))
1957 return (void*) vkQueueWaitIdle;
1958 if (!strcmp(funcName, "vkDeviceWaitIdle"))
1959 return (void*) vkDeviceWaitIdle;
1960 if (!strcmp(funcName, "vkCreateEvent"))
1961 return (void*) vkCreateEvent;
1962 if (!strcmp(funcName, "vkCreateQueryPool"))
1963 return (void*) vkCreateQueryPool;
1964 if (!strcmp(funcName, "vkCreateBuffer"))
1965 return (void*) vkCreateBuffer;
1966 if (!strcmp(funcName, "vkCreateBufferView"))
1967 return (void*) vkCreateBufferView;
1968 if (!strcmp(funcName, "vkCreateImage"))
1969 return (void*) vkCreateImage;
1970 if (!strcmp(funcName, "vkCreateImageView"))
1971 return (void*) vkCreateImageView;
1972 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
1973 return (void*) vkCreateColorAttachmentView;
1974 if (!strcmp(funcName, "vkCreateDepthStencilView"))
1975 return (void*) vkCreateDepthStencilView;
1976 if (!strcmp(funcName, "vkCreateShader"))
1977 return (void*) vkCreateShader;
1978 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
1979 return (void*) vkCreateGraphicsPipeline;
1980 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
1981 return (void*) vkCreateGraphicsPipelineDerivative;
1982 if (!strcmp(funcName, "vkCreateComputePipeline"))
1983 return (void*) vkCreateComputePipeline;
1984 if (!strcmp(funcName, "vkCreateSampler"))
1985 return (void*) vkCreateSampler;
1986 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
1987 return (void*) vkCreateDynamicViewportState;
1988 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
1989 return (void*) vkCreateDynamicRasterState;
1990 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
1991 return (void*) vkCreateDynamicColorBlendState;
1992 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
1993 return (void*) vkCreateDynamicDepthStencilState;
1994 if (!strcmp(funcName, "vkCreateCommandBuffer"))
1995 return (void*) vkCreateCommandBuffer;
1996 if (!strcmp(funcName, "vkBeginCommandBuffer"))
1997 return (void*) vkBeginCommandBuffer;
1998 if (!strcmp(funcName, "vkEndCommandBuffer"))
1999 return (void*) vkEndCommandBuffer;
2000 if (!strcmp(funcName, "vkResetCommandBuffer"))
2001 return (void*) vkResetCommandBuffer;
2002 if (!strcmp(funcName, "vkCmdBindPipeline"))
2003 return (void*) vkCmdBindPipeline;
2004 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2005 return (void*) vkCmdBindDynamicStateObject;
2006 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2007 return (void*) vkCmdBindDescriptorSets;
2008 if (!strcmp(funcName, "vkCmdBindVertexBuffer"))
2009 return (void*) vkCmdBindVertexBuffer;
2010 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2011 return (void*) vkCmdBindIndexBuffer;
2012 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2013 return (void*) vkCmdDrawIndirect;
2014 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2015 return (void*) vkCmdDrawIndexedIndirect;
2016 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2017 return (void*) vkCmdDispatchIndirect;
2018 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2019 return (void*) vkCmdCopyBuffer;
2020 if (!strcmp(funcName, "vkCmdCopyImage"))
2021 return (void*) vkCmdCopyImage;
2022 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2023 return (void*) vkCmdCopyBufferToImage;
2024 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2025 return (void*) vkCmdCopyImageToBuffer;
2026 if (!strcmp(funcName, "vkCmdCloneImageData"))
2027 return (void*) vkCmdCloneImageData;
2028 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2029 return (void*) vkCmdUpdateBuffer;
2030 if (!strcmp(funcName, "vkCmdFillBuffer"))
2031 return (void*) vkCmdFillBuffer;
2032 if (!strcmp(funcName, "vkCmdClearColorImage"))
2033 return (void*) vkCmdClearColorImage;
2034 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2035 return (void*) vkCmdClearDepthStencil;
2036 if (!strcmp(funcName, "vkCmdResolveImage"))
2037 return (void*) vkCmdResolveImage;
2038 if (!strcmp(funcName, "vkCmdBeginQuery"))
2039 return (void*) vkCmdBeginQuery;
2040 if (!strcmp(funcName, "vkCmdEndQuery"))
2041 return (void*) vkCmdEndQuery;
2042 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2043 return (void*) vkCmdResetQueryPool;
2044 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2045 return (void*) vkDbgRegisterMsgCallback;
2046 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2047 return (void*) vkDbgUnregisterMsgCallback;
2048 if (!strcmp(funcName, "vkGetDeviceQueue"))
2049 return (void*) vkGetDeviceQueue;
2050 if (!strcmp(funcName, "vkQueueAddMemReference"))
2051 return (void*) vkQueueAddMemReference;
2052 if (!strcmp(funcName, "vkQueueRemoveMemReference"))
2053 return (void*) vkQueueRemoveMemReference;
Jon Ashburndc899962015-03-02 16:51:38 -07002054#if !defined(WIN32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002055 if (!strcmp(funcName, "vkWsiX11CreatePresentableImage"))
2056 return (void*) vkWsiX11CreatePresentableImage;
2057 if (!strcmp(funcName, "vkWsiX11QueuePresent"))
2058 return (void*) vkWsiX11QueuePresent;
Jon Ashburndc899962015-03-02 16:51:38 -07002059#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002060 else {
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002061 if (gpuw->pGPA == NULL)
2062 return NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002063 return gpuw->pGPA((VkPhysicalGpu)gpuw->nextObject, funcName);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002064 }
2065}